:root {
  /* Palette Veyron Dynamics — reprise à l'identique du tableau de bord VD
     Core (voir web/style.css côté logiciel) : vert sombre + mint + corail,
     plutôt que le bleu/cyan générique d'origine. Objectif : que l'app
     Netlify ressemble enfin au reste du produit (logo, rapports PDF,
     tableau de bord), pas à une maquette tech interchangeable. */
  --bg: #07110f;
  --bg-elevated: #0c1714;
  --bg-card: #13231e;
  --border: #1a2e26;
  --border-strong: #244238;
  --text: #edf8f3;
  --text-dim: #8ca79d;
  --text-faint: #5c7a6d;
  --accent: #5af0b5;
  --accent-dim: #16332a;
  --critical: #ff765e;
  --critical-dim: #3a1f18;
  --warning: #ffc85a;
  --info: #5af0b5;
  --ok: #5af0b5;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, "SF Pro Text", "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  /* Même halo radial que le tableau de bord VD Core : invisible sur
     mobile (l'app occupe toute la largeur), visible en bordure sur un
     écran large (PC, voir #app ci-dessous) — une touche de marque discrète
     plutôt qu'un simple aplat. */
  background: radial-gradient(circle at 50% 0, #12352b 0, transparent 40%), var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  /* 100vh sur mobile inclut la zone que peut occuper la barre d'adresse,
     donc le bas de l'app (barre de navigation) peut se retrouver hors de
     l'écran visible : 100dvh (hauteur "dynamique") corrige ça sur les
     navigateurs récents, et --app-height (calculée en JS depuis
     window.innerHeight, voir app.js) sert de repli le plus précis pour
     les navigateurs plus anciens ou les WebView embarquées. */
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 80px rgba(0,0,0,0.4);
  position: relative;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 8px;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.topbar .site { color: var(--text-faint); letter-spacing: 0.04em; }

.demo-banner {
  margin: 0 20px 10px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #4a3a1a;
  background: #1c1508;
  color: var(--warning);
  font-size: 12.5px;
  text-align: center;
  flex-shrink: 0;
}
.demo-banner.connected {
  border-color: #14392c;
  background: #08160f;
  color: var(--ok);
}

.screen-header {
  padding: 4px 20px 14px;
  flex-shrink: 0;
}
.screen-header h1 {
  font-size: 26px;
  margin: 0 0 4px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.screen-header .sub { color: var(--text-dim); font-size: 13.5px; }
.screen-header .sub .accent { color: var(--accent); }

.back-link {
  color: var(--accent);
  font-size: 14.5px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  -webkit-overflow-scrolling: touch;
}

/* ---- Radar ---- */
.radar-wrap { display: flex; flex-direction: column; align-items: center; padding: 10px 0 18px; }
.radar-status {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--critical);
  text-align: center;
  margin-top: 8px;
  text-transform: uppercase;
}
.radar-status.ok { color: var(--ok); }

/* ---- Filter chips ---- */
.chips {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.chip {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ---- Alert card ---- */
.alert-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--critical);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.alert-card.info { border-left-color: var(--info); }
.alert-card.warning { border-left-color: var(--warning); }
.alert-card .row { display: flex; justify-content: space-between; align-items: flex-start; }
.alert-card h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.alert-card .icon { font-size: 15px; }
.alert-card .zone { color: var(--text-dim); font-size: 13.5px; margin: 4px 0 6px; }
.alert-card .time { font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; color: var(--critical); text-transform: uppercase; }
.alert-card .toggle-details { background: none; border: none; color: var(--text-dim); font-size: 12px; font-family: var(--mono); letter-spacing: 0.04em; cursor: pointer; text-transform: uppercase; }
.alert-card .desc { font-size: 14.5px; line-height: 1.5; margin: 12px 0; }
.alert-card .coords { font-family: var(--mono); font-size: 12px; color: var(--text-faint); margin-bottom: 12px; }
.alert-card .actions { display: flex; gap: 10px; }

.btn {
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #042017; }
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 6px 18px rgba(90,240,181,.22); }
.btn.danger-outline { border-color: var(--critical); color: var(--critical); background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---- Camera list ---- */
.cam-card, .zone-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.cam-card .info h3, .zone-card .info h3 { margin: 0 0 4px; font-size: 16.5px; }
.cam-card .info .meta, .zone-card .info .meta { color: var(--text-dim); font-size: 13px; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-family: var(--mono); }
.status-dot .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status-dot.offline .dot { background: var(--text-faint); }

/* ---- Toggle switch ---- */
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { display: none; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong);
  transition: background 0.15s;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #042017; transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(20px); }

/* ---- Camera detail / video ---- */
.video-frame {
  /* aspect-ratio posé en inline par app.js selon frame_width/frame_height
     réels de la caméra (repli 16/9 sinon) — plus de cadre portrait fixe
     qui forçait un rognage de l'image. */
  max-height: 70vh;
  background: #050807;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 30px;
  position: relative;
  overflow: hidden;
}
/* contain (et non cover) : l'image entière reste visible, quitte à avoir
   de fines bandes noires plutôt que de rogner le haut/bas du flux. */
.video-frame video, .video-frame img.live-stream { width: 100%; height: 100%; object-fit: contain; position: absolute; inset: 0; cursor: zoom-in; }
.video-frame .stream-error { position: relative; z-index: 1; }
.video-frame .placeholder-icon { font-size: 34px; color: var(--accent); }
.video-frame h4 { margin: 4px 0 0; font-size: 16.5px; }
.video-frame p { margin: 0; color: var(--text-dim); font-size: 13.5px; line-height: 1.5; max-width: 280px; }
.video-frame .live-badge {
  position: absolute; top: 12px; left: 12px; background: var(--critical); color: white;
  font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 6px; letter-spacing: 0.04em;
  z-index: 1;
}
.video-frame .expand-btn {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border-radius: 8px;
  background: rgba(5,8,7,0.65); border: 1px solid rgba(255,255,255,0.25); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.video-frame:fullscreen, .video-frame:-webkit-full-screen {
  max-height: none; max-width: none; width: 100vw; height: 100vh; border-radius: 0; border: none; padding: 0;
}
.video-frame:fullscreen img.live-stream, .video-frame:-webkit-full-screen img.live-stream { cursor: zoom-out; }

/* ---- Settings ---- */
.settings-group { margin-bottom: 28px; }
.settings-group .label { color: var(--text-faint); font-size: 12px; letter-spacing: 0.08em; margin-bottom: 8px; text-transform: uppercase; }
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.settings-row .val { color: var(--text-dim); font-size: 14.5px; }
.settings-row input[type=text], .settings-row input[type=password] {
  background: var(--bg-elevated); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; text-align: right; width: 170px;
  font-family: var(--mono);
}
.settings-row select.val {
  background: var(--bg-elevated); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; font-family: inherit; max-width: 60%;
}
.settings-row.link { color: var(--accent); cursor: pointer; }
.settings-row.danger { color: var(--critical); cursor: pointer; border-bottom: none; }
.full-btn {
  display: block; width: 100%; text-align: center; padding: 14px; border-radius: 10px;
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit; margin-top: 6px;
}

/* ---- Bottom nav ---- */
.bottomnav {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 6px);
}
.navbtn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: inherit;
  font-size: 12px;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  position: relative;
}
.navbtn.active { color: var(--accent); }
.navbtn .dot-indicator { position: absolute; top: 2px; right: calc(50% - 22px); width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.navbtn .badge {
  position: absolute; top: -2px; right: calc(50% - 24px); background: var(--critical); color: white;
  font-size: 10px; font-weight: 700; border-radius: 999px; min-width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.navbtn svg { width: 22px; height: 22px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-state .icon { font-size: 30px; margin-bottom: 12px; }

/* ---- Écran de chargement ---- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 0, #12352b 0, transparent 40%), var(--bg);
  transition: opacity 0.5s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
.splash-logo {
  width: 96px;
  height: 96px;
  /* Pas de filter: drop-shadow() ici : combiné à la rotation infinie du
     secteur radar (.radar-sweep) en dessous, Safari (iOS en particulier)
     fige la zone du filtre en un carré visible autour du logo au lieu de
     suivre sa vraie forme (circulaire) — c'est ce carré disgracieux qu'on
     voyait au chargement. */
  animation: splash-fade-in 0.6s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes splash-fade-in {
  0%   { opacity: 0; transform: scale(0.75); }
  100% { opacity: 1; transform: scale(1); }
}
/* Seul le secteur balayé par le radar tourne, en boucle, tant que l'écran
   de chargement est affiché — le bateau, les anneaux et la ligne
   d'horizon restent fixes au centre, comme sur l'icône de l'app. */
.radar-sweep {
  transform-origin: 50px 50px;
  animation: radar-spin 1.6s linear infinite;
}
@keyframes radar-spin {
  to { transform: rotate(360deg); }
}
.splash-text {
  text-align: center;
  opacity: 0;
  animation: splash-text-in 0.6s cubic-bezier(.2,.7,.3,1) forwards;
  animation-delay: 0.25s;
}
.splash-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.splash-sub {
  margin-top: 3px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
@keyframes splash-text-in {
  0%   { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .splash-logo, .splash-text { animation: none; opacity: 1; }
  .radar-sweep { animation: none; }
}

::-webkit-scrollbar { width: 0; height: 0; }
