/* The site's charts (Components/Charts). Colours do one job each: categorical slots for what a series is (fixed to it,
   never to its rank), a blue ramp for how much, and the site's success and danger inks for a change. The categorical
   slots and the ramps were checked against the skins' panels (CVD separation, lightness band, contrast): on the lightest
   panel slot 6 drops under 3:1, so every chart has a table view. Marks are thin: columns at most 24px with 4px rounded
   tops, 2px lines, a 2px gap between touching fills, hairline solid grid. Text never wears a series colour. */

.viz {
  --viz-1: #3987e5;
  --viz-2: #d95926;
  --viz-3: #199e70;
  --viz-4: #c98500;
  --viz-5: #d55181;
  --viz-6: #008300;
  --viz-7: #9085e9;
  --viz-8: #e66767;
  /* Magnitude, low to high (on a dark panel the quiet end sinks into it). */
  --viz-seq-1: #104281;
  --viz-seq-2: #1c5cab;
  --viz-seq-3: #2a78d6;
  --viz-seq-4: #5598e7;
  --viz-seq-5: #86b6ef;
  --viz-seq-6: #b7d3f6;
  /* Stages in order (a funnel), one hue. */
  --viz-ord-1: #2a78d6;
  --viz-ord-2: #5598e7;
  --viz-ord-3: #9ec5f4;
  --viz-ink: var(--text);
  --viz-ink-2: color-mix(in oklab, var(--text) 80%, transparent);
  --viz-muted: var(--muted);
  --viz-grid: color-mix(in oklab, var(--text) 8%, transparent);
  --viz-axis: color-mix(in oklab, var(--text) 20%, transparent);
  --viz-gap: var(--panel-solid);
  --viz-up: var(--success);
  --viz-down: var(--danger);
}

.viz-s1 { --viz-c: var(--viz-1); }
.viz-s2 { --viz-c: var(--viz-2); }
.viz-s3 { --viz-c: var(--viz-3); }
.viz-s4 { --viz-c: var(--viz-4); }
.viz-s5 { --viz-c: var(--viz-5); }
.viz-s6 { --viz-c: var(--viz-6); }
.viz-s7 { --viz-c: var(--viz-7); }
.viz-s8 { --viz-c: var(--viz-8); }
.viz-o1 { --viz-c: var(--viz-ord-1); }
.viz-o2 { --viz-c: var(--viz-ord-2); }
.viz-o3 { --viz-c: var(--viz-ord-3); }

/* ---- A chart's card: its title, legend, the chart, and its table ---- */

.viz-card { margin: 0; display: grid; gap: .75rem; align-content: start; min-width: 0; padding: 1rem 1.1rem; }
.viz-head { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-start; justify-content: space-between; }
.viz-head h3 { margin: 0; font: 600 .98rem/1.3 var(--font); color: var(--viz-ink); }
.viz-head p { margin: .15rem 0 0; }
.viz-body { min-width: 0; position: relative; }
.viz-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--viz-muted); font-size: .85rem; pointer-events: none; }
.viz-legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin: 0; padding: 0; list-style: none; font-size: .78rem; color: var(--viz-ink-2); }
.viz-legend li { display: inline-flex; align-items: center; gap: .4rem; }
.viz-key { width: 10px; height: 10px; border-radius: 3px; background: var(--viz-c); flex: none; }
.viz-key.is-line { width: 14px; height: 2px; border-radius: 1px; }
.viz-table { font-size: .8rem; }
.viz-table > summary { cursor: pointer; color: var(--viz-muted); width: fit-content; list-style: none; display: inline-flex; gap: .35rem; align-items: center; }
.viz-table > summary::-webkit-details-marker { display: none; }
.viz-table > summary::before { content: "▸"; font-size: .7rem; transition: transform .15s; }
.viz-table[open] > summary::before { transform: rotate(90deg); }
.viz-table-scroll { overflow-x: auto; margin-top: .5rem; }
.viz-table table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.viz-table th, .viz-table td { padding: .3rem .55rem; border-bottom: 1px solid var(--viz-grid); text-align: right; white-space: nowrap; }
.viz-table th:first-child, .viz-table td:first-child { text-align: left; }
.viz-table th { color: var(--viz-muted); font-weight: 600; }

/* ---- Stat tiles: a label, the number, the change, and its trend ---- */

.viz-tile { display: grid; gap: .25rem; align-content: start; padding: .9rem 1rem .8rem; min-width: 0; position: relative; }
.viz-tile-label { color: var(--viz-muted); font-size: .78rem; font-weight: 600; letter-spacing: .02em; }
.viz-tile-value { font: 600 1.65rem/1.1 var(--font); color: var(--viz-ink); white-space: nowrap; }
.viz-tile.is-hero { display: flex; flex-direction: column; gap: .3rem; }
.viz-tile.is-hero .viz-tile-value { font-size: clamp(2.6rem, 6vw, 3.6rem); letter-spacing: -.02em; }
.viz-tile-note { color: var(--viz-muted); font-size: .76rem; }
.viz-delta { font-size: .78rem; font-weight: 600; color: var(--viz-ink-2); }
.viz-delta.is-up { color: var(--viz-up); }
.viz-delta.is-down { color: var(--viz-down); }
.viz-delta span { color: var(--viz-muted); font-weight: 500; margin-left: .2rem; }
.viz-spark { position: relative; height: 28px; margin-top: .35rem; }
.viz-tile.is-hero .viz-spark { height: 72px; margin-top: auto; }
.viz-spark svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.viz-spark-line { fill: none; stroke: var(--viz-muted); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.viz-spark-area { fill: var(--viz-muted); opacity: .1; }
.viz-tile.is-hero .viz-spark-line { stroke: var(--viz-1); }
.viz-tile.is-hero .viz-spark-area { fill: var(--viz-1); }
.viz-dot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--viz-c, var(--viz-1)); box-shadow: 0 0 0 2px var(--viz-gap); }

/* ---- Columns over time (stacked), and a line over time ---- */

.viz-chart { --viz-h: 190px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: var(--viz-h) auto; column-gap: .5rem; container-type: inline-size; }
.viz-yaxis { position: relative; font-size: .7rem; color: var(--viz-muted); font-variant-numeric: tabular-nums; min-width: 1.6rem; }
.viz-yaxis span { position: absolute; right: 0; transform: translateY(50%); white-space: nowrap; }
.viz-plot { position: relative; border-bottom: 1px solid var(--viz-axis); }
.viz-gridline { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--viz-grid); }
.viz-bands { position: absolute; inset: 0; display: flex; }
.viz-band { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; outline: none; cursor: default; }
.viz-band:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--accent) 70%, transparent); border-radius: 4px; }
.viz-stack { width: min(24px, 70%); display: flex; flex-direction: column-reverse; gap: 2px; }
.viz-seg { display: block; background: var(--viz-c); min-height: 1px; transition: filter .12s; }
.viz-stack > .viz-seg:last-child { border-radius: 4px 4px 0 0; }
.viz-band:hover .viz-seg, .viz-band:focus-visible .viz-seg { filter: brightness(1.18); }
.viz-xaxis { grid-column: 2; position: relative; height: 1.4rem; font-size: .7rem; color: var(--viz-muted); }
.viz-xaxis span { position: absolute; top: .3rem; transform: translateX(-50%); white-space: nowrap; }
.viz-xaxis span.is-first { transform: none; }
.viz-xaxis span.is-last { transform: translateX(-100%); }
/* A narrow chart (a phone) writes every other day under it, the last always. */
@container (max-width: 440px) {
  .viz-xaxis span:nth-child(even):not(:last-child) { display: none; }
}
.viz-line-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.viz-line { fill: none; stroke: var(--viz-c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.viz-area { fill: var(--viz-c); opacity: .1; }
.viz-end { position: absolute; transform: translate(8px, -50%); font-size: .75rem; font-weight: 600; color: var(--viz-ink); white-space: nowrap; pointer-events: none; }
.viz-cross { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--viz-axis); pointer-events: none; display: none; }
.viz-plot.is-crossed .viz-cross { display: block; }

/* ---- Ranked bars: a label, its bar, and its value at the tip ---- */

.viz-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.viz-bar-row { display: grid; grid-template-columns: minmax(6rem, 38%) 1fr; gap: .6rem; align-items: center; font-size: .82rem; padding: .1rem .2rem; border-radius: 6px; outline: none; }
.viz-bar-row:hover, .viz-bar-row:focus-visible { background: color-mix(in oklab, var(--text) 5%, transparent); }
.viz-bar-label { display: flex; align-items: center; gap: .4rem; min-width: 0; color: var(--viz-ink-2); }
.viz-bar-label > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-bar-label a { color: inherit; }
.viz-bar-track { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.viz-bar { display: block; height: 12px; min-width: 2px; border-radius: 0 4px 4px 0; background: var(--viz-c); flex: none; }
.viz-bar-value { font-weight: 600; color: var(--viz-ink); white-space: nowrap; font-size: .8rem; }
.viz-bar-value small { color: var(--viz-muted); font-weight: 500; margin-left: .3rem; }

/* ---- One whole in parts: the tall segmented bar ---- */

.viz-split { display: flex; gap: 2px; height: 28px; }
.viz-part { flex: var(--viz-w) 1 0; min-width: 3px; background: var(--viz-c); border-radius: 4px; display: flex; align-items: center; padding: 0 .45rem; color: #fff; font-size: .74rem; font-weight: 600; outline: none; }
.viz-part:hover, .viz-part:focus-visible { filter: brightness(1.18); }
.viz-part span { white-space: nowrap; }

/* ---- A heatmap: the week by hour ---- */

.viz-heat { display: grid; grid-template-columns: auto repeat(24, minmax(0, 1fr)); gap: 2px; align-items: center; font-size: .68rem; color: var(--viz-muted); }
.viz-heat-day { padding-right: .35rem; white-space: nowrap; }
.viz-cell { aspect-ratio: 1; min-height: 9px; border-radius: 3px; background: var(--viz-grid); outline: none; }
.viz-cell.l1 { background: var(--viz-seq-1); }
.viz-cell.l2 { background: var(--viz-seq-2); }
.viz-cell.l3 { background: var(--viz-seq-3); }
.viz-cell.l4 { background: var(--viz-seq-4); }
.viz-cell.l5 { background: var(--viz-seq-5); }
.viz-cell.l6 { background: var(--viz-seq-6); }
.viz-cell:hover, .viz-cell:focus-visible { box-shadow: 0 0 0 2px var(--viz-ink); }
.viz-heat-hour { text-align: left; white-space: nowrap; overflow: visible; }
.viz-scale { display: flex; align-items: center; gap: .35rem; font-size: .7rem; color: var(--viz-muted); }
.viz-scale i { width: 14px; height: 10px; border-radius: 2px; display: block; }

/* ---- The tooltip (one for the page, put there by app.js) ---- */

.viz-tip { position: fixed; z-index: 90; pointer-events: none; min-width: 9rem; max-width: 18rem; padding: .5rem .65rem; border-radius: 8px;
  background: var(--panel-solid); border: 1px solid color-mix(in oklab, var(--text) 14%, transparent); box-shadow: var(--shadow); font-size: .78rem; color: var(--text); }
.viz-tip[hidden] { display: none; }
.viz-tip-title { color: var(--muted); margin-bottom: .3rem; font-size: .74rem; }
.viz-tip-row { display: grid; grid-template-columns: 14px auto 1fr; gap: .45rem; align-items: center; }
.viz-tip-row b { font-variant-numeric: tabular-nums; }
.viz-tip-row span { color: var(--muted); }
.viz-tip-row .viz-key { width: 12px; height: 2px; border-radius: 1px; }

@media (prefers-reduced-motion: reduce) {
  .viz-seg, .viz-table > summary::before { transition: none; }
}

@media (forced-colors: active) {
  .viz-seg, .viz-bar, .viz-part, .viz-cell, .viz-key { forced-color-adjust: none; outline: 1px solid CanvasText; }
}
