:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1c2430;
    --muted: #6b7686;
    --border: #d9dee5;
    --accent: #2f6fed;
    --accent-text: #ffffff;
    --error-bg: #fdecec;
    --error-text: #a12626;
    --danger: #c03535;
    --success-bg: #e9f6ee;
    --success-text: #1d6b3c;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12161c;
        --surface: #1b2129;
        --text: #e6eaf0;
        --muted: #94a0b0;
        --border: #2c3440;
        --accent: #5b8ef5;
        --error-bg: #3a1d1f;
        --error-text: #f2b8b8;
        --danger: #f08080;
        --success-bg: #17301f;
        --success-text: #a9dfb9;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.centered {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.card {
    width: 100%;
    max-width: 360px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
}

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

.card .muted {
    margin: 4px 0 24px;
}

form {
    display: grid;
    gap: 8px;
}

label {
    font-size: 0.875rem;
    font-weight: 600;
}

input {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    margin-bottom: 8px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    margin-bottom: 8px;
}

.check input {
    margin: 0;
    width: 16px;
    height: 16px;
}

input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

button {
    font: inherit;
    font-weight: 600;
    padding: 10px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
}

button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 12px;
}

.alert,
.notice {
    margin: 0 0 16px;
    padding: 10px 12px;
    border-radius: 8px;
}

.alert {
    background: var(--error-bg);
    color: var(--error-text);
}

.notice {
    background: var(--bg);
    color: var(--muted);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

.nav-link {
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content {
    padding: 24px;
    max-width: 1040px;
    margin: 0 auto;
}

.page-title {
    margin: 0 0 24px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.panel h2 {
    margin: 0 0 16px;
    font-size: 1.125rem;
}

.add-user {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
}

.field {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.field input {
    margin-bottom: 0;
    width: 100%;
    min-width: 0;
}

.input-row {
    display: flex;
    gap: 8px;
}

.input-row input {
    flex: 1;
    min-width: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.hint {
    margin: 0;
    font-size: 0.875rem;
    color: var(--muted);
}

.actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.add-user .alert {
    grid-column: 1 / -1;
    margin: 0;
}

.result {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    background: var(--success-bg);
    color: var(--success-text);
}

.result p {
    margin: 0 0 8px;
}

.result pre {
    margin: 0 0 12px;
    padding: 12px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 0.875rem;
}

.table-wrap {
    overflow-x: auto;
}

table.users {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

table.users th,
table.users td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.users th {
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

table.users td.email {
    white-space: normal;
    word-break: break-all;
    font-weight: 600;
}

table.users tr:last-child td {
    border-bottom: 0;
}

.actions-col {
    text-align: right;
    width: 1%;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    background: var(--bg);
    border: 1px solid var(--border);
}

button.danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 6px 12px;
}

button:disabled {
    opacity: 0.6;
    cursor: default;
}

#remove-error {
    margin: 16px 0 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (max-width: 640px) {
    .topbar {
        padding: 12px 16px;
    }

    .topbar .brand {
        display: none;
    }

    .topbar {
        gap: 12px;
    }

    .nav {
        gap: 12px;
        min-width: 0;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .nav-link {
        font-size: 0.875rem;
        white-space: nowrap;
    }

    .user {
        flex: none;
    }

    .user button.secondary {
        padding: 6px 10px;
    }

    .user button {
        white-space: nowrap;
    }

    .user-email {
        display: none;
    }

    .content {
        padding: 16px;
    }

    .panel {
        padding: 16px;
    }

    .add-user {
        grid-template-columns: 1fr;
    }

    .actions {
        flex-direction: column-reverse;
    }

    table.users thead {
        display: none;
    }

    table.users,
    table.users tbody,
    table.users tr {
        display: block;
    }

    table.users tr {
        padding: 12px 0;
        border-bottom: 1px solid var(--border);
    }

    table.users tr:last-child {
        border-bottom: 0;
    }

    table.users td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 16px;
        padding: 4px 0;
        border: 0;
        white-space: normal;
        text-align: right;
    }

    table.users td:empty {
        display: none;
    }

    table.users td::before {
        content: attr(data-label);
        flex-shrink: 0;
        color: var(--muted);
        font-size: 0.8125rem;
        font-weight: 400;
        text-align: left;
    }

    table.users td.email {
        word-break: normal;
        overflow-wrap: anywhere;
    }

    table.users .actions-col {
        width: auto;
        justify-content: flex-end;
        padding-top: 8px;
    }
}

:root {
    --series-1: #257de0;
    --series-2: #f47230;
    --series-3: #00b894;
    --series-4: #f2a600;
    --series-5: #ee7fac;
    --heat: 37, 125, 224;
    --chart-grid: #e7e7e7;
    --chart-baseline: #c2c2c2;
    --delta-good: #006c10;
    --delta-bad: #c62d2e;
    --bar: #519ced;
}

@media (prefers-color-scheme: dark) {
    :root {
        --series-1: #338ced;
        --series-2: #e76624;
        --series-3: #00a888;
        --series-4: #d28e05;
        --series-5: #e24d8b;
        --heat: 51, 140, 237;
        --chart-grid: #303030;
        --chart-baseline: #474747;
        --delta-good: #53c556;
        --delta-bad: #eb6263;
        --bar: #2370cd;
    }
}

.content:has(.dash-header) {
    max-width: 1280px;
}

.dash-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.dash-header .page-title {
    margin: 0;
}

.updated {
    margin: 4px 0 0;
    font-size: 0.875rem;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
}

.segmented button {
    background: transparent;
    color: var(--muted);
    border-radius: 0;
    padding: 8px 16px;
    font-weight: 600;
}

.segmented button + button {
    border-left: 1px solid var(--border);
}

.segmented button[aria-pressed="true"] {
    background: var(--bg);
    color: var(--text);
}

.tiles {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    min-height: 112px;
}

.tile-label {
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 600;
}

.tile-value {
    font-size: 2rem;
    font-weight: 650;
    line-height: 1.25;
    margin: 8px 0 4px;
}

.tile-delta {
    font-size: 0.8125rem;
}

.delta {
    font-weight: 600;
}

.delta.good {
    color: var(--delta-good);
}

.delta.bad {
    color: var(--delta-bad);
}

.delta.flat {
    color: var(--muted);
}

.dash-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 24px;
}

.panel .subtitle {
    margin: -12px 0 16px;
    color: var(--muted);
    font-size: 0.875rem;
}

.panel.failed > :not(h2):not(.subtitle) {
    display: none;
}

.panel.failed::after {
    content: "This section couldn't be loaded. It will retry automatically.";
    color: var(--muted);
    font-size: 0.875rem;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
    font-size: 0.8125rem;
    color: var(--muted);
}

.legend li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

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

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

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

.swatch.s4 {
    background: var(--series-4);
}

.swatch.s5 {
    background: var(--series-5);
}

.plot {
    position: relative;
    min-height: 220px;
}

.plot svg {
    display: block;
    overflow: visible;
}

.plot .grid {
    stroke: var(--chart-grid);
    stroke-width: 1;
}

.plot .baseline {
    stroke: var(--chart-baseline);
    stroke-width: 1;
}

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

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

.plot .area {
    stroke: none;
    opacity: 0.1;
}

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

.plot .cursor {
    stroke: var(--chart-baseline);
    stroke-width: 1;
}

.plot .overlay {
    fill: transparent;
    cursor: crosshair;
}

.plot .overlay.hover {
    fill: var(--text);
    opacity: 0.04;
}

.plot .s1.line {
    stroke: var(--series-1);
}

.plot .s2.line {
    stroke: var(--series-2);
}

.plot .s3.line {
    stroke: var(--series-3);
}

.plot .s4.line {
    stroke: var(--series-4);
}

.plot .s5.line {
    stroke: var(--series-5);
}

.plot .s4.area, .plot .s4.dot, .plot .s4.bar {
    fill: var(--series-4);
}

.plot .s5.area, .plot .s5.dot, .plot .s5.bar {
    fill: var(--series-5);
}

.plot .s1.area, .plot .s1.dot, .plot .s1.bar {
    fill: var(--series-1);
}

.plot .s2.area, .plot .s2.dot, .plot .s2.bar {
    fill: var(--series-2);
}

.plot .s3.area, .plot .s3.dot, .plot .s3.bar {
    fill: var(--series-3);
}

.tooltip {
    position: absolute;
    top: 0;
    z-index: 2;
    min-width: 160px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    font-size: 0.8125rem;
    pointer-events: none;
}

.tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
}

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

.tooltip-name {
    color: var(--muted);
    flex: 1;
}

.tooltip-value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.chart-data {
    margin-top: 8px;
    font-size: 0.8125rem;
}

.chart-data summary {
    cursor: pointer;
    color: var(--muted);
}

.chart-data .table-wrap {
    max-height: 240px;
    overflow: auto;
    margin-top: 8px;
}

.bar-list {
    display: grid;
    gap: 8px;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(96px, 35%) 1fr auto;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
}

.bar-label {
    overflow-wrap: anywhere;
}

.bar-track {
    height: 12px;
}

.bar-fill {
    height: 100%;
    background: var(--bar);
    border-radius: 0 4px 4px 0;
}

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

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

table.data th,
table.data td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

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

table.data td.email {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

table.data tr:last-child td {
    border-bottom: 0;
}

table.data.compact td,
table.data.compact th {
    padding: 4px 8px;
}

.inline-bar {
    display: block;
    height: 4px;
    margin-top: 4px;
    border-radius: 2px;
    background: var(--bar);
}

table.heatmap td.heat {
    min-width: 72px;
}

table.heatmap td.heat-0 { background: rgba(var(--heat), 0.06); }
table.heatmap td.heat-1 { background: rgba(var(--heat), 0.14); }
table.heatmap td.heat-2 { background: rgba(var(--heat), 0.22); }
table.heatmap td.heat-3 { background: rgba(var(--heat), 0.32); }
table.heatmap td.heat-4 { background: rgba(var(--heat), 0.42); }
table.heatmap td.heat-5 { background: rgba(var(--heat), 0.54); color: #ffffff; }
table.heatmap td.heat-6 { background: rgba(var(--heat), 0.66); color: #ffffff; }
table.heatmap td.heat-7 { background: rgba(var(--heat), 0.78); color: #ffffff; }
table.heatmap td.heat-8 { background: rgba(var(--heat), 0.9); color: #ffffff; }
table.heatmap td.heat-9 { background: rgba(var(--heat), 1); color: #ffffff; }

table.heatmap td.heat-none {
    background: transparent;
}

.empty {
    color: var(--muted);
    font-size: 0.875rem;
}

body.loading .tiles,
body.loading .dash-grid,
body.loading .panel {
    opacity: 0.6;
    transition: opacity 0.2s;
}

@media (max-width: 1000px) {
    .tiles {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dash-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 640px) {
    .tiles {
        gap: 8px;
    }

    .tile {
        padding: 12px;
        min-height: 0;
    }

    .tile-value {
        font-size: 1.5rem;
    }

    .segmented {
        width: 100%;
    }

    .segmented button {
        flex: 1;
        padding: 8px;
    }

    .bar-row {
        grid-template-columns: minmax(80px, 40%) 1fr auto;
    }
}
