/* ───────────────────────────────────────────────────────────────────
   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 } }
