:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --od: #d9363e;
  --og: #2563eb;
  --warn-bg: #fff7e6;
  --warn: #b45309;
  --err-bg: #fdecec;
  --err: #b42318;
  --info-bg: #eef4ff;
  --info: #1d4ed8;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 14px 0 8px; }
h3:first-child { margin-top: 0; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); font-size: 13px; }

button {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 9px 14px; cursor: pointer; touch-action: manipulation;
}
button:hover { border-color: #c5cad3; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; }
button.small { padding: 6px 10px; font-size: 13px; }

input, select {
  font: inherit; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); margin-top: 4px;
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; margin: 0; }
label.check input { width: auto; margin: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
details { margin: 4px 0 14px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 8px; }

/* barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 650; }
.tag { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 7px; margin-left: 4px; }
.steps { display: flex; gap: 4px; flex: 1; justify-content: center; flex-wrap: wrap; }
.steps button { border: none; background: transparent; color: var(--muted); padding: 7px 10px; }
.steps button b {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--line); color: var(--ink); font-size: 12px; margin-right: 4px;
}
.steps button.active { color: var(--ink); font-weight: 600; }
.steps button.active b { background: var(--accent); color: #fff; }
.steps button.done b { background: #99d5cc; }

.banner { background: var(--err-bg); color: var(--err); padding: 10px 16px; font-size: 14px; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.protocol ul { padding-left: 18px; margin: 0 0 8px; }
.protocol li { margin-bottom: 4px; }

/* espace de travail photo */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.spacer { flex: 1; }
.hint {
  background: #e6f4f1; color: #0b534d; border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; font-size: 14px;
  min-height: 62px;
}
.hint.inline { margin: 0; min-height: 0; padding: 6px 10px; }
.hint.inline:empty { display: none; }
.canvas-wrap {
  position: relative; background: #1d2127; border-radius: var(--radius); overflow: hidden;
  height: min(72vh, 760px);
}
.canvas-wrap.small { height: min(50vh, 460px); margin-bottom: 12px; }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: #8a93a0; pointer-events: none; }
.summary:empty { display: none; }
.summary .big { font-size: 26px; font-weight: 650; }
.summary table { width: 100%; border-collapse: collapse; font-size: 14px; }
.summary td { padding: 3px 0; }
.summary td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }

.pointlist { margin: 0; padding-left: 20px; font-size: 14px; }
.pointlist li { margin-bottom: 3px; color: var(--muted); }
.pointlist li.done { color: var(--ink); }
.pointlist li.next { color: var(--accent); font-weight: 600; }

/* résultats */
.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.res-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.res-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px 0; }
.res-table td { padding: 6px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.res-table td.v { text-align: right; font-weight: 600; }
.res-table td.e { text-align: right; color: var(--muted); font-size: 12px; width: 70px; }
.od { color: var(--od); font-weight: 600; }
.og { color: var(--og); font-weight: 600; }
.warnings { list-style: none; padding: 0; margin: 0 0 12px; }
.warnings li { padding: 8px 12px; border-radius: 8px; margin-bottom: 6px; font-size: 14px; }
.warnings li.error { background: var(--err-bg); color: var(--err); }
.warnings li.warn { background: var(--warn-bg); color: var(--warn); }
.warnings li.info { background: var(--info-bg); color: var(--info); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

/* caméra */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.cam-stage { position: relative; flex: 1; overflow: hidden; }
.cam-mirror { position: absolute; inset: 0; }
.cam-mirror.mirrored { transform: scaleX(-1); }
.cam-mirror video, .cam-mirror canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.level {
  position: absolute; top: 12px; right: 12px; width: 84px; height: 84px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.7); background: rgba(0,0,0,.35);
}
.level::before, .level::after { content: ""; position: absolute; background: rgba(255,255,255,.5); }
.level::before { left: 50%; top: 8px; bottom: 8px; width: 1px; }
.level::after { top: 50%; left: 8px; right: 8px; height: 1px; }
.bubble {
  position: absolute; width: 18px; height: 18px; border-radius: 50%; left: 33px; top: 33px;
  background: #f59e0b; box-shadow: 0 0 0 2px rgba(0,0,0,.3); transition: background .15s;
}
.bubble.ok { background: #22c55e; }
.cam-readout {
  position: absolute; top: 12px; left: 12px; color: #fff; font: 600 14px/1.4 ui-monospace, monospace;
  background: rgba(0,0,0,.45); padding: 6px 10px; border-radius: 8px;
}
.cam-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); color: #fff; font-size: 15px;
  background: rgba(0,0,0,.55); padding: 8px 14px; border-radius: 8px; text-align: center; max-width: 92%;
}
.cam-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: #000; }
.cam-bar .ghost { color: #fff; border-color: #444; }
.shutter { width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff; background: #f59e0b; padding: 0; }
.shutter.ok { background: #22c55e; }
.cam-options { display: flex; gap: 18px; justify-content: center; padding: 0 16px 14px; background: #000; }
.cam-options label.check { color: #bbb; font-size: 13px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(15,18,22,.55); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 12px; padding: 18px; width: min(860px, 100%); max-height: 100%; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.calib-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: #1b1f24; color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: 90%;
}

/* écran de démarrage */
.boot { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.boot-box { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.boot-box .brand { font-size: 18px; margin-bottom: 14px; }
.boot-box p { margin: 0 0 10px; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 8px; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.boot.error .bar > div { background: var(--err); }
.boot-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

[hidden] { display: none !important; }

.mobile-bar { display: none; }
#open-calib .ico { display: none; }
.hint .small { margin-left: 6px; }

/* ---------- mobile & tablette portrait ---------- */
@media (max-width: 900px) {
  body { font-size: 15px; overscroll-behavior-y: none; }
  input, select { font-size: 16px; }             /* évite le zoom automatique d'iOS */
  .two-col, .workspace { grid-template-columns: minmax(0, 1fr); }
  .canvas-col, .side-col { min-width: 0; }
  main { padding: 10px 10px calc(84px + env(safe-area-inset-bottom)); }
  .card { padding: 14px; }

  /* en-tête sur une ligne : seule l'étape active affiche son nom */
  .topbar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); gap: 6px; flex-wrap: nowrap; }
  .brand .tag { display: none; }
  .brand { font-size: 14px; white-space: nowrap; }
  .steps { gap: 0; justify-content: flex-end; flex-wrap: nowrap; }
  .steps button { padding: 8px 5px; white-space: nowrap; }
  .steps button b { margin-right: 0; width: 24px; height: 24px; }
  .steps button span { display: none; }
  .steps button.active span { display: inline; margin-left: 4px; }
  #open-calib { padding: 6px 10px; font-size: 18px; line-height: 1; }
  #open-calib .ico { display: inline; }
  #open-calib .lbl { display: none; }

  /* barre d'outils sur une ligne, défilable */
  .toolbar { flex-wrap: nowrap; overflow-x: auto; gap: 6px; margin-bottom: 6px; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar button { padding: 9px 12px; white-space: nowrap; flex: 0 0 auto; }
  .toolbar .spacer { flex: 1 0 0; min-width: 0; }

  .hint { font-size: 13px; line-height: 1.35; padding: 7px 10px; min-height: 0; height: calc(4.05em + 14px); overflow-y: auto; margin-bottom: 6px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
  .hint.inline { height: auto; }

  /* la photo occupe l'écran disponible */
  .canvas-wrap { height: calc(100dvh - 250px - env(safe-area-inset-bottom)); min-height: 300px; border-radius: 8px; }
  .canvas-wrap.small { height: 48dvh; }

  /* barre du bas : valeurs en direct + étape suivante */
  .desk-only { display: none; }
  .mobile-bar {
    display: flex; align-items: center; gap: 10px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,.06);
  }
  .mobile-bar .primary { flex: 0 0 auto; padding: 12px 16px; }
  .mb-vals { flex: 1; min-width: 0; font-size: 13px; line-height: 1.3; color: var(--muted); }
  .mb-vals b { font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
  .mb-vals .alert { display: inline-block; margin-top: 2px; color: var(--err); font-weight: 600; background: none; border: 0; padding: 0; font-size: 13px; }

  .results-head h2 { margin: 0; }
  .res-grid { grid-template-columns: 1fr; }

  /* modales plein écran */
  .modal { padding: 0; }
  .modal-box { border-radius: 0; height: 100%; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }

  .foot { padding-bottom: 90px; }
}

@media (max-width: 380px) {
  .brand { display: none; }
  .steps { justify-content: flex-start; flex: 1; }
}

/* caméra : zones sûres (encoche, barre de navigation) */
.cam-bar { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.cam-readout, .level { top: max(12px, env(safe-area-inset-top)); }

/* poignées plus grandes au doigt : géré dans app.js (pointer: coarse) */

/* impression */
#report { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  #app, .camera, .modal, .toast { display: none !important; }
  #report { display: block; }
  .rp-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
  .rp-head h1 { font-size: 18pt; margin: 0; }
  .rp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .rp-box { border: 1px solid #bbb; border-radius: 6px; padding: 8px; break-inside: avoid; }
  .rp-box h3 { margin: 0 0 6px; font-size: 11pt; }
  .rp-imgs { display: grid; grid-template-columns: 3fr 2fr; gap: 10px; margin-top: 10px; }
  .rp-imgs img { width: 100%; border: 1px solid #bbb; border-radius: 4px; }
  .res-table td { padding: 3px 0; }
  .warnings li { padding: 4px 8px; margin-bottom: 3px; font-size: 9.5pt; }
  .rp-foot { margin-top: 10px; font-size: 8.5pt; color: #555; }
}
