:root {
    color-scheme: light dark;

    --ink: #12161c;
    --ink-soft: #566274;
    --ink-faint: #8b95a5;
    --surface: #ffffff;
    --surface-sunken: #f4f6f9;
    --surface-raised: #ffffff;
    --line: #dfe4ec;
    --line-soft: #eef1f6;
    --accent: #2f6df6;
    --accent-soft: #e7eeff;
    --ok: #128a52;
    --warn: #b06c00;
    --bad: #c8302f;
    --bar: #c7d8ff;
    --radius: 10px;
    --shadow: 0 1px 2px rgb(18 22 28 / 6%), 0 8px 24px rgb(18 22 28 / 5%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --ink: #e8ecf3;
        --ink-soft: #9aa5b5;
        --ink-faint: #6d788a;
        --surface: #12161c;
        --surface-sunken: #0d1116;
        --surface-raised: #191f27;
        --line: #2a323d;
        --line-soft: #202730;
        --accent: #6c9bff;
        --accent-soft: #1b2740;
        --ok: #4cc38a;
        --warn: #e0a33b;
        --bad: #f0736f;
        --bar: #2b3d63;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--surface-sunken);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1, h2, h3 {
    color: var(--ink);
    font-weight: 650;
    letter-spacing: -0.01em;
    margin: 0;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }

code, .mono {
    font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.92em;
}

/* ---------- shell ---------- */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 0 1.5rem;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink);
    font-weight: 680;
}

.app-brand:hover {
    text-decoration: none;
}

.app-brand-mark {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.app-nav {
    display: flex;
    gap: 0.25rem;
}

.app-nav-link {
    padding: 0.3rem 0.7rem;
    border-radius: 7px;
    color: var(--ink-soft);
    font-weight: 500;
}

.app-nav-link:hover {
    background: var(--surface-sunken);
    color: var(--ink);
    text-decoration: none;
}

.app-nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.5rem;
}

.app-footer {
    padding: 1rem 1.5rem 1.5rem;
    color: var(--ink-faint);
    font-size: 12px;
    text-align: center;
}

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

.card-plain {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-plain + .card-plain {
    margin-top: 1rem;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--line-soft);
}

.card-body {
    padding: 1.1rem;
}

.muted {
    color: var(--ink-soft);
}

.faint {
    color: var(--ink-faint);
}

.tiny {
    font-size: 12px;
}

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

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0.75rem;
}

.stat-tile {
    padding: 0.85rem 1rem;
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.stat-label {
    color: var(--ink-soft);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stat-value {
    margin-top: 0.15rem;
    font-size: 1.4rem;
    font-weight: 660;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.stat-hint {
    color: var(--ink-faint);
    font-size: 12px;
}

/* ---------- tables ---------- */

/*
 * Setting overflow on one axis makes the computed value of the other `auto`, so this element is
 * the scroll container the sticky header below positions against — not the viewport. It therefore
 * needs a height bound to actually scroll, and the header's offset has to be 0 rather than the
 * height of the app bar; a non-zero offset pushes the header down past the first row instead of
 * pinning it.
 */
.table-wrap {
    max-height: 70vh;
    overflow: auto;
}

/* A scrolling child would otherwise square off the card's bottom corners. */
.card-plain > .table-wrap:last-child {
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

table.report {
    width: 100%;
    /* `collapse` hands the borders to the table rather than to the cells, and the header's
       bottom border is then left behind the moment it starts sticking. */
    border-collapse: separate;
    border-spacing: 0;
    font-variant-numeric: tabular-nums;
}

table.report th {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 0.5rem 0.65rem;
    background: var(--surface-raised);
    border-bottom: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}

table.report td {
    padding: 0.4rem 0.65rem;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: top;
}

table.report tbody tr:hover {
    background: var(--surface-sunken);
}

table.report tbody tr.selected {
    background: var(--accent-soft);
}

.num {
    text-align: right;
    white-space: nowrap;
}

.rank {
    width: 2.6rem;
    color: var(--ink-faint);
    text-align: right;
}

.cell-primary {
    font-weight: 560;
    word-break: break-all;
}

.cell-secondary {
    color: var(--ink-soft);
    font-size: 12px;
}

.clip {
    display: block;
    max-width: 46ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A share bar drawn behind the percentage, so scanning the column shows the distribution. */
.share {
    position: relative;
    min-width: 5.5rem;
}

.share-bar {
    position: absolute;
    inset: 0.25rem auto 0.25rem 0;
    border-radius: 3px;
    background: var(--bar);
}

.share-text {
    position: relative;
}

.pill {
    display: inline-block;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.pill-ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill-bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill-flat { background: var(--surface-sunken); color: var(--ink-soft); }

/* ---------- controls ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.field > label {
    color: var(--ink-soft);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.field input,
.field select {
    padding: 0.3rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--ink);
    font: inherit;
}

.field input:focus,
.field select:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

.seg {
    display: inline-flex;
    padding: 2px;
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.seg button {
    padding: 0.25rem 0.65rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink-soft);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
}

.seg button.on {
    background: var(--surface-raised);
    color: var(--ink);
    box-shadow: var(--shadow);
}

.btn-plain {
    padding: 0.35rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
}

.btn-plain:hover {
    background: var(--surface-sunken);
}

.btn-accent {
    padding: 0.4rem 1rem;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.btn-accent:disabled {
    opacity: 0.5;
    cursor: default;
}

.tabs {
    display: flex;
    gap: 0.15rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
}

.tabs button {
    padding: 0.55rem 0.9rem;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--ink-soft);
    font: inherit;
    font-weight: 550;
    white-space: nowrap;
    cursor: pointer;
}

.tabs button:hover {
    color: var(--ink);
}

.tabs button.on {
    border-bottom-color: var(--accent);
    color: var(--accent);
}

/* ---------- drop zone ---------- */

.dropzone {
    display: grid;
    place-items: center;
    gap: 0.4rem;
    padding: 2.5rem 1.5rem;
    background: var(--surface-raised);
    border: 1.5px dashed var(--line);
    border-radius: var(--radius);
    text-align: center;
    transition: border-color 120ms, background 120ms;
}

.dropzone.hot {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.progress-track {
    height: 6px;
    overflow: hidden;
    background: var(--surface-sunken);
    border-radius: 999px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 200ms;
}

.progress-fill.indeterminate {
    width: 35%;
    animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
    0% { margin-left: -35%; }
    100% { margin-left: 100%; }
}

/* ---------- timeline chart ---------- */

.timeline {
    display: block;
    width: 100%;
    height: 120px;
}

.timeline .grid-line {
    stroke: var(--line-soft);
    stroke-width: 1;
}

.timeline .bar-total {
    fill: var(--bar);
}

.timeline .bar-error {
    fill: var(--bad);
}

.timeline .axis-text {
    fill: var(--ink-faint);
    font-size: 10px;
}

#blazor-error-ui {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: none;
    padding: 0.7rem 1.25rem;
    background: var(--bad);
    color: #fff;
}

#blazor-error-ui .dismiss {
    position: absolute;
    top: 0.6rem;
    right: 0.9rem;
    cursor: pointer;
}
