/* ============================================================================
   Base Agency Design System — Chart layer
   Marks follow the fixed specs: bars <=24px with a 4px rounded data-end,
   2px lines, >=8px markers, 2px surface gaps and rings, hairline solid grid.
   ========================================================================= */

.viz { position: relative; width: 100%; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }

/* ---- Chrome ------------------------------------------------------------ */
.viz .grid-line { stroke: var(--gridline); stroke-width: 1; shape-rendering: crispEdges; }
.viz .axis-line { stroke: var(--axis);     stroke-width: 1; shape-rendering: crispEdges; }
.viz .tick {
  fill: var(--ink-muted); font-size: 11px;
  font-variant-numeric: tabular-nums; /* ticks align vertically */
}
.viz .tick--x { text-anchor: middle; }
.viz .tick--y { text-anchor: end; }
[dir="rtl"] .viz .tick--y { text-anchor: start; }
.viz .axis-title {
  fill: var(--ink-muted); font-size: 11px; font-weight: 500;
  letter-spacing: 0.04em; text-transform: uppercase;
}

/* Direct labels — text wears text tokens, never the series colour */
.viz .mark-label {
  fill: var(--ink); font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.viz .mark-label--muted { fill: var(--ink-secondary); font-weight: 500; }
.viz .mark-label--inverse { fill: #fff; }

/* ---- Marks ------------------------------------------------------------- */
.viz .bar { transition: opacity var(--dur-micro) var(--ease-out); }
.viz .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .area { stroke: none; }
/* 2px surface ring keeps a dot legible where it crosses a line */
.viz .dot { stroke: var(--surface); stroke-width: 2; }
.viz .target-marker { stroke: var(--ink); stroke-width: 2.5; stroke-linecap: butt; }

/* Hit targets are bigger than the marks they serve */
.viz .hit { fill: transparent; cursor: pointer; }
.viz .hit:focus { outline: none; }
.viz .hit:focus-visible + .focus-ring,
.viz .hit[data-active="true"] + .focus-ring { opacity: 1; }
.viz .focus-ring {
  fill: none; stroke: var(--series-1); stroke-width: 2; rx: 3;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-micro) var(--ease-out);
}

/* Crosshair on line/area charts */
.viz .crosshair {
  stroke: var(--border-strong); stroke-width: 1;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-micro) var(--ease-out);
}
.viz[data-hover="true"] .crosshair { opacity: 1; }
.viz .crosshair-dot {
  stroke: var(--surface); stroke-width: 2;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-micro) var(--ease-out);
}
.viz[data-hover="true"] .crosshair-dot { opacity: 1; }

/* Dimming: hovering one series recedes the others */
.viz[data-focus-series] .series { opacity: 0.22; transition: opacity var(--dur-quick) var(--ease-out); }
.viz[data-focus-series="1"] .series[data-series="1"],
.viz[data-focus-series="2"] .series[data-series="2"],
.viz[data-focus-series="3"] .series[data-series="3"],
.viz[data-focus-series="4"] .series[data-series="4"],
.viz[data-focus-series="5"] .series[data-series="5"],
.viz[data-focus-series="6"] .series[data-series="6"] { opacity: 1; }

/* ---- Tooltip ----------------------------------------------------------- */
.viz__tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 132px; max-width: 260px;
  padding: var(--space-2) var(--space-3);
  background: var(--brand-navy); color: var(--ink-on-dark);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  font-size: var(--text-xs); line-height: 1.5;
  opacity: 0; translate: 0 4px;
  transition: opacity var(--dur-micro) var(--ease-out), translate var(--dur-micro) var(--ease-out);
}
.viz__tip[data-open="true"] { opacity: 1; translate: 0 0; }
.viz__tip-head {
  font-weight: 600; font-size: var(--text-xs);
  padding-bottom: 4px; margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.16);
}
.viz__tip-row {
  display: flex; align-items: center; gap: var(--space-2);
  white-space: nowrap;
}
.viz__tip-row + .viz__tip-row { margin-top: 2px; }
.viz__tip-key {
  width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto;
}
.viz__tip-name { color: rgba(255,255,255,0.78); }
.viz__tip-val {
  margin-inline-start: auto; font-weight: 600;
  font-variant-numeric: tabular-nums; padding-inline-start: var(--space-3);
}

/* ---- Legend — always present for two or more series -------------------- */
.legend {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4);
  padding-top: var(--space-3);
}
.legend button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 24px; padding: 2px 6px; margin: -2px -6px;
  border: 0; border-radius: var(--radius-sm); background: none; cursor: pointer;
  font-size: var(--text-xs); font-weight: 500; color: var(--ink-secondary);
  transition: background var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out);
}
.legend button:hover { background: var(--surface-hover); color: var(--ink); }
.legend button[aria-pressed="false"] { opacity: 0.42; }
.legend__key { width: 10px; height: 10px; border-radius: 2px; flex: 0 0 auto; }
.legend__key--line {
  width: 14px; height: 3px; border-radius: 2px;
}
.legend__key--dash {
  width: 14px; height: 0; border-radius: 0;
  border-top: 3px dashed currentColor;
}

/* ---- Table view — the twin every chart ships with ---------------------- */
.viz-table { display: none; }
.viz-table[data-open="true"] { display: block; }
.viz-table table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.viz-table th, .viz-table td {
  padding: 7px var(--space-3); text-align: start;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.viz-table thead th {
  font-size: var(--text-2xs); font-weight: 600; color: var(--ink-muted);
  letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--surface-sunken);
}
.viz-table td.num, .viz-table th.num {
  text-align: end; font-variant-numeric: tabular-nums;
}
.viz-table tbody tr:last-child td,
.viz-table tbody tr:last-child th { border-bottom: 0; }
.viz-table .swatch {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 2px; margin-inline-end: 7px; vertical-align: baseline;
}

/* When the table is showing, the plot steps aside */
.viz-slot[data-mode="table"] .viz,
.viz-slot[data-mode="table"] .legend { display: none; }

/* ---- Sparkline (stat tiles) -------------------------------------------- */
.spark { display: block; width: 78px; height: 26px; overflow: visible; }
.spark .spark-line { fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.spark .spark-area { stroke: none; }
.spark .spark-end { stroke: var(--surface); stroke-width: 1.75; }

/* ---- Heatmap ----------------------------------------------------------- */
.heat { display: grid; gap: 3px; }
/* A fixed row height, not a square: five weekday columns across a full-width
   card would make square cells ~200px tall. */
.heat__cell {
  height: 34px; border-radius: 3px; border: 0; padding: 0;
  cursor: pointer; position: relative;
  transition: outline-color var(--dur-micro) var(--ease-out);
  outline: 2px solid transparent; outline-offset: 1px;
}
.heat__cell:hover, .heat__cell:focus-visible { outline-color: var(--brand-navy); }
.heat__scale {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-2xs); color: var(--ink-muted);
}
.heat__scale-ramp { display: flex; gap: 2px; }
.heat__scale-step { width: 15px; height: 9px; border-radius: 2px; }

/* ---- Donut ------------------------------------------------------------- */
.donut-wrap {
  display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap;
}
.donut-wrap .viz { flex: 0 0 auto; width: 168px; }
.donut-wrap .donut-legend { flex: 1 1 200px; min-width: 0; }
.donut-center-value {
  font-size: 21px; font-weight: 700; fill: var(--ink);
  text-anchor: middle; letter-spacing: -0.02em;
}
.donut-center-label {
  font-size: 10px; font-weight: 600; fill: var(--ink-muted);
  text-anchor: middle; letter-spacing: 0.07em; text-transform: uppercase;
}
/* 2px surface gap between adjacent arcs */
.donut-arc { stroke: var(--surface); stroke-width: 2; }

.donut-legend li {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 5px 0; font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
}
.donut-legend li:last-child { border-bottom: 0; }
.donut-legend .legend__key { margin-inline-end: 2px; }
/* wrap at spaces, never mid-word — "Kindergarte/n" is worse than a wrap */
.donut-legend .name { color: var(--ink-secondary); min-width: 0; overflow-wrap: normal; }
.donut-legend .val {
  margin-inline-start: auto; font-weight: 600;
  font-variant-numeric: tabular-nums; padding-inline-start: var(--space-3);
}
.donut-legend .pct {
  font-size: var(--text-xs); color: var(--ink-muted);
  font-variant-numeric: tabular-nums; min-width: 38px; text-align: end;
}

/* ---- Texture — the opt-in backup channel (print / forced-colors) ------- */
@media print, (forced-colors: active) {
  .viz .bar[data-series="2"], .viz .area[data-series="2"] { fill: url(#tex-45); }
  .viz .bar[data-series="3"], .viz .area[data-series="3"] { fill: url(#tex-135); }
}
@media (forced-colors: active) {
  .viz .line { forced-color-adjust: none; }
}
