:root {
  --navy: #0E2345; --gold: #C29B40; --gold-ink: #8A6A22; --bg: #F7F4EC; --card: #FFFFFF; --ink: #1D2433; --muted: #5B6472;
  --line: #E3DED1; --on: #1F7A4D; --off: #8A919C; --stop: #B42318; --warn: #A16207;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0D1320; --card: #161D2C; --ink: #E8E6E1; --muted: #A0A8B6; --line: #2A3347; --gold-ink: #D9B861; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); padding-bottom: env(safe-area-inset-bottom); }
.top { background: var(--navy); color: #F5F1E6; padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top)); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { margin: 0; font-size: 18px; } .top h1 span { color: var(--gold); }
.top .link { color: #F5F1E6; }
nav { display: flex; gap: 4px; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); padding: 0 8px; position: sticky; top: 0; z-index: 3; }
nav a { flex: none; padding: 12px 8px; font-size: 15px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; }
nav a.here { color: var(--ink); border-bottom-color: var(--gold); }
main { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 14px 0 6px; font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 26px; } .stat span { color: var(--muted); font-size: 13px; }
.stat.alert { border-color: var(--gold); box-shadow: inset 4px 0 0 var(--gold); }
.kill.on { border-color: var(--stop); box-shadow: inset 4px 0 0 var(--stop); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap; }
.pill.on { background: var(--on); } .pill.off { background: var(--off); } .pill.stop { background: var(--stop); } .pill.draft { background: var(--warn); }
button, select, input, textarea { font: inherit; color: var(--ink); }
button { padding: 10px 14px; min-height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.danger { background: var(--stop); color: #fff; border-color: var(--stop); }
button.link { background: none; border: 0; padding: 8px; min-height: 0; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); min-height: 44px; }
input.code { font-size: 24px; letter-spacing: 6px; text-align: center; }
label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 4px; }
.agent { border-top: 1px solid var(--line); padding: 12px 0; } .agent:first-of-type { border-top: 0; }
.wt { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px 0 8px 12px; border-left: 3px solid var(--line); margin: 6px 0; }
.wt select { width: auto; min-height: 40px; }
.draft { border-top: 1px solid var(--line); padding: 12px 0; } .draft:first-of-type { border-top: 0; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 320px; overflow: auto; font-size: 14px; margin: 8px 0; }
table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); border-top: 0; }
.wrap { overflow-x: auto; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: 220px; height: 220px; display: block; margin: 8px auto; }
.secret { font-family: ui-monospace, monospace; word-break: break-all; text-align: center; }
#msg div { padding: 10px 16px; color: #fff; } #msg .err { background: var(--stop); } #msg .ok { background: var(--on); }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: min(92vw, 460px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(10, 15, 25, .55); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
ul.log { padding-left: 18px; margin: 0; } ul.log li { margin-bottom: 6px; font-size: 14px; }
a.stat { color: inherit; text-decoration: none; }
.errtxt { color: var(--stop); }
