:root {
    --bg: #f5f4f1;
    --surface: #ffffff;
    --border: #e2dfd8;
    --text: #1f1d1a;
    --muted: #6d6860;
    --accent: #8a4b1f;
    --accent-soft: #f3e6da;
    --series-0: #8a4b1f;
    --series-1: #2f6f8f;
    --good: #2d7a46;
    --bad: #b3372c;
    --warn-bg: #fdf3d7;
    --warn-text: #6b5200;
    --radius: 8px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171614;
        --surface: #211f1c;
        --border: #37332d;
        --text: #ece8e1;
        --muted: #a39c91;
        --accent: #e0a172;
        --accent-soft: #3a2c20;
        --series-0: #e0a172;
        --series-1: #7fc0de;
        --good: #6fca8b;
        --bad: #f08a7f;
        --warn-bg: #3b3214;
        --warn-text: #f1dc8f;
    }
}

* { box-sizing: border-box; }

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

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

h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 22px 0 10px; color: var(--muted); }

.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand { font-weight: 700; font-size: 17px; color: var(--text); padding: 0 8px 14px; display: block; }
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }

.nav-group {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 14px 8px 4px;
}

.nav-link { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.nav-link:hover { background: var(--bg); text-decoration: none; }
.nav-link.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-foot { margin-top: auto; padding-top: 18px; display: grid; gap: 10px; }

.switch {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 0;
    padding: 4px 8px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}

.switch-track {
    width: 30px;
    height: 17px;
    border-radius: 9px;
    background: var(--border);
    position: relative;
    flex: none;
}

.switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--surface);
    transition: left 0.15s;
}

.switch.on .switch-track { background: var(--accent); }
.switch.on .switch-knob { left: 15px; }

.link-button {
    background: none;
    border: 0;
    padding: 4px 8px;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.link-button:hover { color: var(--text); }

.content { padding: 28px 32px 60px; max-width: 1280px; width: 100%; }

.page-head { margin-bottom: 22px; }
.crumb { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.lead { margin: 0; color: var(--muted); }

.notice {
    background: var(--warn-bg);
    color: var(--warn-text);
    border-radius: var(--radius);
    padding: 9px 14px;
    margin-bottom: 20px;
    font-size: 14px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }

.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile.primary { border-color: var(--accent); }
.tile.alert { border-color: var(--bad); }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 30px; font-weight: 650; line-height: 1.25; font-variant-numeric: tabular-nums; }
.tile-value.small { font-size: 20px; }
.tile-sub { font-size: 13px; color: var(--muted); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.card.flush { padding: 0; }
.card.flush .empty { padding: 18px 20px; }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: 20px; }
.card.flush .table th:last-child, .card.flush .table td:last-child { padding-right: 20px; }
.pad { padding: 18px 20px 0; }

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

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table tbody tr:last-child td { border-bottom: 0; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    background: var(--border);
    color: var(--text);
    vertical-align: middle;
    white-space: nowrap;
}

h1 .badge { font-size: 13px; margin-left: 6px; }

.state-active { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.state-new { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--series-1); }
.state-dormant { background: var(--warn-bg); color: var(--warn-text); }
.state-uninstalled, .state-offline { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }

.delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.empty { margin: 0; color: var(--muted); font-size: 14px; }
.note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }

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

.filters input, .filters select, .login input {
    font: inherit;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
}

.filters input[type="search"] { flex: 1 1 260px; max-width: 420px; }

.button {
    font: inherit;
    font-weight: 600;
    padding: 7px 14px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: var(--surface);
    cursor: pointer;
}

.pager { display: flex; gap: 18px; justify-content: center; align-items: center; font-size: 14px; }

.bars { width: 100%; border-collapse: collapse; font-size: 14px; }
.bars th { text-align: left; font-weight: 400; padding: 5px 12px 5px 0; width: 34%; overflow-wrap: anywhere; }
.bars td { padding: 5px 0 5px 12px; }
.bars .bar-cell { width: 100%; padding-left: 0; }
.bar-fill { display: block; height: 12px; min-width: 2px; border-radius: 3px; background: var(--series-0); }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .line.s0 { stroke: var(--series-0); }
.chart .line.s1 { stroke: var(--series-1); }
.chart .bar { fill: var(--series-0); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--muted) 14%, transparent); }

.legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend .key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin: 0 5px 0 12px; }
.legend .key:first-child { margin-left: 0; }
.key.s0 { background: var(--series-0); }
.key.s1 { background: var(--series-1); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.calendar + .note + .facts, .bars + .facts, .empty + .facts { margin-top: 16px; }

.calendar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
.cal-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-day { aspect-ratio: 1; border-radius: 3px; background: var(--border); }
.cal-day.on { background: var(--series-0); }
.cal-day.future { opacity: 0.35; }

details summary { cursor: pointer; color: var(--accent); white-space: nowrap; }
.headers { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 8px 0 0; font-size: 12.5px; }
.headers dt { color: var(--muted); }
.headers dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.log {
    margin: 0;
    font: 12.5px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--muted);
}

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

.login {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 340px;
    display: grid;
    gap: 8px;
}

.login h1 { font-size: 20px; margin-bottom: 10px; }
.login h1 span { color: var(--accent); }
.login label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login .button { margin-top: 14px; padding: 9px 14px; }
.error { margin: 0; color: var(--bad); font-size: 14px; }

@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar nav { display: flex; flex-wrap: wrap; gap: 2px 4px; }
    .nav-group { width: 100%; padding-top: 8px; }
    .sidebar-foot { margin-top: 12px; padding-top: 0; }
    .content { padding: 20px 16px 40px; }
    .columns, .grid { grid-template-columns: 1fr; }
    .calendar { grid-template-columns: repeat(2, 1fr); }
}
