:root {
  --bg: #f4f4f1;
  --card: #ffffff;
  --text: #1d1f22;
  --muted: #62666d;
  --line: #d9dbd6;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --err: #b3261e;
  --notice: #fff4d6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111316;
    --card: #1a1d21;
    --text: #e7e8e6;
    --muted: #9a9ea5;
    --line: #30343a;
    --accent: #7ea2ff;
    --accent-text: #0d1426;
    --err: #ff8a80;
    --notice: #3a3216;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, "Segoe UI", sans-serif; }
main { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
main.narrow { max-width: 420px; }
body[data-page=login] main, body[data-page=welcome] main, body[data-page=signup] main { min-height: 100vh; display: grid; align-content: center; }
h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }

#top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
#top:empty { display: none; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.card p { margin: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label small { font-size: .8rem; }
input:not([type=checkbox]) { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; min-height: 44px; width: 100%; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
button { font: inherit; font-weight: 600; min-height: 44px; padding: 0 18px; border: 0; border-radius: 7px; background: var(--accent); color: var(--accent-text); cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; min-height: 36px; padding: 0 12px; }
button.link { background: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 400; text-decoration: underline; }
.err { color: var(--err); min-height: 1.2em; font-size: .9rem; margin: 0; }
.err:empty { display: none; }
.notice { background: var(--notice); border-radius: 8px; padding: 12px 14px; margin: 0 0 16px; }
.card .notice { margin: 0; }
.trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.apps > p { grid-column: 1 / -1; margin: 0; }
.app { text-decoration: none; color: var(--text); gap: 6px; min-height: 110px; margin: 0; transition: border-color .15s; }
.app:hover { border-color: var(--accent); }
.app strong { font-size: 1.1rem; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.with-button { display: flex; gap: 8px; }
.with-button button { white-space: nowrap; min-height: 44px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; }
legend { font-size: .9rem; color: var(--muted); padding: 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog form { display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 640px) {
  .with-button { flex-direction: column; }
  td.buttons { justify-content: flex-start; }
}

/* ---------- Server stats ---------- */

:root { --good: #0ca30c; --warn: #fab219; --crit: #d03b3b; --track: color-mix(in srgb, var(--accent) 16%, var(--card)); }
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.title-row h1 { margin: 0; }
.title-row .muted { font-size: .85rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.tile { margin: 0; gap: 2px; padding: 16px 18px; }
.tile .label { font-size: .85rem; color: var(--muted); }
.tile .value { font-size: 1.9rem; font-weight: 600; line-height: 1.2; }
.tile .sub { font-size: .8rem; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.stats-grid .card { margin: 0; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: .92rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.meters { display: flex; flex-direction: column; gap: 16px; }
.meter-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .92rem; margin-bottom: 6px; }
.meter-head .muted { font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 5px; background: var(--accent); transition: width .4s; }
.bar.warn > span { background: var(--warn); }
.bar.crit > span { background: var(--crit); }
.level { font-size: .8rem; font-weight: 600; margin-left: 8px; }
.level::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.level.warn::before { background: var(--warn); }
.level.crit::before { background: var(--crit); }

.spark { display: flex; flex-direction: column; gap: 4px; }
.spark[hidden] { display: none; }
.spark-head { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; }
.spark-head strong { font-variant-numeric: tabular-nums; }
.spark-plot { position: relative; height: 72px; touch-action: pan-y; }
.spark-plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spark-plot .grid { stroke: var(--line); stroke-width: 1; }
.spark-plot .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.spark-plot .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-plot .cross { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); pointer-events: none; }
.spark-plot .dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--card); pointer-events: none; }
.spark-plot .tip { position: absolute; top: 2px; transform: translateX(-50%); background: var(--text); color: var(--bg); font-size: .78rem; padding: 3px 8px; border-radius: 5px; white-space: nowrap; pointer-events: none; }
.spark-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); }

.services { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: .95rem; }
.services li { display: flex; justify-content: space-between; gap: 12px; }
.state::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; background: var(--muted); vertical-align: 1px; }
.state.good::before { background: var(--good); }
.state.crit::before { background: var(--crit); }
