:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel2: #1a2539;
  --line: #26324a;
  --text: #e6ecf5;
  --muted: #8b98ad;
  --brand: #2f7cf6;
  --ok: #22c55e;
  --okbg: #0f3a24;
  --warn: #f59e0b;
  --warnbg: #3d2a07;
  --bad: #ef4444;
  --badbg: #451515;
  --armed: #3b82f6;
  --armedbg: #102a55;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding: 0 16px 96px; }
.boot { display: grid; place-items: center; height: 100vh; font-weight: 800; letter-spacing: 4px; color: var(--muted); }
a { color: #8bb8ff; text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.hidden { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(12px + env(safe-area-inset-top)) 0 12px; display: flex; align-items: center; gap: 10px; }
.top .title { flex: 1; min-width: 0; }
.top .title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { background: var(--panel); border: 1px solid var(--line); color: var(--text); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; flex: none; }
.iconbtn svg { width: 20px; height: 20px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.flat { padding: 0; overflow: hidden; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--okbg); color: #86efac; }
.pill.bad { background: var(--badbg); color: #fca5a5; }
.pill.warn { background: var(--warnbg); color: #fcd34d; }
.pill.info { background: var(--armedbg); color: #93c5fd; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* status hero */
.hero { border-radius: 20px; padding: 22px 18px; text-align: center; margin-bottom: 14px; border: 1px solid var(--line); }
.hero .mode { font-size: 30px; font-weight: 800; letter-spacing: 1px; }
.hero .sub { margin-top: 4px; color: rgba(255,255,255,.75); font-size: 14px; }
.hero .count { font-size: 52px; font-weight: 800; line-height: 1; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.hero.disarmed { background: linear-gradient(160deg, #13301f, #0f1f19); border-color: #1f5135; }
.hero.armed { background: linear-gradient(160deg, #12306a, #0e1c3a); border-color: #274f9c; }
.hero.arming, .hero.entry { background: linear-gradient(160deg, #4a3208, #2a1d07); border-color: #7a5410; }
.hero.alarm { background: linear-gradient(160deg, #7f1414, #3d0b0b); border-color: #b91c1c; animation: alarm 1s steps(2) infinite; }
.hero.offline { background: var(--panel); }
@keyframes alarm { 50% { background: #3d0b0b; } }
.hero .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.hero .actions.one { grid-template-columns: 1fr; }

/* buttons */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 12px; padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn.arm { background: var(--armed); border-color: var(--armed); color: #fff; }
.btn.light { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 8px 12px; font-size: 13px; width: auto; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; }
.btnrow { display: flex; gap: 10px; }
.btnrow > * { flex: 1; }

/* sensors */
.sensors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.sensor { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; gap: 10px; align-items: center; transition: background .2s, border-color .2s; }
.sensor .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--panel2); color: var(--muted); flex: none; }
.sensor .ic svg { width: 20px; height: 20px; }
.sensor .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sensor .st { font-size: 12px; color: var(--muted); }
.sensor.triggered { background: var(--badbg); border-color: #7f1d1d; }
.sensor.triggered .ic { background: var(--bad); color: #fff; }
.sensor.triggered .st { color: #fca5a5; font-weight: 700; }
.sensor.ok .ic { color: var(--ok); }
.sensor.off { opacity: .5; }
.sensor.test { border-color: var(--warn); }

/* status tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile .k { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tile .k svg { width: 15px; height: 15px; }
.tile .v { font-size: 16px; font-weight: 700; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v.ok { color: #86efac; } .tile .v.bad { color: #fca5a5; } .tile .v.warn { color: #fcd34d; }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; vertical-align: -1px; margin-left: 4px; }
.bars i { width: 4px; background: var(--line); border-radius: 1px; }
.bars i.on { background: currentColor; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.list li:first-child { border-top: 0; }
.ev .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--panel2); color: var(--muted); flex: none; }
.ev .ic svg { width: 16px; height: 16px; }
.ev.alert .ic { background: var(--badbg); color: #fca5a5; }
.ev.good .ic { background: var(--okbg); color: #86efac; }
.ev.arm .ic { background: var(--armedbg); color: #93c5fd; }
.ev .t { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ev .m { font-size: 14px; }
.day { padding: 8px 16px; font-size: 12px; color: var(--muted); background: var(--panel2); font-weight: 600; }

/* forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 16px; font-family: inherit; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.err { color: #fca5a5; font-size: 13px; min-height: 18px; margin-top: 6px; }

/* switch */
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* bottom nav */
.nav { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(11,18,32,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.nav .in { max-width: 560px; margin: 0 auto; display: flex; }
.nav a { flex: 1; text-align: center; padding: 9px 0 8px; color: var(--muted); font-size: 11px; font-weight: 600; }
.nav a svg { width: 22px; height: 22px; display: block; margin: 0 auto 2px; }
.nav a.on { color: #8bb8ff; }

.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 1; margin-bottom: 12px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.bigicon { width: 64px; height: 64px; border-radius: 18px; background: var(--armedbg); color: #93c5fd; display: grid; place-items: center; margin: 6px auto 14px; }
.bigicon svg { width: 34px; height: 34px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
ol.howto { padding-left: 20px; margin: 0 0 12px; }
ol.howto li { margin-bottom: 6px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--panel2); padding: 2px 6px; border-radius: 6px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; font-size: 12px; margin: 10px 0 0; }

/* auth */
.auth { padding-top: 12vh; }
.brand { text-align: center; margin-bottom: 28px; }
.brand .logo { width: 72px; height: 72px; margin: 0 auto 12px; }
.brand h1 { font-size: 26px; letter-spacing: 1px; }

/* offline banner & toasts */
.banner { background: var(--warnbg); color: #fcd34d; border: 1px solid #7a5410; border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; display: flex; gap: 8px; align-items: flex-start; }
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
#toasts { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { background: #1f2a40; border: 1px solid var(--line); color: var(--text); padding: 11px 14px; border-radius: 12px; font-size: 14px; max-width: 520px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.4); pointer-events: auto; animation: tin .2s ease-out; }
.toast.bad { background: #5b1414; border-color: #991b1b; }
.toast.ok { background: #0f3a24; border-color: #166534; }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; word-break: break-all; }
.devrow { display: flex; align-items: center; gap: 12px; }
.devrow .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--panel2); flex: none; }
.devrow .ic svg { width: 24px; height: 24px; }
