:root {
  --text: #17150f; --header: #17150f; --brand: #d9bd62; --gold: #a38a33; --on-gold: #17150f; --gold-text: #755d16;
  --bg: #f6f4ee; --card: #fff; --field-bg: #fff; --line: #e2ddcd; --field: #cfc8b2; --muted: #5f5a4e; --placeholder: #8a8474;
  --soft: #f3ead0; --on-soft: #4f3f0f; --ok-bg: #e2efe3; --ok: #1f5a2b; --bad: #9b2315;
  --primary: #17150f; --on-primary: #fff; color-scheme: light;
  /* Marges latérales imposées par l'iPhone (sur l'iPhone Duo plié : la colonne d'état à droite). */
  --left: max(16px, env(safe-area-inset-left, 0px)); --right: max(16px, calc(env(safe-area-inset-right, 0px) + 6px));
}
/* Mode sombre : choix de l'utilisateur (data-theme), sinon réglage de l'iPhone. */
:root[data-theme="dark"] {
  --text: #f1ede1; --header: #000; --gold: #c2a74c; --gold-text: #d9bd62; --bg: #12110d; --card: #1d1b15; --field-bg: #26231b; --line: #35322a; --field: #504b3d;
  --muted: #b7b1a0; --placeholder: #8f8979; --soft: #3a3118; --on-soft: #f0dc98; --ok-bg: #17331f; --ok: #9fdcab; --bad: #ff9d8f; --primary: #f1ede1; --on-primary: #17150f; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #f1ede1; --header: #000; --gold: #c2a74c; --gold-text: #d9bd62; --bg: #12110d; --card: #1d1b15; --field-bg: #26231b; --line: #35322a; --field: #504b3d;
    --muted: #b7b1a0; --placeholder: #8f8979; --soft: #3a3118; --on-soft: #f0dc98; --ok-bg: #17331f; --ok: #9fdcab; --bad: #ff9d8f; --primary: #f1ede1; --on-primary: #17150f; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg); }
body { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-areas: "header" "update" "main" "footer"; height: 100dvh; background: var(--bg); color: var(--text); font-family: -apple-system, system-ui, Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
header { grid-area: header; background: var(--header); color: #fff; padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--right) 14px var(--left); display: flex; flex-direction: column; gap: 8px; }
header h1 { margin: 0; font-size: 22px; overflow-wrap: anywhere; }
.brand { font-size: 13px; font-weight: 700; letter-spacing: .08em; color: var(--brand); }
#date, #count { font-size: 12px; color: #cfcabb; white-space: nowrap; }
#count { display: none; }
#bars { display: flex; gap: 4px; }
#bars i { flex: 1; height: 4px; border-radius: 2px; background: #4a4638; }
#bars i.on { background: var(--brand); }
#update { grid-area: update; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px var(--right) 8px var(--left); background: var(--soft); color: var(--on-soft); font-size: 13px; font-weight: 600; }
#steps { display: none; }
main { grid-area: main; min-height: 0; overflow-y: auto; padding: 16px var(--right) 16px var(--left); display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 672px; margin: 0 auto; }
main > * { flex-shrink: 0; }
footer { grid-area: footer; display: flex; gap: 10px; padding: 12px var(--right) max(12px, calc(env(safe-area-inset-bottom, 0px) - 14px)) var(--left); background: var(--card); border-top: 1px solid var(--line); }
h2 { margin: 0; font-size: 14px; color: var(--gold-text); }
h3 { margin: 0; font-size: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.two { display: flex; gap: 8px; }
.two > * { flex: 1; }
.fields { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--muted); }
label em { font-style: normal; color: var(--gold-text); }
label.strong { font-size: 13px; font-weight: 700; color: var(--gold-text); }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--field); border-radius: 10px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--text); background: var(--field-bg); }
textarea { padding: 10px 12px; }
::placeholder { color: var(--placeholder); }
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { opacity: .5; cursor: default; }
.btn { display: flex; flex-direction: row; align-items: center; justify-content: center; min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent; font-size: 15px; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; }
.btn.dark { background: var(--primary); color: var(--on-primary); }
.btn.gold { background: var(--gold); color: var(--on-gold); }
.btn.line { background: var(--card); color: var(--text); border-color: var(--field); }
.btn.text { background: none; color: var(--gold-text); min-height: 44px; font-size: 13px; padding: 0 6px; }
.btn.dashed { background: none; color: var(--gold-text); border: 1px dashed var(--gold-text); font-size: 14px; }
.btn.big { min-height: 60px; font-size: 17px; }
.btn.grow { flex: 1; }
.btn.danger { color: var(--bad); }
.lbl, .group .lbl { font-size: 12px; font-weight: 500; color: var(--muted); }
.group { display: flex; flex-direction: column; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; min-width: 58px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--field); background: var(--field-bg); color: var(--text); font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.muted { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.settings { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.good { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.warn { margin: 0; background: var(--soft); color: var(--on-soft); border-radius: 12px; padding: 12px 14px; font-size: 13px; line-height: 1.5; }
.warn ul { margin: 6px 0 0; padding-left: 18px; }
.badge { font-size: 12px; font-weight: 600; background: var(--soft); color: var(--on-soft); padding: 5px 9px; border-radius: 20px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.sep { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 14px; }
.item span:first-child { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.item strong { font-size: 15px; overflow-wrap: anywhere; }
.item small { font-size: 12px; color: var(--muted); }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.files li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.files li span { flex: 1; min-width: 0; }
.files .btn { flex-shrink: 0; white-space: nowrap; min-width: 48px; }
.card .fields > .btn.text { align-self: flex-start; }
.mail { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.wrapany { overflow-wrap: anywhere; font-size: 14px; }
/* La zone de signature reste claire : l'encre foncée est celle qui s'imprime sur les PDF. */
#pad { width: 100%; height: 190px; border: 1px dashed var(--gold); border-radius: 10px; background: #fdfcf8; touch-action: none; }
#viewer { position: fixed; inset: 0; z-index: 10; background: #4a4638; display: flex; flex-direction: column; }
#viewer .bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--right) 10px var(--left); background: #17150f; color: #fff; font-size: 13px; overflow-wrap: anywhere; }
#viewer .bar span { flex: 1; min-width: 0; }
#viewer .bar .btn { flex-shrink: 0; white-space: nowrap; }
#pages { flex: 1; overflow: auto; padding: 12px var(--right) max(12px, env(safe-area-inset-bottom, 0px)) var(--left); display: flex; flex-direction: column; gap: 12px; }
#pages canvas { width: 100%; max-width: 900px; margin: 0 auto; background: #fff; }
#pages .muted { color: #fff; }
#toast { position: fixed; z-index: 20; left: var(--left); right: var(--right); bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); max-width: 600px; margin: 0 auto; background: #17150f; color: #fff; border: 1px solid #d9bd62; border-radius: 12px; padding: 12px 14px; font-size: 13px; line-height: 1.45; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* En portrait, la colonne d'état s'arrête vers le haut : la barre du bas reprend toute la largeur. */
@media (orientation: portrait) { footer { padding-right: var(--left); } }

/* Écrans courts (iPhone Duo) : en-tête sur une ligne et espacements resserrés. */
@media (max-height: 720px) {
  header { padding-top: calc(env(safe-area-inset-top, 0px) + 10px); padding-bottom: 10px; gap: 6px; }
  header h1 { font-size: 19px; }
  html.in-steps header .top { display: none; }
  html.in-steps #count { display: inline; }
  .intro { display: none; }
  main { padding-top: 12px; gap: 10px; }
  .card { padding: 12px; gap: 10px; }
  .fields { gap: 10px; }
  footer { padding-top: 8px; }
  footer .btn { min-height: 46px; }
  #pad { height: 200px; }
}

/* Écran large (iPhone Duo déplié, tablette) : étapes sur le côté et contenu sur deux colonnes. */
@media (min-width: 700px) {
  html.in-steps body { grid-template-columns: 176px minmax(0, 1fr); grid-template-areas: "header header" "update update" "steps main" "footer footer"; }
  html.in-steps #steps { grid-area: steps; display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; padding: 10px 8px 10px var(--left); border-right: 1px solid var(--line); }
  #steps button { display: flex; align-items: center; gap: 8px; min-height: 44px; flex-shrink: 0; border: 0; border-radius: 10px; background: none; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; padding: 4px 8px; }
  #steps button b { width: 22px; height: 22px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--field); font-size: 11px; }
  #steps button[aria-current="step"] { background: var(--soft); color: var(--on-soft); }
  #steps button[aria-current="step"] b { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
  #bars { display: none; }
  main { max-width: 980px; }
  html.in-steps main { padding-left: 16px; }
  main.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; align-items: start; column-gap: 14px; }
  main.cols > .intro, main.cols > .span { grid-column: 1 / -1; }
  main[data-step="2"] .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main[data-step="7"].cols > * { grid-column: 1; }
  main[data-step="7"].cols > .span { grid-column: 1 / -1; }
  main[data-step="7"].cols > .mailcard { grid-column: 2; grid-row: 2 / span 12; }
  main[data-step="7"].cols.sans-alerte > .mailcard { grid-row: 1 / span 12; }
  #pad { height: 260px; }
  .list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  footer { justify-content: flex-end; }
  footer .btn.grow { flex: 0 1 360px; }
}

/* iPhone Duo plié, application sur toute la largeur : les boutons passent dans la colonne de droite. */
html.duo-side body { grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "header" "update" "main"; }
html.duo-side footer { position: fixed; z-index: 5; right: 8px; top: 262px; bottom: max(14px, calc(env(safe-area-inset-bottom, 0px) - 10px)); width: calc(var(--right) - 14px); flex-direction: column; justify-content: flex-end; gap: 10px; padding: 0; background: none; border: 0; }
html.duo-side footer .btn { flex: 0 0 auto; width: 100%; padding: 0 4px; font-size: 13px; min-height: 64px; }
html.duo-side footer .btn.grow { min-height: 96px; }
html.duo-side #toast { bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); }
