:root {
    color-scheme: light dark;
    --ok: #1a7f4b;
    --ok-bg: #e6f5ec;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #dfe3e8;
    --text: #1c2330;
    --muted: #61708a;
    --accent: #3b5bdb;
    --accent-contrast: #ffffff;
    --danger: #b02a37;
    --danger-bg: #fdecee;
    --dev: #9a6b00;
    --dev-bg: #fff4d6;
    --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 1px 3px rgba(20, 30, 50, 0.05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --ok: #5cd196;
        --ok-bg: #16311f;
        --bg: #14181f;
        --surface: #1b2029;
        --surface-2: #232a35;
        --border: #313a49;
        --text: #e6eaf2;
        --muted: #98a6bd;
        --accent: #7c95f5;
        --accent-contrast: #10131a;
        --danger: #ff8a94;
        --danger-bg: #3a1f22;
        --dev: #f0c45a;
        --dev-bg: #3a3016;
        --shadow: none;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

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

h2 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.5rem;
}

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

a:hover {
    text-decoration: underline;
}

/* Shell -------------------------------------------------------------- */

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

.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.25rem;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-name {
    font-weight: 650;
    letter-spacing: 0.01em;
}

.dev-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    color: var(--dev);
    background: var(--dev-bg);
    border: 1px solid color-mix(in srgb, var(--dev) 35%, transparent);
}

.app-nav {
    display: flex;
    gap: 1rem;
    margin-right: auto;
}

.session-chrome {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.session-email {
    font-weight: 550;
    color: var(--text);
}

@media (max-width: 600px) {
    .app-header { flex-wrap: wrap; gap: 0.75rem; }
    .brand-name, .app-nav a, .session-chrome button { white-space: nowrap; }
    .session-chrome { width: 100%; justify-content: space-between; }
    .session-chrome button { min-height: 44px; min-width: 44px; }
}

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

.app-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 0.8rem;
}

/* Usage remains readable at narrow widths and without color perception. */
.usage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.usage .card { overflow-wrap: anywhere; }
.usage .card h2 { margin-top: 0; }
.usage meter { display: block; width: 100%; height: 1.5rem; accent-color: var(--accent); }
.usage-amount { font-size: 1.1rem; }
.usage-table { width: 100%; table-layout: fixed; }
.usage-compute-table { min-width: 32rem; }
.usage .table-wrap:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.usage .usage-table th, .usage .usage-table td { white-space: normal; overflow-wrap: anywhere; }
.usage .usage-table th, .usage .placeholder-note { color: var(--text); }
.usage-unavailable { margin-top: 1.5rem; }
.usage button { min-height: 44px; }
.usage button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (max-width: 700px) { .usage-grid { grid-template-columns: 1fr; } }

/* Cards & controls --------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control > label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
}

.text-input {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.4rem 0.55rem;
    min-width: 11rem;
}

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

.preset-group {
    display: inline-flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.chip {
    font: inherit;
    cursor: pointer;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

.chip:hover {
    border-color: var(--accent);
}

.chip-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

/* Buttons ------------------------------------------------------------ */

.primary-button {
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 0.5rem 0.95rem;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--accent-contrast);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: progress;
}

.link-button {
    font: inherit;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
}

.link-button:hover {
    text-decoration: underline;
}

/* States ------------------------------------------------------------- */

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

.error {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.error .primary-button {
    margin-top: 0.5rem;
    border-color: var(--danger);
    background: var(--danger);
    color: #fff;
}

.count {
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 500;
}

/* KPI tiles ---------------------------------------------------------- */

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

.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 0.85rem 0.95rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.tile-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.tile-type {
    font-weight: 600;
    font-size: 0.9rem;
    word-break: break-word;
}

.tile-metric {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.tile-value {
    font-size: 1.6rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.tile-unit {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
    margin-left: 0.25rem;
}

.tile-foot {
    font-size: 0.72rem;
    color: var(--muted);
}

.sparkline {
    width: 100%;
    height: 28px;
    display: block;
}

.spark-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.spark-dot {
    fill: var(--accent);
}

/* Table -------------------------------------------------------------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

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

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

.data-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

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

/* Sign-in ------------------------------------------------------------ */

.signin {
    max-width: 30rem;
    margin: 2rem auto;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

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

.signin .text-input {
    width: 100%;
}

.dev-note {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    background: var(--dev-bg);
    color: var(--dev);
    border: 1px solid color-mix(in srgb, var(--dev) 35%, transparent);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.45;
}

/* Processing status (D-17) ------------------------------------------- */

.status-section {
    margin-bottom: 1.5rem;
}

.status-section h2 {
    margin: 0 0 0.6rem;
}

.health-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}

.health-healthy {
    color: var(--ok);
    background: var(--ok-bg);
    border-color: color-mix(in srgb, var(--ok) 35%, transparent);
}

.health-stale {
    color: var(--dev);
    background: var(--dev-bg);
    border-color: color-mix(in srgb, var(--dev) 35%, transparent);
}

.health-error {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.health-inactive {
    color: var(--muted);
    background: var(--surface-2);
    border-color: var(--border);
}

.placeholder-note {
    color: var(--muted);
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
}
