/* Statistics dashboard (screen/statistics.html). App-wide tokens come from
   shared-tokens.css; the --s* chart colours below are the validated
   categorical palette (slots 1-5, adjacent-pair CVD/normal-vision checked
   against this app's card surface in both modes). Dark values are their own
   selected steps, not an automatic flip. */

.stats {
    --s1: #2a78d6;
    --s2: #eb6834;
    --s3: #1baf7a;
    --s4: #eda100;
    --s5: #e87ba4;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --ink-muted: #898781;
    --delta-up: #006300;
    --delta-down: #b91c1c;
}
@media (prefers-color-scheme: dark) {
    .stats {
        --s1: #3987e5;
        --s2: #d95926;
        --s3: #199e70;
        --s4: #c98500;
        --s5: #d55181;
        --grid: #2c2c2a;
        --axis: #383835;
        --delta-up: #4ade80;
        --delta-down: #f87171;
    }
}

.stats-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.stats-head h1 { margin: 0; }
.stats-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.stats-filters select { width: auto; min-width: 150px; }

#stats-root { transition: opacity 0.15s; }
#stats-root.refreshing { opacity: 0.55; pointer-events: none; }

.stats-note {
    font-size: 0.85rem; color: var(--text-muted); background: var(--callout-bg);
    border: 1px solid var(--callout-border); border-radius: var(--radius);
    padding: 10px 14px; margin-bottom: 16px;
}

/* ---- KPI tiles ---- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.kpi-label { font-size: 0.85rem; color: var(--text-muted); }
.kpi-value { font-size: 1.9rem; font-weight: 600; line-height: 1.15; }
.kpi-sub { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 1.2em; }
.kpi-spark { margin-top: 6px; height: 28px; }

.delta { font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--delta-up); }
.delta.down { color: var(--delta-down); }
.delta.flat, .delta.new { color: var(--text-muted); }

/* ---- Chart cards ---- */
.stats .card h2 { margin-bottom: 4px; }
.card-sub { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 12px; }
.chart-host { position: relative; width: 100%; }
.chart-host svg { display: block; width: 100%; overflow: visible; }
.chart-host svg:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 4px; }
.chart-grid line { stroke: var(--grid); stroke-width: 1; }
.chart-axis line { stroke: var(--axis); stroke-width: 1; }
.chart-tick { fill: var(--ink-muted); font-size: 11px; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-cursor { stroke: var(--axis); stroke-width: 1; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 8px; font-size: 0.85rem; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; color: var(--text); min-width: 0; max-width: 100%; }
.legend-item .key { width: 14px; height: 2px; border-radius: 2px; flex-shrink: 0; }
.legend-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Legend text stays in ink: the app's link colour is orange, which would read as a series colour. */
.legend-item a.label { color: var(--text); }
.legend-item a.label:hover { color: var(--primary); }

.tip {
    position: fixed; z-index: 5; pointer-events: none; min-width: 140px; max-width: 280px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.tip[hidden] { display: none; }
.tip-title { color: var(--text-muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.tip-row .key { width: 12px; height: 2px; border-radius: 2px; flex-shrink: 0; }
.tip-row strong { font-weight: 600; }
.tip-row .name { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details.table-view { margin-top: 10px; font-size: 0.85rem; }
details.table-view summary { cursor: pointer; color: var(--text-muted); width: fit-content; }
details.table-view .table-scroll { max-height: 260px; overflow: auto; margin-top: 8px; }

/* ---- Tables ---- */
.stats table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.stats th {
    text-align: left; font-weight: 600; font-size: 0.78rem; color: var(--text-muted);
    padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.stats td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.stats tr:last-child td { border-bottom: none; }
.stats .num { text-align: right; font-variant-numeric: tabular-nums; }
.stats th.num { text-align: right; }
.stats th button.sort {
    background: none; border: none; color: inherit; font: inherit; padding: 0; cursor: pointer; margin: 0;
}
.stats th button.sort:hover { color: var(--text); background: none; }
.stats th button.sort[aria-pressed=true] { color: var(--primary); }
.stats .title-cell { max-width: 340px; }
.stats .title-cell a { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.type-tag { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.table-wrap { overflow-x: auto; }
.table-foot { margin-top: 10px; }
.muted-cell { color: var(--text-muted); }
.spark-cell { width: 96px; }

/* ---- Heatmap ---- */
.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(10px, 1fr)); gap: 2px; min-width: 460px; }
.heat-cell { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--surface-alt); min-height: 12px; }
.heat-cell.on:hover, .heat-cell:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.heat-label { font-size: 0.7rem; color: var(--ink-muted); display: flex; align-items: center; }
.heat-hours { font-size: 0.7rem; color: var(--ink-muted); }
.heat-legend { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.75rem; color: var(--text-muted); }
.heat-legend .ramp { display: flex; gap: 2px; }
.heat-legend .ramp span { width: 18px; height: 10px; border-radius: 2px; }

/* ---- Attention lists ---- */
.attn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.attn-grid .card { margin-bottom: 0; }
.attn-list { list-style: none; margin: 0; padding: 0; }
.attn-list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.attn-list li:last-child { border-bottom: none; }
.attn-list a { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attn-list .why { font-size: 0.8rem; color: var(--text-muted); }
.attn-empty { color: var(--text-muted); font-size: 0.85rem; padding: 8px 0; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.two-col > div h3 { font-size: 0.95rem; margin: 0 0 6px; }

.comment-list { list-style: none; margin: 0; padding: 0; }
.comment-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment-list li:last-child { border-bottom: none; }
.comment-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 2px; }
.request-note { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; overflow-wrap: anywhere; }
.comment-vote { font-weight: 600; }
.comment-vote.up { color: var(--delta-up); }
.comment-vote.down { color: var(--delta-down); }

/* ---- "Not in any collection" card ---- */
.orphan-suggestion { margin-top: 6px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.orphan-suggestion .comment-meta { margin-bottom: 0; }
#orphaned-new-groups:empty { display: none; }
#orphaned-new-groups li { background: var(--surface-alt); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; border-bottom: none; }
#orphaned-new-groups li button { margin-top: 8px; }

@media (max-width: 640px) {
    .stats .hide-sm { display: none; }
    .stats .title-cell { max-width: 150px; }
    .stats .title-cell a { white-space: normal; overflow-wrap: anywhere; }
    .stats th, .stats td { padding-left: 6px; padding-right: 6px; }
    .kpi-value { font-size: 1.6rem; }
}
