:root {
  --bg: #0f1419;
  --card: #1a2129;
  --card2: #232c36;
  --text: #e8edf2;
  --muted: #8b98a5;
  --primary: #3b82f6;
  --armed: #ef4444;
  --partial: #f59e0b;
  --disarmed: #22c55e;
  --unknown: #64748b;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.screen { min-height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(14px + var(--safe-top)) 18px 10px; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.icon-btn { background: none; border: 0; font-size: 26px; width: 40px; height: 40px; display: inline-block; }
.content { flex: 1; padding: 8px 18px calc(96px + var(--safe-bottom)); max-width: 560px; width: 100%; margin: 0 auto; }

.card { background: var(--card); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h2 { font-size: 18px; margin: 0 0 6px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: #f87171; font-size: 14px; }
.big-icon { font-size: 48px; margin: 8px 0; }

label { display: block; margin: 14px 0 0; font-size: 14px; color: var(--muted); }
label small { display: block; margin-top: 4px; font-size: 12px; }
input, select { width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid #2f3a46; background: var(--card2); color: var(--text); font-size: 16px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  color: var(--text); font-size: 15px; padding: 10px 0; margin: 0; border-bottom: 1px solid #263039; }
.switch-row input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--primary); }

.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; border: 0;
  font-size: 16px; font-weight: 600; margin-top: 16px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.secondary { background: var(--card2); }
.btn.danger { background: #3a1d22; color: #fca5a5; }
.btn.link { background: none; color: var(--primary); font-weight: 500; }
.btn:disabled { opacity: .5; }

/* Statut */
.status-wrap { text-align: center; padding: 18px 0 8px; }
.status-ring { --c: var(--unknown); width: 210px; height: 210px; margin: 0 auto; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 10px solid var(--c); box-shadow: 0 0 60px -10px var(--c); transition: all .4s; }
.status-ring[data-state="armed"] { --c: var(--armed); }
.status-ring[data-state="partial"] { --c: var(--partial); }
.status-ring[data-state="disarmed"] { --c: var(--disarmed); }
.status-ring[data-state="triggered"] { --c: var(--armed); animation: pulse 1s infinite; }
.status-ring.busy { animation: spin-glow 1.2s ease-in-out infinite; }
.status-icon { font-size: 52px; line-height: 1; }
.status-text { font-size: 22px; font-weight: 700; margin-top: 8px; }
@keyframes pulse { 50% { box-shadow: 0 0 90px 10px var(--c); } }
@keyframes spin-glow { 50% { opacity: .55; } }

.banner { display: inline-block; font-size: 12px; padding: 6px 12px; border-radius: 999px; margin: 6px 4px 0; }
.banner.demo { background: #1e3a5f; color: #93c5fd; }
.banner.warn { background: #3b2a12; color: #fcd34d; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 26px; }
.action { background: var(--card); border: 2px solid transparent; border-radius: var(--radius);
  padding: 18px 6px; font-size: 15px; font-weight: 600; display: flex; flex-direction: column;
  align-items: center; gap: 8px; transition: transform .1s, border-color .2s; }
.action span { font-size: 30px; }
.action:active { transform: scale(.96); }
.action.current[data-level="armed"] { border-color: var(--armed); }
.action.current[data-level="partial"] { border-color: var(--partial); }
.action.current[data-level="disarmed"] { border-color: var(--disarmed); }
.action:disabled { opacity: .5; }

/* Historique */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 12px; }
.chip { background: var(--card); border: 0; border-radius: 999px; padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.chip.active { background: var(--primary); color: #fff; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  display: flex; gap: 12px; align-items: flex-start; }
.history .ev-icon { font-size: 20px; width: 26px; text-align: center; }
.history .ev-label { font-size: 15px; }
.history .ev-date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.history .day { background: none; padding: 10px 2px 4px; font-size: 13px; color: var(--muted); font-weight: 600; }

/* Barre d'onglets */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: rgba(15,20,25,.92);
  backdrop-filter: blur(10px); border-top: 1px solid #222b34; padding-bottom: var(--safe-bottom); }
.tab { flex: 1; background: none; border: 0; padding: 10px 0 12px; font-size: 20px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab span { font-size: 12px; }
.tab.active { color: var(--text); }

/* Code */
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0; min-height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; justify-content: center; margin-top: 8px; }
.keypad button { height: 72px; border-radius: 50%; border: 0; background: var(--card2); font-size: 26px; }
.keypad button.ghost { background: none; font-size: 18px; }
.keypad button:active { background: #33404d; }

/* Modale */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--card); width: 100%; max-width: 480px; border-radius: 22px 22px 0 0;
  padding: 22px 18px calc(18px + var(--safe-bottom)); text-align: center; }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet-actions .btn { margin-top: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-bottom));
  background: #e8edf2; color: #0f1419; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 20;
  max-width: 90%; text-align: center; }
