:root {
  --bg: #0d1117; --panel: #151b23; --panel2: #1b2330; --line: #2a3442; --text: #e6edf3; --muted: #8b98a8;
  --accent: #4fa3ff; --accent-ink: #06121f; --good: #3fb950; --warn: #d29922; --bad: #f85149;
  --chart-a: #4fa3ff; --chart-b: #3fb950; --chart-c: #d29922;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f7fa; --panel: #ffffff; --panel2: #eef2f6; --line: #d6dde6; --text: #1b2430; --muted: #5b6878;
    --accent: #1f6fd1; --accent-ink: #ffffff; --good: #1a7f37; --warn: #9a6700; --bad: #cf222e;
    --chart-a: #1f6fd1; --chart-b: #1a7f37; --chart-c: #9a6700;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; letter-spacing: .02em; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
code { background: var(--panel2); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: var(--bad); min-height: 1em; }
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; }
input[type=color] { padding: 2px; width: 40px; height: 32px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
textarea { resize: vertical; width: 100%; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--bad); } button.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { background: transparent; } button.small { padding: 3px 8px; font-size: 12px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.check, label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.num { width: 72px; } .mid { width: 220px; } .grow { flex: 1; } .search { width: 260px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.srv-name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; background: var(--panel2); }
.chip.good { border-color: var(--good); color: var(--good); } .chip.bad { border-color: var(--bad); color: var(--bad); }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.me { display: flex; gap: 8px; align-items: center; }

.tabs, .subtabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button, .subtabs button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; color: var(--muted); }
.tabs button.active, .subtabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.subtabs { padding: 0; margin: 0 0 14px; }
.tab { padding: 16px 20px 30px; max-width: 1600px; margin: 0 auto; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; min-width: 0; }
.grid.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.col { min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; }
.row + .row, form.row { margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.form-grid.three { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 3px 10px; font-size: 12px; background: transparent; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }

.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.t-label { color: var(--muted); font-size: 12px; } .t-val { font-size: 26px; font-weight: 700; } .t-sub { color: var(--muted); font-size: 12px; }
.t-val.good { color: var(--good); } .t-val.warn { color: var(--warn); } .t-val.bad { color: var(--bad); }
.now-map { font-size: 24px; font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 10px 0; font-size: 13px; }
.kv dt, .kv .k { color: var(--muted); }
.list { margin: 0; padding-left: 20px; } .list li { padding: 3px 0; }
.list li .acts { float: right; display: inline-flex; gap: 4px; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; } .sw-a { background: var(--chart-a); } .sw-b { background: var(--chart-b); } .sw-c { background: var(--chart-c); }
canvas { width: 100%; display: block; }

.feed-card { display: flex; flex-direction: column; height: calc(100vh - 250px); min-height: 420px; }
.feed { flex: 1; overflow-y: auto; font-size: 13px; border-top: 1px solid var(--line); padding-top: 6px; }
.feed.short { max-height: 560px; }
.ev { padding: 2px 0; display: flex; gap: 8px; } .ev .t { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.ev.chat b { color: var(--accent); } .ev.mod { color: var(--warn); } .ev.kill { color: var(--muted); } .ev.sys { color: var(--muted); font-style: italic; }
.ev.bad { color: var(--bad); }
.say { margin-top: 8px; } .say input[name=text] { flex: 1; }

.table-wrap { overflow-x: auto; max-height: 70vh; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:hover td { background: var(--panel2); }
.id { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); cursor: copy; }
.badge { font-size: 11px; border-radius: 4px; padding: 0 5px; margin-left: 4px; border: 1px solid var(--line); color: var(--muted); }
.badge.admin { color: var(--accent); border-color: var(--accent); } .badge.muted { color: var(--bad); border-color: var(--bad); }
.guest { color: var(--muted); font-size: 12px; }
.bar { display: inline-block; width: 50px; height: 5px; background: var(--panel2); border-radius: 3px; vertical-align: middle; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--good); } .bar.sh i { background: var(--accent); }
.pre { white-space: pre-wrap; background: var(--panel2); border-radius: 6px; padding: 8px; margin: 8px 0 0; max-height: 260px; overflow: auto; }
.pre:empty { display: none; }
.role { border-top: 1px solid var(--line); padding: 8px 0; } .role:first-child { border-top: none; }
.role .perm { color: var(--muted); font-size: 12px; }
.holder { display: inline-flex; gap: 4px; align-items: center; background: var(--panel2); border-radius: 4px; padding: 1px 6px; margin: 2px 4px 2px 0; font-size: 12px; }
.console-card { display: flex; flex-direction: column; }
.console { height: 380px; overflow-y: auto; background: var(--panel2); border-radius: 6px; padding: 8px; font: 12px/1.4 ui-monospace, monospace; white-space: pre-wrap; }
.console .cmd { color: var(--accent); } .console .err { color: var(--bad); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dlg { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.dlg fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
.dlg legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(460px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--good); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.35); white-space: pre-wrap; z-index: 10; }
.toast.bad { border-left-color: var(--bad); }

@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid.two { grid-template-columns: minmax(0, 1fr); } .feed-card { height: 560px; } }
@media (max-width: 640px) {
  .top, .tabs, .tab { padding-left: 16px; padding-right: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .search, .mid { width: 100%; }
  .say { flex-wrap: wrap; }
}

/* ---- one screen, no page scrolling: the window is the app; long content scrolls in its own box ---- */
@media (min-width: 1000px) and (min-height: 600px) {
  html, body { height: 100%; overflow: hidden; }
  #app { height: 100vh; display: flex; flex-direction: column; }
  .top, .tabs { flex: none; }
  .tab { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: 14px; }
  .tab > .card, .sub > .card { margin-bottom: 14px; }
  .tab > .card:last-child, .sub > .card:last-child { margin-bottom: 0; }
  .tiles { flex: none; }
  .grid.two, .grid.three { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr); }
  .grid.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .col { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding-right: 2px; }
  .col.noscroll { overflow: hidden; }
  .col > .card:last-child { margin-bottom: 0; }
  .card.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .card.fill > .table-wrap, .card.fill > .feed, .card.fill > .console, .card.fill > .scroll, .card.fill > .chart-box { flex: 1; min-height: 0; }
  .card.fill > *:not(.table-wrap):not(.feed):not(.console):not(.scroll):not(.chart-box) { flex: none; }
  .table-wrap, .feed.short { max-height: none; }
  .feed-card { height: auto; min-height: 0; }
  .subtabs { flex: none; }
  .sub { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .scroll { overflow-y: auto; min-height: 0; }
  .scroll-card { display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
  .scroll-card > .scroll { flex: 1; }
  .console { height: auto; }
  .chart-box { position: relative; min-height: 140px; }
  .chart-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
}
.chart-box { position: relative; height: 220px; } .chart-box.short { height: 200px; }
.chart-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
@media (min-width: 1000px) and (min-height: 600px) { .chart-box.short { flex: none; height: 200px; } }

/* health tab */
.tiles.eight { grid-template-columns: repeat(8, minmax(0, 1fr)); width: 100%; margin-bottom: 10px; }
.hbar { flex: none; }
.hbar + .hbar { margin: 0 0 10px; }
.grid.quad { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.grid.quad > .card { margin: 0; min-height: 200px; display: flex; flex-direction: column; }
.grid.quad .chart-box { flex: 1; min-height: 160px; height: auto; }
@media (min-width: 1000px) and (min-height: 600px) {
  .grid.quad { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .grid.quad > .card { min-height: 0; }
  .grid.quad .chart-box { min-height: 0; }
}
@media (max-width: 1400px) { .tiles.eight { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .grid.quad { grid-template-columns: minmax(0, 1fr); } }
