:root {
  --bg: #0b0f14; --card: #131a23; --card2: #1a2330; --line: #243040;
  --text: #e6edf3; --muted: #8b98a5; --green: #22c55e; --red: #ef4444; --amber: #f59e0b; --blue: #3b82f6;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --tab-h: 58px; --kill-h: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); height: 100%;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: contain; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.boot { display: grid; place-items: center; height: 100dvh; color: var(--muted); }

/* layout */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto; }
header.top { padding: calc(10px + var(--safe-t)) 16px 10px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line); background: var(--bg); }
header.top h1 { font-size: 17px; margin: 0; flex: 1; }
main { flex: 1; overflow-y: auto; padding: 14px 16px calc(var(--kill-h) + var(--tab-h) + var(--safe-b) + 24px);
  -webkit-overflow-scrolling: touch; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; background: var(--bg);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 20; }
.killbar { display: flex; gap: 10px; padding: 8px 16px; height: var(--kill-h); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tab-h); border-top: 1px solid var(--line); }
.tabs button { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 12px; min-height: 48px; }
.tabs button.on { color: var(--text); }
.tabs svg { width: 22px; height: 22px; }

/* atoms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.pos { color: var(--green); } .neg { color: var(--red); } .warn { color: var(--amber); }
.big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px;
  font-weight: 700; background: var(--card2); border: 1px solid var(--line); }
.pill.paper { color: var(--green); border-color: #1d5a35; background: #0f2a1b; }
.pill.live { color: #fff; background: var(--red); border-color: var(--red); animation: pulse 2s infinite; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--green); } .dot.off { background: var(--red); }
@keyframes pulse { 50% { opacity: .75; } }

button.btn { min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2);
  font-weight: 600; cursor: pointer; }
button.btn:active { transform: scale(.98); }
button.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.btn.ghost { background: transparent; }
button.btn.wide { width: 100%; }
button.btn[disabled] { opacity: .5; }
.killbar .btn { flex: 1; min-height: 46px; font-size: 16px; }
.killbar .btn.danger { flex: 2; font-weight: 800; letter-spacing: .04em; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; font-size: 16px; }
textarea { min-height: 80px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* switch */
.switch { position: relative; width: 56px; height: 32px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; z-index: 2; }
.switch i { position: absolute; inset: 0; background: #2a3646; border-radius: 999px; transition: .15s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; transition: .15s; }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(24px); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); font-size: 22px; }

/* banners */
.banner { padding: 11px 14px; border-radius: 12px; margin-bottom: 10px; font-size: 14px; border: 1px solid; }
.banner.error { background: #2a1113; border-color: #6b1d22; color: #fecaca; }
.banner.warn { background: #2b2210; border-color: #6b5314; color: #fde68a; }
.banner.halt { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.banner.info { background: #10203a; border-color: #1e3a6b; color: #bfdbfe; }

/* meter */
.meter { height: 8px; background: var(--card2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.meter b { display: block; height: 100%; background: var(--amber); border-radius: 999px; }

/* lists */
.item { padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; padding-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--card2); color: var(--muted); font-weight: 700; }
.lvl-error, .lvl-critical { color: var(--red); } .lvl-warn { color: var(--amber); }
.logline { font-size: 13px; padding: 7px 0; border-top: 1px solid var(--line); word-break: break-word; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 0; }

/* segmented */
.seg { display: grid; grid-auto-flow: column; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; min-height: 42px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card2); color: var(--text); }

/* sheet + toast */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  border: 1px solid var(--line); }
.sheet h3 { margin: 0 0 6px; font-size: 19px; } .sheet p { margin: 0 0 14px; color: var(--muted); }
#toasts { position: fixed; top: calc(12px + var(--safe-t)); left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #0d1520; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; max-width: 90%; box-shadow: 0 8px 24px #0009; font-size: 15px; }
.toast.err { border-color: var(--red); color: #fecaca; } .toast.ok { border-color: var(--green); }

/* hold-to-confirm */
.hold { position: relative; overflow: hidden; user-select: none; touch-action: none; }
.hold i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255,255,255,.35); }

@media (min-width: 700px) { body { background: #06090c; } #app { border-inline: 1px solid var(--line); } }
