:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e1e0d9;
  --axis: #c3c2b7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #8a63d2;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;
  --critical-text: #b02a2a;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423; --border: #2c2c2a; --axis: #383835;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781; --accent: #3987e5;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #9a76e0;
    --good-text: #0ca30c; --critical-text: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423; --border: #2c2c2a; --axis: #383835;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781; --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #9a76e0;
  --good-text: #0ca30c; --critical-text: #e66767;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.num, td.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.secondary { color: var(--text-2); }

/* nav */
header.top { display: flex; align-items: center; gap: 4px; padding: 0 16px; height: 48px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; overflow-x: auto; }
header.top .brand { font-weight: 700; margin-right: 12px; white-space: nowrap; color: var(--text); }
header.top .brand:hover { text-decoration: none; }
header.top nav a { color: var(--text-2); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
header.top nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
header.top nav a:hover { text-decoration: none; background: var(--surface-2); }
header.top nav { display: flex; align-items: center; }
header.top nav .nav-tab { color: var(--text-2); padding: 6px 10px; border: 0; border-radius: 6px; background: none;
  font: inherit; }
header.top nav .nav-tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
header.top nav .nav-tab:hover { background: var(--surface-2); }
.nav-menu { position: fixed; min-width: 150px; padding: 4px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; z-index: 11; }
.nav-menu[hidden] { display: none; }
header.top .nav-menu a { display: block; }
header.top .spacer { flex: 1; }
header.top .procs { display: flex; gap: 8px; white-space: nowrap; font-size: 12px; }

main { padding: 20px 16px 48px; max-width: 1500px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--text-2); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.section { margin-top: 20px; }
.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-2); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
td.num, th.num { text-align: right; }
tr:hover td { background: var(--surface-2); }
.wrap { word-break: break-all; }

/* badges: status color + text label, never color alone */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--border); white-space: nowrap; background: var(--surface); color: var(--text); }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.good::before { background: var(--good); }
.badge.warning::before { background: var(--warning); }
.badge.serious::before { background: var(--serious); }
.badge.critical::before { background: var(--critical); }
.badge.info::before { background: var(--accent); }

/* progress */
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }

/* controls */
button, .btn { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--critical-text); }
button:disabled { opacity: .5; cursor: default; }
button.small { padding: 2px 8px; font-size: 12px; }
input, select, textarea { font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }
textarea { width: 100%; min-height: 120px; font-family: ui-monospace, Consolas, monospace; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* session cards */
.sessions { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.session h3 { margin: 0; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.session .meta { color: var(--text-2); font-size: 12px; margin: 8px 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.session .msg { font-size: 12px; color: var(--text-2); min-height: 18px; word-break: break-word; }
.session .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.session.paused { border-color: var(--critical); }

/* alerts */
.alert-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.alert-item:last-child { border-bottom: 0; }
.alert-item .when { color: var(--muted); font-size: 12px; }

/* log terminal */
.terminal { background: #0d0d0d; color: #e6e6e3; font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px; line-height: 1.5; padding: 12px; border-radius: var(--radius); height: calc(100vh - 220px);
  min-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.terminal .WARNING { color: #fab219; }
.terminal .ERROR, .terminal .CRITICAL { color: #ff7b7b; }

/* charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.12); display: none;
  white-space: nowrap; z-index: 5; }
.tooltip .t { color: var(--muted); margin-bottom: 2px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.toast { position: fixed; bottom: 16px; right: 16px; background: var(--text); color: var(--page); padding: 8px 14px;
  border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; z-index: 20; }
.toast.show { opacity: 1; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-wrap .card { width: 100%; max-width: 340px; }
.login-wrap input { width: 100%; padding: 8px 10px; margin: 8px 0 12px; }
.login-wrap button { width: 100%; padding: 8px; }
.error-text { color: var(--critical-text); font-size: 13px; }
