:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --side: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #2a62d9;
  --accent-soft: #e8eefc;
  --accent-text: #ffffff;
  --ok: #1a8f4c;
  --warn: #c27a00;
  --bad: #c62f2f;
  --track: #e8eaee;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #181c22;
    --side: #14181d;
    --text: #e6e9ee;
    --muted: #8b95a5;
    --line: #2a3039;
    --accent: #5b8cff;
    --accent-soft: #1c2740;
    --accent-text: #0b0f14;
    --ok: #3ecf7d;
    --warn: #e5a93a;
    --bad: #ff6b6b;
    --track: #262c35;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; }
h3 { font-size: 17px; margin-bottom: 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.spacer { flex: 1; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

/* ---- shell: sidebar + content ---- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.side {
  background: var(--side); border-right: 1px solid var(--line);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; align-self: start;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; padding: 4px 8px 18px; }
.logo {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: 13px; font-weight: 700;
}
#nav { display: grid; gap: 2px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
#nav a:hover { background: var(--bg); }
#nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 18px; text-align: center; }
.badge { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--muted); }
.badge:empty { display: none; }

.main { min-width: 0; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

.page { padding: 20px; max-width: 1280px; margin: 0 auto; display: grid; gap: 16px; }

/* ---- cards and grids ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.card > h2 { display: flex; align-items: center; gap: 8px; }
.card > h2 .spacer + * { text-transform: none; letter-spacing: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile.warn .value { color: var(--warn); }
.tile.crit .value { color: var(--bad); }
.tile svg { display: block; width: 100%; height: 34px; margin-top: 8px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--accent); opacity: .12; stroke: none; }
.tile.warn .spark-line { stroke: var(--warn); }
.tile.warn .spark-area { fill: var(--warn); }
.tile.crit .spark-line { stroke: var(--bad); }
.tile.crit .spark-area { fill: var(--bad); }

/* ---- forms ---- */
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input[type="text"], input[type="search"], input[type="password"], select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; width: 100%;
}
select { width: auto; }
input:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 13px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small { padding: 3px 9px; font-size: 13px; }

.login { width: min(360px, 100%); display: grid; gap: 14px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"], .toolbar input[type="text"] { flex: 1; min-width: 180px; width: auto; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--card); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.check { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; color: var(--text); }

/* ---- meters and facts ---- */
.meter { margin-bottom: 12px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s; }
.fill.warn { background: var(--warn); }
.fill.crit { background: var(--bad); }

dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0; font-size: 13px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; word-break: break-word; }

.section-title { font-size: 13px; color: var(--muted); margin: 16px 0 6px; }
.section-title:first-child { margin-top: 0; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 10px 6px 0; white-space: nowrap; }
td { padding: 8px 10px 8px 0; border-top: 1px solid var(--line); vertical-align: middle; }
td.actions { text-align: right; white-space: nowrap; padding-right: 0; }
td.actions button { margin-left: 4px; }
td.name { font-weight: 500; }
.table-wrap { overflow-x: auto; }
.empty { padding: 18px 0; text-align: center; color: var(--muted); }

.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.chip.ok { color: var(--ok); }
.chip.bad { color: var(--bad); }
.chip.warn { color: var(--warn); }
.chip.plain { color: var(--muted); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }

.alerts { display: grid; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); font-size: 14px; }
.alert.warn { border-color: var(--warn); }
.alert.crit { border-color: var(--bad); }
.alert.ok { border-color: var(--ok); color: var(--ok); }
.alert .spacer { flex: 1; }

.power-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.power-grid .card { display: grid; gap: 10px; align-content: start; }
.power-grid p { margin: 0; }

pre.logs {
  margin: 0; height: 50vh; overflow: auto; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
}
pre.logs mark { background: var(--warn); color: #000; border-radius: 2px; }

dialog {
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
  padding: 20px; width: min(760px, calc(100vw - 24px));
}
dialog::backdrop { background: rgb(0 0 0 / .5); }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 10;
  max-width: calc(100vw - 32px);
}
#toast.bad { background: var(--bad); color: #fff; }

/* ---- small screens: the sidebar becomes a tab strip ---- */
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side {
    position: sticky; top: 0; z-index: 3; height: auto; display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto;
  }
  .brand { padding: 0 6px 0 2px; }
  .brand span:last-child { display: none; }
  #nav { display: flex; gap: 4px; }
  #nav a { padding: 7px 11px; white-space: nowrap; }
  .ico { display: none; }
  .top { position: static; padding: 10px 14px; flex-wrap: wrap; }
  .page { padding: 14px; }
  #updated { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .fill { transition: none; }
}
