:root {
  --bg: #16181b;
  --panel: #202328;
  --line: #2f333a;
  --text: #f3f1ea;
  --muted: #9aa0a8;
  --yellow: #ffc629;
  --green: #7cf29a;
  --orange: #ffa53d;
  --red: #ff6b5b;
  --tab-h: 64px;
  --safe-b: 0px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body.contrast { --bg: #ffffff; --panel: #f1f1f1; --line: #cfcfcf; --text: #000; --muted: #333; --green: #008a2e; --orange: #b55a00; --red: #c4000f; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Accueil */
.intro { position: fixed; inset: 0; overflow-y: auto; display: flex; justify-content: center;
  background: radial-gradient(120% 80% at 50% 0%, #2a2d33 0%, var(--bg) 60%); }
.intro-inner { max-width: 440px; padding: 48px 24px 32px; text-align: center; }
.intro-logo { width: 96px; height: 96px; filter: drop-shadow(0 8px 24px rgba(255,198,41,.25)); }
.intro h1 { font-size: 44px; margin: 12px 0 4px; letter-spacing: -1px; }
.tagline { color: var(--muted); margin: 0 0 28px; font-size: 17px; }
.btn-primary { display: block; width: 100%; min-height: 58px; border: 0; border-radius: 16px;
  background: var(--yellow); color: #16181b; font-weight: 800; font-size: 19px;
  box-shadow: 0 6px 0 #c9960f; transition: transform .08s, box-shadow .08s; }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9960f; }
.btn-link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 14px; font-size: 15px; }
.btn-link.danger { color: var(--red); }
.intro-msg { min-height: 1.4em; color: var(--orange); }
.intro-features { text-align: left; padding: 0; list-style: none; margin: 18px 0; }
.intro-features li { padding: 10px 0 10px 28px; border-top: 1px solid var(--line); position: relative; color: var(--muted); font-size: 15px; line-height: 1.4; }
.intro-features li::before { content: "●"; color: var(--green); position: absolute; left: 4px; }
.intro-features strong { color: var(--text); }
.intro-foot { color: var(--muted); font-size: 13px; }

/* Application */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 8px) 12px 6px; }
.brand { font-weight: 800; letter-spacing: -.3px; color: var(--yellow); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--yellow); color: #16181b; }
.toggles { margin-left: auto; display: flex; gap: 6px; }
.tgl { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 19px; opacity: .45; }
.tgl.is-on { opacity: 1; border-color: var(--yellow); box-shadow: inset 0 0 0 1px var(--yellow); }
.stage { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; }

.actions { padding: 6px 10px; }
.action-set { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip { min-height: 48px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
  display: inline-flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; }
.chip.is-on { background: var(--yellow); color: #16181b; border-color: var(--yellow); }
.chip-input input { width: 64px; min-height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text); font: inherit; text-align: center; padding: 0 4px; }

.tabs { display: grid; grid-template-columns: repeat(6, 1fr); border-top: 1px solid var(--line); background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom); }
.tab { min-height: var(--tab-h); background: none; border: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); }
.tab span { font-size: 22px; line-height: 1; }
.tab.is-on { color: var(--yellow); }

/* Feuilles */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-card { width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; background: var(--panel);
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(env(safe-area-inset-bottom) + 24px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.close { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 18px; }
.sheet h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; line-height: 1.45; margin: 6px 0; }
.hint.small { font-size: 12px; margin-top: 20px; }
.hint.center { text-align: center; }
.hint.list { padding-left: 18px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button { min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; font-size: 15px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; }
.seg small { font-weight: 500; font-size: 11px; color: var(--muted); }
.seg button.is-on { border-color: var(--yellow); box-shadow: inset 0 0 0 1px var(--yellow); }
.row { display: flex; gap: 8px; margin: 8px 0; }
.btn { flex: 1; min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; }

.calib-card { text-align: left; }
.steps { display: flex; align-items: center; justify-content: center; margin: 18px 0; }
.step { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line); font-weight: 800; }
.step.is-on { border-color: var(--yellow); color: var(--yellow); }
.step.is-done { background: var(--green); border-color: var(--green); color: #16181b; }
.step-line { width: 60px; height: 2px; background: var(--line); }
.calib-text { font-size: 18px; line-height: 1.45; min-height: 5.8em; }
.calib-meter { height: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; margin: 12px 0; }
#calib-bar { height: 100%; width: 0; background: var(--green); transition: width .1s linear; }

/* Phase 2 : panneaux */
.tgl-plain { opacity: 1; }
.panel { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 14px 24px; -webkit-overflow-scrolling: touch; }
.panel-title { font-size: 22px; margin: 8px 0 4px; }
.live-bar { position: sticky; top: -8px; z-index: 2; margin: -8px -14px 8px; padding: 10px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); font-size: 14px; font-weight: 700; color: var(--muted); }
.live-bar.is-stable { color: var(--green); }
.tools-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.tool-card { min-height: 96px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); padding: 12px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left; font-weight: 700; font-size: 15px; }
.tool-card span { font-size: 28px; }
.tool-card:active { border-color: var(--yellow); }
#panel-tools:has(#tool-view:not([hidden])) #tools-home { display: none; }
.tool-view h2 { margin: 4px 0; font-size: 22px; }
.back { background: none; border: 0; color: var(--yellow); font-weight: 700; font-size: 16px; padding: 10px 0; }
.fields { display: grid; gap: 10px; margin: 14px 0; }
.field { display: grid; gap: 5px; font-size: 14px; color: var(--muted); font-weight: 600; margin: 8px 0; }
.field-row { display: flex; align-items: center; gap: 8px; }
.field input, .field select, .field textarea, .j-head select {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-size: 17px; padding: 8px 12px; }
.field textarea { resize: vertical; min-height: 64px; }
.field-row input { flex: 1; min-width: 0; }
.field-row em { font-style: normal; color: var(--muted); min-width: 34px; }
.measure { min-height: 48px; border-radius: 12px; border: 1px solid var(--yellow); background: transparent; color: var(--yellow);
  font-weight: 700; padding: 0 10px; white-space: nowrap; transition: background .2s; }
.measure.flash { background: var(--yellow); color: #16181b; }
.result { border-radius: 16px; background: var(--panel); border: 1px solid var(--line); padding: 14px; }
.result-main { font-size: 26px; font-weight: 800; margin: 0 0 8px; color: var(--yellow); line-height: 1.2; }
.verdict { font-weight: 700; margin: 6px 0 10px; }
.verdict.is-ok { color: var(--green); }
.verdict.is-ko { color: var(--orange); }
.result dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 10px 0; font-size: 15px; }
.result dt { color: var(--muted); }
.result dd { margin: 0; font-weight: 700; text-align: right; }
.save-btn { width: 100%; margin-top: 8px; }

.panel-camera { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.cam-stage { position: relative; flex: 1; min-height: 0; background: #000; }
.cam-stage video, .cam-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam-stage video { object-fit: cover; }
.cam-stage canvas { touch-action: none; }
.cam-msg { position: absolute; left: 16px; right: 16px; bottom: 16px; margin: 0; padding: 12px; border-radius: 12px;
  background: rgba(22,24,27,.85); color: var(--text); font-size: 14px; }
.cam-bar { display: flex; gap: 8px; padding: 8px 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.seg-small button { min-height: 48px; padding: 0 12px; }
.chip-accent { background: var(--yellow); color: #16181b; border-color: var(--yellow); font-weight: 800; }

.j-head { display: grid; gap: 8px; margin: 10px 0; }
.j-head .row { margin: 0; }
.j-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 10px; }
.entry { display: flex; gap: 12px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.entry img, .entry-noimg { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg);
  display: grid; place-items: center; font-size: 28px; }
.entry-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.entry-body strong { font-size: 17px; overflow-wrap: anywhere; }
.entry-meta { font-size: 13px; color: var(--muted); }
.entry-folder { font-size: 12px; font-weight: 700; color: var(--yellow); }
.entry-body p { margin: 4px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.entry-del { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); flex: none; color: var(--muted); }

.save-value { font-size: 22px; font-weight: 800; color: var(--yellow); margin: 12px 0 0; }
.file-btn { position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.save-photo { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: var(--bg); margin: 6px 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; font-size: 15px; margin: 4px 0 12px; }
.check input { width: 22px; height: 22px; accent-color: var(--yellow); }
.logo-row { align-items: center; }
.logo-row .file-btn { flex: none; padding: 0 16px; }
#set-logo-preview { max-height: 48px; max-width: 120px; border-radius: 6px; background: #fff; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 70px); transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; text-align: center; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
