/* ───────────────────────────────────────────────────────────────────
   PiCam — iOS-quality design system
   - Light by default, auto-dark via prefers-color-scheme
   - SF Pro / system stack typography
   - iOS spacing/radii/shadows
   - Spring animations + tap feedback
   ─────────────────────────────────────────────────────────────────── */

:root {
  /* Spacing scale (4-pt grid like iOS) */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  /* Radii */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-2xl: 28px;

  /* iOS-light palette */
  --bg: #f2f2f7;             /* iOS systemGroupedBackground */
  --surface: #ffffff;         /* card background */
  --surface-2: #f7f7fb;       /* nested surface */
  --border: rgba(60, 60, 67, 0.10);
  --separator: rgba(60, 60, 67, 0.18);
  --text: #000000;
  --text-2: #3c3c43;
  --text-3: rgba(60, 60, 67, 0.60);
  --text-4: rgba(60, 60, 67, 0.30);

  --accent: #007aff;          /* iOS systemBlue */
  --green:  #34c759;          /* iOS systemGreen */
  --red:    #ff3b30;          /* iOS systemRed */
  --orange: #ff9500;          /* iOS systemOrange */
  --gray:   #8e8e93;
  --indigo: #5856d6;

  --tap-bg: rgba(0, 0, 0, 0.04);
  --press-scale: 0.97;

  /* Shadows — soft + layered */
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow-2: 0 4px 6px rgba(16, 24, 40, 0.04), 0 2px 4px rgba(16, 24, 40, 0.04);
  --shadow-3: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.04);

  /* Font stack */
  --font-sf: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
             "Segoe UI", system-ui, Roboto, sans-serif;
  --mono:    ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --border: rgba(255, 255, 255, 0.08);
    --separator: rgba(255, 255, 255, 0.12);
    --text: #ffffff;
    --text-2: rgba(235, 235, 245, 0.88);
    --text-3: rgba(235, 235, 245, 0.55);
    --text-4: rgba(235, 235, 245, 0.30);
    --tap-bg: rgba(255, 255, 255, 0.06);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 8px rgba(0, 0, 0, 0.5);
    --shadow-3: 0 12px 24px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sf);
  font-size: 17px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}

/* ─── Layout ─── */
.app {
  min-height: 100dvh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

/* Big-title navigation bar (iOS 11+ pattern) */
.nav {
  position: sticky; top: 0; z-index: 20;
  padding: max(env(safe-area-inset-top), 8px) var(--s5) var(--s4);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid transparent;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3);
  transition: border-bottom-color 0.18s ease;
}
.nav.scrolled { border-bottom-color: var(--separator); }
.nav h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}
.nav-back {
  display: inline-flex; align-items: center;
  color: var(--accent);
  text-decoration: none;
  font-size: 17px; font-weight: 400;
  padding: var(--s1) var(--s2);
  margin-left: calc(var(--s2) * -1);
}
.nav-back svg { width: 20px; height: 20px; margin-right: 2px; }
.nav-action {
  color: var(--accent);
  background: none; border: none;
  font-size: 17px;
  cursor: pointer; padding: var(--s2);
  font-family: inherit;
}

/* Page container */
.page { padding: var(--s4) var(--s5) 0; }
.section-title {
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-3);
  text-transform: uppercase;
  margin: var(--s5) var(--s3) var(--s2);
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-1);
  padding: var(--s4);
  margin-bottom: var(--s3);
}
.card.hero { padding: 0; overflow: hidden; }

/* ─── Inset list (iOS Settings style) ─── */
.list {
  background: var(--surface);
  border-radius: var(--r-xl);
  margin-bottom: var(--s3);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.list-row {
  display: flex; align-items: center;
  gap: var(--s3);
  padding: var(--s4);
  position: relative;
  text-decoration: none;
  color: inherit;
  transition: background-color 0.14s ease, transform 0.18s cubic-bezier(.2,.8,.2,1);
}
.list-row + .list-row::before {
  content: ""; position: absolute; left: var(--s4); right: 0; top: 0;
  border-top: 0.5px solid var(--separator);
}
.list-row:active { background: var(--tap-bg); transform: scale(0.985); }
.list-row .lbl { flex: 1; min-width: 0; }
.list-row .lbl .t { font-size: 17px; font-weight: 400; color: var(--text); }
.list-row .lbl .s { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.list-row .val { color: var(--text-3); font-size: 15px; font-variant-numeric: tabular-nums; }
.list-row .chev { color: var(--text-4); width: 12px; height: 18px; flex: 0 0 auto; }
.list-row .glyph {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  background: var(--gray); color: white;
}
.list-row .glyph svg { width: 18px; height: 18px; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s2);
  padding: 12px var(--s5);
  border-radius: 14px;
  border: none;
  font-size: 17px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(.2,.8,.2,1), background-color 0.14s ease, opacity 0.14s ease;
  background: var(--accent); color: white;
}
.btn:active { transform: scale(var(--press-scale)); opacity: 0.86; }
.btn.secondary { background: var(--surface-2); color: var(--accent); }
.btn.danger { background: var(--red); color: white; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.full { width: 100%; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ─── Pills / Status ─── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.live { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.pill.live .dot { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 1.6s infinite; }
.pill.ok      { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.pill.warn    { color: var(--orange); background: color-mix(in srgb, var(--orange) 14%, transparent); }
.pill.danger  { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }
.pill.entered { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.pill.left    { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }
.pill.motion  { color: var(--gray); background: color-mix(in srgb, var(--gray) 18%, transparent); }
.pill.replay  { color: var(--orange); background: color-mix(in srgb, var(--orange) 14%, transparent); }

@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.35 } }

/* ─── Tab bar (iOS-style) ─── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 0.5px solid var(--separator);
  display: flex;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 8px 4px 6px;
  text-decoration: none;
  color: var(--text-3);
  font-size: 10px; font-weight: 500;
  transition: color 0.14s ease, transform 0.18s cubic-bezier(.2,.8,.2,1);
}
.tabbar a:active { transform: scale(0.93); }
.tabbar a.active { color: var(--accent); }
.tabbar a svg { width: 26px; height: 26px; }

/* ─── Hero (used on Live) ─── */
.hero-cam {
  position: relative; aspect-ratio: 16/9;
  border-radius: var(--r-2xl);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow-3);
  touch-action: none;
}
.hero-cam img, .hero-cam video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.glass {
  position: absolute;
  background: rgba(20, 20, 22, 0.55);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  color: white;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex; align-items: center; gap: 6px;
}
.glass.tl { top: var(--s3); left: var(--s3); }
.glass.tr { top: var(--s3); right: var(--s3); font-variant-numeric: tabular-nums; }
.glass.br { bottom: var(--s3); right: var(--s3); }
.glass-btn {
  background: rgba(20, 20, 22, 0.55);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  color: white;
  border: none; cursor: pointer;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.18s cubic-bezier(.2,.8,.2,1);
}
.glass-btn:active { transform: scale(0.9); }
.glass-btn svg { width: 18px; height: 18px; color: white; pointer-events: none; }

/* Theater mode — when the .hero-cam is moved to <html> + this class,
   it fills the viewport completely. Mounting on <html> (not <body>) escapes
   any transformed/filtered ancestor that traps position:fixed on iOS. */
.hero-cam.theater {
  position: fixed !important;
  top: 0; left: 0; right: 0; bottom: 0;
  inset: 0;
  margin: 0;
  z-index: 2147483647;
  width: 100vw;
  height: 100vh;   /* fallback for older Safari */
  height: 100dvh;
  aspect-ratio: auto;
  border-radius: 0;
  box-shadow: none;
  background: #000;
  transform: translateZ(0);  /* force own GPU layer; avoids iOS paint stalls */
}
.hero-cam.theater img,
.hero-cam.theater video {
  object-fit: contain;
}

/* ─── Inputs ─── */
.input {
  width: 100%; box-sizing: border-box;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 17px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}
.input:focus { border-color: var(--accent); }

/* ─── Login ─── */
.login-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--s5);
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border-radius: var(--r-2xl);
  padding: var(--s8) var(--s5);
  box-shadow: var(--shadow-3);
  text-align: center;
}
.login-card .icon {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--indigo));
  margin: 0 auto var(--s5);
  display: inline-flex; align-items: center; justify-content: center;
}
.login-card .icon svg { width: 32px; height: 32px; color: white; }
.login-card h1 { font-size: 22px; font-weight: 700; margin: 0 0 var(--s5); letter-spacing: -0.01em; }
.login-card .err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: var(--s2); }

/* ─── Misc ─── */
.empty {
  text-align: center;
  padding: var(--s10) var(--s4);
  color: var(--text-3);
}
.empty .icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: var(--s4);
}
.empty .icon svg { width: 28px; height: 28px; color: var(--text-3); }
.thumb-square {
  aspect-ratio: 1/1;
  background: var(--surface-2);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.thumb-square img { width: 100%; height: 100%; object-fit: cover; display: block; }

.fade-in { animation: fadeIn 0.32s cubic-bezier(.2,.8,.2,1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ═══════════════════════════════════════════════════════════════════
   PiCam CONSOLE v2 — security-cam console skin (swarm/live-lane)
   Appended last on purpose: these :root values win over the light
   palette AND over the prefers-color-scheme block above, so the app is
   dark on every device, like a real NVR console.
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --bg: #08080a;
  --surface: #131317;
  --surface-2: #1c1c22;
  --border: rgba(255,255,255,0.07);
  --separator: rgba(255,255,255,0.10);
  --text: #ffffff;
  --text-2: rgba(235,235,245,0.90);
  --text-3: rgba(235,235,245,0.56);
  --text-4: rgba(235,235,245,0.28);
  --tap-bg: rgba(255,255,255,0.07);
  --accent: #0a84ff;
  --green:  #30d158;
  --red:    #ff453a;
  --orange: #ff9f0a;
  --indigo: #5e5ce6;
  --gray:   #8e8e93;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.55);
  --shadow-2: 0 6px 14px rgba(0,0,0,0.55);
  --shadow-3: 0 18px 40px rgba(0,0,0,0.65);
}
html, body { background: var(--bg); color: var(--text); }
.page { padding-top: var(--s3); }
.fade-in { animation: none; }              /* no entry animation on the console: paint instantly */

/* ── Live stage ── */
.stage-card { margin-bottom: var(--s4); background: transparent; box-shadow: none; border-radius: var(--r-2xl); }
.hero-cam { touch-action: none; background: #0b0b0d; box-shadow: var(--shadow-3), 0 0 0 1px rgba(255,255,255,0.06); }
.hero-cam .frame { position: absolute; inset: 0; overflow: hidden; }
.hero-cam #img {
  width: 100%; height: 100%; object-fit: cover;
  transform-origin: center; transition: transform .12s ease, opacity .25s ease;
  pointer-events: none; user-select: none;
  opacity: 0;
}
.hero-cam #img.ready { opacity: 1; }
.hero-cam .frozen {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; pointer-events: none; transform-origin: center center;
}
body.is-down .hero-cam #img { filter: grayscale(1) brightness(.45); }

/* live badge */
.live-badge {
  position: absolute; top: var(--s3); left: var(--s3);
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px 7px 11px;
  border-radius: 999px;
  font-size: 12px; font-weight: 800; letter-spacing: 0.08em;
  color: #fff;
  background: rgba(10,10,12,0.62);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10);
}
.live-badge i { width: 9px; height: 9px; border-radius: 50%; background: var(--gray); display: block; }
.live-badge[data-state="live"]    { background: rgba(255,59,48,0.92); box-shadow: 0 0 22px rgba(255,59,48,0.45); }
.live-badge[data-state="live"] i  { background: #fff; animation: livepulse 1.25s ease-in-out infinite; }
.live-badge[data-state="wait"] i  { background: var(--orange); animation: livepulse 1s ease-in-out infinite; }
.live-badge[data-state="stalled"] { background: rgba(255,159,10,0.92); }
.live-badge[data-state="stalled"] i { background: #fff; }
.live-badge[data-state="down"]    { background: rgba(255,69,58,0.18); box-shadow: inset 0 0 0 1px rgba(255,69,58,0.6); color: #ff8a80; }
.live-badge[data-state="down"] i  { background: #ff453a; }
@keyframes livepulse { 0%,100% { opacity: 1; transform: scale(1) } 50% { opacity: .35; transform: scale(.82) } }

.glass.tr { font-variant-numeric: tabular-nums; font-weight: 600; }
.glass.tr.bad { color: #ffb4ae; box-shadow: inset 0 0 0 1px rgba(255,69,58,0.5); }
.glass.zoomtag { position: absolute; top: calc(var(--s3) + 40px); right: var(--s3); font-variant-numeric: tabular-nums; }

/* signal lost overlay */
.lost {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s2);
  text-align: center; padding: var(--s5);
  background:
    repeating-linear-gradient(45deg, rgba(255,69,58,.07) 0 12px, transparent 12px 24px),
    rgba(12,4,4,0.86);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: inset 0 0 0 2px rgba(255,69,58,0.55);
  animation: lostIn .18s ease-out;
}
.lost[hidden] { display: none; }
@keyframes lostIn { from { opacity: 0 } to { opacity: 1 } }
.lost-icon {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,69,58,0.18);
  display: inline-flex; align-items: center; justify-content: center;
  animation: lostBeat 1.6s ease-in-out infinite;
}
.lost-icon svg { width: 24px; height: 24px; color: #ff453a; }
@keyframes lostBeat { 0%,100% { box-shadow: 0 0 0 0 rgba(255,69,58,.45) } 60% { box-shadow: 0 0 0 16px rgba(255,69,58,0) } }
.lost-title { font-size: clamp(19px, 5.2vw, 30px); font-weight: 800; letter-spacing: 0.06em; color: #ff453a; }
.lost-sub   { font-size: 14px; color: rgba(255,255,255,0.82); }
.lost-btn   { margin-top: var(--s2); padding: 12px 22px; min-height: 46px; }

/* camera controls — big, thumb-sized */
.cam-controls {
  position: absolute; left: var(--s3); right: var(--s3); bottom: var(--s3);
  display: flex; gap: 10px; align-items: center; z-index: 6;
}
.glass-btn { width: 50px; height: 50px; }
.glass-btn svg { width: 22px; height: 22px; }
.glass-btn.primary { background: rgba(255,255,255,0.92); }
.glass-btn.primary svg { color: #101014; }
.glass-btn.busy { opacity: .5; }
.glass-btn:active { transform: scale(0.88); }
#fs { margin-left: auto; }
.hero-cam.theater .cam-controls { bottom: calc(var(--s5) + env(safe-area-inset-bottom)); }
.hero-cam.theater .live-badge   { top: calc(var(--s5) + env(safe-area-inset-top)); }

/* ── lists: bigger touch targets, obvious tappability ── */
.list-row { padding: var(--s4) var(--s4); min-height: 60px; }
.list.big .list-row { min-height: 68px; }
.list.big .list-row .glyph { width: 38px; height: 38px; border-radius: 10px; }
.list.big .list-row .glyph svg { width: 20px; height: 20px; }
.list.big .list-row .t { font-weight: 600; }
.list-row[href]:active { background: var(--tap-bg); transform: scale(0.985); }
.list-row .chev { width: 14px; height: 20px; }

/* ── tab bar: bigger, labeled in Spanish, clear active state ── */
.tabbar { background: rgba(10,10,12,0.82); border-top: 0.5px solid var(--separator); }
.tabbar a {
  min-height: 56px; padding: 9px 4px calc(9px + env(safe-area-inset-bottom, 0px));
  font-size: 0; gap: 4px; position: relative;
}
.tabbar a svg { width: 25px; height: 25px; }
.tabbar a::after {
  font-size: 11px; font-weight: 600; letter-spacing: .01em; line-height: 1;
}
.tabbar a[href="/"]::after       { content: "En vivo"; }
.tabbar a[href="/faces"]::after  { content: "Caras"; }
.tabbar a[href="/events"]::after { content: "Eventos"; }
.tabbar a[href="/replay"]::after { content: "Replay"; }
.tabbar a.active { color: #fff; }
.tabbar a.active::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%;
  height: 2px; border-radius: 0 0 2px 2px; background: var(--accent);
}
.tabbar a:active { transform: scale(0.92); }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  z-index: 2147483000;
  background: rgba(28,28,32,0.96); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-2), inset 0 0 0 1px rgba(255,255,255,0.10);
  transition: opacity .35s ease, transform .35s ease;
}
.toast.out { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ── login polish ── */
.login-card { box-shadow: var(--shadow-3), inset 0 0 0 1px rgba(255,255,255,0.06); }
.login-card .btn.full { min-height: 50px; }
.login-card .input { min-height: 50px; }

@media (prefers-reduced-motion: reduce) {
  .live-badge i, .lost-icon, #skel { animation: none !important; }
}

/* face_detail.html timestamp line — the only legacy class the redesign missed */
.when { color: var(--text-3, #8a8a8f); font-variant-numeric: tabular-nums; }
