/* =====================================================================
   CPH — feuille de style
   Mobile-first. IBM Plex Sans pour l'interface, IBM Plex Mono pour les
   valeurs mesurées. Le rapport imprimé reprend la mise en page du rapport
   de référence (Helvetica/Arial, titres bleus, sections encadrées).
   ===================================================================== */

:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #eceeea;
  --ink: #1a1f24;
  --ink-2: #4d5660;
  --ink-3: #7b8591;
  --line: #d9ddd8;
  --line-2: #c3c9c2;
  --brand: #1b2733;
  --brand-ink: #e9eef2;
  --action: #0f6f78;
  --action-ink: #ffffff;
  --action-2: #0a5157;
  --focus: #1f9aa8;
  --danger: #b3261e;

  /* statuts d'humidité */
  --normal: #1f8a4c;      --normal-bg: #dff3e6;
  --attention: #c27c00;   --attention-bg: #fdf0cf;
  --probleme: #c62828;    --probleme-bg: #fbdcdc;
  --impossible: #6b7280;  --impossible-bg: #e9ebee;

  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 40, .08), 0 4px 14px rgba(20, 30, 40, .06);
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--sans); font-size: 16px; line-height: 1.45; color: var(--ink); background: var(--bg); }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--action); }
button { font: inherit; }
input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: 0 .3em; border-radius: 3px; }
.boot { padding: 3rem 1rem; text-align: center; color: var(--ink-3); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.btn.primary:hover { background: var(--action-2); }
.btn.danger { color: var(--danger); border-color: #e2b3b0; }
.btn.danger:hover { background: #fbecea; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.ghost.active { background: var(--impossible-bg); color: var(--impossible); border-color: var(--line-2); }
.btn.sm { min-height: 34px; padding: 0 .7rem; font-size: .9rem; }
.btn.icon { padding: 0; width: 44px; }
.btn.icon.sm { width: 34px; }
.btn.block { width: 100%; }
.btn.rec { color: var(--danger); border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, .35); } 50% { box-shadow: 0 0 0 6px rgba(179, 38, 30, 0); } }
@media (prefers-reduced-motion: reduce) { .btn.rec { animation: none; } }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.small svg.i, p svg.i { width: 14px; height: 14px; vertical-align: -2px; }

/* ---------- Formulaires ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field > label { font-size: .88rem; color: var(--ink-2); font-weight: 500; }
.field .hint { font-size: .8rem; color: var(--ink-3); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: .55rem .7rem;
  border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--surface);
}
.input:disabled { background: var(--surface-2); color: var(--ink-3); }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.4; }
.input:focus, select.input:focus, textarea.input:focus, .btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 .8rem; }
@media (max-width: 480px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.with-mic { display: flex; gap: .4rem; align-items: stretch; }
.with-mic textarea { flex: 1; }
.with-mic .btn { align-self: flex-start; }

/* ---------- Coque ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--brand-ink);
  padding: .55rem .9rem;
  display: flex; align-items: center; gap: .7rem;
}
.topbar .brand { font-weight: 600; letter-spacing: .01em; text-decoration: none; color: inherit; display: flex; align-items: center; gap: .5rem; }
.topbar .brand .mark { width: 26px; height: 26px; border-radius: 6px; background: var(--action); display: grid; place-items: center; font-family: var(--mono); font-size: .8rem; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .btn { background: transparent; color: inherit; border-color: rgba(255, 255, 255, .22); min-height: 36px; }
.topbar .btn:hover { background: rgba(255, 255, 255, .08); }
.topbar .user { font-size: .8rem; opacity: .75; display: none; }
@media (min-width: 640px) { .topbar .user { display: inline; } }
.offline-banner { background: #5b4b00; color: #fff3c4; text-align: center; padding: .35rem; font-size: .88rem; }

.page { max-width: 960px; margin: 0 auto; padding: 1rem .9rem calc(2rem + var(--safe-b)); }
.page-head { display: flex; align-items: center; gap: .7rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem; margin-bottom: 1rem; }
.card h2 { margin-bottom: .8rem; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }

/* ---------- Connexion ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(180deg, var(--brand) 0 42%, var(--bg) 42%); }
.login { width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1.4rem; }
.login .logo { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.1rem; }
.login .logo .mark { width: 38px; height: 38px; border-radius: 8px; background: var(--action); color: #fff; display: grid; place-items: center; font-family: var(--mono); font-weight: 600; }
.login .logo small { display: block; color: var(--ink-3); font-size: .82rem; }
.login .error { color: var(--danger); font-size: .9rem; margin: .3rem 0 .7rem; }

/* ---------- Tableau de bord ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-bottom: 1rem; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: .7rem .85rem; }
.stat b { display: block; font-family: var(--mono); font-size: 1.5rem; font-weight: 600; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--ink-3); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.filters .input { min-height: 40px; }
.filters .search { flex: 1 1 220px; }
.filters select { flex: 0 1 160px; }

.rlist { display: flex; flex-direction: column; gap: .5rem; }
.rrow {
  display: grid; grid-template-columns: 56px 1fr auto; gap: .8rem; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: .7rem .85rem; text-decoration: none; color: inherit;
}
.rrow:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.rrow .gauge { font-family: var(--mono); font-weight: 600; font-size: 1.05rem; text-align: center; border-radius: var(--radius); padding: .45rem 0; }
.rrow .gauge small { display: block; font-size: .62rem; font-weight: 500; opacity: .8; }
.rrow .title { font-weight: 600; }
.rrow .sub { color: var(--ink-2); font-size: .88rem; }
.rrow .meta { text-align: right; font-size: .82rem; color: var(--ink-3); }
.rrow .meta .pill { margin-top: .3rem; }
.empty { text-align: center; color: var(--ink-3); padding: 2rem 1rem; }

/* ---------- Pastilles de statut ---------- */
.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.pill.brouillon { background: var(--surface-2); color: var(--ink-2); }
.pill.finalise { background: #e2eaf1; color: #27425b; }
.lv-normal, .pill.normal { background: var(--normal-bg); color: var(--normal); }
.lv-attention, .pill.attention { background: var(--attention-bg); color: var(--attention); }
.lv-probleme, .pill.probleme { background: var(--probleme-bg); color: var(--probleme); }
.lv-impossible { background: var(--impossible-bg); color: var(--impossible); }
.lv-none { background: var(--surface-2); color: var(--ink-3); }
.counts { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-bottom: .5rem; font-size: .9rem; }

/* ---------- Éditeur ---------- */
.editor-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.editor-head .title { flex: 1; min-width: 160px; }
.editor-head .title h1 { font-size: 1.15rem; }
.editor-head .title .sub { font-size: .85rem; color: var(--ink-3); }
.savestate { font-size: .8rem; color: var(--ink-3); min-width: 110px; text-align: right; }
.savestate.saving { color: var(--action); }
.savestate.error { color: var(--danger); }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 1rem; }
.steps button {
  border: 0; background: var(--surface-2); color: var(--ink-2); padding: .55rem .2rem;
  border-radius: var(--radius); cursor: pointer; font-size: .85rem; font-weight: 500;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
}
.steps button .n { font-family: var(--mono); font-size: .75rem; opacity: .7; }
.steps button.active { background: var(--brand); color: var(--brand-ink); }
.steps button.done .n { color: var(--normal); opacity: 1; }
.wizard-nav { display: flex; gap: .6rem; justify-content: space-between; margin-top: 1rem; }

.chips-wrap { margin-bottom: .6rem; }
.chips-wrap summary { cursor: pointer; color: var(--action); padding: .3rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0 .2rem; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px;
  padding: .35rem .75rem; font-size: .88rem; cursor: pointer; line-height: 1.2;
}
.chip:hover { background: var(--surface-2); }
.chip.used { border-style: dashed; color: var(--ink-3); }

.points { display: flex; flex-direction: column; gap: .55rem; }
.point { display: grid; grid-template-columns: 6px minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.point .bar { background: var(--line-2); }
.point.lv-normal .bar { background: var(--normal); }
.point.lv-attention .bar { background: var(--attention); }
.point.lv-probleme .bar { background: var(--probleme); }
.point.impossible .bar { background: var(--impossible); }
.point.impossible { background: #fafbfb; }
.point .body { min-width: 0; padding: .6rem .7rem .6rem .8rem; display: grid; grid-template-columns: minmax(0, 1fr) 112px; gap: .4rem .6rem; align-items: start; }
.point .body > * { min-width: 0; }
.point .zone-in { font-weight: 600; border: 0; border-bottom: 1px dashed var(--line-2); border-radius: 0; padding: .2rem 0; min-height: 34px; background: transparent; width: 100%; }
.point .emp-in, .point .com-in { color: var(--ink-2); border: 0; border-bottom: 1px dashed var(--line); border-radius: 0; padding: .15rem 0; min-height: 30px; font-size: .9rem; background: transparent; width: 100%; }
.point .val { display: flex; flex-direction: column; align-items: stretch; gap: .25rem; grid-row: span 2; }
.point .val .unit { position: relative; display: block; }
.point .val .unit::after { content: "%"; position: absolute; right: .55rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-family: var(--mono); pointer-events: none; }
.point .val input {
  width: 100%; font-family: var(--mono); font-weight: 600; font-size: 1.35rem; text-align: right;
  padding: .3rem 1.6rem .3rem .5rem; min-height: 46px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface);
}
.point .val input:disabled { background: var(--surface-2); }
.point .val .lv { text-align: center; font-size: .75rem; font-weight: 600; border-radius: var(--radius); padding: .15rem; }
.point .tools { grid-column: 1 / -1; display: flex; gap: .3rem; justify-content: flex-end; align-items: center; }
.point .tools .tool-txt { font-size: .8rem; }
.point.pending .zone-in { color: var(--ink-2); }
.point.lv-normal .zone-in { color: var(--normal); }
.point.lv-attention .zone-in { color: var(--attention); }
.point.lv-probleme .zone-in { color: var(--probleme); }
.point.impossible .zone-in { color: var(--impossible); }

.dictee { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .6rem 0; }
.dictee .live { flex: 1 1 200px; font-size: .88rem; color: var(--ink-2); font-style: italic; min-height: 1.4em; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.photo { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column; margin: 0; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--surface-2); }
.photo .pbody { padding: .5rem; display: flex; flex-direction: column; gap: .35rem; }
.photo input, .photo select { min-height: 34px; font-size: .85rem; padding: .25rem .4rem; border: 1px solid var(--line); border-radius: var(--radius); width: 100%; }
.photo .btn { align-self: flex-end; }
.uploading { font-size: .85rem; color: var(--action); }

.recap { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem 1rem; font-size: .92rem; }
.recap div span { color: var(--ink-3); display: block; font-size: .78rem; }
.verdict-box { display: grid; grid-template-columns: auto 1fr; gap: .8rem; align-items: center; padding: .9rem 1rem; border-radius: var(--radius-lg); margin-bottom: 1rem; }
.verdict-box .big { font-family: var(--mono); font-size: 2rem; font-weight: 600; line-height: 1; }
.verdict-box .big small { font-size: .8rem; display: block; font-weight: 500; opacity: .8; }
.verdict-box.lv-none { background: var(--surface-2); color: var(--ink-2); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-weight: 600; color: var(--ink-2); font-size: .82rem; }
.table td.num { font-family: var(--mono); font-weight: 600; text-align: right; white-space: nowrap; }
.table td.lvl { white-space: nowrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }
.warn { background: var(--attention-bg); color: #6b4a00; padding: .6rem .8rem; border-radius: var(--radius); font-size: .9rem; margin-bottom: .8rem; }

.logo-preview { max-height: 110px; max-width: 240px; display: block; margin-bottom: .5rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; }
.seuils { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.seuils .field { margin: 0; }
.zones-edit textarea { min-height: 200px; font-size: .9rem; }

#toasts { position: fixed; left: 50%; bottom: calc(1rem + var(--safe-b)); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: .4rem; width: min(92vw, 420px); }
.toast { background: var(--brand); color: var(--brand-ink); padding: .6rem .9rem; border-radius: var(--radius); box-shadow: var(--shadow); font-size: .92rem; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--normal); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 25, .5); z-index: 40; display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 1.1rem; width: min(92vw, 440px); box-shadow: var(--shadow); }
.modal h2 { margin-bottom: .6rem; }
.modal .actions { justify-content: flex-end; }

/* ======================= RAPPORT (aperçu / impression) =======================
   Reproduit la mise en page du rapport de référence : titre gris, sections
   encadrées à titre bleu souligné, tampon centré, tableau de mesures. */
.print-toolbar { position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink); padding: .5rem .9rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.print-toolbar .btn { background: transparent; color: inherit; border-color: rgba(255,255,255,.25); min-height: 36px; }
.print-toolbar .btn.primary { background: var(--action); border-color: var(--action); }
.print-toolbar .spacer { flex: 1; }

.rep {
  --rb: #1a4ed8;          /* bleu titres */
  --rb-line: #c9d4f5;
  --rn: #28a745; --ra: #d39e00; --rp: #dc3545; --rg: #6c757d;
  font-family: Helvetica, Arial, "Liberation Sans", sans-serif; font-size: 10.5pt; line-height: 1.4; color: #222;
  max-width: 190mm; margin: 1rem auto; padding: 0 0 2rem;
}
.rep-title { text-align: center; color: #8e9399; font-size: 19pt; font-weight: 700; line-height: 1.25; padding: 8mm 6mm 5mm; }
.rep-card { background: #fff; border: 1px solid #e3e6ea; border-radius: 6px; padding: 7mm 7mm 3mm; margin: 0 0 5mm; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.rep-head { border-left: 4px solid var(--rb); padding: 1mm 0 1mm 4mm; margin-bottom: 6mm; }
.rep-head h1 { color: var(--rb); font-size: 17pt; font-weight: 700; margin: 0 0 2mm; }
.rep-head p { margin: 0; }
.rep-stamp { border: 2px dashed var(--rb-line); border-radius: 6px; padding: 5mm; text-align: center; margin-bottom: 6mm; }
.rep-stamp img { max-height: 26mm; max-width: 60mm; display: inline-block; border-radius: 3mm; }
.rep-stamp .cap { font-size: 8.5pt; color: #555; margin-top: 2mm; }
.rep-stamp-empty { height: 14mm; }
.rep-section { border: 1px solid #e3e6ea; border-radius: 5px; padding: 4mm 5mm 2mm; margin-bottom: 5mm; break-inside: avoid; }
.rep-section h2 { color: var(--rb); font-size: 13pt; font-weight: 700; margin: 0 0 3.5mm; padding-bottom: 1.5mm; border-bottom: 1px solid var(--rb-line); }
.rep-section p { margin: 0 0 2.2mm; }
.rep-section p.pre { white-space: pre-wrap; }
.rep-kv { width: 100%; border-collapse: collapse; font-size: 10pt; }
.rep-kv th, .rep-kv td { border: 1px solid #e3e6ea; padding: 1.8mm 2.5mm; text-align: left; vertical-align: top; }
.rep-kv th { background: #f6f7f9; font-weight: 700; width: 24%; white-space: nowrap; }
.rep-sum { margin: 0 0 2mm; padding-left: 6mm; }
.rep-sum li { margin: .6mm 0; }
.st { font-weight: 500; }
.st.normal { color: var(--rn); }
.st.attention { color: var(--ra); }
.st.probleme { color: var(--rp); }
.st.none { color: var(--rg); }
.rep-verdict { margin-top: 2mm; }
.rep-table { width: 100%; border-collapse: collapse; font-size: 10pt; }
.rep-table th, .rep-table td { border: 1px solid #e3e6ea; padding: 2mm 2.5mm; text-align: left; vertical-align: top; }
.rep-table th { background: #f6f7f9; font-weight: 700; }
.rep-table th.num, .rep-table td.num { width: 18mm; text-align: left; white-space: nowrap; }
.rep-table td small { color: #666; }
.rep-table tr { break-inside: avoid; }
.rep-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3mm; }
.rep-photos figure { margin: 0; break-inside: avoid; }
.rep-photos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid #ddd; border-radius: 2mm; display: block; }
.rep-photos figcaption { font-size: 8.5pt; color: #333; margin-top: 1mm; }
.rep-legal { font-size: 9pt; color: #333; padding-bottom: 4mm; }
.rep-legal-title { display: block; font-size: 10pt; margin-bottom: 3mm; color: #222; }
.rep-legal p { margin: 0 0 3mm; }
.rep-interp { margin: 0 0 3mm; }
.rep-interp ul { margin: 1.5mm 0 0; padding-left: 6mm; }
.rep-interp .st { font-weight: 700; }
.rep-foot { font-size: 9.5pt; color: #333; padding: 4mm 7mm; }

@page { size: A4; margin: 10mm 10mm 12mm; }
@media print {
  body { background: #fff; }
  .print-toolbar, #toasts, #modal-root { display: none !important; }
  .rep { margin: 0; max-width: none; padding: 0; }
  .rep-card { box-shadow: none; border-color: #ddd; }
  .rep-section h2 { break-after: avoid; }
  .rep-table { break-inside: auto; }
  .rep-card:has(.rep-table) { break-inside: auto; }
  .rep-section:has(.rep-table) { break-inside: auto; }
  .rep-legal { break-inside: avoid; }
}
