/* Design tokens: reference data-viz palette (light / dark selected separately, not auto-inverted). */
:root {
    color-scheme: light;
    --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
    --page: #f9f9f7;
    --surface-1: #fcfcfb;
    --surface-2: #ffffff;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #6f6d68;
    --grid: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --accent: #2a78d6;
    --accent-ink: #ffffff;

    --series-1: #2a78d6; --series-1-fill: rgba(42, 120, 214, 0.12);
    --series-2: #eb6834; --series-2-fill: rgba(235, 104, 52, 0.12);
    --series-3: #1baf7a; --series-3-fill: rgba(27, 175, 122, 0.12);
    --series-4: #eda100; --series-4-fill: rgba(237, 161, 0, 0.12);
    --series-5: #e87ba4; --series-5-fill: rgba(232, 123, 164, 0.12);
    --series-6: #008300; --series-6-fill: rgba(0, 131, 0, 0.12);
    --series-7: #6250d6; --series-7-fill: rgba(98, 80, 214, 0.12);
    --series-8: #e34948; --series-8-fill: rgba(227, 73, 72, 0.12);

    /* Status: reserved, always paired with an icon + label. */
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
    --status-unknown: #898781;
    --status-good-text: #006300;
    --status-critical-text: #b42f2f;
    --status-warning-text: #7a5300;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface-1: #1a1a19;
        --surface-2: #242423;
        --text-primary: #f0efec;
        --text-secondary: #c3c2b7;
        --text-muted: #9a9890;
        --grid: #2c2c2a;
        --baseline: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --accent: #3987e5;

        --series-1: #3987e5; --series-1-fill: rgba(57, 135, 229, 0.16);
        --series-2: #d95926; --series-2-fill: rgba(217, 89, 38, 0.16);
        --series-3: #199e70; --series-3-fill: rgba(25, 158, 112, 0.16);
        --series-4: #c98500; --series-4-fill: rgba(201, 133, 0, 0.16);
        --series-5: #d55181; --series-5-fill: rgba(213, 81, 129, 0.16);
        --series-6: #0ca30c; --series-6-fill: rgba(12, 163, 12, 0.16);
        --series-7: #9085e9; --series-7-fill: rgba(144, 133, 233, 0.16);
        --series-8: #e66767; --series-8-fill: rgba(230, 103, 103, 0.16);

        --status-good-text: #0ca30c;
        --status-critical-text: #e66767;
        --status-warning-text: #fab219;
    }
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--page);
    color: var(--text-primary);
    font: 14px/1.5 var(--font-sans);
}

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

/* Layout */
.topbar {
    display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
    padding: 12px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 650; color: var(--text-primary); font-size: 15px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: var(--text-secondary); padding: 6px 10px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; box-shadow: inset 0 0 0 1px var(--border); }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-muted); font-size: 13px; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; font-weight: 650; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 650; margin: 32px 0 12px; }
.subtitle { color: var(--text-secondary); margin: 0 0 20px; }
.muted { color: var(--text-muted); }

.card {
    background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
}
.grid { display: grid; gap: 16px; }
.grid-servers { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-charts { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* Server card */
.server-card { display: flex; flex-direction: column; gap: 12px; color: inherit; }
.server-card:hover { text-decoration: none; border-color: var(--baseline); }
.server-card header { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.server-card .name { font-weight: 650; font-size: 15px; }
.server-card .meta { color: var(--text-muted); font-size: 12px; }

/* Stat tile */
.stat .label { color: var(--text-secondary); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 600; line-height: 1.3; }
.stat .hint { color: var(--text-muted); font-size: 12px; }

/* Meter (single value against a 0–100 % scale) */
.meter { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--series-1); }
.meter.warning > span { background: var(--status-warning); }
.meter.critical > span { background: var(--status-critical); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.metrics .label { color: var(--text-secondary); font-size: 12px; }
.metrics .value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Status badge: icon + label, color never alone */
.badge {
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
    font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
    background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); color: var(--text-primary);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--status-unknown); }
.badge.good::before { background: var(--status-good); }
.badge.warning::before { background: var(--status-warning); }
.badge.serious::before { background: var(--status-serious); }
.badge.critical::before { background: var(--status-critical); border-radius: 1px; transform: rotate(45deg); }
.badge.warning::before { border-radius: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%); width: 9px; }

/* Chart card */
.chart-card h3 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.chart-card .chart-sub { margin: 0 0 12px; color: var(--text-muted); font-size: 12px; }
.chart-box { position: relative; height: 220px; }

/* Filters: one row above the charts */
.filters { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 16px; }
.filters a {
    padding: 5px 12px; border-radius: 6px; color: var(--text-secondary);
    background: var(--surface-1); box-shadow: inset 0 0 0 1px var(--border); font-size: 13px;
}
.filters a.active { background: var(--text-primary); color: var(--page); box-shadow: none; font-weight: 600; }
.filters a:hover { text-decoration: none; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.empty { padding: 24px; text-align: center; color: var(--text-muted); }

/* Flash & alerts */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--status-good); }
.flash.error { border-left-color: var(--status-critical); }

/* Forms & buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
    padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
}
.btn:hover { border-color: var(--baseline); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--status-critical-text); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.inline-form { display: inline; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.form-grid { display: grid; gap: 14px; max-width: 560px; }
.form-grid label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.form-grid input[type=text], .form-grid input[type=url], .form-grid input[type=password], .form-grid select {
    width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--baseline);
    background: var(--surface-2); color: var(--text-primary); font: inherit;
}
.form-grid .checkbox label { display: inline; font-weight: 400; }
.form-grid .help-text { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.form-grid ul { color: var(--status-critical-text); margin: 4px 0 0; padding-left: 18px; font-size: 12px; }

/* Applications & logs */
.split { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.split .label { color: var(--text-secondary); font-size: 12px; }
.value-sm { font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge.serious::before { border-radius: 2px; }
td.message { max-width: 640px; overflow-wrap: anywhere; }
tr.dimmed td { color: var(--text-muted); }
pre.log {
    margin: 8px 0; padding: 12px; border-radius: 8px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border);
    font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow: auto;
}
.issue-title { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; overflow-wrap: anywhere; font-size: 20px; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin: 0 0 12px; }
.toolbar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.toolbar .grow { flex: 1 1 220px; }
.toolbar select, .toolbar input {
    padding: 7px 10px; border-radius: 6px; border: 1px solid var(--baseline); background: var(--surface-2); color: var(--text-primary); font: inherit; font-weight: 400;
}

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Login */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { margin-bottom: 16px; }

@media (max-width: 720px) {
    main { padding: 16px; }
    .topbar { padding: 10px 16px; gap: 12px; }
    .grid-charts { grid-template-columns: 1fr; }
    .metrics { grid-template-columns: repeat(2, 1fr); }
}
