:root {
  --brand: #1976d2;
  --brand-dark: #1565c0;
  --brand-light-bg: #e3f2fd;
  --brand-light-border: #90caf9;
  --teal: #0390b1;
  --bg: #f5f6f8;
  --page-bg: #eceff1;
  --ink: rgba(0, 0, 0, 0.87);
  --ink-2: rgba(0, 0, 0, 0.6);
  --ink-3: rgba(0, 0, 0, 0.38);
  --border: rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.23);
  --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --warn-bg: #fff4e5;
  --warn-border: #ffcc80;
  --warn-ink: #663c00;
  --warn-icon-bg: #ffe0b2;
  --warn-icon: #ed6c02;
  --ok-bg: #edf7ee;
  --ok-ink: #2e7d32;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, "Roboto Mono", Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* Any element's own `display` (e.g. from a flex utility class) otherwise beats the
   browser's built-in `[hidden] { display: none }` rule, since author styles win over
   UA styles regardless of specificity. Force it back to authoritative everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--page-bg);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
}

.screen {
  min-height: 100dvh;
  box-sizing: border-box;
  background: var(--bg);
  padding: calc(22px + var(--safe-top)) calc(22px + var(--safe-right)) calc(28px + var(--safe-bottom)) calc(22px + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- header bar ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--teal);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  flex: none;
}
.app-header img { width: 22px; height: 29px; object-fit: contain; filter: brightness(0) invert(1); }
.app-header span { font: 500 17px/1.1 var(--font); color: #fff; }

/* ---------- typography ---------- */
h1 { margin: 0; font: 700 30px/1.2 var(--font); color: var(--ink); text-wrap: pretty; }
h1.lg { font-size: 34px; line-height: 1.15; }
p.lead { margin: 0; font: 400 19px/1.5 var(--font); color: var(--ink-2); text-wrap: pretty; }

/* ---------- buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 64px;
  border: none;
  border-radius: 8px;
  font: 700 21px var(--font);
  cursor: pointer;
  padding: 0 16px;
  text-align: center;
}
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.24); }
.btn-primary:active { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--brand); border: 2px solid var(--brand-light-border); min-height: 60px; font-weight: 600; font-size: 18px; }
.btn-success { background: #2e7d32; color: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.24); }
.btn-warn { background: var(--warn-icon); color: #fff; }
.btn-link {
  align-self: center;
  min-height: 48px;
  border: none;
  background: none;
  color: var(--brand);
  font: 600 17px var(--font);
  text-decoration: underline;
  cursor: pointer;
  padding: 0 8px;
}
.btn-back {
  align-self: flex-start;
  min-height: 44px;
  border: none;
  background: none;
  color: var(--brand);
  font: 600 17px var(--font);
  cursor: pointer;
  padding: 0;
}
.actions { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.actions.centered { text-align: center; }

/* ---------- accueil ---------- */
.steps { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.step {
  display: flex;
  gap: 14px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  padding: 16px;
}
.step-num {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  background: var(--brand-light-bg); color: var(--brand);
  font: 700 19px var(--font);
  display: flex; align-items: center; justify-content: center;
}
.step-text { font: 400 18px/1.35 var(--font); color: var(--ink); }

/* ---------- cards ---------- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.card-row .label { font: 400 17px var(--font); color: var(--ink-2); }
.card-row .value { font: 700 18px var(--font-mono); color: var(--ink); text-align: right; }
.card-row .value.model { font-family: var(--font); }

.tip {
  display: flex; gap: 13px; align-items: flex-start;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--card-shadow); padding: 16px;
}
.tip.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.tip-icon {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  font: 700 16px var(--font); display: flex; align-items: center; justify-content: center;
}
.tip-icon.ok { background: #edf7ee; color: #2e7d32; }
.tip-icon.warn { background: var(--warn-icon-bg); color: var(--warn-icon); }
.tip-text { font: 400 18px/1.35 var(--font); color: var(--ink); }
.tip.warn .tip-text { color: var(--warn-ink); }

.diagram {
  border-radius: 8px; border: 1px solid var(--border);
  background: repeating-linear-gradient(135deg, #eceff1 0 9px, #e0e3e7 9px 18px);
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 12px; color: var(--ink-3); font: 400 13px/1.5 var(--font-mono);
  position: relative; overflow: hidden;
}

.notice { background: var(--brand-light-bg); border: 1px solid var(--brand-light-border); border-radius: 8px; padding: 16px; font: 400 17px/1.45 var(--font); color: var(--ink); }

/* ---------- camera screen ---------- */
.screen-camera {
  background: #14171a;
  padding-top: calc(14px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
  color: #fff;
  gap: 0;
}
.camera-topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 0; flex: none; }
.camera-close, .camera-torch {
  min-width: 48px; min-height: 48px; border: none; border-radius: 24px;
  background: rgba(255, 255, 255, 0.16); color: #fff; font: 600 20px var(--font); cursor: pointer;
}
.camera-torch { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 14px; font-size: 15px; }
.camera-torch.on { background: #ffd23f; color: #663c00; }
.camera-title { font: 600 16px var(--font); color: #fff; }
.camera-viewport {
  margin: 18px 0 0; flex: 1; border-radius: 8px; background: #000;
  position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center;
  min-height: 0;
}
.camera-viewport video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-hint-nostream {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #6e767c; font: 400 13px var(--font-mono); text-align: center; padding: 20px;
}
.camera-frame {
  position: absolute; left: 12%; right: 12%; top: 34%; bottom: 34%;
  border-radius: 6px; box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.42); pointer-events: none;
}
.camera-frame i { position: absolute; width: 36px; height: 36px; border: 5px solid #4dd0e1; transition: border-color .15s ease; }
.camera-frame i:nth-child(1) { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 6px 0 0 0; }
.camera-frame i:nth-child(2) { top: 0; right: 0; border-left: none; border-bottom: none; border-radius: 0 12px 0 0; }
.camera-frame i:nth-child(3) { bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 12px; }
.camera-frame i:nth-child(4) { bottom: 0; right: 0; border-left: none; border-top: none; border-radius: 0 0 12px 0; }
.camera-frame.ready i { border-color: #43d17a; }
.camera-bracket {
  position: absolute; border: 3px solid #43d17a; border-radius: 4px;
  pointer-events: none; opacity: 0;
  transition: opacity .15s ease, left .15s ease, top .15s ease, width .15s ease, height .15s ease;
}
.camera-bracket.visible { opacity: 1; }
.camera-bracket.low-confidence { border-color: #ffd23f; }
.camera-caption {
  position: absolute; left: 24px; right: 24px; bottom: 18px; background: rgba(0, 0, 0, 0.6);
  border-radius: 8px; padding: 12px 14px; text-align: center; font: 600 16px/1.35 var(--font); color: #fff;
}
.camera-help { padding: 16px 6px 0; text-align: center; font: 400 15px/1.4 var(--font); color: #b9c0c5; flex: none; }
.camera-controls { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 0; flex: none; }
.camera-nophoto { min-height: 48px; border: none; background: none; color: #4dd0e1; font: 600 16px var(--font); text-decoration: underline; cursor: pointer; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 6px solid rgba(255, 255, 255, 0.35); background: #fff; cursor: pointer; }
.shutter:active { background: #ddd; }
.camera-spacer { width: 70px; }
.camera-canvas { display: none; }

/* ---------- analyse ---------- */
.screen-analyse { align-items: center; text-align: center; }
.analyse-photo { width: 100%; height: 210px; position: relative; }
.scanbar { position: absolute; left: 0; right: 0; top: 20px; height: 3px; background: #4dd0e1; animation: scanbar 1.6s ease-in-out infinite; }
@keyframes scanbar { 0% { transform: translateY(0); } 50% { transform: translateY(150px); } 100% { transform: translateY(0); } }
.progress { width: 100%; height: 14px; border-radius: 8px; background: #e4ddcf; overflow: hidden; flex: none; }
.progress > i { display: block; height: 100%; border-radius: 8px; background: var(--brand); width: 6%; transition: width .3s ease; }

/* ---------- resultat ---------- */
.photo-thumb {
  width: 96px; height: 74px; flex: none; border-radius: 6px; border: 1px solid var(--border);
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  font: 400 10px var(--font-mono); color: var(--ink-3);
  background-color: #eceff1;
}
.thumb-row { display: flex; gap: 14px; align-items: center; }
.digits-row { display: flex; align-items: flex-end; gap: 10px; }
.digit-cell {
  width: 46px; height: 66px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font: 700 32px var(--font-mono); background: #fafafa; color: var(--ink); border: 2px solid var(--border-strong);
}
.digit-cell.unread { background: var(--warn-bg); color: var(--warn-icon); border-color: var(--warn-icon); }
.digit-cell.active { background: var(--brand-light-bg); border-color: var(--brand); }
.unit { font: 600 22px var(--font); color: var(--ink); padding-bottom: 8px; }
.reading-label { font: 600 16px var(--font); color: var(--ink-2); letter-spacing: 0.02em; }
.reading-note { font: 400 16px/1.4 var(--font); color: var(--ink-2); }
.confirm-line { font: 600 20px/1.3 var(--font); color: var(--ink); text-align: center; }

/* ---------- erreur ---------- */
.error-icon {
  width: 64px; height: 64px; border-radius: 50%; background: var(--warn-icon-bg); color: var(--warn-icon);
  font: 700 32px var(--font); display: flex; align-items: center; justify-content: center; flex: none;
}
.tip-list { display: flex; flex-direction: column; gap: 12px; }
.tip-row { display: flex; gap: 12px; align-items: flex-start; }
.tip-arrow { width: 26px; height: 26px; flex: none; border-radius: 50%; background: var(--brand-light-bg); color: var(--brand); font: 700 15px var(--font); display: flex; align-items: center; justify-content: center; }

/* ---------- saisie (keypad) ---------- */
.edit-row { background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--card-shadow); padding: 18px; display: flex; align-items: flex-end; gap: 10px; justify-content: center; }
.edit-cell {
  width: 46px; height: 68px; border-radius: 6px; cursor: pointer;
  font: 700 32px var(--font-mono); background: #fafafa; color: var(--ink); border: 3px solid var(--border-strong);
}
.edit-cell.unread { background: var(--warn-bg); color: var(--warn-icon); border-color: var(--warn-icon); }
.edit-cell.active { background: var(--brand-light-bg); border-color: var(--brand); }
.edit-cell.active.unread { background: var(--warn-bg); color: var(--warn-icon); box-shadow: 0 0 0 3px var(--brand-light-border); }
.hint-center { font: 400 16px/1.4 var(--font); color: var(--ink-2); text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  min-height: 56px; border-radius: 8px; border: 1px solid var(--border-strong); background: #fff;
  color: var(--ink); font: 600 25px var(--font-mono); cursor: pointer;
}
.key:active { background: #f0f0f0; }
.key.empty { visibility: hidden; }

/* ---------- envoye ---------- */
.screen-envoye { align-items: center; text-align: center; }
.result-glyph {
  width: 92px; height: 92px; border-radius: 50%; background: var(--ok-bg); color: var(--ok-ink);
  font: 700 44px var(--font); display: flex; align-items: center; justify-content: center; flex: none;
}
.result-glyph.offline { background: var(--warn-bg); color: var(--warn-icon); }
.receipt { width: 100%; text-align: left; }
.install-card { width: 100%; background: var(--brand-light-bg); border: 1px solid var(--brand-light-border); border-radius: 8px; padding: 18px; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.install-card h2 { margin: 0; font: 700 18px/1.3 var(--font); color: var(--ink); }
.install-card p { margin: 0; font: 400 16px/1.45 var(--font); color: var(--ink-2); }
.install-steps { margin: 0; padding-left: 20px; font: 400 16px/1.5 var(--font); color: var(--ink); }
.install-steps li { margin-bottom: 4px; }

/* ---------- aide ---------- */
.faq-item { background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--card-shadow); overflow: hidden; }
.faq-q { display: flex; gap: 12px; align-items: center; width: 100%; min-height: 58px; padding: 14px 16px; border: none; background: none; text-align: left; cursor: pointer; }
.faq-q span.txt { flex: 1; font: 600 18px/1.35 var(--font); color: var(--ink); }
.faq-q span.sign { font: 700 20px var(--font); color: var(--brand); }
.faq-a { padding: 0 16px 16px; font: 400 17px/1.5 var(--font); color: var(--ink-2); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.87); color: #fff; padding: 14px 18px; border-radius: 8px;
  font: 500 15px/1.4 var(--font); text-align: center; z-index: 1000;
  transform: translateY(calc(100% + 40px)); transition: transform .25s ease; pointer-events: none;
}
#toast.show { transform: translateY(0); }

/* ---------- offline banner ---------- */
#offline-banner {
  background: var(--warn-icon); color: #fff; text-align: center; font: 600 13px var(--font);
  padding: calc(6px + var(--safe-top)) 12px 6px; flex: none;
}

@media (min-width: 560px) {
  #app { max-width: 480px; margin: 0 auto; width: 100%; background: var(--bg); box-shadow: 0 0 0 1px var(--border); min-height: 100dvh; }
}
