/* Charts: the figure frame, axes, marks, tooltip, legend and table twin. Specs from the dataviz skill: marks at
   most 24 px thick with a 4 px rounded data end, 2 px lines, 8 px end dots with a 2 px surface ring, 10% area
   wash, a 2 px surface gap between touching marks, solid hairline grid and axes. Text never wears a series color. */

/* ---------- Frame ---------- */

.chart { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.chart-caption { display: flex; flex-direction: column; gap: 2px; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); }
.chart-title { font-weight: 600; font-size: 14px; margin-right: auto; }
.chart-stat { font-size: var(--text-secondary); color: var(--ink-2); }
.chart-stat strong { color: var(--ink); font-weight: 600; }
.chart-summary { font-size: var(--text-secondary); color: var(--ink-2); }
.chart-note { font-size: var(--text-meta); color: var(--ink-3); }
.chart-toggle { margin-left: auto; }
.chart-body { position: relative; min-width: 0; transition: opacity var(--fade); }
.chart-body.is-refreshing { opacity: 0.6; }
.chart-plot { position: relative; width: 100%; touch-action: pan-y; }
.chart-svg { display: block; width: 100%; overflow: visible; }
.chart-table { min-width: 0; }
.chart-empty { padding: var(--space-6) 0; color: var(--ink-2); font-size: var(--text-secondary); }

/* ---------- Legend: the swatch mirrors the mark (rect for bars, line for lines) ---------- */

.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--text-secondary); color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.legend-line { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.legend-value { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Axes and grid ---------- */

.grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.baseline { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.tick-label { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.axis-label { fill: var(--ink-3); font-size: 11px; }

/* ---------- Marks ---------- */

/* fill for SVG marks, background for HTML bars: each mark class works on both */
.mark-v2 { fill: var(--v2); background-color: var(--v2); }
.mark-v1 { fill: var(--v1); background-color: var(--v1); }
.mark-accent { fill: var(--accent); background-color: var(--accent); }
.mark-muted { fill: var(--mark-muted); background-color: var(--mark-muted); }
.mark-ramp3-1 { fill: var(--ramp3-1); background-color: var(--ramp3-1); }
.mark-ramp3-2 { fill: var(--ramp3-2); background-color: var(--ramp3-2); }
.mark-ramp3-3 { fill: var(--ramp3-3); background-color: var(--ramp3-3); }
.mark-ramp4-1 { fill: var(--ramp4-1); background-color: var(--ramp4-1); }
.mark-ramp4-2 { fill: var(--ramp4-2); background-color: var(--ramp4-2); }
.mark-ramp4-3 { fill: var(--ramp4-3); background-color: var(--ramp4-3); }
.mark-ramp4-4 { fill: var(--ramp4-4); background-color: var(--ramp4-4); }

/* Line strokes and their washes */
.line { stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.line.mark-v2, .stroke-v2 { stroke: var(--v2); }
.line.mark-v1, .stroke-v1 { stroke: var(--v1); }
.line.mark-accent, .stroke-accent { stroke: var(--accent); }
.line.mark-muted { stroke: var(--mark-muted); }
/* A line takes its series color as a stroke, never as a fill */
.line { fill: none !important; }
.wash { stroke: none; fill-opacity: 0.1; }
.end-dot { stroke: var(--surface); stroke-width: 2; }
.end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.end-label-detail { fill: var(--ink-2); font-weight: 400; }
.crosshair { stroke: var(--ink-3); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.hover-dot { stroke: var(--surface); stroke-width: 2; pointer-events: none; }

/* Reference step line ("Rollout set to 25%"): solid, never dashed */
.ref-line { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linejoin: round; }
.ref-label { fill: var(--ink-2); font-size: 11px; }
.note-marker { fill: var(--ink-2); }
.note-hit { fill: transparent; cursor: default; }

/* Columns and segments: the whole slot is the hit target; the hovered one lifts */
.col { outline: none; }
.col .hit { fill: transparent; }
.col.is-active .seg { opacity: 0.78; }
.col:focus-visible .hit { stroke: var(--focus); stroke-width: 2; }
.plot-focus:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- Bar list (horizontal, HTML) ---------- */

.bar-list { display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-secondary); }
.bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 30%) minmax(0, 1fr);
  align-items: center; gap: var(--space-3);
  padding: 2px 0; border-radius: 4px;
}
.bar-row:hover, .bar-row:focus-visible, .bar-row.is-active { background: var(--hover); }
.bar-label { color: var(--ink); overflow-wrap: anywhere; line-height: 1.3; }
.bar-cell { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.bar-track { display: flex; gap: 2px; height: 16px; min-width: 0; }
.bar-seg { height: 100%; min-width: 0; }
.bar-seg:last-child { border-radius: 0 var(--radius-mark) var(--radius-mark) 0; }
.bar-value { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.bar-value strong { color: var(--ink); font-weight: 600; }
.bar-row.is-muted .bar-label { color: var(--ink-3); }
.bar-row.is-muted .bar-seg { opacity: 0.55; }
@media (max-width: 479px) { .bar-row { grid-template-columns: minmax(84px, 34%) minmax(0, 1fr); } }

/* ---------- Single stacked bar (part to whole) ---------- */

.stacked-bar { display: flex; gap: 2px; height: 24px; }
.stacked-seg {
  position: relative; height: 100%; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-meta); font-weight: 600; white-space: nowrap; overflow: visible;
}
.stacked-seg:first-child { border-radius: var(--radius-mark) 0 0 var(--radius-mark); }
.stacked-seg:last-child { border-radius: 0 var(--radius-mark) var(--radius-mark) 0; }
.stacked-seg:only-child { border-radius: var(--radius-mark); }
.stacked-seg.is-active, .stacked-seg:hover, .stacked-seg:focus-visible { opacity: 0.8; }
.stacked-legend { margin-top: var(--space-2); }
.seg-label { padding: 0 6px; color: #ffffff; pointer-events: none; }
.seg-label.on-light { color: #0b0b0b; }

/* ---------- Inline bar (in table cells, one shared scale) ---------- */

.inline-bar { display: flex; gap: 2px; height: 8px; margin-top: 4px; min-width: 0; }
.inline-bar .bar-seg:last-child { border-radius: 0 2px 2px 0; }

/* ---------- Tooltip: value first, series second, line keys ---------- */

.chart-tooltip {
  position: fixed; left: 0; top: 0;
  z-index: var(--z-tooltip);
  min-width: 120px; max-width: min(280px, calc(100vw - 16px));
  padding: var(--space-2) 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--surface); color: var(--ink);
  font-size: var(--text-meta); line-height: 1.4;
  pointer-events: none;
  animation: fade-in var(--fade) ease-out;
}
.chart-tooltip.is-pinned { pointer-events: auto; }
.tt-title { color: var(--ink-3); margin-bottom: 4px; }
.tt-rows { display: flex; flex-direction: column; gap: 2px; }
.tt-row { display: flex; align-items: center; gap: 6px; }
.tt-value { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.tt-label { color: var(--ink-2); }
.tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tt-note { margin-top: 4px; color: var(--ink-2); }

/* ---------- Forced colors: system colors, and the 45 degree texture keeps v1 apart ---------- */

@media (forced-colors: active) {
  .mark-v2, .mark-accent, .mark-ramp3-3, .mark-ramp4-4 { fill: Highlight; background-color: Highlight; }
  .mark-v1, .mark-muted, .mark-ramp3-1, .mark-ramp4-1 { fill: url(#tex-45); background: repeating-linear-gradient(45deg, CanvasText 0 1px, Canvas 1px 4px); }
  .mark-ramp3-2, .mark-ramp4-2, .mark-ramp4-3 { fill: CanvasText; background-color: CanvasText; }
  .line.mark-v2, .line.mark-accent { stroke: Highlight; }
  .line.mark-v1, .line.mark-muted { stroke: CanvasText; }
  .grid-line, .baseline, .crosshair, .ref-line { stroke: GrayText; }
  .tick-label, .axis-label, .end-label, .ref-label { fill: CanvasText; }
  .chart-tooltip { border-color: CanvasText; }
}
