/* alteo/kpi — front + editor styles */

/* AWP-74: row-aware gutter padding.
 *
 * Tailwind's `first:` / `last:` variants key off `:first-child` / `:last-child`
 * — the LIST position, not the grid ROW position. On a 3-column grid with 4-6
 * items (2 rows), the 2nd row's first tile (index 3) is not `:first-child` and
 * never got its `md:tw-pl-0`, and the 1st row's last tile (index 2) is not
 * `:last-child` and never got its `md:tw-pr-0`. Net effect: the 2nd-row-first
 * tile had ~49px less usable width than the tile directly above it, which is
 * exactly the tile that lost the "1 000" one-liner. Fixed here with an
 * nth-child rule keyed to the actual column count (`alteo-kpi__grid--cols-N`,
 * set in render.php from the same `$cols_md` that drives `md:tw-grid-cols-N`).
 *
 * Tailwind here compiles with `important: '.alteo-scope'`
 * (tailwind.config.js) — utilities land as `.alteo-scope .tw-px-6{…!important}`,
 * so overriding them needs `!important` too, not just higher specificity.
 */
@media (min-width: 768px) {
	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:nth-child(3n+1),
	.alteo-kpi__grid--cols-2 > .alteo-kpi__tile:nth-child(2n+1),
	.alteo-kpi__grid--cols-1 > .alteo-kpi__tile {
		padding-left: 0 !important;
	}

	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:nth-child(3n),
	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:last-child,
	.alteo-kpi__grid--cols-2 > .alteo-kpi__tile:nth-child(2n),
	.alteo-kpi__grid--cols-1 > .alteo-kpi__tile {
		padding-right: 0 !important;
	}
}

/* AWP-98: no divider in front of a row-start tile.
 *
 * `md:tw-divide-x` draws a left border on every tile except the FIRST CHILD
 * (Tailwind's `> :not([hidden]) ~ :not([hidden])`), again list position, not
 * row position — so on a 2-row band the 2nd row's first tile ("1 000 m²" on
 * /energetika/energetikai-projektek/ #karbantartas) got a hairline the tile
 * above it ("2003") never had. The line predates AWP-74 but sat 48px away
 * behind `lg:tw-px-12`; AWP-74's row-start `padding-left: 0` (above) pulled
 * the value flush against it, which is what made it stand out. Row-start
 * tiles now drop the border too, so dividers only ever sit BETWEEN tiles of
 * the same row, on every row.
 *
 * Specificity: Tailwind's divide rule is `.alteo-scope .md\:tw-divide-x >
 * :not([hidden]) ~ :not([hidden])` = 0-4-0 + !important, hence the repeated
 * class (0-5-0). */
@media (min-width: 768px) {
	.alteo-scope .alteo-kpi__grid--cols-3 > .alteo-kpi__tile.alteo-kpi__tile:nth-child(3n+1),
	.alteo-scope .alteo-kpi__grid--cols-2 > .alteo-kpi__tile.alteo-kpi__tile:nth-child(2n+1) {
		border-left-width: 0 !important;
	}
}

/* AWP-74: keep "<value> <unit>" (e.g. "1 000 m²") on one line. Belt-and-
 * suspenders alongside the U+00A0 NBSP in the HU `items_*_value` content —
 * matches the client's own mock CSS (`.kpi-num { flex-wrap: nowrap;
 * white-space: nowrap; }`, `statisztika-1a/1b` + `alteo-2a/2b` mocks). Once
 * the row-position padding fix above is in, the tile has enough width that
 * this is a safety net rather than the load-bearing fix.
 *
 * Regression fix (AWP-73…87 round): this was originally unscoped — applying
 * to EVERY `alteo/kpi` instance, including single-column bands whose tile is
 * the FULL content-column width. There, forcing nowrap on a long value
 * (e.g. "176,5 GWh") is what caused the horizontal overflow at narrow mobile
 * widths (360/390px) — the exact bug this rule exists to prevent, just
 * inverted. The load-bearing case is specifically the 3-column grid (see
 * comment above: "2nd-row-first tile had ~49px less usable width" — that
 * measurement was on a `cols-3` band), so the nowrap safety net is scoped to
 * `.alteo-kpi__grid--cols-3` only. 1- and 2-column bands fall back to the
 * default `flex-wrap: wrap` — their tiles are wide enough (full column or
 * half of it) that wrapping the unit onto its own line, on the rare content
 * that needs it, beats a clipped/overflowing number.
 */
.alteo-kpi__grid--cols-3 .alteo-kpi__value-row {
	flex-wrap: nowrap;
	white-space: nowrap;
}

/* Even the load-bearing cols-3 case must not force nowrap below the `md:`
 * breakpoint (768px) — below it every KPI grid renders as a single stacked
 * column (`tw-grid-cols-1` is the base, `md:tw-grid-cols-3` only takes over
 * at 768px+), so a `cols-3` tile is exactly as wide as a `cols-1` tile there
 * and needs the same wrap fallback. */
@media (max-width: 767.98px) {
	.alteo-kpi__grid--cols-3 .alteo-kpi__value-row {
		flex-wrap: wrap;
		white-space: normal;
	}
}

/* AWP-74, part 2: hold the "landing" value/unit size + tile gutter back at
 * their `md:` sizing through the 1024–1439px window, not just `lg:` (1024px).
 *
 * Every `alteo/kpi` instance on this site renders inside the `page-tartalom`
 * template, which puts the floating-TOC sidebar next to the content column —
 * the column is NOT the viewport width. Measured with Playwright on the
 * `#karbantartas` band (`/energetika/energetikai-projektek/`): the content
 * column is only ~686px wide at a 1024px viewport (~196px per 3-col tile,
 * ~148px of that past the tile's own padding) — nowhere near enough for the
 * `lg:tw-text-7xl` (72px) value + `lg:tw-text-xl` (20px) unit, which need
 * ~242px. That combination only actually fits once the column has widened to
 * ~290px, which measured out to ~1440px viewport, not 1024px. Tailwind's own
 * `lg:` breakpoint (1024px) switches a beat too early for this sidebar
 * layout, independent of the row-position padding bug above.
 *
 * Rather than move the real `lg:` breakpoint (which the rest of the theme
 * relies on), this caps just the KPI value/unit size and tile gutter back
 * down to their `md:` values for 1024–1439px, and lets them grow at 1440px+
 * (`max-width: 1439.98px` mirrors Tailwind's compiled `lg:` range shifted one
 * step later — chosen from the same Playwright measurements, not a stock
 * Tailwind screen). Shrinking a value/gutter can only reduce overflow risk,
 * never introduce it, so this is safe across every existing KPI band (icon
 * or no icon, 1–6 items) — it only changes the 1024–1439px window's look.
 *
 * `compact` size-mode KPI bands are excluded (`.alteo-kpi__value` /
 * `.alteo-kpi__unit` are only added by render.php for the default "landing"
 * mode) — compact's own value size is already small (`tw-text-3xl
 * lg:tw-text-4xl`) and never had an `lg:` gutter jump to begin with.
 *
 * Regression fix (AWP-73…87 round): the value/unit font-size cap was
 * originally unscoped by column count, so it also shrank every SINGLE-column
 * band's number by the same 33% (72px → 48px) even though a `cols-1` tile is
 * the full content-column width (~590–782px at these breakpoints) — 3×+ more
 * room than the 72px value ever needs. That narrowing was only ever meant to
 * rescue the cramped `cols-2`/`cols-3` tiles measured above; it is now scoped
 * to `.alteo-kpi__grid--cols-2` / `--cols-3` so `cols-1` bands keep their
 * full `lg:tw-text-7xl` size at 1024–1439px.
 *
 * The gutter cap mirrors the row-position rule above tile-by-tile (row-start
 * / row-end / true-middle) instead of a blanket left+right reset — a blanket
 * reset would fight the row-position rule on whichever side that rule
 * already zeroed (same 0-3-0 specificity, decided only by source order).
 *
 * Specificity note: Tailwind here compiles to `.alteo-scope .tw-text-7xl` /
 * `.alteo-scope .tw-px-12` (0-2-0, `important: '.alteo-scope'`). The
 * value/unit rules pair the `cols-2`/`cols-3` ancestor with one class repeat
 * (0-3-0 total: 1 for the ancestor + 2 for the repeated class) to win outright
 * over Tailwind's utility, independent of stylesheet load order — and to stay
 * BELOW the AWP-82 bold-emphasis override further down (0-4-0), which must
 * keep winning if `emphasis=bold` and a `cols-2`/`cols-3` grid are ever
 * combined. The gutter rules reuse the row-position selectors above, which
 * are already 0-3-0 the same way.
 */
@media (min-width: 1024px) and (max-width: 1439.98px) {
	/* Row-start tiles already have padding-left:0 from the rule above —
	 * cap their padding-right. `:not(:last-child)` guards the (currently
	 * unused) 4-/5-item partial-last-row case, where the true last tile is
	 * also a row-start and must stay padding-right:0, not capped. */
	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:nth-child(3n+1):not(:last-child),
	.alteo-kpi__grid--cols-2 > .alteo-kpi__tile:nth-child(2n+1):not(:last-child) {
		padding-right: 1.5rem !important;
	}

	/* Row-end tiles (incl. the grid's true last tile) already have
	 * padding-right:0 from the rule above — cap their padding-left. */
	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:nth-child(3n),
	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:last-child,
	.alteo-kpi__grid--cols-2 > .alteo-kpi__tile:nth-child(2n) {
		padding-left: 1.5rem !important;
	}

	/* True middle tiles (3-col layout only) start from the unmodified
	 * `lg:tw-px-12` on both sides — cap both. */
	.alteo-kpi__grid--cols-3 > .alteo-kpi__tile:nth-child(3n+2) {
		padding-left: 1.5rem !important;
		padding-right: 1.5rem !important;
	}

	.alteo-kpi__grid--cols-2 .alteo-kpi__value.alteo-kpi__value,
	.alteo-kpi__grid--cols-3 .alteo-kpi__value.alteo-kpi__value {
		font-size: 3rem !important; /* matches md:tw-text-5xl */
	}

	.alteo-kpi__grid--cols-2 .alteo-kpi__unit.alteo-kpi__unit,
	.alteo-kpi__grid--cols-3 .alteo-kpi__unit.alteo-kpi__unit {
		font-size: 1rem !important; /* matches md:tw-text-base */
	}
}

/* -------------------------------------------------------------------------
   AWP-82 — "bold" tile emphasis (inc/block-tile-emphasis.php, ACF field
   `emphasis`). Not turned on for any live alteo/kpi instance in this round
   (scaffold for the number-tile family alongside flip-card-grid); wired so
   a future opt-in needs no further plumbing. Only ever reached when
   `emphasis = bold` — render.php builds a fully separate class string for
   the default path, so these rules never match a default tile.
   ------------------------------------------------------------------------- */
.alteo-kpi__accent-bar {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 4px;
}

.alteo-kpi__watermark {
	position: absolute;
	right: 12px;
	bottom: 12px;
	width: 148px;
	height: 148px;
	opacity: 0.22;
	pointer-events: none;
}

/* 4 class tokens (0,4,0) — deliberately outranks BOTH the 1024–1439px
   `.alteo-kpi__value.alteo-kpi__value.alteo-kpi__value` cap above (0,3,0)
   and Tailwind's `.tw-text-6xl` etc. (0,2,0), regardless of load order.
   `landing` size_mode is a genuine alignfull band (up to 1440px gutter, ≤3
   columns), so a vw-scaled clamp is a reasonable match for its own width —
   unlike flip-card-grid's front face, which sits inside `page-tartalom`'s
   narrow content column (see that block's style.css for the measured-width
   writeup and why it uses fixed breakpoint tiers instead of clamp()). */
.alteo-scope .tw-font-headline.alteo-kpi__value.alteo-kpi__value--bold {
	font-size: clamp(76px, 8.5vw, 118px) !important;
	font-weight: 400 !important;
	font-family: "Abril Fatface", Georgia, serif;
	line-height: 0.88 !important;
}

/* `compact` size_mode IS column-native (narrow) — the vw-clamp above would
   risk the same overflow flip-card-grid had at 1024px. Not empirically
   measured (no live instance uses `emphasis=bold` yet) — re-verify against
   real content before the first compact + bold opt-in; this is a
   conservative placeholder, not a tuned value. */
[data-size-mode="compact"].alteo-scope .tw-font-headline.alteo-kpi__value.alteo-kpi__value--bold {
	font-size: 40px !important;
}

.alteo-scope .tw-font-headline.alteo-kpi__label--bold {
	font-size: 19px !important;
	font-weight: 500 !important;
}

/* -------------------------------------------------------------------------
   AWP-81 — `list` layout (ACF field `layout = list`, client mock
   `statisztika-1b`). Only ever reached when the author opts in; render.php
   builds a completely separate markup branch for the default `grid`, so
   nothing below can match a grid tile.

   The only thing Tailwind cannot express here is the right-aligned value
   column: it has to be a FIXED basis so every row's number ends on the same
   vertical line (that alignment is the whole point of the mock), while still
   shrinking on a narrow column. A `tw-basis-[7.5rem]` utility would express
   the desktop value but not the three breakpoint steps, and these blocks
   routinely render inside `page-tartalom`'s floating-TOC content column,
   which is ~686px at a 1024px viewport — not the viewport width. Measured
   there, 7.5rem fits "1 000 m²" and clips nothing.
   ------------------------------------------------------------------------- */
.alteo-kpi__row-value {
	flex: 0 0 7.5rem;
	white-space: nowrap;
}

/* Narrow content column / mobile: give the number column less room and let a
   long value wrap rather than push the label off the edge. */
@media (max-width: 767.98px) {
	.alteo-kpi__row-value {
		flex-basis: 4.75rem;
		white-space: normal;
	}
}

@media (min-width: 768px) and (max-width: 1023.98px) {
	.alteo-kpi__row-value {
		flex-basis: 6rem;
	}
}

/* The hero row's label must not run the full band width on a wide viewport —
   the mock sets it beside the number in a short, 2-line measure. `max-width`
   with a ch unit keeps that shape independent of the band's own width. */
.alteo-kpi__hero-text {
	max-width: 34ch;
}

/* The hero number is display-size; on the narrowest column it would otherwise
   force the whole flex row to overflow before the wrap kicks in. */
.alteo-kpi__hero-value {
	max-width: 100%;
	overflow-wrap: anywhere;
}
