:root {
  color-scheme: dark;
  --bg: #070b16;
  --bg-2: #0b1220;
  --surface: #111a2e;
  --surface-2: #16213a;
  --line: #22304f;
  --line-soft: #1a2640;
  --text: #eef2fb;
  --text-2: #a9b4cc;
  --muted: #6f7c98;
  /* entity colors (validated dark palette, see dataviz check) */
  --pv: #d95926;
  --pv-glow: #ffb347;
  --load: #3987e5;
  --batt: #199e70;
  --batt-glow: #3de0a6;
  --grid: #9085e9;
  /* status */
  --good: #2fbf71;
  --warn: #e0a100;
  --bad: #e5484d;
  --radius: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --num: "Space Grotesk", "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }
body { min-height: 100vh; background:
  radial-gradient(1200px 600px at 10% -10%, #14234a55, transparent 60%),
  radial-gradient(900px 500px at 110% 10%, #2a1b4d44, transparent 60%), var(--bg); }
a { color: #8fb8ff; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-size: 0.85em; }
.muted { color: var(--muted); }
.dim { color: var(--text-2); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 12px 22px; background: #070b16cc; backdrop-filter: blur(12px); border-bottom: 1px solid var(--line-soft); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 7px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.spacer { flex: 1; }
.live { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--good); box-shadow: 0 0 0 0 #2fbf7188; animation: pulse 2s infinite; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #2fbf7188; } 70% { box-shadow: 0 0 0 8px #2fbf7100; } 100% { box-shadow: 0 0 0 0 #2fbf7100; } }
.usermenu { position: relative; }
.usermenu > button { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; display: flex; gap: 8px; align-items: center; }
.usermenu .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px; min-width: 190px; box-shadow: 0 20px 40px #0008; }
.usermenu .menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px;
  border-radius: 8px; cursor: pointer; }
.usermenu .menu button:hover { background: var(--surface-2); }
.role-badge { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- layout ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 22px; }
.card { background: linear-gradient(180deg, var(--surface), #0f1729); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 18px 20px; }
.card h2, .card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .cols-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding: 14px 16px; }
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .live .txt { display: none; }
}
.section-title { display: flex; align-items: baseline; gap: 12px; margin: 26px 2px 12px; }
.section-title h2 { margin: 0; font-size: 18px; font-weight: 650; }

/* ---------- tiles ---------- */
.tile { position: relative; overflow: hidden; }
.tile .k { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.tile .v { font-family: var(--num); font-size: 28px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 14px; color: var(--text-2); font-weight: 500; margin-left: 3px; }
.tile .s { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ---------- forms / buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 550; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #3a4d78; background: #1b2847; }
.btn.primary { background: #2563eb; border-color: #2563eb; }
.btn.primary:hover { background: #1d4fd0; }
.btn.danger { background: #3a1418; border-color: #6b2027; color: #ffb4b8; }
.btn.danger:hover { background: #4d1a20; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: #4b74d8; box-shadow: 0 0 0 3px #2563eb33; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
.field-help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 38px; height: 22px; appearance: none; background: var(--line); border-radius: 999px; position: relative;
  cursor: pointer; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .2s; }
.switch input:checked { background: #2563eb; }
.switch input:checked::after { transform: translateX(16px); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; color: var(--muted); font-weight: 550; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.t tr:hover td { background: #ffffff05; }
table.t td.r, table.t th.r { text-align: right; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 550; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.good { color: #7ee2a8; border-color: #1f5a3a; background: #0f2a1d; }
.pill.warn { color: #ffd479; border-color: #5b4712; background: #2a210a; }
.pill.bad { color: #ff9ea2; border-color: #6b2027; background: #2a0f12; }
.pill.info { color: #a9c6ff; border-color: #29467f; background: #0f1d3a; }

/* ---------- toast / modal ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid #4b74d8; padding: 11px 14px;
  border-radius: 10px; box-shadow: 0 12px 30px #0009; max-width: 380px; animation: tin .2s ease-out; }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--good); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.modal-bg { position: fixed; inset: 0; background: #02050dcc; backdrop-filter: blur(4px); z-index: 90; display: grid;
  place-items: center; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(520px, 100%);
  max-height: 90vh; overflow: auto; box-shadow: 0 30px 80px #000a; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
pre.code { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto;
  font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-all; }

/* ---------- uPlot dark ---------- */
.uplot { font-family: var(--font); }
.u-legend { color: var(--text-2); font-size: 12.5px; }
.u-legend .u-marker { border-radius: 2px; }
.u-legend th { font-weight: 500; }
.u-legend td { font-family: var(--num); color: var(--text); }
.chart-empty { display: grid; place-items: center; height: 220px; color: var(--muted); font-size: 14px; }
