/* Colors come from the validated reference palette: light and dark are separate steps of the
   same hues, chosen for their own surface, not an automatic flip. */
:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --ink: #0b0b0b;
    --ink-secondary: #52514e;
    --ink-muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --wash: rgba(11, 11, 11, 0.04);
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --critical: #d03b3b;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --ink: #f0efec;
        --ink-secondary: #c3c2b7;
        --ink-muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --wash: rgba(255, 255, 255, 0.05);
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-secondary: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font: 15px/1.45 var(--font);
}

.page {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

h1, h2, p {
    margin: 0;
}

/* ------------------------------------------------------------------ header and filters */

.top {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 20px;
}

h1 {
    font-size: 26px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.subtitle, .note, .section-note {
    color: var(--ink-secondary);
    font-size: 13px;
}

.actions {
    display: flex;
    gap: 8px;
}

.button, .segmented button, .table-toggle {
    font: inherit;
    font-size: 13px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
}

.button:hover, .table-toggle:hover {
    background: var(--wash);
}

button:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--series-1);
    outline-offset: 2px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    margin-bottom: 20px;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    padding: 2px;
}

.segmented button {
    border: 0;
    border-radius: 7px;
    background: transparent;
}

.segmented button:hover {
    background: var(--wash);
}

.segmented button[aria-checked="true"] {
    background: var(--ink);
    color: var(--surface);
    font-weight: 600;
}

.banner {
    border: 1px solid var(--critical);
    border-left-width: 4px;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 20px;
    background: var(--surface);
}

.banner::before {
    content: "⚠ ";
    color: var(--critical);
    font-weight: 700;
}

/* While data reloads, the previous render stays, dimmed: no skeletons, no layout jump. */
#content {
    transition: opacity 120ms ease;
}

#content.loading {
    opacity: 0.6;
}

/* ------------------------------------------------------------------ stat tiles */

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.tile, .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    margin: 0;
    min-width: 0;
}

.tile-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tile-value {
    font-size: 32px;
    font-weight: 600;
    margin-top: 6px;
    line-height: 1.1;
}

.tile.hero .tile-value {
    font-size: 48px;
}

.tile-sub {
    color: var(--ink-muted);
    font-size: 12px;
    margin-top: 4px;
}

/* A short stroke of the series color beside the text carries identity; text stays ink. */
.key {
    display: inline-block;
    width: 14px;
    height: 3px;
    border-radius: 2px;
    flex: none;
}

.key.series-1 {
    background: var(--series-1);
}

.key.series-2 {
    background: var(--series-2);
}

.key.series-3 {
    background: var(--series-3);
}

/* ------------------------------------------------------------------ chart cards */

.charts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.card.wide {
    grid-column: 1 / -1;
}

@media (max-width: 760px) {
    .charts {
        grid-template-columns: minmax(0, 1fr);
    }
}

.card-head {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 8px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
}

.card-sub {
    color: var(--ink-secondary);
    font-size: 12px;
    margin-top: 2px;
}

.table-toggle {
    padding: 3px 10px;
    font-size: 12px;
    white-space: nowrap;
}

.plot {
    position: relative;
    width: 100%;
}

.plot svg {
    display: block;
    width: 100%;
    overflow: visible;
}

.plot svg:focus-visible {
    outline: 2px solid var(--series-1);
    outline-offset: 4px;
    border-radius: 4px;
}

.empty {
    color: var(--ink-muted);
    font-size: 13px;
    padding: 48px 0;
    text-align: center;
}

.axis-label {
    fill: var(--ink-muted);
    font: 11px var(--font);
    font-variant-numeric: tabular-nums;
}

.end-label {
    fill: var(--ink-secondary);
    font: 600 12px var(--font);
}

.gridline {
    stroke: var(--grid);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.baseline {
    stroke: var(--axis);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.crosshair {
    stroke: var(--ink-muted);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.series-line {
    fill: none;
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.series-area {
    stroke: none;
    fill-opacity: 0.1;
}

.series-1 {
    --color: var(--series-1);
}

.series-2 {
    --color: var(--series-2);
}

.series-3 {
    --color: var(--series-3);
}

.series-line, .series-area, .series-dot, .bar-fill {
    color: var(--color);
}

.series-line {
    stroke: currentColor;
}

.series-area, .series-dot {
    fill: currentColor;
}

.series-dot {
    stroke: var(--surface);
    stroke-width: 2;
}

/* ------------------------------------------------------------------ table views */

.table-view {
    max-height: 320px;
    overflow: auto;
    border-top: 1px solid var(--grid);
    margin-top: 8px;
}

.table-view table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table-view th, .table-view td {
    text-align: left;
    padding: 5px 8px;
    border-bottom: 1px solid var(--grid);
}

.table-view th {
    position: sticky;
    top: 0;
    background: var(--surface);
    color: var(--ink-secondary);
    font-weight: 600;
}

.table-view td.number, .table-view th.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ metadata */

.section-title {
    font-size: 18px;
    font-weight: 600;
}

.section-note {
    margin: 2px 0 12px;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

.bars {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 4px 6px;
    margin: 0 -6px;
    border-radius: 6px;
    font-size: 13px;
}

.bar-row:hover, .bar-row:focus-visible {
    background: var(--wash);
}

.bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
}

.bar-label.other {
    color: var(--ink-secondary);
    font-style: italic;
}

.bar-track {
    height: 12px;
    position: relative;
}

.bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    min-width: 2px;
    background: currentColor;
    /* Rounded at the data end, square at the baseline. */
    border-radius: 0 4px 4px 0;
}

.bar-value {
    color: var(--ink-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ tooltip */

.tooltip {
    position: fixed;
    z-index: 10;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: 8px 10px;
    font-size: 12px;
    max-width: 280px;
}

.tooltip .tip-title {
    color: var(--ink-secondary);
    margin-bottom: 4px;
}

.tooltip .tip-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip .tip-value {
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
}

.tooltip .tip-name {
    color: var(--ink-secondary);
}

@media (forced-colors: active) {
    .series-line {
        stroke: CanvasText;
    }

    .bar-fill, .key {
        background: CanvasText;
    }
}
