:root {
  --ink: #14213d;
  --ink-2: #2b3a5c;
  --bg: #f3f4f7;
  --card: #ffffff;
  --line: #dde1e9;
  --text: #1a1f2b;
  --muted: #667085;
  --accent: #e85d04;
  --accent-ink: #ffffff;
  --ok: #1f8a70;
  --ok-bg: #e3f4ee;
  --warn: #b54708;
  --warn-bg: #fff1e6;
  --bad: #c0362c;
  --bad-bg: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1424;
    --card: #172036;
    --line: #2a3654;
    --text: #e8ecf4;
    --muted: #9aa6bf;
    --ok-bg: #12352e;
    --warn-bg: #3a2512;
    --bad-bg: #3a1b19;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
[hidden] { display: none !important; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ink); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 0;
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: .2px; display: inline-flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 18px; height: 18px; border-radius: 4px; background: var(--accent); display: inline-block;
  mask: url(/icon.svg) center/contain no-repeat; -webkit-mask: url(/icon.svg) center/contain no-repeat; background: #fff; }
.nav { display: flex; gap: 4px; overflow-x: auto; margin: 8px -16px 0; padding: 0 12px; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a, .nav button {
  flex: none; color: #c9d2e6; text-decoration: none; padding: 10px 10px 12px; font-size: .95rem;
  border: 0; background: none; border-bottom: 3px solid transparent; cursor: pointer; font: inherit;
}
.nav a.on { color: #fff; border-bottom-color: var(--accent); }
.nav .sep { width: 1px; background: #33456d; margin: 10px 4px; flex: none; }

/* ---------- mise en page ---------- */
.app { max-width: 860px; margin: 0 auto; padding: 16px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list > li + li { margin-top: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-decoration: none; color: inherit; width: 100%;
  background: none; border: 0; text-align: left; font: inherit; cursor: pointer; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: .875rem; }
.chev { color: var(--muted); font-size: 1.3rem; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 4px; }

/* ---------- boutons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn.icon { min-width: 40px; padding: 6px; min-height: 40px; }
.btn.huge { min-height: 76px; font-size: 1.15rem; border-radius: 18px; width: 100%; box-shadow: 0 6px 16px rgba(232,93,4,.25); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions .btn { flex: 1 1 140px; }

/* ---------- formulaires ---------- */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
label.f > span em { color: var(--bad); font-style: normal; }
label.f > small { display: block; color: var(--muted); margin-top: 4px; font-size: .82rem; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; min-height: 46px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.check { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.code-input { font-size: 1.8rem !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.inline-field { display: flex; gap: 8px; }
.inline-field input { flex: 1; min-width: 0; }

/* ---------- auth ---------- */
.auth { max-width: 400px; margin: 6vh auto 0; }
.auth .logo { width: 56px; height: 56px; margin: 0 auto 14px; display: block; }
.auth h1 { text-align: center; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 20px; }
.qr-enroll { display: block; margin: 8px auto 12px; width: 220px; height: 220px; border-radius: 10px; background: #fff; padding: 8px; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--bg); padding: 8px 10px; border-radius: 8px;
  text-align: center; word-break: break-all; font-size: .95rem; user-select: all; }

/* ---------- badges / états ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.accent { background: var(--accent); color: #fff; border-color: transparent; }
.dot { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: .85rem;
  border: 2px solid var(--line); color: var(--muted); }
.dot.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.dot.next { border-color: var(--accent); color: var(--accent); }
.notice { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .95rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.info { background: var(--card); border: 1px solid var(--line); }

/* ---------- ronde ---------- */
.run-head { background: var(--ink); color: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.run-head .muted { color: #b8c3da; }
.progress { height: 10px; background: rgba(255,255,255,.18); border-radius: 99px; overflow: hidden; margin: 12px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.cp-list .item { padding: 12px 14px; }
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; background: var(--bg); flex: none; }
.photo-full { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 12px; background: #000; display: block; }
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 6px 12px; margin: 10px 0 0; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.instructions { background: var(--warn-bg); color: var(--text); border-left: 4px solid var(--accent); padding: 10px 12px; border-radius: 8px;
  margin-bottom: 14px; white-space: pre-wrap; }

/* ---------- feuille (modale) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(8,12,24,.55); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out; }
.sheet { background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; padding: 22px; }
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }

.busy { position: fixed; inset: 0; z-index: 60; background: rgba(8,12,24,.6); display: grid; place-items: center; color: #fff; font-weight: 600; }
.busy::before { content: ""; width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin .8s linear infinite; margin: 0 auto 12px; display: block; }
.busy div { text-align: center; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 70; max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: transform .25s; font-weight: 500; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- éditeur admin ---------- */
.field-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); }
.field-card + .field-card { margin-top: 10px; }
.field-card .row { margin-bottom: 8px; }
.field-card label.f { margin-bottom: 10px; }
.qr-preview { width: 150px; height: 150px; background: #fff; border-radius: 10px; padding: 8px; display: block; }
.qr-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.order-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.order-item .n { width: 26px; text-align: center; color: var(--muted); font-weight: 700; flex: none; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 16px; border: 2px dashed var(--line); border-radius: var(--radius); }
.selbar { position: sticky; bottom: 10px; margin-top: 12px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; }

/* ---------- scanner caméra en direct ---------- */
.scan { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; overflow: hidden; touch-action: none; }
.scan-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 14px; background: linear-gradient(rgba(0,0,0,.65), transparent); }
.scan-title { flex: 1; text-align: center; font-weight: 600; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; font-size: 1.2rem;
  cursor: pointer; flex: none; display: grid; place-items: center; }
.scan-btn.on { background: #ffd166; color: #000; }
.scan-btn[hidden] { display: block !important; visibility: hidden; }
.scan-frame { position: absolute; left: 50%; top: 46%; width: min(72vw, 72vh, 420px); aspect-ratio: 1; transform: translate(-50%, -50%);
  box-shadow: 0 0 0 200vmax rgba(0,0,0,.45); border-radius: 18px; transition: box-shadow .2s; }
.scan-frame i { position: absolute; width: 38px; height: 38px; border: 5px solid #fff; }
.scan-frame i:nth-child(1) { top: -3px; left: -3px; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.scan-frame i:nth-child(2) { top: -3px; right: -3px; border-left: 0; border-bottom: 0; border-top-right-radius: 18px; }
.scan-frame i:nth-child(3) { bottom: -3px; left: -3px; border-right: 0; border-top: 0; border-bottom-left-radius: 18px; }
.scan-frame i:nth-child(4) { bottom: -3px; right: -3px; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.scan-frame.ok i { border-color: #2ee59d; }
.scan-status { position: absolute; left: 16px; right: 16px; top: calc(46% + min(36vw, 36vh, 210px) + 18px); text-align: center;
  font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.scan-status.err { background: rgba(192,54,44,.92); border-radius: 12px; padding: 12px; text-shadow: none; top: 40%; }
.scan-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  background: linear-gradient(transparent, rgba(0,0,0,.75)); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.scan-zoom { width: min(80%, 360px); accent-color: #fff; }
.scan-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.scan-link { border: 1px solid rgba(255,255,255,.5); background: rgba(0,0,0,.35); color: #fff; border-radius: 99px; padding: 10px 16px;
  font: inherit; font-size: .92rem; cursor: pointer; }
.scan-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scan-flash.on { opacity: .55; }

/* ---------- numéro de version ---------- */
.version { text-align: center; color: var(--muted); font-size: .78rem; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); opacity: .8; }

/* ---------- plans 2D ---------- */
.plan-vp { position: relative; width: 100%; height: 100%; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: repeating-conic-gradient(var(--bg) 0 25%, var(--card) 0 50%) 0 0 / 22px 22px; cursor: grab; }
.plan-vp:active { cursor: grabbing; }
.plan-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; --inv: 1; will-change: transform; }
.plan-img { display: block; pointer-events: none; -webkit-user-drag: none; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.18); }
.plan-layer { position: absolute; inset: 0; }
.plan-zoom { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 2; }
.plan-zbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 1.3rem; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; }

.pin { position: absolute; width: 0; height: 0; z-index: 1; }
.pin-body { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%) scale(var(--inv)); transform-origin: 50% 100%;
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: 17px 17px 17px 17px; display: grid; place-items: center;
  font: 700 15px/1 system-ui, sans-serif; color: #fff; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); white-space: nowrap; cursor: pointer; }
.pin-body::after { content: ""; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); border: 7px solid transparent;
  border-top-color: #fff; border-bottom: 0; }
.pin.todo .pin-body { background: #c0362c; }
.pin.done .pin-body { background: #1f8a70; }
.pin.next .pin-body { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.pin.next { z-index: 3; }
.pin.admin .pin-body { background: var(--ink); font-size: 13px; font-weight: 600; }
.pin.sel .pin-body, .pin.dragging .pin-body { background: var(--accent); }
.pin.sel, .pin.dragging { z-index: 4; }
.pin.dragging .pin-body { transform: translate(-50%, -100%) scale(calc(var(--inv) * 1.2)); opacity: .9; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(232,93,4,.25), 0 2px 6px rgba(0,0,0,.4); } }

.plan-btn { margin-top: 10px; justify-content: center; }
.plan-btn .badge { margin-left: 4px; }
.plan-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 8px; background: #fff; border: 1px solid var(--line); flex: none; }
.plan-thumb-lg { width: 100%; max-height: 220px; object-fit: contain; background: #fff; border-radius: 10px; border: 1px solid var(--line); }
.plan-edit-vp { width: 100%; max-height: min(66vh, 720px); min-height: 280px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.plan-hint { scroll-margin-top: 100px; position: sticky; top: 92px; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  margin-bottom: 10px; font-size: .92rem; box-shadow: var(--shadow); }
.plan-hint.on { background: var(--warn-bg); border-color: var(--accent); }
.plan-hint .btn { margin-left: 6px; min-height: 30px; padding: 2px 8px; }
.pl-item { display: flex; align-items: center; }
.pl-item .item { flex: 1; min-width: 0; }
.pl-item.sel { outline: 2px solid var(--accent); }

/* plein écran pendant la ronde */
.planfs { position: fixed; inset: 0; z-index: 75; background: var(--bg); display: flex; flex-direction: column; }
.planfs-top { display: flex; align-items: center; gap: 12px; background: var(--ink); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; }
.planfs-title { font-weight: 700; }
.planfs-sub { font-size: .85rem; color: #c9d2e6; }
.planfs-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.planfs-tab { flex: none; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 99px; padding: 8px 12px; font: inherit;
  font-size: .9rem; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.planfs-tab.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.planfs-main { flex: 1; min-height: 0; position: relative; display: flex; }
.planfs-view { flex: 1; min-height: 0; position: relative; }
.planfs-legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 14px; font-size: .85rem; background: var(--card); border-top: 1px solid var(--line); }
.planfs-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.lg.done { background: #1f8a70; } .lg.next { background: var(--accent); } .lg.todo { background: #c0362c; }
.planfs-info { position: absolute; left: 10px; right: 10px; top: 10px; z-index: 6; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 520px; margin: 0 auto; }
.planfs-bottom { padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px); background: var(--card); }
