/* Statistics page. Chart colours are set here once for the dark and the light theme; the SVG marks only
   carry class names, so a theme switch needs no redraw. The palette was checked for colour-blind separation
   and contrast against both card backgrounds (#161920 and #ffffff). */
:root {
  --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70;                       /* series 1-3, always in this order */
  --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #b7d3f6; /* less -> more */
  --viz-none: #232833; --viz-grid: #272c38; --viz-axis: #8d95a8;
}
@media (prefers-color-scheme: light) {
  :root {
    --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a;
    --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #104281;
    --viz-none: #eceff4; --viz-grid: #e3e7ee; --viz-axis: #5f6878;
  }
}

.viz-page.stale { opacity: .5; transition: opacity .15s; }
.viz-kpis { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.kpi b { display: block; font-size: 26px; line-height: 1.15; font-weight: 600; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .note { font-size: 12px; margin-top: 2px; color: var(--muted); }
.kpi .note.up { color: var(--good); } .kpi .note.down { color: var(--bad); }

.viz { min-width: 0; }
.viz-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.viz-head h2 { margin: 0 0 2px; }
.viz-body { position: relative; min-width: 0; }
.viz-body svg { display: block; width: 100%; overflow: visible; }
.viz-body svg:focus-visible, .rank .rowbar:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; border-radius: 6px; }
.viz-body .tablewrap { margin: 0 -16px -14px; max-height: 340px; overflow: auto; }
.viz-body td, .viz-body th { font-variant-numeric: tabular-nums; }
.viz-foot { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* marks */
.viz-body text { fill: var(--viz-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-body text.value { fill: var(--text); font-weight: 600; }
.grid-line { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.cross { stroke: var(--viz-axis); stroke-width: 1; shape-rendering: crispEdges; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--panel); stroke-width: 2; }
.l1 { stroke: var(--viz-1); } .l2 { stroke: var(--viz-2); } .l3 { stroke: var(--viz-3); }
.s1 { fill: var(--viz-1); } .s2 { fill: var(--viz-2); } .s3 { fill: var(--viz-3); }
.q0 { fill: var(--viz-none); } .q1 { fill: var(--seq-1); } .q2 { fill: var(--seq-2); } .q3 { fill: var(--seq-3); }
.q4 { fill: var(--seq-4); } .q5 { fill: var(--seq-5); } .q6 { fill: var(--seq-6); }
.col.on rect, .col.on path, .cell.on, .land.on { filter: brightness(1.25); }
@media (prefers-color-scheme: light) { .col.on rect, .col.on path, .cell.on, .land.on { filter: brightness(.88); } }
.land { stroke: var(--panel); stroke-width: .6; vector-effect: non-scaling-stroke; }
.land.has { cursor: default; }
.land:focus { outline: none; } .land:focus-visible { stroke: var(--text); stroke-width: 1.5; }

/* legend: a short stroke for lines, a small block for bars */
.viz-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.key.stroke { width: 14px; height: 2px; border-radius: 1px; }
.key.k1 { background: var(--viz-1); } .key.k2 { background: var(--viz-2); } .key.k3 { background: var(--viz-3); }
.key.q0 { background: var(--viz-none); } .key.q1 { background: var(--seq-1); } .key.q2 { background: var(--seq-2); } .key.q3 { background: var(--seq-3); }
.key.q4 { background: var(--seq-4); } .key.q5 { background: var(--seq-5); } .key.q6 { background: var(--seq-6); }
.scale { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--muted); }
.scale .key { width: 18px; } .scale .end { margin: 0 4px; } .scale .bin { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }

/* ranked bars: name, bar, figure - one colour, value at the tip */
.rank { display: grid; grid-template-columns: minmax(70px, max-content) minmax(40px, 1fr) max-content; gap: 6px 10px; align-items: center; }
.rank .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.rank .rowbar { height: 14px; display: flex; align-items: center; min-width: 0; }
.rank .rowbar i { display: block; height: 14px; min-width: 2px; background: var(--viz-1); border-radius: 0 4px 4px 0; }
.rank .rowbar:hover i, .rank .rowbar:focus-visible i { filter: brightness(1.2); }
.rank .figure { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rank .figure small { color: var(--muted); font-weight: 400; margin-left: 4px; }

.geo { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(220px, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .geo { grid-template-columns: minmax(0, 1fr); } }

/* tooltip: the figure leads, the name follows */
.viz-tip { position: fixed; z-index: 30; pointer-events: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; max-width: 260px; }
.viz-tip .t { color: var(--muted); margin-bottom: 4px; }
.viz-tip .r { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.viz-tip .r b { font-variant-numeric: tabular-nums; }
.viz-tip .r span { color: var(--muted); }
