:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --line: #2a313b;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4c9aff;
  --ok: #3ecf8e;
  --warn: #f5a524;
  --bad: #f2555a;
  --rec: #3d7bd9;
  --arch: #8a6bd1;
  --radius: 8px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8; --panel: #ffffff; --panel-2: #f0f2f5; --line: #dde2e8;
    --text: #1b2028; --muted: #66707d; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
button, input, select {
  font: inherit; color: inherit; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
input[type=checkbox] { width: auto; }
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; }
.err { color: var(--bad); }

header.top {
  display: flex; align-items: center; gap: 4px; padding: 0 16px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
header.top .brand { font-weight: 700; margin-right: 18px; letter-spacing: .5px; }
header.top .brand span { color: var(--bad); }
header.top nav a {
  color: var(--muted); padding: 13px 12px; border-bottom: 2px solid transparent;
}
header.top nav a.active { color: var(--text); border-bottom-color: var(--accent); }
header.top .spacer { flex: 1; }
header.top .mode { font-size: 12px; padding: 3px 10px; border-radius: 12px; margin-right: 12px; color: #fff; }
header.top .mode.home { background: var(--ok); }
header.top .mode.away { background: var(--accent); }
header.top .clock { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 12px; }

main { padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ── Direct ── */
.grid { display: grid; gap: 6px; height: calc(100vh - 48px - 32px); }
.tile {
  position: relative; background: #000; border-radius: 6px; overflow: hidden;
  min-height: 0; cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile .label {
  position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 4px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px; display: flex; gap: 6px; align-items: center;
}
.tile .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aaa; pointer-events: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.recording { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.dot.starting, .dot.waiting { background: var(--warn); }
.dot.nodisk { background: var(--bad); }
.disk-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin: 12px 0; }
.disk-list .card .row { margin-top: 8px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--accent); color: #fff; margin-left: 6px; }
.badge.off { background: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* ── Lecture ── */
.playback { display: grid; grid-template-columns: 1fr; gap: 12px; }
.player { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.player video { width: 100%; height: 52vh; min-height: 220px; display: block; background: #000; }
.player .osd {
  position: absolute; right: 10px; top: 10px; background: rgba(0,0,0,.6); color: #fff;
  padding: 3px 10px; border-radius: 4px; font-variant-numeric: tabular-nums;
}
.controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sep { display: inline-block; width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.timeline { user-select: none; }
.tl-axis, .tl-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; }
.tl-axis .scale { position: relative; height: 20px; color: var(--muted); font-size: 11px; }
.tl-axis .scale span { position: absolute; transform: translateX(-50%); top: 2px; }
.tl-row { height: 30px; }
.tl-row .name { padding-right: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.tl-row.sel .name { color: var(--accent); font-weight: 600; }
.tl-row .track {
  position: relative; height: 22px; background: var(--panel-2); border-radius: 4px; cursor: crosshair; overflow: hidden;
}
.tl-row.sel .track { outline: 1px solid var(--accent); }
.tl-row .seg { position: absolute; top: 3px; bottom: 3px; background: var(--rec); border-radius: 2px; }
.tl-row .seg.t1 { background: var(--arch); }
.tl-row .seg.cur { background: var(--bad); }
.tl-cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--warn); pointer-events: none; }
.tl-sel { position: absolute; top: 0; bottom: 0; background: rgba(245,165,36,.18); border-left: 1px solid var(--warn); border-right: 1px solid var(--warn); pointer-events: none; }
.tl-hover { position: absolute; top: -22px; background: var(--panel); border: 1px solid var(--line); padding: 0 6px; font-size: 11px; border-radius: 4px; pointer-events: none; white-space: nowrap; transform: translateX(-50%); z-index: 2; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ── Événements ── */
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ev { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: inherit; display: block; }
.ev:hover { border-color: var(--accent); }
.ev.live { border-color: var(--bad); }
.ev img, .ev .noimg { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #000; }
.ev .noimg { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.ev .meta { padding: 8px 10px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.chip.c-person { background: #f2555a22; border-color: #f2555a; }
.chip.c-face { background: #3ecf8e22; border-color: #3ecf8e; }
.chip.c-vehicle { background: #f5a52422; border-color: #f5a524; }
.chip.c-animal { background: #8a6bd122; border-color: #8a6bd1; }
.plate { display: inline-flex; align-items: center; font: 600 13px/1 ui-monospace, "DejaVu Sans Mono", monospace; letter-spacing: 1px;
  background: #fff; color: #111; border: 1px solid #333; border-radius: 3px; overflow: hidden; }
.plate::before { content: ""; width: 7px; align-self: stretch; background: #1f4fbf; margin-right: 5px; }
.plate span { padding: 3px 6px 3px 0; }
.plates { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; align-items: center; }
.ev .plates img { height: 26px; width: auto; aspect-ratio: auto; border-radius: 3px; }
/* visages (profils) */
.faces { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.faces .face { display: inline-flex; flex-direction: column; align-items: center; cursor: pointer; font-size: 11px; }
.ev .faces img { width: 48px; height: 48px; aspect-ratio: 1; object-fit: cover; border-radius: 50%; border: 2px solid #3ecf8e; }
.faces .face.unknown img { border-color: var(--muted); }
.prof { border-top: 1px solid var(--line); padding: 10px 0; }
.prof-faces { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.prof-face { position: relative; }
.prof-face img { width: 56px; height: 56px; object-fit: cover; border-radius: 50%; display: block; }
button.x { padding: 0 6px; line-height: 18px; font-size: 13px; }
button.small { padding: 2px 8px; font-size: 12px; }
.prof-face button.x { position: absolute; top: -4px; right: -4px; }
.ptz { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 10px; align-items: flex-end; z-index: 3; }
.ptz .pad { display: grid; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); gap: 4px; }
.ptz button { background: rgba(0,0,0,.55); color: #fff; border: 1px solid rgba(255,255,255,.25); padding: 0; font-size: 16px; touch-action: none; }
.ptz button:active, .ptz button.on { background: var(--accent); }
.ptz .side { display: flex; flex-direction: column; gap: 4px; }
.ptz .side button { width: 38px; height: 38px; }
.ptz .side .save { width: auto; height: auto; }
.ptz select, .ptz .side .save { background: rgba(0,0,0,.6); color: #fff; border-color: rgba(255,255,255,.25); font-size: 12px; padding: 4px 6px; width: auto; height: auto; }
.ptz .msg2 { color: #fff; font-size: 11px; background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 4px; max-width: 220px; }
.tile .det { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; }
.tile .det .chip { color: #fff; background: rgba(0,0,0,.55); }
.tl-row .evm { position: absolute; top: 0; height: 4px; background: var(--warn); border-radius: 1px; cursor: pointer; z-index: 1; }
.tl-row .evm.c-person { background: #f2555a; }
.tl-row .evm.c-face { background: #3ecf8e; }
.zone { position: relative; display: inline-block; max-width: 100%; user-select: none; cursor: crosshair; }
.zone img { display: block; max-width: 100%; }
.zone .grid9 { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(16, 1fr); grid-template-rows: repeat(9, 1fr); }
.zone .grid9 div { border: 1px solid rgba(255,255,255,.12); }
.zone .grid9 div.off { background: rgba(242,85,90,.45); }

/* ── Admin ── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.card { background: var(--panel-2); border-radius: var(--radius); padding: 12px; }
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 20px; font-weight: 600; margin-top: 2px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; background: var(--ok); }
.bar > div.warn { background: var(--warn); }
.bar > div.bad { background: var(--bad); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
pre.log { margin: 6px 0 0; padding: 8px; background: var(--bg); border-radius: 4px; font-size: 11px; max-height: 120px; overflow: auto; white-space: pre-wrap; color: var(--muted); }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 4px 20px; }
.settings input, .settings select, dialog input { width: 100%; }
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(640px, calc(100vw - 32px)); max-height: 92vh; overflow: auto; padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── Connexion ── */
.login { max-width: 340px; margin: 12vh auto; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login input { width: 100%; }
.login button { width: 100%; margin-top: 16px; }

@media (max-width: 700px) {
  header.top .clock { display: none; }
  /* (sur un téléphone : le menu passe sur sa propre ligne, et défile s'il le faut, au lieu de déborder) */
  header.top { height: auto; flex-wrap: wrap; padding: 6px 10px; row-gap: 0; }
  header.top nav { order: 3; width: 100%; display: flex; overflow-x: auto; }
  header.top nav a { padding: 8px 10px; white-space: nowrap; }
  .tl-axis, .tl-row { grid-template-columns: 80px 1fr; }
  main { padding: 10px; }
}
#disc-list input { width: auto; flex: 1; min-width: 110px; }

/* l'image en grand (page Événements) */
dialog.grand { width: min(1400px, 96vw); max-width: 96vw; padding: 10px; }
.grand-img { position: relative; text-align: center; background: #000; border-radius: 4px; min-height: 120px; }
.grand-img img { width: 100%; max-height: 78vh; object-fit: contain; display: block; margin: 0 auto; transition: opacity .15s; }
.grand-img .hint { position: absolute; top: 8px; left: 10px; color: #ddd; }
.grand-info { margin: 8px 2px; }
.grand-boutons { gap: 8px; flex-wrap: wrap; }
.ev img.zoomable { cursor: zoom-in; }

/* onglets (Administration, Événements) */
nav.onglets { display: flex; gap: 2px; overflow-x: auto; margin: 0 0 12px; border-bottom: 1px solid var(--line); }
nav.onglets a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
nav.onglets a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
main [data-onglet][hidden], main [data-vue][hidden] { display: none !important; }
.afaire { padding: 8px 10px; border-radius: 6px; margin: 4px 0; border-left: 4px solid var(--line); background: var(--panel-2); }
.afaire.err { border-left-color: var(--bad); }
.afaire.warn { border-left-color: #f5a524; }
.afaire.info { border-left-color: var(--accent); }
.ok-txt { color: var(--ok); margin: 4px 0; }
button.kept { border-color: var(--warn, #d97706); color: var(--warn, #d97706); }
/* Ils reviennent */
.rev-list { display: grid; gap: 10px; }
.rev-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; }
.rev-card.done { color: var(--muted); }
.rev-pics { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.rev-pics img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; }
.rev-pics img.rev-plate { width: auto; height: 40px; object-fit: contain; }
.rev-card .events { margin-top: 4px; }
button.warn-btn { border-color: var(--warn); color: var(--warn); }
.prof.watch { border-left: 3px solid var(--warn); padding-left: 8px; }
.zone svg { position: absolute; inset: 0; width: 100%; height: 100%; }
