/* Stat module styles. Layered on top of /common/css/dl.css. */

:root {
    /* Stat's series-chart aliases now resolve to the shared chart
       palette defined in /common/css/dl.css. Editing a color in one
       place updates browse, stat and any future module that reads
       --chart-*. The names below are the channel-specific spellings
       stat's JS uses (DL.Stat.Series.CHANNELS[].color); each maps onto
       its semantic --chart-* slot. */
    --st-sac:   var(--chart-sac);
    --st-depth: var(--chart-depth);
    --st-avg:   var(--chart-avg);
    --st-dur:   var(--chart-dur);
    --st-temp:  var(--chart-temp);
    --st-gas:   var(--chart-gas);
    --st-asc:   var(--chart-asc);
    --st-desc:  var(--chart-desc);
    --st-rate:  var(--chart-rate);
}

/* (The headline / metric / activity / highlights card blocks that
   lived here were replaced by the shared stat shell in stat/page.js —
   quick metrics, data panels and the details table; see the "04 Stat
   redesign" block at the end of this file.) */

/* Dives-per-year table (Overview tab, beside the yearly chart). */
.year-count-table {
    font-variant-numeric: tabular-nums;
}
.year-count-table tbody th[scope="row"] { font-weight: 500; }
.year-count-table tbody tr:last-child > * { border-bottom: none; }
.year-count-table tfoot th,
.year-count-table tfoot td {
    border-top: 1px solid var(--border-strong);
    border-bottom: none;
    font-weight: 600;
}

/* Card-level icon / label pair in chart-card and calendar headings. */
.card-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.card-label {
    flex: 1 1 auto;
    min-width: 0;
}

/* Landmark rows ("≈ 1.23 × Akashi Kaikyō Bridge"). */
.landmark-row {
    display: grid;
    grid-template-columns: minmax(6rem, auto) 1fr;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--font-size-md);
}
.landmark-row:last-child { border-bottom: none; }
.landmark-row .factor {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--accent);
}
.landmark-row .name { color: var(--text); }
.landmark-row .sub  { color: var(--text-muted); font-size: var(--font-size-xs); }

/* ── Chart grid ──────────────────────────────────────────────────── */
.charts-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
    margin: 16px 0;
}
@media (min-width: 880px) {
    .charts-grid { grid-template-columns: 1fr 1fr; }
}
.chart-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 14px 14px 18px;
    border: 1px solid var(--border);
    height: 320px;
    display: flex;
    flex-direction: column;
    /* A grid item's automatic minimum size is min-content, and a Chart.js
       canvas plus its channel chips have a wide min-content — so at 390px the
       card blew out to 675px and took the whole page 311px past the viewport.
       min-width: 0 lets the 1fr track actually govern. Measured before/after. */
    min-width: 0;
}
/* Same reasoning one level down: the host is a flex child of the card. */
.chart-card > * { min-width: 0; }
.chart-card h4 {
    margin: 0 0 8px;
    font-size: 13px;
    opacity: 0.7;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chart-card .chart-host {
    flex: 1;
    position: relative;
    min-height: 0;
}
.chart-card canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}
.chart-card .chart-sub {
    margin-top: 6px;
    font-size: 11.5px;
    opacity: 0.5;
}
.chart-card .chart-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    font-size: 13px;
}

/* Per-card "expand to fullscreen" button. Sits at the far right of the
   h4 header — the header is already `display: flex; gap: 8px`, so a
   `margin-left: auto` pushes it past the title without re-flowing the
   icon/label pair. */
.chart-expand-btn {
    margin-left: auto;
    flex: 0 0 auto;
    color: var(--text-muted);
}
.chart-expand-btn:hover { color: var(--text); }
/* While a card is in the fullscreen modal the in-card expand button
   is redundant — the modal supplies its own close affordance. */
.chart-card.is-fullscreen .chart-expand-btn { display: none; }

/* ── Chart fullscreen modal ──────────────────────────────────────── */
/* The clicked card is moved (not cloned) into `.chart-modal-host` so
   its Chart.js instance keeps its lifecycle; we just override the
   320 px height so it can fill the viewport. */
.chart-modal {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    /* Above .dl-header (1000) and .stat-modal (1100): the sticky app header
       would otherwise paint over the fullscreen overlay's top strip and swallow
       the fixed-position close button sitting at top:18px. */
    z-index: 1200;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 28px 28px 28px;
    animation: chart-modal-in 140ms ease-out;
}
@media (max-width: 480px) {
    .chart-modal { padding: 12px; }
    .chart-modal-host { max-height: 90dvh; max-height: 90vh; }
}
@keyframes chart-modal-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.chart-modal-host {
    width: 100%;
    max-width: 1400px;
    display: flex;
    /* `min-height: 0` lets the inner card honour its `height: 100%`
       inside the flex column without expanding to its content size. */
    min-height: 0;
}
.chart-modal-host > .chart-card.is-fullscreen {
    flex: 1;
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    padding: 18px 22px 22px;
}
/* Heatmap (chart-card-wide) keeps `height: auto` in the grid; force
   it to fill the modal so the SVG has room to scale, and let it scroll
   vertically when the year stack exceeds the viewport. */
.chart-modal-host > .chart-card-wide.is-fullscreen {
    height: 100%;
    overflow: auto;
}
.chart-modal-host > .chart-card-wide.is-fullscreen .chart-host {
    overflow: visible;
}
.chart-modal-close {
    position: fixed;
    top: 18px;
    right: 22px;
    z-index: 1;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    color: var(--text);
    line-height: 1;
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 120ms;
}
.chart-modal-close:hover { background: var(--bg-elev); }

/* ── Chart groups (collapsible <details>) ────────────────────────── */
.charts-groups {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin: 16px 0;
}
.chart-group {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-elev, var(--bg-card));
    padding: 4px 12px 14px;
}
.chart-group-summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 4px 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    opacity: 0.92;
}
/* Hide the default disclosure triangle (Webkit + Firefox) so our own
   caret span is the only marker. */
.chart-group-summary::-webkit-details-marker { display: none; }
.chart-group-summary::marker { display: none; }
.chart-group-caret {
    display: inline-block;
    transition: transform 0.15s ease;
    opacity: 0.6;
    font-size: 12px;
}
.chart-group:not([open]) .chart-group-caret {
    transform: rotate(-90deg);
}
.chart-group .charts-grid {
    /* The group already adds margin; remove the default top/bottom of
       the inner grid so successive groups don't double-space. */
    margin: 8px 0 0;
}

/* Heatmap card spans the full grid row on wide layouts. */
.chart-card-wide {
    /* `grid-column: 1 / -1` works because the parent .charts-grid
       declares its column tracks explicitly via grid-template-columns. */
    grid-column: 1 / -1;
    /* Heatmap content is taller than the standard 320px card; let
       the SVG dictate height. */
    height: auto;
}
.chart-card-wide .chart-host {
    min-height: 0;
    overflow-x: auto;          /* horizontal scroll on narrow screens */
}
/* ── Stat page: tabs ────────────────────────────────────────────── */
/* Tab strip sits under the headline strip; panels host the existing
 * card grids (metric-grid, activity-card, charts-groups, …). Display
 * is `contents` so the inner layout containers keep ownership of grid
 * / flex sizing — switching to display:none on hidden panels still
 * works because `[hidden]` wins. */
/* The strip is the shared .dl-tabs primitive (underline, one row that
   scrolls sideways on a phone — it used to wrap into three rows). */
.stat-tabs {
    flex-wrap: nowrap;
    margin: 0 0 var(--space-5);
    -webkit-overflow-scrolling: touch;
    scroll-padding-inline: var(--space-4);
}
.stat-tab {
    transition: color var(--duration-fast) var(--ease-standard),
                border-color var(--duration-fast) var(--ease-standard);
}
.stat-tab.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.stat-tab:focus-visible {
    outline: var(--focus-width) solid var(--focus-ring);
    outline-offset: calc(var(--focus-offset) * -1);
}
.stat-tab-panel { display: contents; }
.stat-tab-panel[hidden] { display: none; }

.stat-tab-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 32px 16px;
    font-size: 0.95rem;
}

/* ── Courses card (Courses tab) ─────────────────────────────────── */
/* One row per education_course_first. Icons are SVGs under
 * /common/img/courses/<id>.png; missing icons fall back to default.png
 * via the <img onerror> shim in courses.js. Rows are anchors that
 * link to the first-completion dive in /browse/. */
.courses-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 16px 18px;
    margin: 16px 0;
}
.courses-card h3 {
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.courses-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.course-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-elev);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.12s ease, background 0.12s ease;
}
.course-row:hover {
    border-color: var(--accent);
    background: var(--bg-card);
}
.course-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.course-row .course-icon {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: block;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}
.course-row .course-icon img {
    width: 100%;
    height: 100%;
    display: block;
}
.course-row .course-text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.course-row .course-name {
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.course-row .course-meta {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
}
.courses-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 24px 8px;
    font-size: 0.95rem;
}

/* ── Add-completion affordances ────────────────────────────────────
 * The "+ Add course" button sits in the courses-card heading right-
 * aligned. Manual-only rows are <div> not <a> (no dive target) and
 * carry a × delete chip in the trailing slot.
 */
.courses-card-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}
.course-row-manual {
    cursor: default;
}
.course-row-manual:hover {
    /* No hover state — there's nothing to navigate to. */
    border-color: var(--border);
    background: var(--bg-elev);
}
.course-row-delete {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.course-row-delete:hover {
    border-color: var(--err);
    color: var(--err);
    background: var(--bg-card);
}
.course-row-edit {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.course-row-edit:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-card);
}
.stat-completion-modal {
    min-width: min(420px, 90vw);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.stat-completion-modal .dlf-field {
    margin: 0;
}

/* ── C-card thumbnails on a course row ─────────────────────────────
 * Small clickable certification-card previews (front + optional back),
 * sitting between the course text and the × delete chip. Clicking opens
 * the shared DL.ImageViewer on the full-size served bytes.
 */
.course-card-thumbs {
    flex: 0 0 auto;
    display: inline-flex;
    gap: 6px;
    align-items: center;
}
.course-card-thumb {
    width: 44px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    overflow: hidden;
    cursor: pointer;
    display: inline-flex;
    transition: border-color 0.12s ease;
}
.course-card-thumb:hover {
    border-color: var(--accent);
}
.course-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── C-card upload slots in the add-completion modal ──────────────── */
.completion-card-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.completion-card-upload {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.completion-card-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.completion-card-preview {
    max-height: 140px;
    width: auto;
    align-self: flex-start;
    border: 1px solid var(--border);
    border-radius: 8px;
    object-fit: contain;
    background: var(--bg-card);
}
.completion-card-remove {
    align-self: flex-start;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color 0.12s ease, color 0.12s ease;
}
.completion-card-remove:hover {
    border-color: var(--err);
    color: var(--err);
}

/* ── What can I do? tab ─────────────────────────────────────────────
 * Knowledge-progression view: per-category section containing
 * (1) progress bar, (2) horizontal ladder showing where the user
 * stands on the certification path, (3) detail table of every
 * capability with status icon, prerequisite course chips, and date.
 * Status palette (semantic CSS tokens, no per-state hardcodes):
 *   done              — accent (gold-ish) — full colour, ✓
 *   licensed_not_done — informational blue — ◐ (try it next)
 *   locked            — muted grey         — ◯ (course missing)
 */

/* ── Top summary block ─────────────────────────────────────────── */
.cando-summary-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--panel-padding);
    margin: 0 0 var(--space-4);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-6);
}
.cando-summary-num {
    font-variant-numeric: tabular-nums;
    line-height: 1;
    white-space: nowrap;
}
.cando-summary-done {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    color: var(--text);
}
.cando-summary-of {
    font-size: var(--font-size-xl);
    color: var(--text-muted);
}
.cando-summary-mid {
    flex: 1 1 16rem;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.cando-summary-label {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-weight: 600;
}
.cando-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-subtle);
    border-radius: 999px;
    overflow: hidden;
}
/* One solid state colour: the bar measures "done", nothing else. */
.cando-progress-bar-fill {
    display: block;
    height: 100%;
    background: var(--ok);
    border-radius: 999px;
}
.cando-summary-stats {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}
.cando-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-3);
    min-height: var(--control-sm);
    border-radius: 999px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg-subtle);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.cando-stat-done     { color: var(--ok);   border-color: var(--ok);   background: var(--ok-soft); }
.cando-stat-licensed { color: var(--info); border-color: var(--info); background: var(--info-soft); }

/* ── Per-category section ──────────────────────────────────────── */
.cando-group {
    margin-bottom: var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.cando-group > summary {
    list-style: none;
    cursor: pointer;
    padding: var(--space-3) var(--panel-padding);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    user-select: none;
    font-weight: 600;
    font-size: var(--font-size-lg);
    color: var(--text);
}
.cando-group > summary::-webkit-details-marker { display: none; }
.cando-group > summary::marker { content: ""; }
.cando-group .cando-group-glyph { display: inline-flex; color: var(--text-muted); }
.cando-group .cando-group-counter {
    font-weight: 500;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.cando-group-caret {
    display: inline-flex;
    color: var(--text-muted);
    transition: transform var(--duration-fast) var(--ease-standard);
}
.cando-group:not([open]) .cando-group-caret { transform: rotate(-90deg); }

/* Mini progress bar inside the summary row. */
.cando-cat-bar {
    flex: 0 1 10rem;
    margin-left: auto;
    height: 6px;
    background: var(--bg-subtle);
    border-radius: 999px;
    overflow: hidden;
}
.cando-cat-bar-fill {
    display: block;
    height: 100%;
    background: var(--ok);
    border-radius: 999px;
}

/* ── Ladder ────────────────────────────────────────────────────── */
/* Colour encodes state: green = done (the filled track runs only up to
   the last done node), blue = licensed but not yet done, grey = locked.
   The ladder keeps a minimum width per node and scrolls inside its own
   box on a narrow card, so labels never collide. */
.cando-ladder-scroll {
    overflow-x: auto;
    padding: var(--space-4) var(--panel-padding) var(--space-2);
    scrollbar-width: thin;
}
.cando-ladder {
    position: relative;
    height: calc(64px / var(--dl-zoom));
    margin: 0 calc(48px / var(--dl-zoom));
    min-width: calc((var(--cando-n, 6) - 1) * 104px / var(--dl-zoom));
}
.cando-ladder-track,
.cando-ladder-track-fill {
    position: absolute;
    top: 8px;
    left: 0;
    height: 3px;
    border-radius: 999px;
}
.cando-ladder-track { right: 0; background: var(--border-strong); }
.cando-ladder-track-fill { background: var(--ok); pointer-events: none; }
.cando-ladder-node {
    position: absolute;
    top: 0;
    width: 0;
}
.cando-ladder-dot {
    position: absolute;
    top: 0;
    left: -9px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
    background: var(--bg-subtle);
    box-shadow: 0 0 0 1px var(--border-strong);
    z-index: 1;
}
.cando-ladder-node-done .cando-ladder-dot {
    background: var(--ok);
    box-shadow: 0 0 0 2px var(--ok);
}
.cando-ladder-node-licensed_not_done .cando-ladder-dot {
    background: var(--info);
    box-shadow: 0 0 0 2px var(--info);
}
.cando-ladder-node-current .cando-ladder-dot { transform: scale(1.2); }
.cando-ladder-label {
    position: absolute;
    top: 26px;
    left: 0;
    transform: translateX(-50%);
    width: calc(96px / var(--dl-zoom));
    font-size: var(--font-size-xs);
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}
.cando-ladder-node-done .cando-ladder-label,
.cando-ladder-node-current .cando-ladder-label { color: var(--text); }
.cando-ladder-node-licensed_not_done .cando-ladder-label { color: var(--info); }

/* ── Detail table ──────────────────────────────────────────────── */
/* Fixed layout + a colgroup: every category's table puts its columns at
   the same x, so "Done · date" and the course chips line up down the tab. */
.cando-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    margin: var(--space-2) 0 0;
}
.cando-col-status { width: calc(48px / var(--dl-zoom)); }
.cando-col-state  { width: 22%; }
.cando-col-gates  { width: 34%; }
.cando-row {
    border-top: 1px solid var(--border);
    vertical-align: top;
}
.cando-row:hover { background: var(--bg-subtle); }
.cando-row > td { padding: var(--space-3) var(--space-3); }
.cando-cell-status { padding-left: var(--panel-padding) !important; padding-right: 0 !important; }
.cando-row-done .cando-cell-status                { color: var(--ok); }
.cando-row-licensed_not_done .cando-cell-status   { color: var(--info); }
.cando-row-locked .cando-cell-status              { color: var(--text-subtle); }
.cando-cell-name { min-width: 0; }
.cando-row-name {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text);
}
.cando-row-locked .cando-row-name { color: var(--text-muted); }
.cando-row-desc {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 2px;
}
.cando-cell-state {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.cando-row-done .cando-cell-state              { color: var(--ok);   font-weight: 600; }
.cando-row-licensed_not_done .cando-cell-state { color: var(--info); font-weight: 600; }
.cando-cell-gates {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    align-content: flex-start;
    padding-right: var(--panel-padding) !important;
}
.cando-course-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: var(--font-size-xs);
    border: 1px solid var(--border);
    background: var(--bg-subtle);
    color: var(--text-muted);
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
}
.cando-course-done {
    color: var(--ok);
    border-color: var(--ok);
    background: var(--ok-soft);
}
.cando-course-none {
    font-size: var(--font-size-xs);
    color: var(--text-subtle);
    font-style: italic;
}

/* Phone: each capability row restacks — status | name, then state and
   chips under the name (they used to overflow the card edge). */
@media (max-width: 720px) {
    .cando-table, .cando-table tbody { display: block; }
    .cando-table colgroup { display: none; }
    .cando-row {
        display: grid;
        grid-template-columns: calc(40px / var(--dl-zoom)) minmax(0, 1fr);
        padding: var(--space-3) var(--space-4) var(--space-3) 0;
        row-gap: var(--space-1);
    }
    .cando-row > td { padding: 0 !important; display: block; }
    .cando-cell-status { grid-row: 1 / span 3; padding-left: var(--space-4) !important; }
    .cando-cell-name, .cando-cell-state, .cando-cell-gates { grid-column: 2; }
    .cando-cell-gates { display: flex !important; }
    .cando-cat-bar { display: none; }
    .cando-group > summary { flex-wrap: wrap; }
    .cando-group .cando-group-counter { margin-left: auto; }
    .cando-ladder { margin: 0 calc(40px / var(--dl-zoom)); }
}

/* ── Series chart card (dives.html) ──────────────────────────────── */
/* Per-dive series chart (cohort page, Trends tab). The card itself is a
   .dl-data-panel; these rules only style series-chart.js's insides. */
.series-card { margin: 0 0 var(--space-4); }
.series-card .channel-chips {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-2);
}
.series-card .channel-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--control-sm);
    padding: 0 var(--space-3);
    border-radius: 999px;
    background: var(--bg-subtle);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: var(--font-size-sm);
    user-select: none;
}
.series-card .channel-chip[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.series-card .channel-chip .swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}
.series-card .series-hint {
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    margin: var(--space-1) 0 var(--space-3);
}
.series-card .chart-wrap {
    position: relative;
    height: calc(380px / var(--dl-zoom));
}
.series-card canvas {
    width: 100% !important;
    height: 100% !important;
}
@media (max-width: 720px) {
    .series-card .channel-chip { min-height: var(--touch-target); }
    .series-card .chart-wrap { height: calc(300px / var(--dl-zoom)); }
}

/* Cohort clamp warning ("Selected 612 dives but the cohort was clamped
   to 500"). */
.stat-banner {
    background: var(--warn-soft);
    color: var(--warn);
    border: 1px solid var(--warn);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    margin: 0 0 var(--space-4);
}

/* ── Landmark modal ──────────────────────────────────────────────── */
.stat-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Above .dl-header (1000) — the sticky header is opaque and would cover
       the card's title row on a short viewport. */
    z-index: 1100;
}
.stat-modal-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 18px;
    width: min(720px, 92vw);
    max-height: 88vh;
    overflow: auto;
    border: 1px solid var(--border);
}
.stat-modal-card h3 {
    margin: 0 0 6px;
    font-size: 16px;
}
.stat-modal-card .modal-sub {
    opacity: 0.55;
    font-size: 12.5px;
    margin-bottom: 14px;
}
.stat-modal-card .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}
.lm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.lm-table th, .lm-table td {
    padding: 7px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    text-align: left;
    vertical-align: middle;
}
.lm-table th {
    font-weight: 600;
    opacity: 0.65;
    background: rgba(255,255,255,0.02);
}
.lm-table tr.is-user td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.lm-table tr.is-overridden td { opacity: 0.4; }
.lm-table td.depth { font-variant-numeric: tabular-nums; }
.lm-table td.actions {
    text-align: right;
    white-space: nowrap;
}
.lm-table td.actions .dlf-button { padding: 4px 10px; font-size: 12.5px; }
.lm-source {
    font-size: 11px;
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.lm-form {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 14px;
    align-items: end;
}
.lm-form .dlf-field { margin: 0; }
.lm-form .lm-form-actions { display: flex; gap: 6px; }

@media (max-width: 600px) {
    .landmark-row { grid-template-columns: 90px 1fr; }
    .lm-form { grid-template-columns: 1fr; }
}

/* ── SAC tab ──────────────────────────────────────────────────────── */
/* Dive-type scope switcher (All / Fun / Work): a pill-style segmented
   control sitting above the gauge. Distinct from the underline page
   tabs so it reads as a sub-filter of the SAC tab, not another tab
   strip. Selecting a scope re-renders the tab content below in place. */
/* Segmented control (SAC scope + calendar metric): sized to its
   content, never a full-width bar. */
.sac-scope {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    margin: 0 0 var(--space-4);
    padding: 3px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-width: 100%;
}
.sac-scope-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    min-height: var(--control-sm);
    padding: 0 var(--space-4);
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--duration-fast) var(--ease-standard),
                background var(--duration-fast) var(--ease-standard);
}
.sac-scope-btn:hover { color: var(--text); background: var(--accent-soft); }
/* Text on the accent fill always uses --text-on-accent (rule #5). */
.sac-scope-btn.is-active {
    color: var(--text-on-accent);
    background: var(--accent);
    border-color: var(--accent);
}
.sac-scope-btn.is-active:hover { color: var(--text-on-accent); }
.sac-scope-btn:focus-visible {
    outline: var(--focus-width) solid var(--focus-ring);
    outline-offset: var(--focus-offset);
}
@media (max-width: 720px) {
    .sac-scope-btn { min-height: var(--touch-target); }
}
.sac-scope-content { display: contents; }

/* Status card + the two trend cards side by side on desktop. */
.sac-overview {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    margin: 0 0 var(--space-4);
}
@media (min-width: 960px) {
    .sac-overview { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
}
.sac-status-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--panel-padding);
    min-width: 0;
}
.sac-status-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text);
}
.sac-status-title > .dl-icon { color: var(--text-muted); }
.sac-status-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
}
.sac-big-value {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.sac-rating-chip {
    padding: 2px var(--space-3);
    border-radius: 999px;
    font-size: var(--font-size-sm);
    font-weight: 700;
    border: 1px solid currentColor;
}
.sac-band-excellent, .sac-band-good { color: var(--ok);  background: var(--ok-soft); }
.sac-band-average                   { color: var(--accent); background: var(--accent-soft); }
.sac-band-high                      { color: var(--warn); background: var(--warn-soft); }
.sac-band-veryHigh                  { color: var(--err); background: var(--err-soft); }
.sac-status-basis {
    margin: var(--space-2) 0 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}
.sac-gauge { margin: var(--space-5) 0 var(--space-2); }
.sac-gauge-track {
    position: relative;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--ok), var(--warn) 55%, var(--err));
}
.sac-gauge-marker {
    position: absolute;
    top: 50%;
    width: 4px;
    height: 22px;
    border-radius: 2px;
    background: var(--text);
    box-shadow: 0 0 0 2px var(--bg-card);
    transform: translate(-50%, -50%);
}
/* The all-dive average: a hollow ring, so it can't be mistaken for the
   headline value. */
.sac-gauge-marker--all {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 3px solid var(--text-muted);
    box-shadow: none;
}
.sac-gauge-scale {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}
.sac-gauge-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    margin-top: var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}
.sac-gauge-legend__item { display: inline-flex; align-items: center; gap: var(--space-2); }
.sac-gauge-legend__swatch {
    width: 4px;
    height: 14px;
    border-radius: 2px;
    background: var(--text);
}
.sac-gauge-legend__swatch--all {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: transparent;
    border: 3px solid var(--text-muted);
}

.sac-stat-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-4);
    align-content: start;
}
@media (min-width: 960px) {
    .sac-stat-grid { grid-template-columns: minmax(0, 1fr); }
}
.sac-stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    min-width: 0;
}
.sac-stat-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-muted);
}
.sac-stat-value {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
    margin-top: var(--space-2);
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.sac-stat-value.is-good   { color: var(--ok); }
.sac-stat-value.is-bad    { color: var(--err); }
.sac-stat-value.is-steady { color: var(--text-muted); }
.sac-stat-value .dl-not-recorded { font-size: var(--font-size-sm); font-weight: 400; }
.sac-stat-dir {
    margin-top: 2px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
}
.sac-stat-caption {
    margin-top: var(--space-1);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════════════════
   §14 Statistics — hero, chart-card treatment, fade-in, tab transition
   ══════════════════════════════════════════════════════════════════════════ */


/* §14 chart card. Edited here rather than declared in dl-components.css,
   because this rule already exists and stat.css lazy-loads after browse.css —
   a second declaration elsewhere would lose the cascade tie. */
.chart-card {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}
@media (hover: hover) {
    .chart-card:not(.is-fullscreen):hover {
        box-shadow: var(--shadow-sm);
        border-color: var(--border-strong);
    }
}

/* Chart fade-in. `.is-revealed` is added by renderChartsForTab() once a tab's
   cards are built, so each card fades in exactly once — never on tab revisit,
   because the class persists. Cards start visible and only animate when the
   class lands, so a JS failure cannot leave the page blank. */
.chart-card.is-revealed { animation: dl-fade-up 420ms var(--ease-standard) both; }
@media (prefers-reduced-motion: reduce) {
    .chart-card.is-revealed { animation: none; }
}

/* Tab panel transition — opacity only. A transform would shift the Chart.js
   canvases and break pointer hit-testing, which this app already fights via
   dl-chart-pointer-fix.js. */
.stat-tab-panel:not([hidden]) { animation: dl-fade-in 220ms var(--ease-standard) both; }
@media (prefers-reduced-motion: reduce) {
    .stat-tab-panel:not([hidden]) { animation: none; }
}


/* WCAG 2.5.5 on touch. The ⛶ expand control rendered 21px wide — 16 of them per
   stat tab. It sits in the card header, so growing it does not move the chart. */
@media (max-width: 720px) {
    .chart-expand-btn {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
    }
}

/* ── Stat page: calendar tab ────────────────────────────────────── */
/* A year of real calendar days as a button grid. Geometry is the only
   literal in here; every colour is a token, so each theme gets a correct
   tint ramp for free (the fills themselves are computed at runtime in
   stat/calendar.js by blending --bg-elev toward --accent). */
:root {
    --stat-cal-cell: 13px;
    --stat-cal-gap: 3px;
}

.stat-cal-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 18px;
    border: 1px solid var(--border);
    margin: 16px 0;
}
.stat-cal-card h3 {
    margin: 0 0 12px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-cal-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}
.stat-cal-stepper {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}
.stat-cal-yearnow {
    min-width: 3.5rem;
    text-align: center;
    font-size: var(--font-size-md);
}
.stat-cal-yearsel {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-variant-numeric: tabular-nums;
}
.stat-cal-caret { font-size: 0.7em; opacity: .7; }
/* The metric pills reuse .sac-scope from the SAC tab; only the outer
   margin needs trimming so they sit on the toolbar line. */
.stat-cal-metric { margin: 0; }

.stat-cal-summary,
.stat-cal-note {
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    margin-bottom: var(--space-3);
}

/* The 53-column grid scrolls inside its own box rather than pushing the
   page wide. It never has to below 600 px — the month list takes over. */
.stat-cal-scroll { overflow-x: auto; }
.stat-cal-body {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-2);
    align-items: start;
    width: max-content;
}
.stat-cal-corner { width: 100%; }
.stat-cal-months-axis {
    display: grid;
    gap: var(--stat-cal-gap);
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1;
}
.stat-cal-months-axis > span { white-space: nowrap; }
.stat-cal-wdays {
    display: grid;
    grid-template-rows: repeat(7, var(--stat-cal-cell));
    gap: var(--stat-cal-gap);
    font-size: 10px;
    line-height: var(--stat-cal-cell);
    color: var(--text-subtle);
    text-align: right;
    padding-right: 2px;
}
.stat-cal-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(7, var(--stat-cal-cell));
    gap: var(--stat-cal-gap);
}

/* The 1px outline is what makes the cell legible at every tint — WCAG
   1.4.11 asks that the *shape* be discernible, and the lightest step of a
   sequential fill will not clear 3:1 against the card on its own. */
.stat-cal-cell {
    width: var(--stat-cal-cell);
    height: var(--stat-cal-cell);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 2px;
    cursor: pointer;
    transition: box-shadow var(--duration-fast) var(--ease-standard);
}
.stat-cal-cell:focus-visible {
    outline: var(--focus-width) solid var(--focus-ring);
    outline-offset: var(--focus-offset);
}
.stat-cal-cell.is-today { box-shadow: 0 0 0 1px var(--accent); }
.stat-cal-cell.is-selected {
    border-color: var(--accent-active);
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.stat-cal-pad {
    width: var(--stat-cal-cell);
    height: var(--stat-cal-cell);
}

.stat-cal-legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-3);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}
.stat-cal-legend-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}
.stat-cal-swatch {
    width: var(--stat-cal-cell);
    height: var(--stat-cal-cell);
    border: 1px solid var(--border);
    border-radius: 2px;
    flex: 0 0 auto;
}

/* ≤600 px fallback: twelve month rows with a sparkbar each. */
.stat-cal-monthlist { display: grid; gap: var(--space-1); }
.stat-cal-monthrow {
    display: grid;
    grid-template-columns: 6rem 1fr 2.5rem;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--touch-target);
    padding: 0 var(--space-2);
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.stat-cal-monthrow:hover:not(:disabled) { background: var(--bg-subtle); }
.stat-cal-monthrow:disabled { opacity: .45; cursor: default; }
.stat-cal-monthrow:focus-visible {
    outline: var(--focus-width) solid var(--focus-ring);
    outline-offset: var(--focus-offset);
}
.stat-cal-monthcount {
    text-align: right;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.stat-cal-sparktrack {
    height: 8px;
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.stat-cal-spark {
    display: block;
    height: 100%;
    background: var(--accent);
}

.stat-cal-detail-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-5);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}
.stat-cal-detail-head h4 { margin: 0; }
.stat-cal-day { margin-top: var(--space-4); }
.stat-cal-day.is-selected {
    border-left: 3px solid var(--accent);
    padding-left: var(--space-3);
    margin-left: calc(var(--space-3) * -1);
}
.stat-cal-day h4 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    font-size: var(--font-size-sm);
}
.stat-cal-row { cursor: pointer; }
.stat-cal-row:focus-visible {
    outline: var(--focus-width) solid var(--focus-ring);
    outline-offset: calc(var(--focus-offset) * -1);
}

@media (prefers-reduced-motion: reduce) {
    .stat-cal-cell { transition: none; }
}

/* ══════════════════════════════════════════════════════════════════════════
   04 Stat redesign — stat/index.html + stat/dives.html (stat/page.js).
   Everything below is scoped under body.stat-page: stat.css is also lazy-
   loaded on /browse/dive.html and by the lookups / site-picker modals, so
   .chart-card and friends must keep their old look there.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Shell: header → quick metrics → tabs ───────────────────────────── */
.stat-page .stat-header { margin-bottom: var(--space-4); }
.stat-page .stat-header .dl-page-header__meta { gap: var(--space-2) var(--space-4); }
.stat-page .stat-filter-chip { display: inline-flex; align-items: center; gap: var(--space-1); }
.stat-page .stat-filter-chip .dl-icon { color: var(--text-subtle); }
.stat-page .stat-headline { margin: 0 0 var(--space-4); }
.stat-page .stat-headline .dl-quick-metric__value { white-space: nowrap; }

/* Panels are display:contents; give their direct blocks a rhythm and let
   empty hosts collapse instead of adding gaps. */
.stat-page .stat-tab-panel > * { margin: 0 0 var(--space-5); }
.stat-page .stat-tab-panel > :empty { display: none; }
.stat-page .charts-groups { gap: var(--space-5); }
.stat-page .stat-tab-empty {
    color: var(--text-muted);
    font-size: var(--font-size-md);
    padding: var(--space-6) var(--space-4);
    text-align: center;
}
.stat-page .stat-muted { color: var(--text-muted); font-size: var(--font-size-sm); margin: 0; }

/* Phone: the tab strip is one scrolling row; a fade on the trailing edge
   says "there is more to the right". Mask is alpha-only (no colour). */
@media (max-width: 720px) {
    .stat-page .stat-tabs {
        margin-left: calc(var(--space-4) * -1);
        margin-right: calc(var(--space-4) * -1);
        padding: 0 var(--space-4);
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
                mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    }
    .stat-page .stat-tab { min-height: var(--touch-target); padding: 0 var(--space-3); }
}

/* ── Overview ───────────────────────────────────────────────────────── */
.stat-page .stat-overview { display: flex; flex-direction: column; gap: var(--space-4); }
.stat-insights {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}
.stat-insight {
    flex: 1 1 calc(14rem);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.stat-insight__label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    font-weight: 600;
}
.stat-insight__label .dl-icon { color: var(--accent); }
.stat-insight__value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.stat-insight__text { color: var(--text-muted); font-size: var(--font-size-sm); }

.stat-overview-charts {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
}
@media (min-width: 1040px) {
    .stat-overview-charts { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
}
.stat-ov-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4) var(--panel-padding) var(--panel-padding);
    min-width: 0;
}
.stat-ov-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}
.stat-ov-card__title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text);
}
.stat-ov-card__title .dl-icon { color: var(--text-muted); }
.stat-ov-card__desc { margin: 0; color: var(--text-muted); font-size: var(--font-size-sm); }
.stat-ov-chart {
    position: relative;
    height: calc(260px / var(--dl-zoom));
    min-width: 0;
}
.stat-ov-chart canvas { width: 100% !important; height: 100% !important; display: block; }
.stat-ov-card .chart-sub { font-size: var(--font-size-xs); color: var(--text-muted); }
.stat-ov-years {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-4);
    align-items: start;
}
.stat-ov-years__table {
    max-height: calc(260px / var(--dl-zoom));
    overflow: auto;
    min-width: 9rem;
}
.stat-ov-years__table thead th { position: sticky; top: 0; background: var(--bg-card); }
@media (max-width: 600px) {
    .stat-ov-years { grid-template-columns: minmax(0, 1fr); }
    .stat-ov-years__table { max-height: none; }
    .stat-ov-chart { height: calc(220px / var(--dl-zoom)); }
}

/* Key/value values with a muted second line ("Toni House Reef / 54 dives"). */
.stat-val { display: inline-flex; flex-direction: column; min-width: 0; }
.stat-val__main { color: var(--text); }
.stat-val__meta { color: var(--text-muted); font-size: var(--font-size-xs); font-weight: 400; }
.stat-kv .dl-kv__key { display: flex; align-items: center; gap: var(--space-1); }
.stat-kv .dl-kv__key .dl-icon { color: var(--text-subtle); flex: 0 0 auto; }
.stat-kv--warn .dl-kv__value,
.stat-kv--warn .stat-val__main { color: var(--warn); font-weight: 700; }
.stat-panel--warn { border-color: var(--warn); }
.stat-page .stat-panel .dl-data-panel__header .dl-state-badge { margin-left: auto; }

/* ── Details: metric table ─────────────────────────────────────────── */
.stat-metric-table { font-variant-numeric: tabular-nums; }
.stat-metric-table th[scope="row"] { font-weight: 600; white-space: nowrap; color: var(--text); }
.stat-metric-table th[scope="row"] .dl-icon {
    vertical-align: -3px;
    margin-right: var(--space-2);
    color: var(--text-subtle);
}
.stat-metric-table td { white-space: nowrap; }
.stat-metric-table td .dl-not-recorded { font-size: var(--font-size-xs); }
.stat-metric-na::after { content: "·"; color: var(--text-subtle); }
@media (max-width: 600px) {
    /* Each metric becomes a small block: name, then the four figures
       with their own labels. */
    .stat-metric-table thead { display: none; }
    .stat-metric-table, .stat-metric-table tbody { display: block; }
    .stat-metric-table tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-1) var(--space-3);
        padding: var(--space-3) 0;
        border-bottom: 1px solid var(--border);
    }
    .stat-metric-table th[scope="row"] { grid-column: 1 / -1; border: 0; padding: 0; }
    .stat-metric-table td { border: 0; padding: 0; text-align: left; display: flex; justify-content: space-between; gap: var(--space-2); }
    .stat-metric-table td::before { content: attr(data-label); color: var(--text-muted); font-size: var(--font-size-xs); }
    .stat-metric-table td.stat-metric-na { display: none; }
    .stat-metric-table tbody tr:hover { background: none; }
}

/* ── Records tab ───────────────────────────────────────────────────── */
.stat-records {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}
.stat-record {
    flex: 1 1 calc(25% - var(--space-3));
    min-width: calc(11rem);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.stat-record__label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    font-weight: 600;
}
.stat-record__label .dl-icon { color: var(--accent); flex: 0 0 auto; }
.stat-record__value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.stat-record__meta { font-size: var(--font-size-xs); color: var(--text-muted); }
.stat-page .stat-section > .dl-section-header { margin-bottom: var(--space-3); }

.stat-next { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-5); }
.stat-next__top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.stat-next__label { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 600; color: var(--text); }
.stat-next__label .dl-icon { color: var(--text-muted); }
.stat-next__value { font-size: var(--font-size-lg); font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-next__meta { font-size: var(--font-size-sm); color: var(--text-muted); }
.stat-progress {
    height: 8px;
    background: var(--bg-subtle);
    border-radius: 999px;
    overflow: hidden;
}
.stat-progress__fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

.stat-ladders {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
    gap: var(--space-5) var(--space-6);
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}
.stat-timeline__title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-muted);
}
.stat-timeline__list { list-style: none; margin: 0; padding: 0; }
.stat-timeline__item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) 0 var(--space-2) var(--space-5);
}
.stat-timeline__item::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-strong);
}
.stat-timeline__item:first-child::before { top: 50%; }
.stat-timeline__item:last-child::before  { bottom: 50%; }
.stat-timeline__item:only-child::before  { display: none; }
.stat-timeline__item::after {
    content: "";
    position: absolute;
    left: 1px;
    top: calc(50% - 5px);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--bg-card);
}
.stat-timeline__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
}
a.stat-timeline__main:hover .stat-timeline__name { color: var(--accent); text-decoration: underline; }
.stat-timeline__name { font-weight: 600; overflow-wrap: anywhere; }
.stat-timeline__meta { font-size: var(--font-size-xs); color: var(--text-muted); }
.stat-timeline__value {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stat-highlights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr));
    gap: var(--space-4);
    align-items: start;
}
.stat-runners { margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.stat-runners__title { margin: 0 0 var(--space-2); font-size: var(--font-size-xs); font-weight: 600; color: var(--text-muted); }
.stat-runners__list { margin: 0; padding: 0 0 0 var(--space-5); display: grid; gap: var(--space-1); }
.stat-runners__list li { display: flex; justify-content: space-between; gap: var(--space-3); }
.stat-runners__name { color: var(--text); overflow-wrap: anywhere; }
.stat-runners__count { color: var(--text-muted); font-size: var(--font-size-sm); white-space: nowrap; }

.stat-landmarks__total {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}
.stat-landmarks__value { font-size: var(--font-size-2xl); font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-landmarks__label { color: var(--text-muted); font-size: var(--font-size-sm); }
.stat-page .stat-landmarks .dl-data-panel__actions { margin-left: auto; }

/* ── Chart groups + cards ───────────────────────────────────────────── */
/* A group is a section title above its cards, not a box around boxes. */
.stat-page .chart-group {
    border: 0;
    background: none;
    padding: 0;
    border-radius: 0;
}
.stat-page .chart-group-summary {
    padding: 0;
    min-height: var(--touch-target);
    gap: var(--space-2);
    font-size: var(--font-size-lg);
    font-weight: 600;
    opacity: 1;
    border-bottom: 1px solid var(--border);
}
.stat-page .chart-group-count {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-weight: 400;
}
.stat-page .chart-group-caret {
    margin-left: auto;
    display: inline-flex;
    opacity: 1;
    font-size: inherit;
    color: var(--text-muted);
    transition: transform var(--duration-fast) var(--ease-standard);
}
.stat-page .chart-group .charts-grid { margin: var(--space-3) 0 0; gap: var(--space-4); }
@media (min-width: 880px) {
    .stat-page .charts-grid--odd > .chart-card:last-child { grid-column: 1 / -1; }
}
.stat-page .chart-card {
    height: calc(320px / var(--dl-zoom));
    padding: var(--space-3) var(--space-4) var(--space-4);
    border-radius: var(--radius-lg);
}
.stat-page .chart-card h4 {
    opacity: 1;
    color: var(--text);
    font-size: var(--font-size-md);
    font-weight: 600;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    min-height: var(--control-sm);
}
.stat-page .chart-card h4 .card-icon { color: var(--text-muted); }
.stat-page .chart-card .chart-sub {
    opacity: 1;
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    margin-top: var(--space-2);
}
.stat-page .chart-card .dl-btn.chart-expand-btn {
    width: var(--control-sm);
    min-width: var(--control-sm);
    height: var(--control-sm);
    min-height: var(--control-sm);
    margin: calc(var(--space-1) * -1) calc(var(--space-2) * -1) calc(var(--space-1) * -1) auto;
}
@media (max-width: 720px) {
    .stat-page .chart-card { height: calc(280px / var(--dl-zoom)); }
    .stat-page .chart-card .dl-btn.chart-expand-btn {
        width: var(--touch-target);
        min-width: var(--touch-target);
        height: var(--touch-target);
        min-height: var(--touch-target);
    }
}

/* Single-category charts become facts at the top of their group. */
.chart-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin: var(--space-3) 0 0;
}
.chart-fact {
    flex: 1 1 calc(14rem);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.chart-fact__title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
}
.chart-fact__value {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text);
    overflow-wrap: anywhere;
}
.chart-fact__note { font-size: var(--font-size-xs); color: var(--text-subtle); }

/* ── Calendar ──────────────────────────────────────────────────────── */
.stat-page #calendar-host { container-type: inline-size; }
.stat-page .stat-cal-card {
    margin: 0;
    padding: var(--space-4) var(--panel-padding) var(--panel-padding);
    border-radius: var(--radius-lg);
}
/* Cells grow with the card (53 week columns + the weekday gutter) up
   to 22 px, so the year fills the card instead of ~55 % of it. */
@supports (width: 1cqi) {
    .stat-page .stat-cal-card {
        --stat-cal-cell: clamp(12px, calc((100cqi - 7rem) / 53 - var(--stat-cal-gap)), 22px);
    }
}
.stat-page .stat-cal-card h3.stat-cal-title {
    text-transform: none;
    letter-spacing: 0;
    opacity: 1;
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text);
}
.stat-page .stat-cal-card h3.stat-cal-title > .dl-icon { color: var(--text-muted); }
.stat-page .stat-cal-stepper { gap: var(--space-1); }
.stat-page .stat-cal-yearsel { min-width: 6rem; justify-content: center; font-weight: 700; }
.stat-page .stat-cal-caret { display: inline-flex; opacity: 1; color: var(--text-muted); }
.stat-page .stat-cal-summary { font-size: var(--font-size-sm); color: var(--text); }
.stat-page .stat-cal-months-axis,
.stat-page .stat-cal-wdays { font-size: var(--font-size-xs); }
.stat-page .stat-cal-hint { margin: var(--space-4) 0 0; color: var(--text-muted); font-size: var(--font-size-sm); }

/* ── Courses (cohort tab) ──────────────────────────────────────────── */
.stat-page .courses-card .dl-data-panel__body { padding-top: var(--space-3); }

/* ── Print / reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .stat-page .chart-group-caret,
    .cando-group-caret { transition: none; }
}
.stat-page .courses-card { padding: 0; margin: 0; border-radius: var(--radius-lg); }
.chart-facts__note {
    flex: 1 0 100%;
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--text-subtle);
}
.stat-page .charts-groups > .sac-scope,
.stat-page .sac-scope { align-self: flex-start; }
.stat-timeline__list.is-folded > .stat-timeline__item:nth-child(6)::before { bottom: 0; }
.stat-timeline > .dl-btn { margin-top: var(--space-1); }
@media (max-width: 600px) {
    .stat-insights { gap: var(--space-2); }
    .stat-insight { flex: 1 1 calc(50% - var(--space-2)); padding: var(--space-3); }
    .stat-insight__value { font-size: var(--font-size-lg); }
    .stat-insight__text { font-size: var(--font-size-xs); }
    .stat-records { gap: var(--space-2); }
    .stat-record { flex: 1 1 calc(50% - var(--space-2)); padding: var(--space-3); }
    .stat-record__value { font-size: var(--font-size-lg); }
}
@media (max-width: 600px) {
    .stat-metric-table th[scope="row"],
    .stat-metric-table td { height: auto; min-height: 0; line-height: 1.4; }
    .sac-stat-value { font-size: var(--font-size-lg); }
}

/* ── TV mode (tasks/missing/tv/04-stat) ──────────────────────────────── */
/* Every selector under .dl-tv; sizes only, colours from tokens (rule #5).
   Old TV engines understand grid-gap, not gap, on a grid — each grid the
   TV inherits gets the legacy alias with the same value. No inset, no
   raw vh (var(--tv-vh)). */
.dl-tv .charts-grid {
    grid-template-columns: 1fr 1fr;     /* even if the WebView reports < 880 px */
    grid-gap: 16px;
}
.dl-tv .chart-card {
    height: calc(42 * var(--tv-vh));   /* two card rows ≈ one screen */
    min-height: 280px;
}
.dl-tv .chart-card h4 { font-size: var(--font-size-md); opacity: 0.85; }
.dl-tv .chart-card[data-tv-card] { cursor: default; }
.dl-tv .chart-group-caret { display: none; }
.dl-tv .chart-modal {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: calc(100 * var(--tv-vh));
    padding: var(--tv-safe-y) var(--tv-safe-x);
}
.dl-tv .chart-modal.is-focused { outline: none; }
.dl-tv .chart-modal-host { max-width: none; }
.dl-tv .chart-modal-host > .chart-card.is-fullscreen { transform: none; }
/* TV spacing pass: inset into the card's corner instead of sitting on it
   (the card starts at the same safe-area edge the button was pinned to). */
.dl-tv .chart-modal-close {
    top: calc(var(--tv-safe-y) + var(--space-3));
    right: calc(var(--tv-safe-x) + var(--space-3));
}
.dl-tv .stat-cal-card { --stat-cal-cell: 16px; }
.dl-tv .stat-cal-body { grid-gap: var(--space-2); }
.dl-tv .stat-cal-grid,
.dl-tv .stat-cal-wdays,
.dl-tv .stat-cal-months-axis { grid-gap: var(--stat-cal-gap); }
.dl-tv .stat-cal-cell.is-focused { outline-offset: 0; }
.dl-tv .stat-tab { min-height: var(--control-lg); }
/* The strip scrolls horizontally (overflow-x: auto clips both axes), so it
   needs room inside it for the 4 px ring + 4 px offset of a focused tab. */
.dl-tv .stat-tabs { padding: calc(var(--tv-focus-width) + var(--tv-focus-offset)); }
