:root {
  --bg: #f4f5f7; --surface: #fff; --surface-2: #eef0f3; --text: #16181d; --muted: #646b78; --line: #dde1e7;
  --accent: #f08c00; --accent-ink: #1b1200; --accent-soft: #fff1dc; --danger: #d93b3b; --ok: #1f9d55; --info: #2b6cd8;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --header: #15171c; --header-ink: #f2f3f5;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1114; --surface: #181b20; --surface-2: #20242b; --text: #eceef1; --muted: #9aa1ad; --line: #2b3038;
    --accent-soft: #3a2806; --shadow: none; --header: #0b0c0f; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
body { min-height: 100dvh; font-size: 15px; line-height: 1.45; }
a { color: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* En-tête */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--header); color: var(--header-ink);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; text-decoration: none; letter-spacing: .2px; }
.brand svg { width: 26px; height: 26px; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.topbar nav a, .topbar nav button { color: var(--header-ink); text-decoration: none; padding: 7px 10px; border-radius: 8px; font-size: .92rem; background: none; border: 0; cursor: pointer; font: inherit; }
.topbar nav a.active, .topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,.1); }
.sync-pill { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; padding: 4px 9px; border-radius: 99px; background: rgba(255,255,255,.1); }
.sync-pill.pending { background: var(--accent); color: var(--accent-ink); }
.sync-pill.offline { background: var(--danger); color: #fff; }
@media (max-width: 640px) { .topbar nav .hide-sm { display: none; } }

main { max-width: 1200px; margin: 0 auto; padding: 18px 16px 90px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-bottom: 16px; }
.page-head .grow { flex: 1 1 260px; min-width: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { text-decoration: none; } .crumbs a:hover { text-decoration: underline; }

/* Boutons et champs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 38px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.lg { padding: 12px 20px; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
label.field { display: grid; gap: 4px; font-size: .88rem; font-weight: 600; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); }
label.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; cursor: pointer; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile { overflow: hidden; text-decoration: none; display: flex; flex-direction: column; }
.tile .cover { aspect-ratio: 16/10; background: var(--surface-2) center/cover no-repeat; position: relative; }
.tile .cover .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; }
.tile .body { padding: 12px 14px; display: grid; gap: 4px; }
.tile .actions { padding: 0 14px 14px; display: flex; gap: 8px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.due { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: rgba(31,157,85,.12); color: var(--ok); }
.badge.err { background: rgba(217,59,59,.12); color: var(--danger); }
.cover .badge { position: absolute; top: 10px; left: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; } .stat b { display: block; font-size: 1.6rem; } .stat span { color: var(--muted); font-size: .85rem; }
.section { margin: 26px 0 12px; display: flex; align-items: center; gap: 10px; }
.section h2 { margin: 0; }
.list { display: grid; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.list-item img { width: 64px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }

/* Onglets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }

/* Galerie */
.month { margin: 18px 0 8px; font-weight: 700; color: var(--muted); font-size: .9rem; text-transform: capitalize; }
.thumbs { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (max-width: 500px) { .thumbs { grid-template-columns: repeat(3, 1fr); gap: 4px; } }
.thumb { position: relative; aspect-ratio: 4/3; border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: pointer; border: 0; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: .72rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); text-align: left; }
.thumb.excluded img { opacity: .3; filter: grayscale(1); }
.thumb.excluded::after { content: "Exclue"; position: absolute; top: 6px; right: 6px; font-size: .7rem; background: var(--danger); color: #fff; padding: 1px 6px; border-radius: 99px; }
.thumb.ref::before { content: "Référence"; position: absolute; top: 6px; left: 6px; z-index: 1; font-size: .7rem; background: var(--accent); color: var(--accent-ink); padding: 1px 6px; border-radius: 99px; font-weight: 700; }
.thumb .sel { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.3); }
.thumb.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.thumb.selected .sel { background: var(--accent); }
.selbar { position: sticky; bottom: 12px; z-index: 5; margin-top: 12px; padding: 10px 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Lecteur */
.player { background: #000; border-radius: var(--radius); overflow: hidden; position: relative; }
.player .stage { position: relative; aspect-ratio: 16/9; display: grid; place-items: center; }
.player .stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.player .stamp { position: absolute; left: 12px; bottom: 12px; background: rgba(0,0,0,.6); color: #fff; padding: 4px 10px; border-radius: 8px; font-weight: 600; font-size: .9rem; }
.player .loading { position: absolute; top: 12px; right: 12px; color: #fff; font-size: .8rem; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 8px; }
.player .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; background: #111; color: #eee; }
.player .controls input[type=range].scrub { flex: 1 1 200px; }
.player .controls select { width: auto; background: #222; color: #eee; border-color: #333; padding: 5px 8px; }
.player .controls .btn { background: #222; color: #eee; border-color: #333; }
.player:fullscreen { display: flex; flex-direction: column; border-radius: 0; }
.player:fullscreen .stage { flex: 1; aspect-ratio: auto; }

/* Comparateur */
.compare { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; user-select: none; touch-action: none; }
.compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.compare .after { clip-path: inset(0 0 0 50%); }
.compare .handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: #fff; transform: translateX(-50%); box-shadow: 0 0 6px rgba(0,0,0,.5); }
.compare .handle::after { content: "⇆"; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #000; display: grid; place-items: center; font-weight: 700; }
.compare .lbl { position: absolute; top: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 3px 9px; border-radius: 8px; font-size: .82rem; }

/* Vidéos */
.video-card video { width: 100%; display: block; background: #000; border-radius: var(--radius) var(--radius) 0 0; aspect-ratio: 16/9; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }

/* Visionneuse plein écran */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.94); display: flex; flex-direction: column; color: #fff; }
.lightbox .lb-img { flex: 1; position: relative; min-height: 0; }
.lightbox .lb-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.lightbox .lb-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.lightbox .btn { background: #222; color: #fff; border-color: #333; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); color: #fff; border: 0; width: 44px; height: 64px; font-size: 26px; cursor: pointer; border-radius: 8px; }
.lightbox .nav.prev { left: 8px; } .lightbox .nav.next { right: 8px; }

/* Modale */
.modal-back { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 90dvh; overflow: auto; padding: 20px; }
.modal .row.end { justify-content: flex-end; margin-top: 18px; }

/* Toast */
#toasts { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { background: #1d2026; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .92rem; animation: tin .2s ease; }
.toast.err { background: var(--danger); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* Connexion */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--header); }
.login .card { width: min(380px, 100%); padding: 26px; }
.login .brand { color: var(--text); font-size: 1.3rem; margin-bottom: 16px; }

/* Bouton d'action flottant (mobile) */
.fab { position: fixed; right: 16px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 30; width: 62px; height: 62px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(0,0,0,.3); text-decoration: none; }
.fab svg { width: 30px; height: 30px; }

/* ---------- Écran de capture ---------- */
.cam { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; overflow: hidden; touch-action: none; }
.cam video, .cam .ghost { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam .ghost { pointer-events: none; transition: opacity .15s; }
.cam .ghost.diff { mix-blend-mode: difference; }
.cam .gridlines { position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% + .5px), transparent calc(33.33% + .5px), transparent calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% + .5px), transparent calc(66.66% + .5px)),
  linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% - .5px), rgba(255,255,255,.35) calc(33.33% + .5px), transparent calc(33.33% + .5px), transparent calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% - .5px), rgba(255,255,255,.35) calc(66.66% + .5px), transparent calc(66.66% + .5px)); }
.cam .level { position: absolute; left: 50%; top: 50%; width: 46%; height: 0; border-top: 2px solid rgba(255,255,255,.75); transform: translate(-50%,-50%); pointer-events: none; transition: border-color .2s; }
.cam .level.flat { border-color: #3ee07d; }
.cam .level::before, .cam .level::after { content: ""; position: absolute; top: -7px; width: 2px; height: 12px; background: inherit; border-left: 2px solid currentColor; }
.cam .top, .cam .bottom { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 12px 14px; z-index: 2; }
.cam .top { top: 0; padding-top: max(12px, env(safe-area-inset-top)); background: linear-gradient(rgba(0,0,0,.7), transparent); }
.cam .bottom { bottom: 0; padding-bottom: max(16px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75)); flex-direction: column; gap: 12px; }
.cam .title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam .title small { display: block; font-weight: 400; opacity: .75; }
.cam .ibtn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; text-decoration: none; }
.cam .ibtn.on { background: var(--accent); color: var(--accent-ink); }
.cam .ibtn svg { width: 22px; height: 22px; }
.cam .shutter-row { display: flex; align-items: center; justify-content: space-around; width: 100%; max-width: 420px; }
.cam .shutter { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,.25); cursor: pointer; padding: 0; }
.cam .shutter:active { background: #fff; }
.cam .shutter:disabled { opacity: .4; }
.cam .sliders { display: flex; gap: 16px; width: 100%; max-width: 520px; font-size: .8rem; }
.cam .sliders label { flex: 1; display: grid; gap: 2px; }
.cam .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 3; }
.cam .flash.go { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
.cam .hint { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); background: rgba(0,0,0,.65); padding: 6px 12px; border-radius: 99px; font-size: .85rem; z-index: 2; white-space: nowrap; }
.cam .last { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; border: 2px solid #fff; background: #222; }
.cam .err { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 30px; z-index: 1; }

/* Impression du panneau QR */
.qr-sheet { text-align: center; padding: 30px; }
.qr-sheet img { width: 320px; height: 320px; margin: 20px auto; }
@media print { .topbar, .no-print, .fab { display: none !important; } main { padding: 0; } .card { border: 0; box-shadow: none; } }
