/**
 * 棒グラフ（縦・横） - フロント & エディタ共通スタイル
 *
 * テーマ（SWELL / AFFINGER 等）の既存 CSS と衝突しないよう、
 * すべて .ccb-chart 配下にスコープし、必要な値は明示的に打ち消している。
 */

.ccb-chart {
	margin: 0 0 1.5em;
}

.ccb-chart * {
	box-sizing: border-box;
}

/* --- カード --- */

.ccb-chart.is-card {
	overflow: hidden;
	background-color: var(--ccb-card-bg, #fff);
	border: 1px solid var(--ccb-card-border, #e5e7eb);
	border-radius: var(--ccb-card-radius, 4px);
}

.ccb-chart__topbar {
	height: var(--ccb-topbar, 6px);
	background-color: var(--ccb-topbar-color, #e8a33d);
}

.ccb-chart__inner {
	padding: var(--ccb-card-padding, 0);
}

/* --- 見出し --- */

/*
 * テーマは `.post_content p { margin: 1em 0 }` のような本文用の指定を持っている。
 * これは「クラス1＋要素1」で、こちらの `.ccb-chart__title`（クラス1）より詳細度が
 * 高いため、要素セレクタを足して確実に上書きする。
 */
.ccb-chart .ccb-chart__head {
	margin: 0 0 18px;
}

.ccb-chart .ccb-chart__head.has-divider {
	margin-bottom: 18px;
	padding-bottom: 14px;
	border-bottom: 1px solid var(--ccb-card-border, #e5e7eb);
}

.ccb-chart .ccb-chart__head.is-align-center {
	text-align: center;
}

.ccb-chart p.ccb-chart__eyebrow {
	margin: 0 0 10px;
	padding: 0;
	color: var(--ccb-eyebrow-color, #c98b2e);
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.18em;
	line-height: 1.4;
	text-indent: 0;
}

.ccb-chart p.ccb-chart__title {
	margin: 0;
	padding: 0;
	color: var(--ccb-title-color, #1f2937);
	font-size: var(--ccb-title-size, 20px);
	font-weight: 700;
	line-height: 1.5;
	text-indent: 0;
}

.ccb-chart p.ccb-chart__note {
	margin: 8px 0 0;
	padding: 0;
	color: var(--ccb-note-color, #6b7280);
	font-size: var(--ccb-note-size, 13px);
	line-height: 1.6;
	text-indent: 0;
}

/* --- グラフ本体 --- */

/*
 * 画面が狭いときは、グラフごと横スクロールさせる。
 * width: max-content で内容ぶんの幅を持たせ、min-width: 100% で
 * 収まりきるときは親いっぱいに広げる。
 */
/*
 * 一番上の目盛りの数字と、バーの上に出る値ラベルは、グラフの上端より
 * わずかに外へはみ出す。overflow-x を指定すると縦方向も切り取られるため、
 * その分の余白をここで確保しておく。
 */
.ccb-chart__scroll {
	padding-top: calc(var(--ccb-value-size, 12px) + 6px);
}

.ccb-chart.is-scrollable .ccb-chart__scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.ccb-chart.is-scrollable .ccb-chart__body {
	width: max-content;
	min-width: 100%;
}

.ccb-chart.is-scrollable .ccb-chart__item {
	min-width: var(--ccb-min-col, 54px);
}

.ccb-chart__body {
	display: flex;
	align-items: flex-start;
}

/* --- 縦軸 --- */

.ccb-chart__axis {
	position: relative;
	flex: 0 0 auto;
	height: var(--ccb-plot, 260px);
	margin-right: 8px;
	text-align: right;
}

/*
 * 目盛りの数字は絶対配置なので、そのままだと親の幅が 0 になり、
 * 数字がグラフの外へはみ出して（カードの overflow で）切れてしまう。
 * 一番長い数字と同じ文字を流し込んでおき、幅だけを確保する。
 */
.ccb-chart__ysizer {
	display: block;
	height: 0;
	overflow: hidden;
	font-size: var(--ccb-axis-size, 11px);
	visibility: hidden;
}

.ccb-chart__tick {
	position: absolute;
	right: 0;
	display: block;
	color: var(--ccb-axis-text, #6b7280);
	font-size: var(--ccb-axis-size, 11px);
	line-height: 1;
	white-space: nowrap;
	transform: translateY(50%);
}

/* --- 目盛り線 --- */

.ccb-chart__plot {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;
}

/* 横スクロールさせるときは、内容ぶんの幅を保てるよう縮小を止める。 */
.ccb-chart.is-scrollable .ccb-chart__plot {
	min-width: auto;
}

.ccb-chart__grid {
	position: absolute;
	top: 0;
	right: 0;
	left: 0;
	height: var(--ccb-plot, 260px);
	border-bottom: 1px solid var(--ccb-axis, #9ca3af);
	border-left: 1px solid var(--ccb-axis, #9ca3af);
	pointer-events: none;
}

.ccb-chart__gridline {
	position: absolute;
	right: 0;
	left: 0;
	display: block;
	height: 0;
	border-top: 1px solid var(--ccb-grid, #e5e7eb);
}

/* --- 基準線 --- */

/*
 * 基準線はバーより手前に描く。バーは値ラベルのために position: relative を
 * 持っており、あとに並ぶぶん上に重なるため、z-index で明示的に前へ出す。
 */
.ccb-chart__baseline {
	position: absolute;
	z-index: 2;
	right: 0;
	left: 0;
	display: block;
	height: 0;
	border-top: 2px dashed currentColor;
}

.ccb-chart__baselabel {
	position: absolute;
	right: 4px;
	bottom: 3px;
	padding: 1px 4px;
	background-color: rgba(255, 255, 255, 0.85);
	border-radius: 2px;
	font-size: var(--ccb-axis-size, 11px);
	font-weight: 700;
	line-height: 1.2;
	white-space: nowrap;
}

/* --- バー --- */

.ccb-chart__items {
	position: relative;
	display: flex;
	align-items: flex-end;
}

.ccb-chart__item {
	display: flex;
	flex: 1 1 0;
	flex-direction: column;
	min-width: 0;
}

.ccb-chart__barcol {
	display: flex;
	align-items: flex-end;
	justify-content: center;
	height: var(--ccb-plot, 260px);
}

/*
 * バーの高さは、アニメーション時は view.js がインラインで直接書き込む。
 * CSS のクラスや変数に頼らないことで、テーマ側の CSS や詳細度に
 * 左右されず、必ず「0 → 最終値」の向きで伸ばせる。
 */
.ccb-chart__bar {
	position: relative;
	width: var(--ccb-bar-width, 62%);
	border-radius: var(--ccb-bar-radius, 0) var(--ccb-bar-radius, 0) 0 0;
	transition: height var(--ccb-duration, 900ms) cubic-bezier(0.33, 1, 0.68, 1);
}

/*
 * 初期状態をセットする一瞬だけトランジションを切る。
 * これがないと、読み込み時に「最終値 → 0」へ縮む動きが見えてしまう。
 */
.ccb-chart.ccb-arming .ccb-chart__bar,
.ccb-chart.ccb-arming .ccb-chart__value {
	transition: none !important;
}

/* --- 値ラベル --- */

.ccb-chart__value {
	position: absolute;
	bottom: 100%;
	left: 50%;
	margin-bottom: 5px;
	color: var(--ccb-value-color, #c98b2e);
	font-size: var(--ccb-value-size, 12px);
	font-weight: var(--ccb-value-weight, 700);
	line-height: 1.2;
	white-space: nowrap;
	transform: translateX(-50%);
	transition: opacity 400ms ease;
}

.ccb-chart.is-value-inside .ccb-chart__value {
	top: 6px;
	bottom: auto;
	margin-bottom: 0;
}

/* JS が有効なときだけ隠す。JS が動かない環境では最初から見えている。 */
.ccb-chart.ccb-armed .ccb-chart__value {
	opacity: 0;
}

.ccb-chart.ccb-armed.is-visible .ccb-chart__value {
	opacity: 1;
}

.ccb-chart__suffix,
.ccb-chart__prefix {
	font-size: 0.85em;
}

/* --- 横軸のラベル --- */

.ccb-chart__xlabel {
	padding-top: 8px;
	color: var(--ccb-xlabel-color, #374151);
	font-size: var(--ccb-xlabel-size, 12px);
	line-height: 1.3;
	text-align: center;
	word-break: break-word;
}

/* ===== 横棒（is-horizontal） ===== */

/*
 * 縦棒と同じ要素・同じクラスのまま、位置の指定だけを入れ替えている。
 * バーは高さではなく幅で伸び、目盛りは下、項目名は左に並ぶ。
 */

/* バーの右端に出る数値と、一番右の目盛りのぶんを空けておく。 */
.ccb-chart.is-horizontal .ccb-chart__body {
	padding-right: var(--ccb-value-space, 1.4em);
}

.ccb-chart.is-horizontal .ccb-chart__scroll {
	padding-top: 0;
}

/* --- 項目名（左） --- */

/*
 * 項目名が長くてもグラフが潰れないよう、左の列は幅の 45% までに抑え、
 * あふれる場合は「…」で省略する。
 */
.ccb-chart.is-horizontal .ccb-chart__catcol {
	flex: 0 1 auto;
	max-width: 45%;
	margin-right: 10px;
}

/* 高さと行の高さを揃えて、上下中央に置く（省略記号のため flex にはしない）。 */
.ccb-chart.is-horizontal .ccb-chart__catlabel {
	display: block;
	height: var(--ccb-row, 34px);
	overflow: hidden;
	color: var(--ccb-xlabel-color, #374151);
	font-size: var(--ccb-xlabel-size, 12px);
	line-height: var(--ccb-row, 34px);
	text-align: right;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* --- 目盛り線（縦） --- */

.ccb-chart.is-horizontal .ccb-chart__rows {
	position: relative;
}

.ccb-chart.is-horizontal .ccb-chart__grid {
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	height: auto;
}

.ccb-chart.is-horizontal .ccb-chart__gridline {
	top: 0;
	right: auto;
	bottom: 0;
	width: 0;
	height: auto;
	border-top: 0;
	border-left: 1px solid var(--ccb-grid, #e5e7eb);
}

/* --- 目盛りの数字（下） --- */

.ccb-chart.is-horizontal .ccb-chart__axis {
	position: relative;
	height: calc(var(--ccb-axis-size, 11px) * 1.4 + 8px);
	margin-right: 0;
	text-align: left;
}

.ccb-chart.is-horizontal .ccb-chart__tick {
	top: 7px;
	right: auto;
	transform: translateX(-50%);
}

/* --- バー --- */

.ccb-chart.is-horizontal .ccb-chart__items {
	display: block;
}

.ccb-chart.is-horizontal .ccb-chart__item {
	display: block;
	min-width: 0;
}

.ccb-chart.is-horizontal .ccb-chart__barcol {
	align-items: center;
	justify-content: flex-start;
	height: var(--ccb-row, 34px);
}

.ccb-chart.is-horizontal .ccb-chart__bar {
	height: var(--ccb-bar-width, 62%);
	border-radius: 0 var(--ccb-bar-radius, 0) var(--ccb-bar-radius, 0) 0;
	transition: width var(--ccb-duration, 900ms) cubic-bezier(0.33, 1, 0.68, 1);
}

/* --- 値ラベル（バーの右端） --- */

.ccb-chart.is-horizontal .ccb-chart__value {
	top: 50%;
	bottom: auto;
	left: 100%;
	margin: 0 0 0 8px;
	transform: translateY(-50%);
}

.ccb-chart.is-horizontal.is-value-inside .ccb-chart__value {
	top: 50%;
	right: 8px;
	left: auto;
	margin: 0;
}

/* --- 基準線（縦） --- */

.ccb-chart.is-horizontal .ccb-chart__baseline {
	top: 0;
	right: auto;
	bottom: 0;
	width: 0;
	height: auto;
	border-top: 0;
	border-left: 2px dashed currentColor;
}

.ccb-chart.is-horizontal .ccb-chart__baselabel {
	top: 2px;
	right: auto;
	bottom: auto;
	left: 5px;
}

/* 「視差効果を減らす」設定のときは動かさない（view.js 側でも処理を飛ばしている）。 */
@media (prefers-reduced-motion: reduce) {
	.ccb-chart__bar,
	.ccb-chart__value {
		transition: none;
	}
}
