:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface-1: #fcfcfb;
    --surface-2: #f0efec;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --accent: #2a78d6;
    --accent-ink: #ffffff;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --good: #006300;
    --critical: #d03b3b;
    --warning-bg: #fff4dc;
    /* sequential blue, near-zero -> max */
    --seq-0: #cde2fb; --seq-1: #b7d3f6; --seq-2: #9ec5f4; --seq-3: #86b6ef; --seq-4: #6da7ec;
    --seq-5: #5598e7; --seq-6: #3987e5; --seq-7: #2a78d6; --seq-8: #256abf; --seq-9: #1c5cab;
    --seq-10: #184f95; --seq-11: #104281; --seq-12: #0d366b;
    --radius: 10px;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface-1: #1a1a19;
        --surface-2: #232321;
        --text-primary: #f0efec;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --accent: #3987e5;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --series-4: #c98500;
        --good: #0ca30c;
        --critical: #e66767;
        --warning-bg: #3a2e12;
        --seq-0: #0d366b; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf;
        --seq-5: #2a78d6; --seq-6: #3987e5; --seq-7: #5598e7; --seq-8: #6da7ec; --seq-9: #86b6ef;
        --seq-10: #9ec5f4; --seq-11: #b7d3f6; --seq-12: #cde2fb;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --good: #0ca30c;
    --critical: #e66767;
    --warning-bg: #3a2e12;
    --seq-0: #0d366b; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf;
    --seq-5: #2a78d6; --seq-6: #3987e5; --seq-7: #5598e7; --seq-8: #6da7ec; --seq-9: #86b6ef;
    --seq-10: #9ec5f4; --seq-11: #b7d3f6; --seq-12: #cde2fb;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--page);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
}

main {
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

h1:focus { outline: none; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 4px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 0.85rem; }
code { font-size: 0.85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

.app-header {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.app-header .tagline { color: var(--text-secondary); margin: 2px 0 0; }

.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}
.card-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-head p { margin: 0; }

/* segmented control */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.segmented button {
    border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-size: 0.9rem;
    padding: 6px 14px; border-radius: 6px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

/* drop zone */
.dropzone {
    position: relative; border: 1.5px dashed var(--axis); border-radius: var(--radius);
    padding: 28px 16px; text-align: center; background: var(--surface-1); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--surface-2); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone strong { display: block; font-size: 1.05rem; margin-bottom: 4px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.excluded td { color: var(--text-muted); }

.badge { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.badge.warn { background: var(--warning-bg); color: var(--text-primary); }
.badge.error { color: var(--critical); }

button.link { border: 0; background: none; color: var(--text-muted); cursor: pointer; font: inherit; padding: 2px 6px; }
button.link:hover { color: var(--critical); }
button.secondary-btn { border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); border-radius: 6px; padding: 5px 12px; font: inherit; font-size: 0.85rem; cursor: pointer; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: 0.82rem; }
.tile .value { font-size: 1.5rem; font-weight: 600; }
.tile .sub { color: var(--text-muted); font-size: 0.8rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 16px; }

/* charts */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
.chart .axis-title { fill: var(--text-secondary); font-size: 12px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; }
.heat-cell { shape-rendering: crispEdges; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.82rem; color: var(--text-secondary); margin-top: 6px; }
.legend .key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 6px; }
.ramp { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--text-muted); margin-top: 6px; }
.ramp .bar { flex: 0 1 140px; height: 8px; border-radius: 4px; }
.tooltip-box rect { fill: var(--surface-1); stroke: var(--border); }
.tooltip-box text { fill: var(--text-primary); font-size: 11.5px; }

/* traits */
.traits { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 10px; }
.traits li { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.traits strong { display: block; font-size: 0.92rem; }
.traits span { color: var(--text-secondary); font-size: 0.85rem; }

/* recommendation */
.rec-values td.num strong { font-size: 1.05rem; }
.delta { font-size: 0.78rem; color: var(--text-muted); margin-left: 6px; }
.reasons { margin: 6px 0 0; padding-left: 18px; color: var(--text-secondary); font-size: 0.85rem; }
.reasons li { margin-bottom: 3px; }
.preview-note { font-size: 0.8rem; color: var(--text-muted); }

.error-banner { background: var(--warning-bg); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: 0.9rem; }

.empty { text-align: center; padding: 40px 16px; color: var(--text-secondary); }

footer { margin-top: 32px; font-size: 0.8rem; color: var(--text-muted); text-align: center; }

#blazor-error-ui {
    background: var(--warning-bg); color: var(--text-primary); bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.loading-progress { position: absolute; display: block; width: 6rem; height: 6rem; inset: 30vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: var(--grid); stroke-width: 0.5rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
    stroke: var(--accent); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(30vh + 3.25rem) 0 auto 0.2rem; color: var(--text-secondary); }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

.brand { display: flex; align-items: center; gap: 14px; }
.brand img { flex: none; border-radius: 11px; }
.segmented .count { margin-left: 6px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--text-secondary); border-radius: 99px; padding: 0 7px; }
.segmented button[aria-pressed="true"] .count { background: var(--accent); color: var(--accent-ink); }
footer p { margin: 0 0 4px; }
footer strong { color: var(--text-secondary); font-weight: 600; }
