:root {
  --body: #12181F; --head: #0B1016; --card: #1B2530; --card-alt: #1F2935; --line: #364858; --btn: #222D3A;
  --btn-line: #506478; --text: #FFFFFF; --muted: #9FB1C0; --accent: #44B3E6; --green: #3FB950; --green-bg: #12462D;
  --red: #EB6969; --red-bg: #69221E; --amber: #E6841F; --amber-bg: #4A3417; --gray: #6E7F8E;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--body); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
header#top { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--head);
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; color: var(--text); font-size: 18px; letter-spacing: .5px; }
.brand img { width: 30px; height: 30px; }
.brand b { color: var(--accent); }
#who button { white-space: nowrap; }
#who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; min-width: 0; }
#who .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px; }
footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 16px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--head); color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
button, .btn { background: var(--btn); color: var(--text); border: 1px solid var(--btn-line); border-radius: 4px; padding: 7px 14px;
  font: inherit; font-size: 13px; font-weight: 600; letter-spacing: .4px; cursor: pointer; min-height: 36px; }
button:hover { background: #273542; }
button:disabled { opacity: .5; cursor: default; }
button.on { border-color: var(--accent); color: var(--accent); }
input, select { background: #0F151C; color: var(--text); border: 1px solid var(--btn-line); border-radius: 4px; padding: 9px 10px; font: inherit; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 18px 0 8px; color: #A5B9CA; letter-spacing: .6px; text-transform: uppercase; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: 12px; }
.err { color: var(--red); min-height: 20px; }
.login { max-width: 380px; margin: 8vh auto 0; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 24px; }
.login label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 13px; }
.login button { width: 100%; margin-top: 18px; min-height: 42px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 14px; min-width: 0; }
a.card { display: block; color: var(--text); }
a.card:hover { border-color: var(--accent); }
.card.alarm { border-color: var(--red); }
.vrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.vname { font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin-top: 10px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 3px; font-size: 12px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.pill.online, .pill.ok { background: var(--green-bg); color: #8EE3A2; }
.pill.offline, .pill.critical, .pill.high { background: var(--red-bg); color: #FFB4B4; }
.pill.medium, .pill.warn { background: var(--amber-bg); color: #FFC57A; }
.pill.low, .pill.unknown, .pill.off { background: #2A3540; color: var(--muted); }
.summary { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 12px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tabs button { flex: 0 0 auto; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #26323F; vertical-align: top; }
th { background: var(--card-alt); color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .4px; text-transform: uppercase; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #222E3A; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stale td { color: var(--gray); }
.empty { padding: 18px; color: var(--muted); }
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.trend-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.trend-controls select { width: auto; max-width: 100%; flex: 1 1 260px; }
svg.chart { width: 100%; height: auto; display: block; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
svg.chart .grid { stroke: #26323F; stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
svg.chart .band { fill: rgba(68,179,230,.15); stroke: none; }
@media (max-width: 640px) {
  main { padding: 12px; }
  .grid, .devices { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  #who .name { display: none; }
}
.card > .kv:first-child { margin-top: 0; }
@media (max-width: 420px) {
  #who { gap: 6px; }
  #who .pill { display: none; }
  #who button { padding: 7px 9px; font-size: 12px; }
}
a.btn { display: inline-flex; align-items: center; color: var(--text); }
.login.wide { max-width: 480px; }
.login.left { margin: 16px 0; }
.login .kv { margin-top: 6px; }
.qr { background: #FFFFFF; border-radius: 6px; padding: 8px; width: max-content; margin: 8px 0; }
.qr img { display: block; width: 200px; height: 200px; }
code.key { display: block; font: 15px/1.5 ui-monospace, Menlo, monospace; background: #0F151C; border: 1px solid var(--line); border-radius: 4px;
  padding: 8px 10px; word-break: break-all; letter-spacing: .5px; }
.ok { color: #8EE3A2; min-height: 20px; }
.notice { border-color: var(--amber); margin-bottom: 12px; }
.notice input { margin: 6px 0; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.addform { margin-bottom: 12px; }
.addform h2 { margin-top: 0; }
.addform label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.row3 { display: grid; grid-template-columns: 2fr 2fr 1fr auto; gap: 10px; align-items: end; }
.row3 .end button { width: 100%; }
td.actions { white-space: nowrap; }
td.actions button { margin: 2px 4px 2px 0; min-height: 32px; padding: 5px 10px; font-size: 12px; }
td select { width: auto; padding: 6px 8px; }
@media (max-width: 760px) { .row3 { grid-template-columns: 1fr; } }
