/* charts.css: the marks and chrome of charts.js, on the tokens of site.css. Thin marks, hairline solid grid, text in
 * text tokens (never the series colour), the series colour on the mark or its key only. */

.chart-card { display: flex; flex-direction: column; }
.chart-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.chart-grid > .card { margin: 0; }
@media (min-width: 980px) {
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.chart-card .card-head { margin-bottom: 4px; }
.chart { position: relative; min-width: 0; }
.chart-plot { position: relative; min-height: calc(var(--plot-h, 200px) + 30px); }
.chart-canvas { position: relative; touch-action: pan-y; border-radius: 6px; }
.chart-canvas svg { display: block; overflow: visible; }
.chart-empty { margin: 0; padding: 40px 0; text-align: center; color: var(--text-dim); }
.chart-summary { margin: 6px 0 0; font-size: 0.78rem; color: var(--text-dim); }
.chart-data > summary {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
}
.chart-data[open] > summary { margin-bottom: 6px; }
.chart-data .table-scroll { max-height: 320px; overflow: auto; }
.chart-data table { font-size: 0.78rem; }
.chart-data thead th { position: sticky; top: 0; background: var(--surface); }

/* without JS the table is the chart: the server renders it open, charts.js closes it under the drawn chart */
.chart:not(.chart-ready) .chart-plot { display: none; }

/* legend: a button per series (click hides it); the key mirrors the mark: a block for bars, a stroke for lines */
.chart-legend { display: flex; flex-wrap: wrap; gap: 2px 14px; margin: 0 0 4px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  margin-left: -4px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.legend-item:hover { color: var(--text); background: var(--surface-2); }
.legend-item[aria-pressed="false"] { opacity: 0.5; }
.legend-item[aria-pressed="false"] > span:last-child { text-decoration: line-through; }
.key { display: inline-block; flex: none; background: var(--s); }
.key-bar { width: 10px; height: 10px; border-radius: 3px; }
.key-line { width: 14px; height: 2px; border-radius: 1px; }
.key-line.dash { background: linear-gradient(90deg, var(--s) 0 5px, transparent 5px 8px, var(--s) 8px 13px, transparent 13px); }

/* series colours: categorical slots, status, and the de-emphasis grey */
.s-c1 { --s: var(--c1); }
.s-c2 { --s: var(--c2); }
.s-c3 { --s: var(--c3); }
.s-c4 { --s: var(--c4); }
.s-c5 { --s: var(--c5); }
.s-c6 { --s: var(--c6); }
.s-pos { --s: var(--pos); }
.s-neg { --s: var(--neg); }
.s-muted { --s: var(--muted-fill); }

/* marks */
.chart-canvas .bar { fill: var(--s); }
.chart-canvas .line { fill: none; stroke: var(--s); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-canvas .line.dash { stroke-dasharray: 5 4; stroke-linecap: butt; }
.chart-canvas .dot { fill: var(--s); stroke: var(--surface); stroke-width: 2; }

/* chrome: hairline solid grid, quiet axis, labels in text tokens */
.chart-canvas .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-canvas .zero, .chart-canvas .axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-canvas text { fill: var(--text-dim); font: 11px var(--font-sans); font-variant-numeric: tabular-nums; }
.chart-canvas .tick-x.major { fill: var(--text); font-weight: 600; }
.chart-canvas .crosshair { stroke: var(--text-dim); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.chart-canvas .hover-band { fill: var(--text); opacity: 0.06; pointer-events: none; }
.chart-canvas .mark-band { fill: var(--accent); opacity: 0.22; pointer-events: none; }
.chart-canvas .mark-label { fill: var(--text); font-size: 11px; font-weight: 600; pointer-events: none; }

/* tooltip: values lead, names follow, a stroke key per series */
.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 0.78rem;
  pointer-events: none;
}
.chart-tip[hidden] { display: none; }
.tip-time { color: var(--text-dim); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tip-row { display: grid; grid-template-columns: 14px auto 1fr; align-items: center; gap: 0 8px; }
.tip-value { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.tip-name { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* sparklines in KPI tiles: the de-emphasis line, the latest bucket in the accent */
.spark { height: 34px; width: 100%; }
.spark svg { display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark-zero { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.spark-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }

@media (forced-colors: active) {
  .chart-canvas .bar { fill: CanvasText; }
  .chart-canvas .line { stroke: CanvasText; }
  .key { background: CanvasText; }
}

[data-window-group], [data-window-body] { display: contents; }

/* the time window (charts.js's window controller): the bar of a page or of a chart card, the selection while dragging */
.window-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; }
.chart-card .window-bar { margin: 0 0 6px; }
.window-text { margin: 0; font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--text); }
.window-label { font-size: 0.8rem; }
.window-reset[hidden] { display: none; }
.window-status { font-size: 0.8rem; }
.window-status:empty { display: none; }
.window-hint { margin: 0 0 8px; font-size: 0.75rem; color: var(--text-dim); flex-basis: 100%; }
.window-hint[hidden] { display: none; }
.chart-window .chart-canvas { cursor: crosshair; user-select: none; -webkit-user-select: none; }
.chart-canvas .select-band { fill: var(--accent); opacity: 0.18; stroke: var(--accent); stroke-width: 1; pointer-events: none; }
.window-hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .window-hint-mouse { display: none; }
  .window-hint-touch:not([hidden]) { display: block; }
}
