:root {
  --bg: #0f1216;
  --card: #181c22;
  --card2: #20252d;
  --line: #2a3039;
  --text: #e9edf2;
  --muted: #8b95a3;
  --green: #2fbf71;
  --amber: #f0a92e;
  --red: #ef4444;
  --orange: #f97316;
  --blue: #30C6CC;
  --gray: #6b7280;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
input { font: inherit; }
.hidden { display: none !important; }

/* Layout */
.top { position: sticky; top: 0; z-index: 5; background: rgba(15,18,22,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: calc(var(--safe-top) + 10px) 16px 10px; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.title { font-weight: 700; font-size: 18px; }
.live { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); display: inline-block; }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }
main { padding: 14px 16px calc(var(--safe-bottom) + 90px); max-width: 720px; margin: 0 auto; }

.tabs { display: flex; gap: 6px; margin-top: 10px; background: var(--card); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; padding: 9px 6px; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; position: relative; }
.tabs button.on { background: var(--card2); color: var(--text); }
.tabs .badge { position: absolute; top: 5px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.tabs .badge.warn { background: var(--amber); }

.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: rgba(24,28,34,.96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.nav button { flex: 1; background: none; padding: 10px 0 12px; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.nav button.on { color: var(--text); }
.nav svg { width: 24px; height: 24px; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card h2 { margin: 0 0 2px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.state { font-size: 30px; font-weight: 800; margin: 4px 0 2px; }
.state.green { color: var(--green); }
.state.red { color: var(--red); }
.state.amber { color: var(--amber); }
.sub { color: var(--muted); font-size: 14px; }
.card.alarm { border-color: var(--red); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { background: #2a1416; } to { background: #3d1518; } }
.banner { background: #3a1d1d; border: 1px solid #7f1d1d; color: #fecaca; border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.banner.info { background: #1d2a3a; border-color: #1e3a5f; color: #bfdbfe; }

.btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.btn { padding: 15px 10px; border-radius: 12px; background: var(--card2); font-weight: 700; font-size: 16px; border: 1px solid var(--line); }
.btn:active { transform: scale(.98); }
.btn.green { background: #173a28; border-color: #1f6b43; color: #bff3d4; }
.btn.red { background: #3b1a1a; border-color: #7f1d1d; color: #fecaca; }
.btn.blue { background: #0f3436; border-color: #30C6CC; color: #d6f6f7; }
.btn.wide { grid-column: 1 / -1; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; }
.more { margin-top: 10px; text-align: center; }
.link { background: none; color: var(--blue); font-size: 14px; padding: 6px; }

/* Summary chips */
.summary { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip { padding: 6px 11px; border-radius: 999px; background: var(--card2); font-size: 13px; color: var(--muted); border: 1px solid var(--line); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.amber { color: var(--amber); }
.chip.red { color: var(--red); }
.chip.blue { color: var(--blue); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.filters .chip { white-space: nowrap; }
.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); margin-bottom: 10px; }

/* Zones */
.zone { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.zone:last-child { border-bottom: 0; }
.zlist { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.zlist h3 { margin: 0; padding: 10px 14px; font-size: 13px; color: var(--muted); background: var(--card2); text-transform: uppercase; letter-spacing: .04em; }
.zinfo { flex: 1; min-width: 0; }
.zname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zmeta { font-size: 12px; color: var(--muted); }
.zstat { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.zstat.secure { color: var(--green); background: #143022; }
.zstat.open { color: var(--amber); background: #3a2c12; }
.zstat.trouble { color: var(--orange); background: #3a2112; }
.zstat.tripped { color: #fff; background: var(--red); }
.zstat.bypassed { color: #c7dbff; background: #1d2a44; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* Activity */
.ev { padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.ev:last-child { border-bottom: 0; }
.ev .t { color: var(--muted); font-size: 12px; min-width: 64px; }
.ev .x { flex: 1; font-size: 14px; }
.ev .p { font-size: 11px; color: var(--muted); }
.ev.alarm .x { color: var(--red); font-weight: 700; }
.ev.trouble .x { color: var(--orange); }

/* Sheet / keypad */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 440px; border-radius: 20px 20px 0 0; padding: 18px 18px calc(var(--safe-bottom) + 18px); border: 1px solid var(--line); }
.sheet h3 { margin: 0; text-align: center; font-size: 18px; }
.sheet .sub { text-align: center; margin-top: 4px; }
.pins { display: flex; justify-content: center; gap: 16px; margin: 18px 0; }
.pin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--muted); }
.pin.f { background: var(--text); border-color: var(--text); }
.pins.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { padding: 17px 0; font-size: 24px; font-weight: 600; border-radius: 14px; background: var(--card2); }
.key:active { background: var(--line); }
.key.fn { font-size: 15px; color: var(--muted); }
.sheet .cancel { width: 100%; margin-top: 12px; background: none; color: var(--muted); padding: 10px; }
.sheet .err { color: var(--red); text-align: center; min-height: 20px; font-size: 14px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login { max-width: 360px; margin: 14vh auto 0; padding: 0 20px; }
.login h1 { font-size: 26px; margin: 14px 0 22px; text-align: center; }
.login img { display: block; margin: 0 auto; width: 260px; max-width: 80%; height: auto; }
.field { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); margin-bottom: 12px; }
.login .btn { width: 100%; }

/* Toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 84px); background: var(--card2); border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px; z-index: 30; font-size: 14px; max-width: 90%; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.err { border-color: #7f1d1d; color: #fecaca; }

.row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); font-size: 14px; }
.steps { margin: 8px 0 0 18px; padding: 0; color: var(--muted); font-size: 14px; }

.picker { width: 100%; margin-top: 10px; padding: 11px 36px 11px 12px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%238b95a3' stroke-width='2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; border-radius: 12px; border: 1px solid var(--line); background-color: var(--card); color: var(--text); font: inherit; font-weight: 600; -webkit-appearance: none; appearance: none; }
.alarm-strip { width: 100%; margin-top: 8px; padding: 10px; border-radius: 10px; background: var(--red); color: #fff; font-weight: 700; animation: pulse2 1s infinite alternate; }
@keyframes pulse2 { from { opacity: 1; } to { opacity: .7; } }
