/* Panel nuevo de Vigilante — móvil primero (390 px), centrado con max-width 560 px en pantallas anchas. */

@font-face {
  font-family: 'Vigilante Sans';
  src: url('../../fonts/GoogleSans-Regular.woff2') format('woff2'), url('../../fonts/GoogleSans-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vigilante Sans';
  src: url('../../fonts/GoogleSans-Medium.woff') format('woff');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0E1116;
  --surface: #171B22;
  --line: #232934;
  --nav: #12161C;
  --text: #E8EAED;
  --text-2: #9AA3AF;
  --text-3: #AEB6C2;
  --icon: #C9D1DC;
  --ok: #7FDDB4;
  --warn: #FFB86B;
  --bad: #FF8A80;
  --link: #8AB8FF;
  --font: 'Vigilante Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --nav-h: 80px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
a, .link { color: var(--link); }
.muted { color: var(--text-2); }

.brand { font-weight: 700; font-size: 20px; letter-spacing: 0.5px; display: flex; align-items: center; gap: 10px; }
.brand-eye { width: 28px; height: 28px; object-fit: contain; flex: none; }
.login-card .brand-eye { width: 40px; height: 40px; }

/* ---------- Botones genéricos ---------- */
.btn {
  min-height: 48px; width: 100%; border: 0; border-radius: 14px; padding: 0 16px;
  font-weight: 600; font-size: 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--link); color: #0E1A33; }
.btn-ghost { background: transparent; color: var(--text-3); }
.btn-warn { background: #3A2A14; color: var(--warn); }
.link {
  background: none; border: 0; padding: 0; min-height: 44px; display: inline-flex; align-items: center;
  font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- Acceso ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px 16px; }
/* Aviso del estado de la casa sobre el acceso (Entrada en azul de armada, Disparada en rojo). */
.login-alert { width: 100%; max-width: 400px; border-radius: 20px; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; background: #162A4A; color: #EEF3FF; }
.login-alert[data-kind="triggered"] { background: #5A1714; color: #FFEDEA; }
.login-alert p { margin: 0; }
.login-alert-title { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.login-alert-sub { font-size: 15px; white-space: pre-line; }
.login-alert-conn { align-self: flex-start; padding: 4px 10px; border-radius: 999px; background: #2E2112; color: var(--warn); font-size: 13px; font-weight: 500; }
.login-alert-hint { margin-top: 6px !important; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: rgba(0, 0, 0, 0.22); font-size: 15px; }
.login-alert-hint svg { flex: none; }
.load-fail { margin: 24px 16px; padding: 14px 16px; border-radius: 14px; background: var(--surface); color: var(--text); text-align: center; }
.load-fail a { color: var(--link); }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 24px; padding: 28px 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand { font-size: 26px; }
.login-sub { margin: -6px 0 4px; color: var(--text-2); }
.login-error { margin: 0; padding: 10px 12px; border-radius: 12px; background: #3A1714; color: #FFB4AB; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-3); }
.field input {
  min-height: 48px; border-radius: 12px; border: 1px solid #2E3542; background: var(--bg); color: var(--text);
  font: 400 16px var(--font); padding: 0 14px;
}

/* ---------- Estructura ---------- */
.shell { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: calc(20px + env(safe-area-inset-top)) 20px 8px; }
.conn {
  display: flex; align-items: center; gap: 8px; border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.conn[data-tone="ok"] { background: #16241E; color: var(--ok); }
.conn[data-tone="ok"] .conn-dot { background: #3FBF8F; }
.conn[data-tone="bad"] { background: #2E2112; color: var(--warn); }
.conn[data-tone="bad"] .conn-dot { background: #F59E0B; }
.conn[data-tone="wait"] { background: #1E232C; color: var(--text-2); }
.conn[data-tone="wait"] .conn-dot { background: #5A6475; }
.view { outline: none; }

/* Barra inferior */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--nav); border-top: 1px solid var(--line); z-index: 10; }
.tabbar-in {
  max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 8px 0 calc(22px + env(safe-area-inset-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; min-height: 50px;
  background: none; border: 0; color: var(--text-2); font-size: 12px; cursor: pointer;
}
.tab[aria-current="page"] { color: var(--text); font-weight: 600; }

/* ---------- Inicio ---------- */
.state-card {
  margin: 12px 16px 0; padding: 28px 20px; border-radius: 24px; background: #1A1F27;
  display: flex; flex-direction: column; align-items: center; gap: 14px; transition: background-color 0.3s, opacity 0.3s;
}
.state-ring {
  width: 112px; height: 112px; border-radius: 50%; border: 3px solid #5A6475;
  display: flex; align-items: center; justify-content: center;
}
.state-card[data-state="armed_away"] .state-ring,
.state-card[data-state="entry"] .state-ring,
.state-card[data-state="exit"] .state-ring { border-color: #8AB8FF; }
.state-card[data-state="armed_home"] .state-ring { border-color: #5FD3C6; }
.state-card[data-state="triggered"] .state-ring { border-color: var(--bad); }
.state-card[data-state="unknown"] .state-ring { border-color: #3A4250; }
.state-ring { position: relative; }
/* Armada: un destello recorre el aro sin parar. */
.state-card[data-state="armed_away"] .state-ring::before,
.state-card[data-state="armed_home"] .state-ring::before {
  content: ''; position: absolute; inset: -8px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0 62%, var(--glow) 86%, #FFFFFF 97%, transparent 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 11px), #000 calc(100% - 10px), #000 calc(100% - 2px), transparent 100%);
          mask: radial-gradient(farthest-side, transparent calc(100% - 11px), #000 calc(100% - 10px), #000 calc(100% - 2px), transparent 100%);
  filter: blur(2px); animation: ring-spin 2.6s linear infinite;
}
.state-card[data-state="armed_away"] .state-ring { --glow: #8AB8FF; box-shadow: 0 0 22px rgba(138, 184, 255, 0.28); }
.state-card[data-state="armed_home"] .state-ring { --glow: #5FD3C6; box-shadow: 0 0 22px rgba(95, 211, 198, 0.28); }
@keyframes ring-spin { to { transform: rotate(1turn); } }
/* Cuenta atrás: número grande y el aro se vacía según pasa el tiempo. */
.state-ring.counting { border-color: rgba(138, 184, 255, 0.22) !important; }
.state-ring.counting::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(#8AB8FF calc(var(--left, 1) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  transition: background 0.9s linear;
}
.state-count { font-size: 48px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; color: #FFFFFF; }
.state-title { margin: 0; font-size: 34px; font-weight: 700; line-height: 1.15; text-align: center; }
.state-sub { margin: 0; font-size: 15px; color: var(--text-3); text-align: center; line-height: 1.45; white-space: pre-line; }
.state-sub:empty { display: none; }
/* Datos antiguos: se atenúan solo el icono y el aro; los textos mantienen contraste ≥ 4.5:1. */
body.stale .state-card { filter: saturate(0.6); }
body.stale .state-ring { opacity: 0.45; }

.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 16px 16px 0; }
.action {
  height: 96px; border: 0; border-radius: 20px; font-weight: 600; font-size: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
}
.action:disabled { opacity: 0.5; cursor: default; }
.action-away { background: #1E3A66; color: #E8F0FF; }
.action-night { background: #164340; color: #E3F7F4; }
.action-disarm { grid-column: 1 / -1; background: var(--link); color: #0E1A33; }
.hint { margin: 10px 20px 0; font-size: 13px; color: var(--text-2); text-align: center; }

.card { margin: 16px 16px 0; background: var(--surface); border-radius: 20px; }
.list-card { margin-top: 22px; padding: 6px 0; }
.card-title { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-2); }
.list-card .card-title { margin: 12px 16px 6px; }
.row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line); min-height: 48px; }
.row svg { flex: none; }
.row-label { flex: 1; min-width: 0; }
.row-value { color: var(--text-3); text-align: right; }
.row-value[data-tone="ok"] { color: var(--ok); font-weight: 500; }
.row-value[data-tone="warn"] { color: var(--warn); font-weight: 500; }
.row-value[data-tone="bad"] { color: var(--bad); font-weight: 600; }

.last-card { padding: 14px 16px 6px; }
.last-card .card-title { margin-bottom: 10px; }
.event { display: flex; gap: 12px; font-size: 15px; padding: 6px 0; }
.event-time { color: var(--text-2); font-variant-numeric: tabular-nums; flex: none; }
.last-card .link { margin-top: 2px; }

.sos {
  position: relative; overflow: hidden; display: block; width: calc(100% - 32px); margin: 18px 16px 24px; height: 56px;
  border: 1.5px solid #6B2A27; border-radius: 16px; background: transparent; color: var(--bad);
  font-weight: 600; font-size: 16px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.sos-fill { position: absolute; inset: 0; background: rgba(255, 138, 128, 0.22); transform: scaleX(0); transform-origin: left center; }
.sos-label { position: relative; }
.sos.holding { border-color: var(--bad); }

.section-title { margin: 0; font-size: 24px; font-weight: 700; }

/* ---------- Hoja del PIN ---------- */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 100dvh;
  background: var(--surface); color: var(--text); border-radius: 24px 24px 0 0;
}
.sheet::backdrop { background: rgba(5, 7, 10, 0.72); }
.sheet-in { padding: 22px 20px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sheet-title { margin: 0; font-size: 22px; font-weight: 700; }
.sheet-sub { margin: 0; color: var(--text-3); text-align: center; font-size: 15px; }
.pin-host { margin-top: 8px; }
.pin-pad { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pin-dots { display: flex; gap: 14px; min-height: 14px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #5B6E96; }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.pin-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: min(300px, calc(100vw - 40px)); }
.pin-key {
  height: 60px; border: 0; border-radius: 16px; background: #232A35; color: var(--text);
  font-weight: 600; font-size: 24px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.pin-key:active { background: #2E3644; }
.pin-del { background: transparent; color: var(--text-3); font-size: 15px; font-weight: 500; }
.pin-ok { background: var(--link); color: #0E1A33; font-size: 15px; font-weight: 700; }
.pin-pad.busy { opacity: 0.6; }
.pin-msg { margin: 4px 0 0; color: #FFB4AB; text-align: center; font-size: 15px; }
.sheet .btn { max-width: 300px; }

/* ---------- Aviso ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom));
  width: calc(100% - 32px); max-width: 528px; padding: 12px 16px; border-radius: 14px; z-index: 30;
  background: #2A303B; color: var(--text); font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.toast[data-tone="ok"] { background: #16241E; color: var(--ok); }
.toast[data-tone="bad"] { background: #3A1714; color: #FFB4AB; }

/* ---------- Pantallas completas: Entrada y Disparada ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
body.ov-open { overflow: hidden; }
.ov { position: fixed; inset: 0; z-index: 20; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); }
.ov-top { align-self: stretch; display: flex; justify-content: space-between; align-items: center; }
.ov-conn { margin: 0; padding: 6px 12px; border-radius: 999px; background: #2E2112; color: var(--warn); font-size: 13px; font-weight: 500; text-align: center; }

/* Entrada */
.ov-entry {
  min-height: 100%; max-width: 560px; margin: 0 auto; background: #14203A; color: #EEF3FF;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 561px) { .ov:has(.ov-entry) { background: #101A30; } }
.ov-quiet { font-size: 13px; color: #B7C6E6; display: flex; align-items: center; gap: 6px; }
.ov-line { margin: 22px 0 0; font-size: 15px; color: #B7C6E6; text-align: center; }
.ov-title { margin: 6px 0 0; font-size: 28px; font-weight: 700; text-align: center; }
.ov-ring {
  --p: 100%; margin-top: 22px; width: 176px; height: 176px; border-radius: 50%; flex: none;
  background: conic-gradient(#8AB8FF 0 var(--p), #24345A var(--p) 100%);
  display: flex; align-items: center; justify-content: center;
}
.ov-ring-in { width: 150px; height: 150px; border-radius: 50%; background: #14203A; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ov-ring-num { font-size: 60px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.ov-ring-unit { font-size: 14px; color: #B7C6E6; margin-top: 4px; }
.ov-hint { margin-top: 18px; display: flex; align-items: center; gap: 10px; background: #1D2C4E; border-radius: 14px; padding: 12px 16px; font-size: 15px; }
.ov-hint svg { flex: none; }
.ov-entry .pin-pad { margin-top: 16px; gap: 14px; }
.ov-entry .pin-dots span { border-color: #7F92BA; }
.ov-entry .pin-dots span.on { background: #EEF3FF; border-color: #EEF3FF; }
.ov-entry .pin-grid { width: min(300px, calc(100vw - 40px)); gap: 10px; }
.ov-entry .pin-key { height: clamp(48px, 7.4dvh, 60px); background: #1D2C4E; color: #EEF3FF; }
.ov-entry .pin-key:active { background: #28396A; }
.ov-entry .pin-del { background: transparent; color: #B7C6E6; }
.ov-entry .pin-ok { background: #8AB8FF; color: #0E1A33; }
.ov-msg { margin: 10px 0 0; color: #FFB4AB; font-size: 15px; text-align: center; }
.ov-foot { margin: auto 0 0; padding-top: 16px; font-size: 13px; color: #B7C6E6; text-align: center; line-height: 1.45; white-space: pre-line; }
.ov-entry .ov-conn { margin-top: 12px; }

/* Disparada */
.ov-trig { min-height: 100%; max-width: 560px; margin: 0 auto; background: var(--bg); display: flex; flex-direction: column; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.trig-head { background: #5A1714; padding: calc(24px + env(safe-area-inset-top)) 20px 22px; display: flex; flex-direction: column; gap: 10px; color: #FFE3DF; }
.trig-head .brand { font-size: 18px; color: #FFE3DF; }
.trig-title { margin: 14px 0 0; font-size: 34px; font-weight: 700; color: #FFFFFF; line-height: 1.15; }
.trig-line { margin: 0; font-size: 17px; color: #FFE3DF; }
.trig-siren { margin-top: 10px; display: flex; align-items: center; gap: 10px; background: #3F0F0D; border-radius: 14px; padding: 12px 14px; }
.trig-siren svg { flex: none; }
.trig-siren-label { flex: 1; font-size: 15px; color: #FFE3DF; }
.trig-siren-time { font-size: 17px; font-weight: 600; color: #FFFFFF; font-variant-numeric: tabular-nums; }
.trig-actions { display: flex; flex-direction: column; gap: 12px; padding: 18px 16px 0; }
.trig-btn { min-height: 56px; border-radius: 18px; font-weight: 600; font-size: 16px; cursor: pointer; }
.trig-disarm { height: 60px; border: 0; background: #F3F4F6; color: #111418; font-weight: 700; font-size: 17px; }
.trig-silence { border: 1.5px solid #4A525F; background: transparent; color: var(--text); }
.trig-note { margin: 0 4px; font-size: 13px; color: var(--text-2); line-height: 1.45; }
.trig-cam { margin: 20px 16px 0; background: var(--surface); border-radius: 20px; overflow: hidden; }
.trig-cam-view { position: relative; aspect-ratio: 16 / 9; background: #0A0D11; }
.trig-video { width: 100%; height: 100%; object-fit: contain; display: block; background: #0A0D11; }
.trig-cam-foot { padding: 12px 16px; font-size: 15px; }
.trig-cam-none { margin: 0; padding: 18px 16px; font-size: 15px; color: var(--text-2); }
.trig-call {
  margin: 18px 16px 0; min-height: 56px; border-radius: 18px; background: #B3261E; color: #FFFFFF; font-weight: 700; font-size: 17px;
  text-decoration: none; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.trig-call:focus-visible, .trig-btn:focus-visible { outline-color: #FFFFFF; }

@media (prefers-reduced-motion: reduce) {
  .state-card { transition: none; }
  .state-ring::before { animation: none !important; }
}

/* ---------- Cámaras ---------- */
.cam-title { margin: 6px 20px 0; font-size: 28px; font-weight: 700; }
.cam-tabs { margin: 16px 16px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; background: var(--surface); border-radius: 14px; padding: 4px; }
.cam-tab { height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--text-3); font-weight: 500; font-size: 14px; cursor: pointer; }
.cam-tab[aria-selected="true"] { background: #2A313D; color: var(--text); font-weight: 600; }
.cam-body { padding-bottom: 24px; }
.cam-note { margin: 10px 20px 0; font-size: 13px; color: var(--text-2); line-height: 1.45; }
.cam-backup { margin-bottom: 4px; }
.cam-backup-warn { color: var(--warn); }
.cam-backup-bad { color: var(--bad); }
.cam-empty { margin: 32px 20px 0; text-align: center; color: var(--text-2); font-size: 15px; }
.cam-empty p { margin: 0 0 12px; }
.cam-retry { max-width: 220px; margin: 0 auto; border: 1px solid var(--line); }

.cam-grid { margin: 16px 16px 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 700px) { .cam-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cam-tile { background: var(--surface); border-radius: 16px; overflow: hidden; min-width: 0; }
.cam-view { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 104px; margin: 0; padding: 0; border: 0; background: #0A0D11; overflow: hidden; }
.cam-live { cursor: pointer; }
.cam-video { width: 100%; height: 100%; object-fit: cover; background: #0A0D11; }
.cam-wait { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text-2); background: repeating-linear-gradient(135deg, #1E242E 0 10px, #1A2029 10px 20px); pointer-events: none; }
.cam-priv { flex-direction: column; gap: 6px; background: #12161C; font-size: 12px; color: var(--text-2); }
.cam-open { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: #1E242E; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; }
.cam-open:disabled { opacity: 0.6; cursor: default; }
.cam-foot { padding: 10px 12px; }
.cam-name { font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
.cam-lens { margin-top: 2px; font-size: 12px; color: var(--text-3); }
.cam-lens[data-open="1"] { color: var(--ok); }

.cam-day { margin: 22px 20px 8px; }
.cam-list { margin-top: 0; padding: 4px 0; overflow: hidden; }
.cam-item + .cam-item, .cam-row + .cam-row, .cam-row-btn + .cam-detail { border-top: 1px solid var(--line); }
.cam-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; min-height: 64px; width: 100%; background: none; border: 0; text-align: left; }
.cam-row-btn { cursor: pointer; padding-right: 16px; }
.cam-row-ic { flex: none; width: 40px; height: 40px; border-radius: 12px; background: #1E2A3F; display: flex; align-items: center; justify-content: center; }
.cam-row-ic.is-alert { background: #3F0F0D; }
.cam-row-ic.is-test { background: #2A2410; }
.cam-row-main { flex: 1; min-width: 0; }
.cam-row-title { font-size: 15px; font-weight: 500; }
.cam-row-sub { margin-top: 2px; font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-row-btn .cam-row-sub { white-space: normal; }
.cam-row-btn[aria-expanded="true"] .cam-chev { transform: rotate(90deg); }
.cam-ibtn { flex: none; width: 44px; height: 44px; border: 0; border-radius: 12px; background: #1E242E; color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cam-detail { padding: 0 0 8px; background: #141820; }
.cam-vrow { background: none; min-height: 56px; }
.cam-player-host { padding: 0 12px 10px; }
.cam-player { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; }
.cam-photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 4px 16px 8px; }
.cam-thumb { padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 16 / 9; background: #0A0D11; cursor: pointer; min-height: 44px; }
.cam-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }


/* ---------- Historial ---------- */
.hist { padding-bottom: 24px; }
.hist-filters { margin: 14px 16px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.hist-chip { min-height: 44px; padding: 0 16px; border: 1px solid #3A414D; border-radius: 999px; background: transparent; color: #C9D1DC; font-weight: 500; font-size: 14px; cursor: pointer; }
.hist-chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #111418; font-weight: 600; }
.hist-day { margin: 22px 20px 8px; font-size: 13px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-2); }
.hist-card { margin-top: 0; padding: 4px 0; }
.hist-row { display: flex; gap: 14px; padding: 14px 16px; }
.hist-row + .hist-row { border-top: 1px solid var(--line); }
.hist-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.hist-text { flex: 1; min-width: 0; }
.hist-title { font-size: 15px; overflow-wrap: anywhere; }
.hist-row[data-kind="conexion"] .hist-title { color: var(--warn); }
.hist-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; overflow-wrap: anywhere; }
.hist-time { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; flex: none; }
.hist-more { margin: 16px 16px 0; width: calc(100% - 32px); background: var(--surface); color: var(--text); }

/* ---------- Ajustes ---------- */
.ajustes { padding-bottom: 24px; }
.ajustes .list-card { margin-top: 16px; }
.ajustes .row:has(.btn) { padding: 12px 16px; }
.ajustes .row-value { overflow-wrap: anywhere; }
.ajustes .cam-note { margin: 4px 16px 10px; }

/* ---------- Ajustes: hub y páginas ---------- */
.nav-row { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; color: var(--text); text-align: left; font: inherit; min-height: 56px; cursor: pointer; }
.nav-row .row-label { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-weight: 500; }
.nav-sub { font-size: 13px; color: var(--text-2); }
.nav-chev { color: var(--text-2); font-size: 24px; line-height: 1; }
.nav-row-off { color: var(--text-2); }
.nav-row-off .row-value { font-size: 13px; }
.page-head { display: flex; flex-direction: column; align-items: flex-start; padding: 0 8px; }
.back-btn { min-height: 44px; display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 0 12px; color: var(--link); font-size: 16px; font-weight: 500; cursor: pointer; }
.back-btn span:first-child { font-size: 26px; line-height: 1; }
.page-title { outline: none; }
.form-card { padding-bottom: 16px; }
.form-card .card-title { margin: 14px 16px 6px; }
.form-body { display: flex; flex-direction: column; gap: 14px; padding: 8px 16px 0; }
.fld .field-hint, .sw-label .field-hint { font-size: 13px; color: var(--text-2); line-height: 1.35; }
.fld .field-err { font-size: 13px; color: var(--bad); }
.field select, .field input[type="time"] {
  min-height: 48px; border-radius: 12px; border: 1px solid #2E3542; background: var(--bg); color: var(--text);
  font: 400 16px var(--font); padding: 0 14px; width: 100%;
}
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--bad); }
.field input:disabled { opacity: 0.5; }
.sw-row { display: flex; align-items: center; gap: 14px; min-height: 48px; justify-content: space-between; }
.sw-label { flex: 1; display: flex; flex-direction: column; gap: 2px; color: var(--text); cursor: pointer; }
.sw-input { width: 28px; height: 28px; flex: none; accent-color: #8AB8FF; cursor: pointer; }
.form-status { margin: 12px 16px 0; padding: 10px 12px; border-radius: 12px; background: #1E232C; color: var(--text-3); font-size: 14px; }
.form-status[data-tone="ok"] { background: #16241E; color: var(--ok); }
.form-status[data-tone="bad"] { background: #3A1714; color: #FFB4AB; }
.form-actions { padding: 14px 16px 0; }
form > .form-sticky { margin-top: 16px; padding-bottom: 8px; }
.ajustes-body { padding-bottom: 16px; }

/* ---------- Ajustes: cámaras, sensores y hojas de edición ---------- */
.sheet-edit { max-height: 92dvh; overflow-y: auto; }
.sheet-in-form { align-items: stretch; gap: 14px; }
.sheet-in-form .sheet-title { text-align: left; outline: none; }
.sheet-form { display: flex; flex-direction: column; gap: 14px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; align-items: center; }
.sheet-actions .btn { max-width: none; }
.sheet:not(.sheet-edit) .sheet-actions .btn { max-width: 300px; }
.sheet .sheet-title { overflow-wrap: anywhere; text-align: center; }
.sheet-form .form-status { margin: 0; }
.dev-row { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 56px; border-top: 1px solid #1E232C; }
.dev-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dev-name { font-weight: 500; overflow-wrap: anywhere; }
.dev-sub { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.dev-btn { min-height: 44px; min-width: 44px; padding: 0 12px; border: 0; border-radius: 12px; background: #232A35; color: var(--text); font: 500 15px var(--font); cursor: pointer; }
.dev-btn-bad { background: #3A1714; color: #FFB4AB; }
.dev-add { margin: 12px 16px 0; width: calc(100% - 32px); }
.sw-input:disabled { opacity: 0.5; }
.tapo-box { padding: 0; }
.dev-move { display: flex; gap: 6px; flex: none; }
.dev-btn-sq { padding: 0; width: 44px; font-size: 20px; }
.dev-btn:disabled { opacity: 0.35; cursor: default; }
.dev-row { flex-wrap: wrap; } .dev-main { flex: 1 1 140px; }

/* ---------- Ajustes: emparejar un móvil ---------- */
.pair-code { margin: 0; text-align: center; font: 700 34px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.18em; color: var(--text); user-select: all; }
.pair-left { margin: 0; text-align: center; font-size: 14px; color: var(--text-2); }
.pair-qr { align-self: center; padding: 10px; background: #fff; border-radius: 12px; min-width: 200px; min-height: 200px; display: flex; align-items: center; justify-content: center; }
.pair-qr .cam-note { color: #333; margin: 0; }

/* Ajustes > Sistema */
.sys-row { align-items: flex-start; }
.sys-row .nav-sub { overflow-wrap: anywhere; }
.sys-row .row-value { white-space: nowrap; }

/* Cámaras: grabar, mover y borrar */
.cam-rec { display: block; width: 100%; min-height: 44px; margin-top: 8px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: #1E242E; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; }
.cam-rec[data-on="1"] { background: #3F0F0D; color: #FFB4AB; border-color: #6B2420; }
.cam-rec:disabled { opacity: 0.6; cursor: default; }
.cam-rec-all { margin: 16px 16px 0; padding: 14px 16px; }
.cam-rec-title { margin: 0; font-size: 16px; font-weight: 600; }
.cam-rec-all-text { margin: 4px 0 12px; font-size: 13px; color: var(--text-2); }
.cam-mon-text { margin: 4px 0 12px; font-size: 13px; color: var(--text-2); }
.cam-monitor .cam-act { width: 100%; }
.cam-monitor .cam-act[hidden] { display: none; }
.cam-rec-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cam-act { min-height: 44px; border: 1px solid var(--line); }
.cam-act:disabled { opacity: 0.6; }
.cam-ibtn-del { color: #FFB4AB; }
.cam-del-row { padding: 8px 16px 4px; }
.cam-del-row .btn { max-width: none; }
.ptz { display: flex; flex-direction: column; gap: 10px; padding: 10px 0 2px; }
.ptz[hidden] { display: none; }
.ptz-dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); gap: 6px; justify-content: center; }
.ptz-btn { border: 0; border-radius: 14px; background: #1E242E; color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.ptz-btn:active { background: #2A313D; }
.ptz-up { grid-column: 2; grid-row: 1; }
.ptz-left { grid-column: 1; grid-row: 2; }
.ptz-right { grid-column: 3; grid-row: 2; }
.ptz-down { grid-column: 2; grid-row: 3; }
.ptz-status { margin: 0; text-align: center; font-size: 13px; color: var(--ok); }
.ptz-status[data-tone="bad"] { color: var(--warn); }
.ptz-sec-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); }
.ptz-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.ptz-hint { font-size: 13px; color: var(--text-2); }
.ptz-hint[data-tone="bad"] { color: var(--warn); }
.ptz-chip { display: inline-flex; align-items: stretch; border-radius: 12px; background: #1E242E; overflow: hidden; min-height: 44px; }
.ptz-chip-go { padding: 0 14px; border: 0; background: none; color: var(--text); font-size: 14px; cursor: pointer; }
.ptz-chip-del { width: 44px; border: 0; border-left: 1px solid var(--line); background: none; color: #FFB4AB; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.ptz-acts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cam-rec[hidden] { display: none; }

/* ---------- Aviso de corte de luz (Inicio), Vaciar registro, botones neutros ---------- */
.power-alert {
  display: flex; flex-direction: column; gap: 12px; padding: 16px; margin: 0 0 14px;
  background: #3A2A14; border: 1px solid #6B4A1E; border-radius: 16px; color: var(--text);
}
.power-alert[hidden] { display: none; }
.power-alert-title { color: var(--warn); font-size: 17px; }
.power-alert-desc { margin: 6px 0 0; color: var(--text-3); font-size: 15px; line-height: 1.4; }
.power-alert-ok { background: var(--warn); color: #2A1B05; }
.hist-purge { margin: 28px 16px 8px; }
.ajustes .row > .btn:not(.btn-warn):not(.btn-primary):not(.btn-ghost),
.form-actions > .btn:not(.btn-warn):not(.btn-primary):not(.btn-ghost) { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
a.btn { text-decoration: none; }

/* Captura y zoom del visor */
.cam-foot { position: relative; }
.cam-quick { position: absolute; top: 4px; right: 6px; display: flex; gap: 2px; }
.cam-lensbtn:disabled { opacity: 0.4; cursor: default; }
.cam-foot .cam-name, .cam-foot .cam-lens { padding-right: 46px; }
.cam-foot:has(.cam-quick > :nth-child(2)) .cam-name, .cam-foot:has(.cam-quick > :nth-child(2)) .cam-lens { padding-right: 92px; }
.cam-full-stage { overflow: hidden; }
.cam-zoomable { touch-action: none; }
.cam-zoomable .cam-video { transform-origin: center center; will-change: transform; }
.cam-zoom-reset[hidden] { display: none; }
.chime-row { border-top: 1px solid var(--line); }
.chime-row[hidden] { display: none; }

/* Captura dentro de la app Android: se muestra para hacer una captura de pantalla */
.cam-snap-preview { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px; text-align: center; color: #fff; }
.cam-snap-preview img { max-width: 100%; max-height: 70vh; object-fit: contain; border-radius: 8px; }
.cam-snap-preview p { max-width: 32rem; margin: 0; }
.cam-snap-preview .btn { min-height: 44px; min-width: 120px; }

/* Visor a pantalla completa: el vídeo ocupa toda la pantalla; barra fina superpuesta abajo y panel de movimiento flotante */
.cam-full { position: fixed; inset: 0; z-index: 25; background: #000; overflow: hidden; }
.cam-full-stage { position: absolute; inset: 0; overflow: hidden; }
.cam-slide { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; will-change: transform; }
.cam-slide .cam-video, .cam-slide .cam-photo { width: 100%; height: 100%; object-fit: contain; background: #000; }
.cam-neigh, .cam-closed { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 0 24px; text-align: center; background: repeating-linear-gradient(135deg, #1E242E 0 10px, #1A2029 10px 20px); }
.cam-closed { position: relative; width: 100%; height: 100%; background: #12161C; color: var(--text-2); }
.cam-closed-title { margin: 0; font-size: 17px; font-weight: 600; color: var(--text); }
.cam-closed-open { min-height: 48px; max-width: 220px; }
.cam-neigh-name { font-size: 20px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.cam-neigh-state { font-size: 14px; color: var(--text-2); }
.cam-bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 4px max(8px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); background: rgba(5, 7, 10, 0.58); transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s; }
.cam-bar[data-hidden] { opacity: 0; transform: translateY(100%); visibility: hidden; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s; }
.cam-bar-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-bar-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.cam-bbtn { width: 48px; height: 48px; min-width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.cam-bbtn:active, .cam-bbtn[data-on="1"] { background: rgba(255, 255, 255, 0.18); }
.cam-bbtn:disabled { opacity: 0.4; cursor: default; }
.cam-zoom-reset { position: absolute; left: max(12px, env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); z-index: 2; min-height: 44px; padding: 0 14px; font-size: 13px; border: 1px solid var(--line); background: rgba(23, 27, 34, 0.75); }
.cam-ptz-float { position: absolute; right: max(8px, env(safe-area-inset-right)); bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 4; width: min(290px, calc(100vw - 16px)); max-height: calc(100dvh - 90px - env(safe-area-inset-bottom) - env(safe-area-inset-top)); overflow-y: auto; box-sizing: border-box; padding: 6px 12px 12px; gap: 8px; border-radius: 16px; background: rgba(15, 18, 24, 0.78); border: 1px solid var(--line); }
.cam-ptz-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cam-ptz-title { font-size: 14px; font-weight: 600; }
.cam-ptz-float .ptz-btn { background: rgba(255, 255, 255, 0.12); }
.cam-ptz-float .ptz-chip { background: rgba(255, 255, 255, 0.12); }
.cam-ptz-float .ptz-acts { grid-template-columns: 1fr; }
@media (orientation: landscape) and (max-height: 520px) {
  .cam-ptz-float { bottom: calc(56px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .cam-bar, .cam-bar[data-hidden] { transition: none; }
}
