/* SUD FORAGES TP — Demandes de relevés. Lisible en extérieur : fort contraste, grands boutons, pas de gris pâle. */
:root {
  --bordeaux: #7a1f2b;
  --bordeaux-dark: #5a1420;
  --bordeaux-soft: #f6e7ea;
  --bleu: #1f4e8c;
  --bleu-dark: #153866;
  --bleu-soft: #e6eef8;
  --bg: #eef0f3;
  --card: #ffffff;
  --text: #101418;
  --muted: #3d4650;
  --line: #c6ccd3;
  --ok: #17692c;
  --ok-soft: #e3f3e7;
  --warn: #8a4b00;
  --warn-soft: #fff1d6;
  --danger: #a1001c;
  --danger-soft: #fde6ea;
  --demo: #5b2a86;
  --demo-soft: #efe6f8;
  --radius: 14px;
  --tap: 56px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 2px 8px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--bleu); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
.boot { padding: 40px 20px; text-align: center; font-weight: 700; color: var(--bordeaux); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* En-tête */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bordeaux); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.brand { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; flex: 1; }
.brand-name { font-weight: 800; letter-spacing: .03em; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar [hidden] { display: none; }
.brand-sub { font-size: 14px; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { color: #fff; border-color: rgba(255, 255, 255, .5); background: transparent; }
.netstate { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.18); white-space: nowrap; }
.netstate.offline { background: #fff; color: var(--danger); }
.demo-banner { background: var(--demo); color: #fff; text-align: center; font-weight: 700; font-size: 15px; padding: 6px 12px; }
.offline-banner { background: var(--warn-soft); color: var(--warn); border-bottom: 2px solid var(--warn); padding: 10px 16px; font-weight: 600; font-size: 16px; }
.update-banner { background: var(--bleu); color: #fff; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.update-banner button { background: #fff; color: var(--bleu); border: 0; border-radius: 10px; padding: 8px 14px; font-weight: 700; }

main { max-width: 760px; margin: 0 auto; padding: 16px 14px 120px; }
main.wide { max-width: 1180px; }
h1 { font-size: 26px; margin: 8px 0 14px; line-height: 1.2; }
h2 { font-size: 21px; margin: 22px 0 10px; }
h3 { font-size: 18px; margin: 14px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 15px; }

/* Cartes */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 12px 0; border: 1px solid #dfe3e8; }
.card.tight { padding: 12px 14px; }
.card.alert { border-left: 6px solid var(--danger); }
.card.warn { border-left: 6px solid var(--warn); background: #fffaf0; }
.card.info { border-left: 6px solid var(--bleu); }
.card.ok { border-left: 6px solid var(--ok); }
.card.demo { border: 2px dashed var(--demo); background: var(--demo-soft); }
.card h2, .card h3 { margin-top: 0; }
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 6px 12px; margin: 6px 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 12px 20px;
  border-radius: 12px; border: 2px solid var(--bleu); background: #fff; color: var(--bleu);
  font-weight: 700; font-size: 18px; text-decoration: none; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--bordeaux); border-color: var(--bordeaux); color: #fff; }
.btn.secondary { background: var(--bleu); border-color: var(--bleu); color: #fff; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger.filled { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--bleu); text-decoration: underline; min-height: 44px; padding: 8px 10px; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 76px; font-size: 21px; }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 16px; }
.btn .ico svg { width: 26px; height: 26px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.btn-row > .btn { flex: 1 1 160px; }
.stack > * + * { margin-top: 12px; }

/* Barre d'actions fixe (zone du pouce) */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; justify-content: center;
}
.actionbar > .btn { flex: 1; max-width: 360px; }
.actionbar > .btn:first-child:not(:only-child) { flex: 0 0 auto; padding: 12px 16px; }
.actionbar > .btn:last-child { flex: 1 1 auto; }

/* Formulaire */
.field { margin: 16px 0; }
.field > label, .field > .label { display: block; font-weight: 700; margin-bottom: 6px; }
.req { color: var(--danger); }
.hint { font-size: 15px; color: var(--muted); margin: 4px 0 0; }
.input, textarea.input, select.input {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  border: 2px solid #8a939d; border-radius: 12px; background: #fff; font-size: 18px;
}
textarea.input { min-height: 110px; resize: vertical; }
.input:focus, .btn:focus-visible, .choice:focus-within { outline: 3px solid #f2a900; outline-offset: 2px; }
.field.invalid .input, .field.invalid .choices { border-color: var(--danger); }
.error-text { color: var(--danger); font-weight: 700; font-size: 16px; margin-top: 6px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; border-radius: 12px; }
.choice {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 12px 14px; border: 2px solid #8a939d; border-radius: 12px; background: #fff;
  font-weight: 700; cursor: pointer;
}
.choice input { width: 26px; height: 26px; accent-color: var(--bordeaux); flex: none; }
.choice.selected { border-color: var(--bordeaux); background: var(--bordeaux-soft); box-shadow: inset 0 0 0 1px var(--bordeaux); }
.choice .sub { display: block; font-weight: 500; font-size: 15px; color: var(--muted); }
.checkline { display: flex; gap: 14px; align-items: flex-start; padding: 14px; border: 2px solid #8a939d; border-radius: 12px; background: #fff; font-weight: 700; cursor: pointer; }
.checkline input { width: 30px; height: 30px; accent-color: var(--bordeaux); flex: none; margin: 0; }
.checkline.checked { border-color: var(--ok); background: var(--ok-soft); }

.steps { display: flex; gap: 6px; margin: 4px 0 10px; }
.steps span { flex: 1; height: 8px; border-radius: 4px; background: #c9ced5; }
.steps span.done { background: var(--bleu); }
.steps span.current { background: var(--bordeaux); }
.step-title { font-size: 15px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

/* Documents */
.doc-block { border: 2px solid #8a939d; border-radius: var(--radius); padding: 14px; background: #fff; margin: 14px 0; }
.doc-block.missing { border-color: var(--danger); border-style: dashed; }
.doc-block.complete { border-color: var(--ok); }
.doc-block.optional { border-style: dashed; }
.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.doc-head h3 { margin: 0; }
.doc-block > .btn-row > .btn { flex: 1 1 100%; }
.pages { display: grid; gap: 10px; margin-top: 12px; }
.page-item { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfc; }
.thumb-wrap { width: 96px; height: 120px; border-radius: 8px; overflow: hidden; background: #dde1e6; display: flex; align-items: center; justify-content: center; cursor: zoom-in; border: 0; padding: 0; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: contain; transition: transform .2s; background: #fff; }
.thumb-wrap .pdf-badge { font-weight: 800; color: var(--bordeaux); font-size: 20px; }
.page-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.page-tools .btn { min-height: 44px; padding: 6px 10px; font-size: 15px; border-width: 2px; }
.page-label { font-weight: 700; margin-bottom: 6px; }
.gauge { height: 14px; border-radius: 7px; background: #d9dde2; overflow: hidden; margin: 8px 0 4px; }
.gauge > span { display: block; height: 100%; background: var(--ok); }
.gauge.warn > span { background: var(--warn); }
.gauge.over > span { background: var(--danger); }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin: 10px 0; }
.thumb-grid a { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; aspect-ratio: 3 / 4; }
.thumb-grid img { width: 100%; height: 100%; object-fit: cover; }
.processing { display: flex; align-items: center; gap: 10px; color: var(--bleu); font-weight: 700; margin-top: 10px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--bleu-soft); border-top-color: var(--bleu); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Pastilles d'état */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 700; border: 2px solid currentColor; background: #fff; line-height: 1.5; }
.chip.type { color: var(--bleu-dark); background: var(--bleu-soft); }
.chip.st-prealerte { color: var(--warn); background: var(--warn-soft); }
.chip.st-disponible { color: var(--bleu-dark); background: var(--bleu-soft); }
.chip.st-rdv_confirme { color: var(--ok); background: var(--ok-soft); }
.chip.st-realise { color: #333; background: #e7e9ec; }
.chip.st-annule { color: #444; background: #e7e9ec; text-decoration: line-through; }
.chip.mail-en_attente, .chip.mail-envoi_en_cours { color: var(--bleu-dark); background: #fff; border-style: dashed; }
.chip.mail-accepte { color: var(--ok); background: var(--ok-soft); }
.chip.mail-simule { color: var(--demo); background: var(--demo-soft); }
.chip.mail-a_traiter, .chip.mail-echec, .chip.mail-incertain { color: var(--danger); background: var(--danger-soft); }
.chip.mail-abandonne { color: #555; background: #eee; }
.chip.local { color: var(--warn); background: var(--warn-soft); }
.chip.local-error { color: var(--danger); background: var(--danger-soft); }

/* Listes */
.list { display: grid; gap: 10px; }
.item {
  display: block; text-decoration: none; color: inherit; background: #fff; border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); border: 1px solid #dfe3e8; border-left: 6px solid var(--bleu);
}
.item.prealerte { border-left-color: var(--warn); }
.item.problem { border-left-color: var(--danger); }
.item.local { border-left-color: var(--warn); background: #fffaf0; }
.item-title { font-weight: 800; font-size: 19px; overflow-wrap: anywhere; }
.item-sub { color: var(--muted); font-size: 16px; }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.filters .field { margin: 0; }
.filters .input { min-height: 48px; padding: 8px 10px; font-size: 16px; }
.counter { display: inline-flex; min-width: 30px; height: 30px; align-items: center; justify-content: center; border-radius: 15px; background: var(--danger); color: #fff; font-weight: 800; padding: 0 8px; }
.home-actions { display: grid; gap: 14px; margin: 18px 0; }
.home-actions .btn { min-height: 92px; font-size: 23px; }

/* Historique */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 3px solid var(--line); }
.timeline li { position: relative; padding: 4px 0 12px 16px; }
.timeline li::before { content: ""; position: absolute; left: -8px; top: 10px; width: 13px; height: 13px; border-radius: 50%; background: var(--bleu); }
.timeline .when { font-size: 14px; color: var(--muted); }

.mail-preview { white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; background: #f7f8fa; border: 1px solid var(--line); border-radius: 10px; padding: 12px; max-height: 420px; overflow: auto; }
.not-sent-stamp { display: inline-block; border: 3px solid var(--demo); color: var(--demo); font-weight: 900; padding: 4px 10px; border-radius: 8px; letter-spacing: .05em; transform: rotate(-2deg); background: #fff; }
details { margin: 10px 0; }
details > summary { cursor: pointer; font-weight: 700; padding: 10px 0; min-height: 44px; }

/* Superpositions */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10, 12, 16, .92); display: flex; flex-direction: column; }
.overlay-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; color: #fff; }
.overlay-bar .btn { min-height: 48px; }
.overlay-body { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
.overlay-body img { max-width: 100%; max-height: 100%; background: #fff; }
.overlay-body.actual { display: block; }
.overlay-body.actual img { max-width: none; max-height: none; }
.overlay-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.dialog-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 16, .55); display: flex; align-items: flex-end; justify-content: center; padding: 12px; }
.dialog { background: #fff; border-radius: 18px; max-width: 520px; width: 100%; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); margin-bottom: env(safe-area-inset-bottom); }
.dialog h2 { margin-top: 0; }
@media (min-width: 700px) { .dialog-backdrop { align-items: center; } }
.toast-zone { position: fixed; left: 0; right: 0; bottom: 96px; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { background: #1d2329; color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600; max-width: 520px; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.progress { height: 18px; border-radius: 9px; background: #d9dde2; overflow: hidden; margin: 10px 0; }
.progress > span { display: block; height: 100%; background: var(--bleu); transition: width .2s; }
.state-line { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.state-steps { list-style: none; padding: 0; margin: 10px 0; }
.state-steps li { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }
.state-steps .dot { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 3px solid #9aa3ad; margin-top: 3px; }
.state-steps li.done .dot { background: var(--ok); border-color: var(--ok); }
.state-steps li.current .dot { border-color: var(--bleu); background: var(--bleu-soft); }
.state-steps li.error .dot { background: var(--danger); border-color: var(--danger); }

@media (min-width: 900px) {
  .two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
}
