:root {
  --bg: #0f1115; --card: #181b22; --card2: #20242d; --text: #eef0f4; --muted: #8b93a3;
  --line: #2a2f3a; --green: #22c55e; --red: #ef4444; --amber: #f59e0b; --blue: #3b82f6;
  --gray: #6b7280;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f3f4f7; --card: #ffffff; --card2: #eef0f4; --text: #11151c; --muted: #5d6573; --line: #dde1e8; color-scheme: light; }
}
* { 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, "SF Pro Text", system-ui, sans-serif; }
body { padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 560px; margin: 0 auto; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.err { color: var(--red); }
code { background: var(--card2); padding: 1px 5px; border-radius: 4px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 10px; }
.title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.conn { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gray); }
.conn.ok::before { background: var(--green); }
.conn.bad::before { background: var(--red); }
.conn.warn::before { background: var(--amber); }

.state { display: flex; gap: 16px; align-items: center; padding: 20px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--line); transition: background .3s; }
.state-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--gray) center/30px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E"); flex: none; }
.state-label { font-size: 24px; font-weight: 700; }
.state-sub { color: var(--muted); font-size: 14px; }
.state.desarmado .state-icon { background-color: var(--green); }
.state.armado .state-icon, .state.parcial .state-icon { background-color: var(--blue); }
.state.saliendo .state-icon { background-color: var(--amber); }
.state.alarma { background: color-mix(in srgb, var(--red) 25%, var(--card)); border-color: var(--red); }
.state.alarma .state-icon { background-color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.btn { border: 0; border-radius: 14px; padding: 14px; font: 600 16px/1 inherit; font-family: inherit;
  background: var(--card2); color: var(--text); cursor: pointer; }
.btn:active { transform: scale(.98); opacity: .85; }
.btn:disabled { opacity: .35; }
.btn.primary { background: var(--blue); color: #fff; width: 100%; }
.btn.act { padding: 18px 10px; }
.btn.arm { background: var(--blue); color: #fff; }
.btn.part { background: color-mix(in srgb, var(--blue) 22%, var(--card)); color: var(--text); }
.btn.disarm { grid-column: 1 / -1; background: var(--green); color: #fff; }
.btn.small { padding: 9px 14px; font-size: 14px; }
.btn.danger { color: var(--red); }

.lcd { font: 14px/1.35 ui-monospace, "SF Mono", Menlo, monospace; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; white-space: pre; color: var(--muted); margin-bottom: 14px; overflow: hidden; }

.tabs { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.tab { flex: 1; border: 0; background: none; color: var(--muted); padding: 8px; border-radius: 9px; font: 600 14px inherit; font-family: inherit; }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; border: 1px solid var(--line); overflow: hidden; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .sub { color: var(--muted); font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); flex: none; }
.dot.active { background: var(--amber); }
.dot.alarm, .dot.tamper { background: var(--red); }
.dot.bypassed { background: var(--gray); }
.badge { font-size: 12px; color: var(--muted); }
.ev-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; width: 86px; flex: none; }
.ev-day { background: var(--card2); color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 14px !important; }

.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.switch { width: 22px; height: 22px; }

.setup { padding-top: 15vh; display: flex; flex-direction: column; gap: 14px; }
.setup input { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 16px; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; z-index: 10; }
.sheet-body { width: 100%; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 22px 22px 0 0;
  padding: 22px 22px calc(env(safe-area-inset-bottom) + 22px); }
.pin-title { text-align: center; font-weight: 600; font-size: 18px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 22px; min-height: 14px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; background: var(--text); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { border: 0; background: var(--card2); color: var(--text); border-radius: 14px; padding: 18px 0;
  font: 500 24px inherit; font-family: inherit; }
.keypad button:active { opacity: .6; }
.keypad .muted-key { font-size: 15px; color: var(--muted); }
.keypad .ok-key { font-size: 18px; font-weight: 700; background: var(--blue); color: #fff; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px); max-width: 528px;
  margin: 0 auto; background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; z-index: 20; font-weight: 500; }
.toast.error { background: var(--red); color: #fff; }

.confirm { display: flex; flex-direction: column; gap: 12px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
