/* Studio section styles: statistics. Owned by the stats view; tokens come from styles.css :root.
   Series colours are the tokens --series-1 and --series-2 (validated categorical slots 1-2, light mode). */

.stats-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
#range-group { min-width: 0; }
.stats-back { margin: 0 0 12px; }
.stats-rule { margin: -12px 0 20px; }

/* KPI deltas: arrow and word carry the direction; colour is secondary. */
.kpi-delta {
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.kpi-delta.is-up { color: var(--ok-fg); }
.kpi-delta.is-down { color: var(--text-2); }
.kpi-delta .kpi-arrow { display: inline-block; width: 10px; height: 10px; fill: currentColor; vertical-align: -1px; margin-right: 2px; }
.kpi-delta .kpi-arrow rect { fill: currentColor; }
.stats-kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stats-kpis .kpi-value { font-variant-numeric: tabular-nums; }

/* Chart: the host scrolls sideways on narrow screens; the SVG is drawn at its real pixel size. */
.chart-card { margin-bottom: 24px; }
.chart {
  position: relative;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border-radius: var(--radius-xs);
  touch-action: pan-x pan-y;
}
.chart:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
/* Global rule styles.css:80 caps every svg at 100% width; the chart keeps its drawn width and scrolls inside .chart. */
.chart-svg { display: block; max-width: none; font-variant-numeric: tabular-nums; }
.chart-svg .grid-line { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis,
.chart-svg .x-label,
.chart-svg .end-label { fill: var(--text-2); font-size: var(--fs-xs); }
.chart-svg .end-label { font-weight: 600; }
.chart-svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .line.series-1 { stroke: var(--series-1); }
.chart-svg .line.series-2 { stroke: var(--series-2); }
.chart-svg .crosshair { stroke: var(--line-strong); stroke-width: 1; }
.chart-svg .dot { stroke: var(--surface); stroke-width: 2; }
.chart-svg .dot.series-1 { fill: var(--series-1); }
.chart-svg .dot.series-2 { fill: var(--series-2); }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.chart-legend li { display: inline-flex; align-items: center; gap: 8px; }
.key-line { display: inline-block; width: 16px; height: 3px; border-radius: var(--radius-hair); }
.key-line.series-1 { background: var(--series-1); }
.key-line.series-2 { background: var(--series-2); }
.chart-hint { margin: 8px 0 0; }

/* Hover and focus tooltip: values lead, names follow. Positioned inside the scrolling host. */
.chart-tip {
  position: absolute;
  top: 8px;
  z-index: 2;
  min-width: 150px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  font-size: var(--fs-sm);
  pointer-events: none;
  transform: translateX(12px);
}
.chart-tip[hidden] { display: none; }
.chart-tip.is-flip { transform: translateX(calc(-100% - 12px)); }
.chart-tip .tip-date { display: block; margin-bottom: 4px; font-weight: 600; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.chart-tip .tip-key { display: inline-block; width: 12px; height: 3px; border-radius: var(--radius-hair); }
.chart-tip .tip-key.series-1 { background: var(--series-1); }
.chart-tip .tip-key.series-2 { background: var(--series-2); }
.chart-tip .tip-val { font-variant-numeric: tabular-nums; color: var(--text); }
.chart-tip .tip-name { color: var(--text-2); }

.chart-table { margin-top: 12px; }
.chart-table > summary {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  color: var(--primary);
  cursor: pointer;
}
.chart-table .table-wrap { margin-top: 8px; }
.chart-table > summary::-webkit-details-marker { display: none; }
.chart-table > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-xs); }

/* Content tab: sortable header links, linked titles. */
.stat-table td.num, .stat-table th.num { font-variant-numeric: tabular-nums; }
.stat-table .cell-main { min-width: 0; max-width: 360px; overflow-wrap: anywhere; }
.stat-table .stat-title a { color: var(--text); text-decoration: none; }
.stat-table .stat-title a:hover { text-decoration: underline; }
.sort-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  color: inherit;
  text-decoration: none;
}
.sort-link:hover { text-decoration: underline; }
.sort-icon { width: 10px; height: 10px; fill: currentColor; flex: none; }

.stats-top { margin-top: 8px; }
.stats-top .section-head a { display: inline-flex; align-items: center; min-height: var(--hit); }
