/* ============================================================================
   FCR CHART CORE — styles for the DOM/SVG chart engine (fcr-chart-core.js).

   Ported from the Red Hat Survey Explorer (library/survey-explorer/site.css)
   and de-branded: every colour is a var() with a literal fallback, and the
   token names match assets/css/fcr-kit.css (--text, --text-soft, --muted,
   --surface-*, --border-*, --amber, --blue-300, --teal-300, --font-display,
   --radius, --shadow-sm). Chart-specific tokens are namespaced --chart-*.
   Load fcr-kit.css first if you want the FCR palette; this file stands alone
   on any dark surface without it.

   Card-internal rules are scoped under .qcard on purpose: generic names like
   .tag and .legend exist elsewhere in the kit, and scoping keeps this file
   from reaching outside a chart card. The only unscoped rules are .qcard
   itself and .tip (one shared tooltip node, appended to <body>).
   ========================================================================== */

/* The DECLARATIONS that used to sit here now live in fcr-tokens.css under
   "CHART PALETTE TOKENS".  The series palette is a brand decision, so per
   SPEC 1.5 it belongs in the skin layer — a re-skin must be able to change
   the chart colours without opening the chart engine.  Every use site below
   reads them as var(--token, <the same literal>), so this file still renders
   standalone if it is ever loaded without fcr-tokens.css.

   Tokens defined there for this file:
     --chart-primary / --chart-reference / --chart-muted   series roles
     --chart-s1 … --chart-s8                               categorical set (8)
     --chart-ramp-low/-mid/-high                           diverging ramp
     --chart-on-light, --chart-separator, --chart-label
     --chart-grid, --chart-grid-soft
     --chart-warn-ink, --chart-warn-tint                   warning ink */

/* ------------------------------------------------------------------ card -- */
.qcard {
  background: var(--surface, rgba(255,255,255,.045));
  border: 1px solid var(--border, rgba(255,255,255,.11));
  border-radius: var(--radius, 16px);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm, 0 8px 24px -14px rgba(0,0,0,.55));
  margin-bottom: 16px;
  color: var(--text, #ffffff);
}
.qcard__head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.qcard__head .header-spacer { flex: 1 1 auto; }
.qcard__id {
  font-family: var(--font-display, system-ui, sans-serif); font-weight: 800; font-size: 12px;
  letter-spacing: .06em; color: #fff; flex: none;
  background: var(--chart-id-bg, var(--surface-3, rgba(255,255,255,.10)));
  border-radius: 5px; padding: 2px 8px;
}
/* The question sits ABOVE the chart, in readable type — a chart is unreadable
   without the wording that produced it. */
.qcard__text {
  font-family: var(--font-display, system-ui, sans-serif); font-weight: 700;
  font-size: 16.5px; line-height: 1.3; color: #fff; margin: 8px 0 0;
}
.qcard__sub { margin: 5px 0 0; font-size: 13px; color: var(--text-soft, #c4d2e8); }
.qcard__ctx { margin: 2px 0 0; font-size: 12px; color: var(--muted, #93a6c4); }

/* A chart whose coverage is narrower than the reader assumes says so, loudly,
   directly under its title. */
.qcard .coverwarn {
  margin: 7px 0 0; font-family: var(--font-display, system-ui, sans-serif); font-weight: 800;
  font-size: 13px; letter-spacing: .01em; color: var(--chart-warn-ink, #ff4d4d);
  background: rgba(255,77,77,.10); border-left: 3px solid var(--chart-warn-ink, #ff4d4d);
  border-radius: 0 7px 7px 0; padding: 6px 11px;
}

/* ------------------------------------------------- meta line: base + tags -- */
.qcard__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 11px 0 4px; }
.qcard .base {
  font-size: 12.5px; color: var(--text-soft, #c4d2e8);
  background: var(--surface-2, rgba(255,255,255,.07));
  border: 1px solid var(--border, rgba(255,255,255,.11));
  border-radius: 999px; padding: 3px 11px;
}
.qcard .base b { color: #fff; font-weight: 800; }
.qcard .tag {
  font-size: 10.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  border-radius: 999px; padding: 3px 9px;
}
/* Low base is a warning, not a footnote: amber, named series, on the card. */
.qcard .tag--warn {
  background: rgba(245,177,76,.16); color: var(--amber, #f5b14c);
  border: 1px solid rgba(245,177,76,.45); text-transform: none; letter-spacing: .02em;
}
.qcard .tag--unit {
  background: rgba(119,207,242,.12); color: var(--blue-300, #77CFF2);
  border: 1px solid rgba(119,207,242,.35); text-transform: none; letter-spacing: .02em;
}
.qcard .tag--empty {
  background: rgba(255,255,255,.06); color: var(--muted, #93a6c4);
  border: 1px solid var(--border-2, rgba(255,255,255,.18));
}
/* Every card states its own scale — bars are scaled per card, so the scale is
   part of the data, not decoration. */
.qcard .tag--scale {
  background: rgba(255,255,255,.04); color: var(--muted, #93a6c4);
  border: 1px solid var(--border, rgba(255,255,255,.11));
  text-transform: none; letter-spacing: .02em; font-weight: 700;
}

/* ---------------------------------------------------------------- legend -- */
/* 2026-09-10, polish 4 (Ben): THE one chart label type — same size and same
   colour as every axis tick, category label, value label and series label in
   every renderer (--chart-label-size / --chart-label-color, defined in the
   host page's token file; the literal fallbacks are this file's previous
   values). Generous vertical padding, unchanged. */
.qcard .legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 12px; }
.qcard .legend__item {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--chart-label-size, 13px); line-height: 1.4; padding: 5px 0;
  color: var(--chart-label-color, #fff);
}
.qcard .legend__sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.qcard .legend__sw--dash {
  height: 0; border-radius: 0; border-top: 2px dashed rgba(255,255,255,.72);
}
.qcard .legend__n { color: var(--muted, #93a6c4); }
.qcard .legend__item[data-emphasis="muted"] { opacity: .75; }
/* The option legend used to be a size smaller than the series legend
   (11.5px). One size now — polish 4 — so the override is gone. */
/* D4 (Ben, 2026-09-09): the reader's own category in an option legend —
   bold label + a --lr-reader ring on the swatch, never a swatch recolour
   (the swatch colour is the option's identity). */
.qcard .legend__item--highlight { font-weight: 800; color: #fff; }
.qcard .legend__item--highlight .legend__sw {
  box-shadow: 0 0 0 2px var(--lr-reader, #d81b60);
}

/* ------------------------------------------------------------------ bars -- */
.qcard .chart { margin-top: 4px; }
.qcard .optrow {
  display: grid; grid-template-columns: minmax(140px, 34%) minmax(0,1fr);
  gap: 12px; padding: 5px 0;
}
.qcard .optrow + .optrow { border-top: 1px solid rgba(255,255,255,.05); }
/* D4 (Ben, 2026-09-09): the reader's own row in a breakdown chart (§4.8.1) —
   a --lr-reader rail + tint, bars keep their own series colour untouched. */
.qcard .optrow--highlight {
  box-shadow: inset 3px 0 0 var(--lr-reader, #d81b60);
  background: rgba(216,27,96,.08);
  border-radius: 6px;
  padding-left: 8px;
}
.qcard .optrow--highlight .labtext { font-weight: 800; color: #fff; }
.qcard .optrow__lab {
  display: flex; align-items: flex-start; gap: 4px;
  font-size: var(--chart-label-size, 13px); color: var(--chart-label-color, var(--text-soft, #c4d2e8));
  line-height: 1.35; padding-top: 2px;
}
.qcard .optrow__lab .labtext { flex: 1; min-width: 0; }
.qcard .optrow__lab .flag { color: var(--amber, #f5b14c); font-weight: 800; cursor: help; }
.qcard .optrow__bars { display: flex; flex-direction: column; gap: 3px; min-width: 0; position: relative; }

/* ---- value axis: labelled ticks + gridlines ------------------------------
   REGISTRATION TRICK (steal verbatim): `.bar` is a `minmax(0,1fr) 74px` grid
   with an 8px gap, so the track column always runs from left:0 to right:82px
   inside `.optrow__bars`. The tick scale (margin-right:82px) and the gridline
   overlay (right:82px) use that SAME inset, which keeps ticks, lines and bars
   registered at every container width without measuring anything in JS.
   74 + 8 = 82: change one number and you must change all three. */
.qcard .gridlines {
  position: absolute; left: 0; right: 82px; top: -5px; bottom: -5px;
  pointer-events: none; z-index: 2;
}
.qcard .gridlines i {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: rgba(255,255,255,.10); transform: translateX(-.5px);
}
.qcard .gridlines i.gl--zero { background: rgba(255,255,255,.24); }
.qcard .axisrow {
  display: grid; grid-template-columns: minmax(140px, 34%) minmax(0,1fr);
  gap: 12px; padding: 2px 0 7px;
}
.qcard .axisrow__bars { min-width: 0; }
.qcard .axisrow + .optrow { border-top: 0; }
.qcard .axis { position: relative; height: 15px; margin-right: 82px; }
.qcard .axis__tick {
  position: absolute; top: 0; transform: translateX(-50%);
  font-family: var(--font-display, system-ui, sans-serif); font-weight: 700;
  font-size: var(--chart-label-size, 13px);
  color: var(--chart-label-color, var(--muted, #93a6c4)); white-space: nowrap;
}
.qcard .axis__tick::before {
  content: ""; position: absolute; left: 50%; top: 100%;
  width: 1px; height: 4px; background: rgba(255,255,255,.22); transform: translateX(-.5px);
}
.qcard .axis__cap {
  font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  /* 2026-09-16 (a11y fix, color-contrast): --muted-2 measured ~4.27:1 here
     (just under the 4.5:1 minimum) — a color of its own, scoped to this
     selector only, clears it. --muted-2 is untouched for every other use. */
  color: #7a8fae;
}
/* the first/last tick labels would otherwise overhang the track's edges */
.qcard .axis__tick:last-child { transform: translateX(-100%); }
.qcard .axis__tick:last-child::before { left: 100%; }
.qcard .axis__tick:first-child { transform: none; }
.qcard .axis__tick:first-child::before { left: 0; }

.qcard .bar {
  display: grid; grid-template-columns: minmax(0,1fr) 74px; align-items: center; gap: 8px;
  position: relative; z-index: 1; cursor: default; outline: none;
}
.qcard .bar__track {
  position: relative; background: rgba(255,255,255,.055);
  border-radius: 4px; height: 15px; overflow: hidden;
}
.qcard .bar__fill { height: 100%; border-radius: 4px; min-width: 2px; transition: width .18s ease; }

/* ---- EMPHASIS -----------------------------------------------------------
   Keyed off [data-emphasis], never off a series key. (The original bound this
   to literal keys — `.bar[data-series="TOTAL"]` — which is the single biggest
   thing that stopped the engine being reusable.) Four roles, one visual step
   apart, so a reader can tell which series leads without reading the legend:
   reference gets the ring, primary full strength, secondary one step back,
   muted two. */
.qcard .bar[data-emphasis="primary"] .bar__fill { opacity: 1; }
.qcard .bar[data-emphasis="reference"] .bar__fill {
  opacity: 1; box-shadow: 0 0 0 1px var(--chart-reference-ring, rgba(203,213,225,.45));
}
.qcard .bar[data-emphasis="secondary"] .bar__fill { opacity: .82; }
.qcard .bar[data-emphasis="muted"] .bar__fill { opacity: .58; }

/* ---- bar end-labels: value and base read as ONE unit --------------------- */
.qcard .bar__val {
  font-family: var(--font-display, system-ui, sans-serif); font-weight: 800;
  font-size: var(--chart-label-size, 13px);
  color: var(--chart-label-color, var(--text, #ffffff)); white-space: nowrap;
}
/* The base suffix inside a value label takes the one label SIZE but keeps its
   quieter ink: value and base are read as one unit precisely because the base
   is the secondary half of it (polish 4 leaves this deliberate ink alone). */
.qcard .bar__val .n {
  font-weight: 600; color: var(--muted, #93a6c4); font-size: var(--chart-label-size, 13px); margin-left: 4px;
}

/* Hover/focus affordance: the mark lifts so the reader sees it respond. */
.qcard .bar--hover .bar__fill, .qcard .bar:focus-visible .bar__fill { filter: brightness(1.14); }
.qcard .bar--hover .bar__track, .qcard .bar:focus-visible .bar__track {
  box-shadow: inset 0 0 0 1px var(--border-2, rgba(255,255,255,.18));
}
.qcard .bar:focus-visible .bar__val { text-decoration: underline; }

/* Dashed reference tick, on EVERY bar row, so the comparison survives the
   reference series being hidden. */
.qcard .normtick {
  position: absolute; top: -2px; bottom: -2px; width: 0;
  border-left: 1px dashed rgba(255,255,255,.72); pointer-events: none;
}

/* --------------------------------------------- line / pie / stacked (SVG) -- */
.qcard .chart svg { display: block; max-width: 100%; overflow: visible; }
.qcard .pies { display: flex; flex-wrap: wrap; gap: 18px; }
.qcard .pie { text-align: center; }
.qcard .pie figcaption {
  font-size: var(--chart-label-size, 13px); color: var(--chart-label-color, var(--text-soft, #c4d2e8));
  margin-top: 4px; max-width: 190px; line-height: 1.3;
}
.qcard .stackrow { margin: 8px 0; }
.qcard .stackrow__lab {
  font-size: var(--chart-label-size, 13px); color: var(--chart-label-color, var(--text-soft, #c4d2e8));
  margin-bottom: 3px;
}
/* D4: a highlighted SERIES row (the reader's own series, when a caller marks
   one) gets a bold, reader-coloured row label — the segments inside keep
   their own option colours; renderStacked separately outlines a highlighted
   OPTION's segment. */
.qcard .stackrow--highlight .stackrow__lab { font-weight: 800; color: var(--lr-reader, #d81b60); }
.qcard .pie--highlight figcaption { font-weight: 800; color: var(--lr-reader, #d81b60); }
.qcard .tipnode { cursor: default; }
.qcard [data-emphasis="muted"].tipnode, .qcard polyline[data-emphasis="muted"] { opacity: .58; }
/* A stacked/pie mark's colour is the OPTION's identity (from optionRamp),
   never the series' — series emphasis is a SERIES concept (a whole row/
   figure reading as "the reference"), conveyed there by the row label /
   figcaption, not by darkening individual option segments. Dimming a
   segment's fill also fights its own in-segment value label (fcr-
   chart-core.js's renderStacked draws that label at full opacity in a fixed
   ink), so a "muted" series (series A, routinely) would otherwise print a
   barely-legible number on a half-transparent segment. Reset to full
   opacity for exactly these two chart types; every other type keeps the
   general rule above. */
.qcard svg[data-chart-svg="stacked"] [data-emphasis="muted"].tipnode,
.qcard svg[data-chart-svg="pie"] [data-emphasis="muted"].tipnode { opacity: 1; }
.qcard .chart__empty {
  color: var(--muted, #93a6c4); font-size: 13px; font-style: italic; padding: 10px 0;
}

/* ------------------------------------------------------ callouts / notes -- */
/* Everything explanatory sits BELOW the chart, side by side, at body scale —
   the dense chart area stays clean and the context stays readable. */
.qcard .callouts {
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--border-2, rgba(255,255,255,.18));
  display: flex; flex-wrap: wrap; gap: 10px;
}
.qcard .callouts__label {
  flex: 0 0 100%; font-family: var(--font-display, system-ui, sans-serif); font-weight: 800;
  font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted, #93a6c4); margin-bottom: -2px;
}
.qcard .callout {
  flex: 1 1 300px; min-width: 260px;
  background: var(--surface-2, rgba(255,255,255,.07));
  border: 1px solid var(--border, rgba(255,255,255,.11));
  border-left: 2px solid var(--muted-2, #8a9fc0);
  border-radius: 0 8px 8px 0; padding: 8px 11px;
  font-size: 12px; line-height: 1.45; color: var(--text-soft, #c4d2e8);
}
.qcard .callout b { color: #fff; font-weight: 800; }
.qcard .callout--warn { border-left-color: var(--amber, #f5b14c); }
.qcard .callout--warn b { color: var(--chart-warn-tint, #ffd9a1); }
.qcard .callout--info { border-left-color: var(--blue); }
.qcard .callout--info b { color: var(--blue-300); }

/* --------------------------------------------------- shared tooltip node -- */
/* One node for the whole page, appended to <body>; values written with
   textContent only. */
.tip {
  position: fixed; z-index: 300; pointer-events: none;
  max-width: 330px; padding: 8px 11px;
  background: var(--chart-tip-bg, #04203f);
  border: 1px solid var(--border-2, rgba(255,255,255,.18));
  border-radius: 9px; box-shadow: 0 18px 44px -18px rgba(0,0,0,.9);
  font-family: var(--font-body, system-ui, sans-serif);
}
.tip[hidden] { display: none; }
.tip__val {
  font-family: var(--font-display, system-ui, sans-serif); font-weight: 800;
  font-size: 15px; color: #fff;
}
.tip__opt { font-size: 12.5px; color: var(--text-soft, #c4d2e8); margin-top: 2px; line-height: 1.35; }
.tip__cmp { margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--chart-tip-cmp, #bfe6ff); }
.tip__cmp.hidden { display: none; }
.tip__ser {
  display: flex; align-items: center; gap: 7px; margin-top: 6px;
  font-size: 11.5px; color: var(--muted, #93a6c4);
}
.tip__key { width: 14px; height: 3px; border-radius: 2px; flex: none; }

/* --------------------------------------------------------------- a11y ----- */
.qcard .sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .qcard .bar__fill { transition: none; }
}
