:root {
  --bg: #0f1216;
  --panel: #161b21;
  --panel-2: #1c232b;
  --line: #29313b;
  --text: #e6e9ed;
  --muted: #8b95a1;
  --accent: #4f8cff;
  --good: #2fb67c;
  --warn: #e2a33b;
  --bad: #e5534b;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #dde2e8;
    --text: #1a1f26;
    --muted: #5f6b78;
    --accent: #2563eb;
    --good: #18875a;
    --warn: #b7791f;
    --bad: #c9382f;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 8px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.card > h3:first-child, .card-head h3 { margin-top: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.good-text { color: var(--good); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.narrow { width: 100%; max-width: 380px; }
.notice { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 8px 10px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled, select:disabled, textarea:disabled { opacity: .75; }
input[type=checkbox] { width: auto; display: inline-block; margin: 0; accent-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-error { color: var(--bad); min-height: 1em; margin: 6px 0 0; }
.row-end { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.icon { padding: 6px 9px; }
.card .btn.primary.wide, form.card .btn.primary { width: 100%; padding: 10px; }
.link { background: none; border: 0; padding: 0; margin-top: 8px; color: var(--accent); font: inherit; cursor: pointer; }

/* brand + top bar */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .muted { font-weight: 500; }
.brand-icon { width: 26px; height: 26px; border-radius: 7px; }
form.card .brand { margin-bottom: 14px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { padding: 7px 11px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.nav a:hover { color: var(--text); text-decoration: none; background: var(--panel-2); }
.nav a.on { color: var(--text); background: var(--panel-2); }
.user { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.demo-banner { padding: 8px 16px; background: color-mix(in srgb, var(--warn) 18%, var(--panel)); border-bottom: 1px solid var(--line); font-size: 13px; }
.main { padding: 18px max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head select { width: auto; margin: 0; }
.live { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.good { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.dot.bad { background: var(--bad); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile-n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.tile-l { color: var(--muted); font-size: 12px; }
.tile.good .tile-n { color: var(--good); }
.tile.warn .tile-n { color: var(--warn); }
.tile.bad .tile-n { color: var(--bad); }
.mini-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.mini-tiles.three { grid-template-columns: repeat(3, 1fr); }
.mini-tiles > div { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.mini-tiles .tile-n { font-size: 18px; }

/* toolbar, chips, segmented */
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input { width: 260px; margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.chip span { color: var(--muted); margin-left: 4px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.on span { color: rgba(255, 255, 255, .8); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { padding: 6px 12px; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--panel-2); color: var(--text); }
.bulk { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 12px; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); }
.bulk select { width: auto; margin: 0; padding: 4px 8px; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
.data th, .data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.data tbody tr { cursor: pointer; }
.data tbody tr:hover { background: var(--panel-2); }
.data tbody tr.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.data tbody tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.check, td.check { width: 34px; padding-right: 0; }
.empty { text-align: center !important; color: var(--muted); padding: 32px !important; cursor: default; white-space: normal !important; }
.mini th, .mini td { padding: 7px 6px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.mini th { color: var(--muted); font-weight: 500; font-size: 12px; }
.mini tr:last-child td { border-bottom: 0; }
.mini.clickable tbody tr { cursor: pointer; }
.mini.clickable tbody tr:hover { background: var(--panel-2); }
.mini select { width: auto; margin: 0; padding: 4px 8px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.online { color: var(--good); } .status.online::before { background: var(--good); }
.status.stale { color: var(--warn); } .status.stale::before { background: var(--warn); }
.status.offline { color: var(--bad); } .status.offline::before { background: var(--bad); }
.status.never { color: var(--muted); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11.5px; font-weight: 600; border: 1px solid currentColor; color: var(--muted); white-space: nowrap; }
.tag.good, .tag.ev-info, .tag.cmd-done { color: var(--good); }
.tag.warn, .tag.ev-error, .tag.cmd-pending, .tag.cmd-delivered { color: var(--warn); }
.tag.bad, .tag.ev-crash, .tag.cmd-failed { color: var(--bad); }

/* side drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 10; width: min(500px, 100vw);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0, 0, 0, .3);
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) 20px; overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer-head .muted { margin-top: 4px; }
.alerts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.cmd-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.cmd-grid.two { grid-template-columns: 1fr 1fr; }
.events, .notes, .plain { list-style: none; margin: 0; padding: 0; }
.events li { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.events summary { display: flex; gap: 8px; align-items: center; padding: 8px 10px; cursor: pointer; flex-wrap: wrap; }
.ev-msg { flex: 1; min-width: 140px; }
.events pre { margin: 0; padding: 10px; border-top: 1px solid var(--line); background: var(--panel-2); font: 12px/1.5 var(--mono); overflow-x: auto; border-radius: 0 0 8px 8px; }
.notes li { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; margin-bottom: 10px; }
.notes p { margin: 0 0 2px; white-space: pre-wrap; }
.plain li { padding: 4px 0; }
.links li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.links li:last-child { border-bottom: 0; }
.note-form { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.note-form textarea { margin: 0; }
.ev-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.ev-form select, .ev-form input { width: auto; margin: 0; }
.ev-form input[name=details] { flex: 1; min-width: 160px; }
.ev-form .short { width: 90px; }
.ev-form .check { margin: 0; }

/* charts */
.uptime-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.uptime { width: 100%; height: 28px; display: block; }
.uptime rect.up { fill: var(--good); }
.uptime rect.down { fill: var(--bad); }
.uptime rect.none { fill: var(--line); }
.uptime rect:hover { opacity: .75; }
.uptime-foot { display: flex; justify-content: space-between; margin-top: 4px; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 8px; }
.sw.up { background: var(--good); } .sw.down { background: var(--bad); }
.bars { width: 100%; height: auto; display: block; }
.bars .grid { stroke: var(--line); stroke-width: 1; }
.bars .baseline { stroke: var(--muted); stroke-width: 1; }
.bars .axis { fill: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.bars .bar path { fill: var(--accent); }
.bars .bar .hit { fill: transparent; }
.bars .bar:hover path { fill: color-mix(in srgb, var(--accent) 75%, var(--text)); }
.bars .bar:hover .hit { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.meter { display: inline-block; width: 120px; height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; vertical-align: middle; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-cell { width: 130px; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 16px; align-items: start; }
.cols .card { margin: 0; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.checks li:last-child { border-bottom: 0; }

/* modal */
dialog#modal { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 0; width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog#modal.wide { width: min(760px, calc(100vw - 32px)); }
dialog#modal::backdrop { background: rgba(0, 0, 0, .55); }
.modal-body { padding: 22px; }
.big-code { font: 700 36px/1 var(--mono); letter-spacing: .12em; text-align: center; padding: 22px 8px; margin: 14px 0; background: var(--panel-2); border: 1px dashed var(--line); border-radius: var(--radius); user-select: all; }
.big-code.small-code { font-size: 22px; letter-spacing: .04em; }

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

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; }
  .user .tag { display: none; }
}
@media (max-width: 640px) {
  .toolbar input { width: 100%; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-n { font-size: 20px; }
  .page-head .btn { padding: 6px 10px; }
  .drawer { border-left: 0; }
  .note-form { flex-direction: column; align-items: stretch; }
  .bar-cell, .meter { width: 70px; }
  .grid2 { grid-template-columns: 1fr; }
  .cmd-grid { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .mini-tiles.three { grid-template-columns: 1fr 1fr; }
  .user button[data-action=account] { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
}
