:root {
  --bg: #0f1720; --card: #17212c; --card2: #1e2a37; --text: #e6edf3; --muted: #8b9bab;
  --line: #2a3846; --green: #22c55e; --red: #ef4444; --amber: #f59e0b; --blue: #3b82f6;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: rgba(15,23,32,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 0 0 auto; }
.status { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px;
  border-radius: 999px; background: var(--card2); color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on .dot { background: var(--green); }
.pill.off .dot { background: var(--red); }
.pill.off { color: #fca5a5; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.toggle { font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.empty { color: var(--muted); padding: 8px 0; list-style: none; }

.partitions { display: grid; gap: 12px; }
.partition { border-left: 6px solid var(--muted); }
.partition.ok { border-left-color: var(--green); }
.partition.armed { border-left-color: var(--red); }
.partition.warn { border-left-color: var(--amber); }
.partition.alarm { border-left-color: var(--red); background: #3a1416; animation: pulse 1s infinite alternate; }
.partition.all { border-left-color: var(--blue); }
.partition-name { color: var(--muted); font-size: 14px; }
.partition-state { font-size: 28px; font-weight: 700; margin: 2px 0 6px; }
.partition.ok .partition-state { color: var(--green); }
.partition.armed .partition-state, .partition.alarm .partition-state { color: #f87171; }
.partition.warn .partition-state { color: var(--amber); }
.partition-extra { font-size: 14px; color: var(--amber); margin-bottom: 6px; }
@keyframes pulse { from { background: #3a1416; } to { background: #5c1a1d; } }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.actions > .btn-disarm:nth-child(3) { grid-column: 1 / -1; }
.btn { appearance: none; border: 0; border-radius: 12px; padding: 14px 12px; font: inherit; font-weight: 600;
  color: #fff; cursor: pointer; min-height: 48px; }
.btn:disabled { opacity: .5; cursor: wait; }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn-arm { background: #b91c1c; }
.btn-stay { background: #b45309; }
.btn-disarm { background: #15803d; }
.btn-primary { background: var(--blue); }
.btn-ghost { background: var(--card2); color: var(--text); }
.btn-small { padding: 6px 10px; min-height: 34px; font-size: 13px; font-weight: 500; }

.zones, .events { list-style: none; margin: 0; padding: 0; }
.zone { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.zone:first-child { border-top: 0; }
.zname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.zdot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; background: var(--green); }
.zdot.open { background: var(--amber); }
.zdot.alarm { background: var(--red); box-shadow: 0 0 0 4px rgba(239,68,68,.25); }
.zdot.bypassed { background: var(--muted); }
.badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--card2); }
.badge.alarm { background: var(--red); color: #fff; }
.badge.muted { color: var(--muted); }
.zstate { font-size: 13px; color: var(--muted); min-width: 42px; text-align: right; }

.ev { display: grid; grid-template-columns: auto auto 1fr; gap: 4px 10px; padding: 8px 0;
  border-top: 1px solid var(--line); font-size: 14px; }
.ev:first-child { border-top: 0; }
.ev-time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev-src { color: var(--muted); font-size: 12px; padding-top: 1px; }
.ev-text { min-width: 0; overflow-wrap: anywhere; }
.ev.alarm .ev-text { color: #f87171; font-weight: 600; }
.ev.warn .ev-text { color: var(--amber); }
@media (max-width: 480px) {
  .ev { grid-template-columns: auto 1fr; }
  .ev-text { grid-column: 1 / -1; }
  .partition-state { font-size: 24px; }
}

.foot { color: var(--muted); font-size: 12px; text-align: center; margin: 0; }

dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; width: min(92vw, 380px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog p { font-size: 18px; margin: 0 0 16px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-actions .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  background: var(--card2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  transition: transform .2s, visibility .2s; max-width: calc(100vw - 32px); z-index: 10; visibility: hidden; }
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.bad { border-color: var(--red); color: #fca5a5; }

body.alarm-active .topbar { background: rgba(127,29,29,.95); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(100%, 340px); text-align: center; }
.login-icon { width: 72px; height: 72px; }
.login-box h1 { font-size: 26px; margin: 8px 0 20px; }
.login-box form { display: grid; gap: 10px; text-align: left; }
.login-box label { color: var(--muted); font-size: 14px; }
.login-box input { font: inherit; padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); }
.error { color: #fca5a5; min-height: 1.4em; margin: 0; }
