:root {
  --bg: #111418;
  --card: #1b2027;
  --line: #2a313b;
  --text: #e9edf2;
  --muted: #8b95a3;
  --ok: #2fbf71;
  --bad: #e5484d;
  --rec: #f5a524;
  --accent: #3b82f6;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); min-height: 1.2em; }

main { max-width: 720px; margin: 0 auto; padding: 12px; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row.between { justify-content: space-between; align-items: center; margin-top: 0; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 4px 2px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: #232a33; color: var(--text);
  padding: 10px 14px; border-radius: 10px; font: inherit; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.link { background: none; border: none; color: var(--muted); padding: 10px 0; text-decoration: underline; }
.btn:active { transform: scale(.98); }

.pill { font-size: .85rem; padding: 4px 10px; border-radius: 99px; background: #232a33; }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--bad); }
.pill.rec { color: var(--rec); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: grid; gap: 10px; }
input, select {
  font: inherit; color: var(--text); background: #11151a; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; width: 100%;
}
select { width: auto; }
label { display: grid; gap: 6px; margin-top: 12px; }
input[type="range"] { padding: 0; }

.video-wrap { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; display: grid; place-items: center; }
.video-wrap video-stream, .video-wrap video, .video-wrap .live-img { width: 100%; height: 100%; display: block; object-fit: contain; }
.placeholder { color: var(--muted); }

.arm-btn {
  width: 100%; border: 2px solid var(--line); border-radius: 16px; background: #15191f; color: var(--text);
  padding: 16px 12px; display: grid; gap: 4px; justify-items: center; font: inherit; cursor: pointer;
  transition: background .2s, border-color .2s;
}
.arm-btn .arm-icon { font-size: 1.8rem; }
.arm-btn span:nth-child(2) { font-size: 1.3rem; font-weight: 700; }
.arm-btn small { color: var(--muted); }
.arm-btn.armed { background: #3a1416; border-color: var(--bad); }
.arm-btn.armed span:nth-child(2) { color: #ff8b8e; }

.meter { position: relative; height: 8px; background: #11151a; border-radius: 99px; margin: 14px 0 6px; overflow: hidden; }
#meter-bar { height: 100%; width: 0; background: var(--ok); transition: width .4s; }
#meter-threshold { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); }

.events { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.events li { display: grid; grid-template-columns: 112px 1fr auto; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding-top: 8px; }
.thumb { position: relative; width: 112px; aspect-ratio: 16/9; border: 0; padding: 0; border-radius: 8px; overflow: hidden; background: #000; color: var(--text); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.3rem; text-shadow: 0 0 6px #000; }
.ev-info { display: grid; min-width: 0; }  /* no usar "info": go2rtc tiene un estilo global con ese nombre */
.actions { display: flex; gap: 4px; }
.icon { background: none; border: 0; color: var(--text); font-size: 1.15rem; padding: 6px; cursor: pointer; text-decoration: none; }

details summary { cursor: pointer; font-weight: 600; }

dialog { background: #000; border: 0; padding: 0; width: min(900px, 100vw); border-radius: 12px; }
dialog::backdrop { background: rgba(0,0,0,.8); }
dialog video { width: 100%; display: block; }
dialog form { padding: 8px; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #2a313b; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

h3.sub { font-size: .95rem; margin: 18px 0 4px; }
.zones { position: relative; margin-top: 8px; border-radius: 10px; overflow: hidden; background: #000;
  aspect-ratio: 16 / 9; touch-action: none; user-select: none; -webkit-user-select: none; }
.zones img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }
.zones-layer { position: absolute; inset: 0; cursor: crosshair; }
.zone { position: absolute; background: rgba(229, 72, 77, .35); border: 2px solid var(--bad); border-radius: 4px; }
.zone.drawing { border-style: dashed; }

.next-sched { margin: 10px 0 0; color: var(--muted); text-align: center; }
.next-sched b { color: var(--text); }

.switch { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.sched-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.sched-list li { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.sched-head { display: flex; align-items: center; gap: 8px; }
.sched-head .tag { font-weight: 600; flex: 1; }
.sched-head .tag.arm { color: #ff8b8e; }
.sched-head .tag.disarm { color: var(--ok); }
.sched-head input[type="time"] { width: auto; padding: 6px 8px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #11151a;
  color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; }
.days button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.pin-dlg { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 18px;
  width: min(340px, 94vw); padding: 18px; text-align: center; }
.pin-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.pin-sub { margin: 4px 0 0; min-height: 1.2em; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 16px 0 4px; min-height: 16px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; background: var(--text); }
.pin-dots span.empty { background: none; border: 2px solid var(--line); }
.pin-error { margin: 4px 0; font-size: .9rem; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 12px; }
.keypad button { height: 58px; border-radius: 14px; border: 1px solid var(--line); background: #232a33; color: var(--text);
  font: inherit; font-size: 1.4rem; cursor: pointer; }
.keypad button:active { background: #2f3843; }
.keypad .k-muted { font-size: .95rem; color: var(--muted); background: none; }
.pin-ok { width: 100%; }

.ptz { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; margin-top: 12px; }
.joy { position: relative; width: 168px; height: 168px; border-radius: 50%; touch-action: none; user-select: none;
  -webkit-user-select: none; background: radial-gradient(circle, #232a33 0 30%, #15191f 31% 100%);
  border: 2px solid var(--line); cursor: grab; }
.joy .ar { position: absolute; color: var(--muted); font-size: .8rem; pointer-events: none; }
.joy .up { top: 8px; left: 50%; transform: translateX(-50%); }
.joy .down { bottom: 8px; left: 50%; transform: translateX(-50%); }
.joy .left { left: 10px; top: 50%; transform: translateY(-50%); }
.joy .right { right: 10px; top: 50%; transform: translateY(-50%); }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.5); transition: transform .15s; }
.joy.active .joy-knob { transition: none; }
.ptz-side { display: grid; gap: 8px; }
.ptz-side label { margin-top: 0; }
.ptz-side select { width: 100%; }
.patrol-list { padding-left: 22px; margin: 10px 0; display: grid; gap: 6px; }
.patrol-list li { padding-left: 4px; }
.patrol-list li.hint { list-style: none; margin-left: -22px; }
.patrol-list .p-row { display: flex; align-items: center; gap: 8px; }
.patrol-list .p-row span { flex: 1; }
@media (max-width: 380px) { .ptz { grid-template-columns: 1fr; justify-items: center; } .ptz-side { width: 100%; } }
.live-badge { position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: rgba(0,0,0,.55); color: #7ee787; pointer-events: none; }
.live-badge.stale { color: #ffb86b; }
.meter-label { margin: 10px 0 4px; }
.sos { border: 2px solid var(--bad); background: #2a1416; }
.sos-title { font-size: 1.2rem; font-weight: 700; margin: 0 0 4px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn.sos-call { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 700; flex: 1; }
.tg-chats { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.tg-chats li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
