:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warning-text: #8a5a00;
  --serious: #ec835a;
  --serious-text: #a3401a;
  --critical: #d03b3b;
  --critical-text: #b02a2a;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04);
  --term-bg: #fcfcfb;
  --term-fg: #1d1d1b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --line: #333331;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3987e5;
    --accent-soft: #1f2d42;
    --good-text: #5fd35f;
    --warning-text: #fab219;
    --serious-text: #ec835a;
    --critical-text: #f07a7a;
    --shadow: none;
    --term-bg: #141413;
    --term-fg: #e8e7e3;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #262624; --line: #333331;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f; --accent: #3987e5; --accent-soft: #1f2d42;
  --good-text: #5fd35f; --warning-text: #fab219; --serious-text: #ec835a; --critical-text: #f07a7a; --shadow: none;
  --term-bg: #141413; --term-fg: #e8e7e3;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.9rem; margin: 0 0 0.4rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--critical-text); min-height: 1.2em; margin: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 0 16px 48px; display: grid; gap: 16px; }
.top { max-width: 1280px; margin: 0 auto; padding: 18px 16px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.top-right { display: flex; align-items: center; gap: 10px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }

/* Buttons */
.btn { font: inherit; font-size: 0.85rem; font-weight: 600; border-radius: 8px; padding: 6px 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--critical-text); }
.btn.small { padding: 4px 9px; font-size: 0.8rem; }

/* Status: always icon + word, never colour alone */
.status { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
.status .dot { width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; flex: none; }
.status.good { color: var(--good-text); } .status.good .dot { background: var(--good); }
.status.warning { color: var(--warning-text); } .status.warning .dot { background: var(--warning); color: #3a2a00; }
.status.serious { color: var(--serious-text); } .status.serious .dot { background: var(--serious); }
.status.critical { color: var(--critical-text); } .status.critical .dot { background: var(--critical); }
.status.neutral { color: var(--muted); } .status.neutral .dot { background: var(--line); color: var(--text-2); }
.pill { padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }

/* Attention list */
.attention ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.attention li { display: flex; gap: 8px; align-items: flex-start; }

/* Stat tiles */
.tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.tile { padding: 14px 16px 10px; }
.tile .label { font-size: 0.8rem; font-weight: 600; color: var(--text-2); }
.tile .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 0; }
.tile .sub { font-size: 0.8rem; color: var(--muted); min-height: 1.2em; }

/* Sparkline */
.spark { position: relative; height: 44px; margin-top: 8px; touch-action: none; }
.spark svg { width: 100%; height: 100%; display: block; overflow: visible; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.spark .base { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .cross { stroke: var(--text-2); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .mark { fill: var(--accent); stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark.mini { height: 22px; width: 90px; margin: 0; }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--text); color: var(--surface); font-size: 0.78rem; font-weight: 600; padding: 4px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -130%); }

/* Meters */
.meter-row { display: grid; gap: 4px; margin-bottom: 12px; }
.meter-row:last-child { margin-bottom: 0; }
.meter-head { display: flex; justify-content: space-between; gap: 8px; font-size: 0.85rem; }
.meter-head .name { font-weight: 600; }
.meter { height: 8px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.meter.warning > span { background: var(--warning); }
.meter.critical > span { background: var(--critical); }

/* Key/value lists */
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 0.88rem; }
dl.kv dt { color: var(--text-2); }
dl.kv dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* Services */
.svc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.svc-head h2 { margin: 0; }
.stack-name { margin: 18px 0 6px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.svc { display: grid; grid-template-columns: minmax(150px, 1.3fr) minmax(120px, 0.8fr) minmax(190px, 1.6fr) minmax(170px, 1.1fr) auto; gap: 8px 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.svc .name { font-weight: 650; overflow-wrap: anywhere; }
.svc .image { font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; }
.svc .urls { display: grid; gap: 3px; font-size: 0.85rem; min-width: 0; }
.svc .urls .url { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.svc .urls a { overflow-wrap: anywhere; }
.svc .usage { display: flex; gap: 10px; align-items: center; font-size: 0.82rem; color: var(--text-2); }
.svc .usage .nums { display: grid; min-width: 82px; }
.svc .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 900px) {
  .svc { grid-template-columns: 1fr auto; }
  .svc .urls, .svc .usage { grid-column: 1 / -1; }
  .svc .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .svc .state { justify-self: end; }
}

/* Fail2ban / small tables */
table.mini { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 10px; }
table.mini th, table.mini td { text-align: right; padding: 4px 0 4px 10px; border-top: 1px solid var(--line); }
table.mini th:first-child, table.mini td:first-child { text-align: left; padding-left: 0; }
table.mini th { color: var(--text-2); font-weight: 600; border-top: 0; }

ul.plain { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 0.88rem; }
ul.plain li { display: flex; justify-content: space-between; gap: 10px; }
details summary { cursor: pointer; color: var(--text-2); font-size: 0.85rem; margin-top: 10px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
details pre { font-size: 0.75rem; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 8px; border-radius: 8px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 360px); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 5px; font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Logs dialog */
dialog.logs { width: min(1100px, calc(100vw - 24px)); height: min(80vh, 900px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); }
dialog.logs[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.logs-head { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.logs-head h2 { margin: 0 auto 0 0; }
.logs-head label { display: flex; gap: 6px; align-items: center; }
#logs-body { flex: 1; margin: 0; padding: 12px 14px; overflow: auto; font-size: 0.76rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); }

/* System services */
.sys-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.sys-tools input[type="search"] { flex: 1; min-width: 180px; }
.sys-tools label { display: flex; gap: 6px; align-items: center; font-size: 0.85rem; color: var(--text-2); }
.sys-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 0 24px; max-height: 520px; overflow-y: auto; }
.sys-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 0; border-top: 1px solid var(--line); min-width: 0; }
.sys-row .unit { font-weight: 600; font-size: 0.88rem; overflow-wrap: anywhere; }
.sys-row .desc { grid-column: 1 / -1; font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }

/* Terminal page */
.term-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.term-top { width: 100%; max-width: none; }
.unlock { width: min(100% - 32px, 440px); margin: 40px auto; display: grid; gap: 12px; }
.unlock label { display: grid; gap: 5px; font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.unlock h2, .unlock p { margin: 0; }
.term { flex: 1; min-height: 0; margin: 0 16px 16px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--term-bg); }
.term .xterm { height: 100%; }
