:root {
  --accent: #ff6a00;
  --accent-ink: #fff;
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #1d1f24;
  --muted: #7a7f8a;
  --line: #e4e6eb;
  --ok: #17a34a;
  --bad: #d93025;
  --warn: #e8a100;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --card: #1b1e24; --ink: #eceef2; --muted: #9aa0ab; --line: #2a2e36; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1em; margin: 6px 0; }

.app { min-height: 100%; display: flex; flex-direction: column; }
.splash { flex: 1; display: grid; place-items: center; }
.logo { font-weight: 800; font-size: 22px; letter-spacing: .5px; color: var(--accent); }
.logo b, .brand b { color: var(--ink); font-weight: 600; }
.logo.big { font-size: 34px; text-align: center; margin: 8px 0 2px; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 90px 1fr 90px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar > :last-child { justify-self: end; }
.brand { font-weight: 800; color: var(--accent); font-size: 15px; }
.back { font-size: 30px; line-height: 1; padding: 0 8px; color: var(--accent); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 22px; font-weight: 600;
}

.content { flex: 1; padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }
.content.full { padding-bottom: 24px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); min-width: 70px; }
.tab.active { color: var(--accent); }
.tab-icon { width: 24px; height: 24px; background: currentColor; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; }
.i-home { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3 2 11h3v9h6v-6h2v6h6v-9h3z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3 2 11h3v9h6v-6h2v6h6v-9h3z'/%3E%3C/svg%3E"); }
.i-bell { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 22a2.5 2.5 0 0 0 2.5-2.5h-5A2.5 2.5 0 0 0 12 22zm7-6V11a7 7 0 0 0-5.5-6.8V3a1.5 1.5 0 0 0-3 0v1.2A7 7 0 0 0 5 11v5l-2 2v1h18v-1z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 22a2.5 2.5 0 0 0 2.5-2.5h-5A2.5 2.5 0 0 0 12 22zm7-6V11a7 7 0 0 0-5.5-6.8V3a1.5 1.5 0 0 0-3 0v1.2A7 7 0 0 0 5 11v5l-2 2v1h18v-1z'/%3E%3C/svg%3E"); }
.i-user { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10zm0 2c-5 0-9 2.5-9 5.5V22h18v-2.5C21 16.5 17 14 12 14z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10zm0 2c-5 0-9 2.5-9 5.5V22h18v-2.5C21 16.5 17 14 12 14z'/%3E%3C/svg%3E"); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input, select {
  display: block; width: 100%; margin-top: 5px; padding: 11px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.btn {
  display: inline-block; border: 0; border-radius: 22px; padding: 11px 22px; font: inherit; font-weight: 600;
  background: var(--line); color: var(--ink); cursor: pointer; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn.danger { background: transparent; color: var(--bad); width: 100%; border: 1px solid var(--bad); }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link.danger { color: var(--bad); }

.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; padding: 28px 22px; }

.summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: 12px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--muted); }
.stat.ok strong { color: var(--ok); } .stat.bad strong { color: var(--bad); } .stat.warn strong { color: var(--warn); }
@media (max-width: 520px) { .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.device { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: block; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; top: 8px; left: 8px; font-size: 11px; padding: 3px 8px; border-radius: 10px; background: rgba(0,0,0,.55); color: #fff; }
.badge.online::before { content: "● "; color: #3ddc84; }
.badge.offline::before, .badge.auth_error::before { content: "● "; color: #ff5b4f; }
.badge.lens { left: auto; right: 8px; }
.device-info { padding: 10px 14px; display: flex; justify-content: space-between; gap: 8px; }
.empty { text-align: center; padding: 40px 0; }

/* Vista en directo */
.stage { background: #000; border-radius: var(--radius); overflow: hidden; display: grid; gap: 2px; }
.stage.dual { grid-template-columns: 1fr; }
@media (min-width: 800px) { .stage.dual { grid-template-columns: 1fr 1fr; } }
.stage:fullscreen { border-radius: 0; align-content: center; }
.tile { position: relative; aspect-ratio: 16 / 9; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile-label { position: absolute; left: 8px; top: 8px; color: #fff; background: rgba(0,0,0,.5); font-size: 12px; padding: 2px 8px; border-radius: 8px; }
.tile-error { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 12px; font-size: 13px; }
.spinner { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px; border: 3px solid rgba(255,255,255,.25); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.segmented { display: flex; background: var(--card); border-radius: 22px; padding: 4px; margin: 12px 0; box-shadow: var(--shadow); }
.seg { flex: 1; border: 0; background: none; padding: 8px; border-radius: 18px; font: inherit; color: var(--muted); cursor: pointer; }
.seg.active { background: var(--accent); color: #fff; }
.toolbar { display: flex; justify-content: space-around; background: var(--card); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); margin: 12px 0; }
.tool { border: 0; background: none; font-size: 18px; min-width: 52px; min-height: 40px; border-radius: 10px; cursor: pointer; color: var(--ink); font-weight: 700; }
.tool.active { color: var(--accent); }
.live-info { text-align: center; font-size: 12px; margin-bottom: 8px; }

.ptz { display: flex; align-items: center; justify-content: center; gap: 28px; padding: 10px 0 20px; flex-wrap: wrap; }
.joystick { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 4px; background: var(--card); border-radius: 50%; padding: 14px; box-shadow: var(--shadow); }
.pad { border: 0; background: var(--bg); color: var(--ink); border-radius: 50%; font-size: 18px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.pad.pressed { background: var(--accent); color: #fff; }
.pad.center { display: grid; place-items: center; font-size: 11px; color: var(--muted); background: none; }
.up { grid-column: 2; grid-row: 1; } .left { grid-column: 1; grid-row: 2; } .center { grid-column: 2; grid-row: 2; }
.right { grid-column: 3; grid-row: 2; } .down { grid-column: 2; grid-row: 3; }
.zoom { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.zoom .pad { width: 56px; height: 56px; }

.events { display: flex; flex-direction: column; gap: 8px; }
.event { display: grid; grid-template-columns: 1fr; gap: 2px; background: var(--card); border-radius: 12px; padding: 12px 14px; border-left: 4px solid var(--muted); box-shadow: var(--shadow); }
.event.motion { border-left-color: var(--warn); } .event.human { border-left-color: var(--bad); } .event.vehicle { border-left-color: #2f7cf6; }
.event-type { font-weight: 600; }

.profile { display: flex; align-items: center; gap: 14px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 700; }
.menu a { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
.menu a:last-child { border-bottom: 0; }
.warn-box { background: #fff4e5; color: #8a5200; border-radius: 10px; padding: 10px 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.inline-form input, .inline-form select { flex: 1 1 140px; margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(20,20,20,.9); color: #fff; padding: 10px 16px; border-radius: 20px; z-index: 50; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }

/* --- funciones (sirena, luz, grabaciones, ajustes) --- */
.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 0 12px; }
.feature { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--card); border: 0; border-radius: 12px; padding: 10px 4px; font: inherit; font-size: 12px; color: var(--ink); cursor: pointer; box-shadow: var(--shadow); }
.feature.on { background: var(--accent); color: #fff; }
.f-icon { font-size: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 4px 10px; font-size: 13px; }
.block { display: block; }
.ok { color: var(--ok); }

.settings .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); margin: 0; color: var(--ink); font-size: 14px; }
.settings .row:last-child { border-bottom: 0; }
.settings .row.col { flex-direction: column; align-items: stretch; }
.settings select { width: auto; min-width: 150px; margin: 0; }
.settings h3 { font-size: 14px; margin: 14px 0 8px; }
input.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; cursor: pointer; flex: none; margin: 0; padding: 0; border: 0; transition: background .2s; }
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .2s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { left: 21px; }
input[type=range] { padding: 0; accent-color: var(--accent); }
.wifi-form select, .wifi-form input { margin-bottom: 8px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }

/* --- grabaciones --- */
.pb-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.pb-controls input, .pb-controls select { margin: 0; }
.pb-video { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); display: block; }
.timeline { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 12px 0; box-shadow: var(--shadow); }
.tl-bar { position: relative; height: 34px; background: var(--bg); border-radius: 8px; cursor: pointer; overflow: hidden; }
.tl-seg { position: absolute; top: 0; bottom: 0; background: rgba(255,106,0,.35); }
.tl-ev { position: absolute; top: 0; width: 2px; height: 100%; background: var(--warn); }
.tl-ev.human { background: var(--bad); } .tl-ev.vehicle { background: #2f7cf6; }
.tl-hours { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.section-title { font-size: 15px; margin: 8px 0; }
.event { display: grid; gap: 2px; }
a.event { color: inherit; }
.meter { height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.meter-fill { height: 100%; background: var(--accent); }

/* --- zoom digital --- */
.tile { overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.tile video { transform-origin: center center; will-change: transform; }
.tile.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile.zoomed { cursor: grab; }
.pb-panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 10px; margin: 0 0 12px; }
.pb-panel .zoombar { box-shadow: none; margin: 0; padding: 2px 0; background: none; }
.pb-tools { gap: 2px; flex-wrap: nowrap; }
.pb-tools .tool { min-width: 42px; }
.pb-seekrow { display: flex; align-items: center; gap: 8px; }
.pb-seek { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.pb-time { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.pb-speeds { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; padding-top: 4px; font-size: 13px; }
.speed { border: 1px solid var(--line); background: none; color: var(--ink); border-radius: 999px; min-width: 44px; min-height: 32px; font-weight: 700; cursor: pointer; }
.speed.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.zoombar { display: flex; justify-content: center; align-items: center; gap: 6px; background: var(--card); border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow); margin: 0 0 12px; flex-wrap: wrap; }
.zoom-label { font-size: 13px; padding: 0 6px; }
.pb-box { border-radius: var(--radius); background: #000; }
.pb-box .pb-video { border-radius: 0; }

/* --- miniaturas de eventos --- */
.event.with-thumb { grid-template-columns: 112px 1fr; align-items: center; gap: 12px; }
.thumb-img { width: 112px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: #000; display: block; cursor: pointer; }
.thumb-img.empty { display: grid; place-items: center; color: #777; font-size: 20px; background: var(--bg); }

/* --- historial de fotos --- */
.features { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 560px) { .features { grid-template-columns: repeat(6, 1fr); } }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.photo { margin: 0; background: var(--card); border-radius: 10px; overflow: hidden; cursor: pointer; box-shadow: var(--shadow); border-bottom: 3px solid var(--warn); }
.photo.human { border-bottom-color: var(--bad); } .photo.vehicle { border-bottom-color: #2f7cf6; }
.photo img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.photo figcaption { font-size: 12px; padding: 6px 8px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; }
.lightbox img { max-width: 100%; max-height: calc(100% - 90px); object-fit: contain; }
.lb-stage { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; flex: 1; min-height: 0; }
.lb-stage img { max-height: 100%; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: 0; border-radius: 10px; background: rgba(255,255,255,.18); color: #fff; font-size: 40px; line-height: 1; cursor: pointer; z-index: 1; }
.lb-nav:hover:not(:disabled) { background: rgba(255,255,255,.32); }
.lb-nav:disabled { opacity: .25; cursor: default; }
.lb-prev { left: 4px; } .lb-next { right: 4px; }
.lb-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; color: #fff; margin-top: 10px; font-size: 13px; }

/* --- alta de cámara / información --- */
.qr-video { width: 100%; border-radius: 10px; background: #000; margin: 8px 0; }
.row.disc { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.warn-text { color: var(--warn); }
.settings .row-btns input { width: auto; flex: 1; margin: 0; }
