/* The Key metrics view (metrics.js). Series colours are the dataviz reference
   palette's slots 1 and 2 (blue #2a78d6, orange #eb6834): both pass the
   lightness, chroma, colour-blind separation and 3:1 contrast checks on the
   console's white surface. Text never wears a series colour. */

#view-metrics {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: var(--hair);
  --axis: var(--line);
}
#view-metrics.refreshing .metrics-body { opacity: 0.55; transition: opacity 120ms; }

.metrics-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.metrics-filters .seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.metrics-filters .seg button { border: 0; background: transparent; padding: 0 12px; height: 32px; font: inherit; font-size: 13px; color: var(--fg-2); cursor: pointer; }
.metrics-filters .seg button + button { border-left: 1px solid var(--line); }
.metrics-filters .seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--navy); font-weight: 600; }
.metrics-filters .date { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 8px; background: var(--surface); }
.metrics-filters .date span { color: var(--muted); font-size: 12px; font-weight: 600; }
.metrics-filters .date input { border: 0; height: 30px; padding: 0 4px; box-shadow: none; }
.metrics-filters .range { color: var(--muted); font-size: 13px; margin-left: auto; }

.metrics-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: var(--gap); padding-bottom: 8px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--fg-2); }
.stat-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; color: var(--fg); line-height: 1.15; }
.stat.muted-value .stat-value { color: var(--faint); }
.stat-sub { font-size: 12px; color: var(--muted); }

#metrics-charts { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--gap); }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.chart-head h2 { font-size: 15px; }
.chart-head p { margin: 2px 0 0; }
.chart .plot { position: relative; min-width: 0; }
/* console.css sizes every svg as an 18px outline icon; a plot is not one. */
.chart .plot svg { display: block; overflow: visible; width: auto; height: auto; fill: none; stroke: none; stroke-width: 0; flex: none; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .label { fill: var(--fg-2); font-size: 12px; }
.chart .value { fill: var(--fg); font-size: 12px; font-weight: 600; }
.chart .mark.s1 { fill: var(--series-1); }
.chart .mark.s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit.on, .chart .hit:focus-visible { fill: rgba(29, 52, 67, 0.05); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--fg-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.s1, .key.s1 { background: var(--series-1); }
.swatch.s2, .key.s2 { background: var(--series-2); }

.tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-2); padding: 8px 10px; font-size: 12px; pointer-events: none; min-width: 150px; z-index: 2; }
.tip-title { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; color: var(--fg-2); }
.tip-row b { color: var(--fg); font-variant-numeric: tabular-nums; min-width: 2ch; }
.key { width: 10px; height: 2px; border-radius: 1px; display: inline-block; }

.chart-table { overflow: auto; max-height: 320px; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.chart-table th, .chart-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--hair); }
.chart-table td:not(:first-child), .chart-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.chart-table th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface); }

@media (max-width: 1100px) {
  #metrics-charts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .metrics-filters .range { margin-left: 0; width: 100%; }
  .stat-value { font-size: 26px; }
}
