:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #aeaeb2;
  --separator: rgba(60, 60, 67, .16);
  --field: #ffffff;
  --accent: #0071e3;
  --danger: #d70015;
  --switch-off: #e9e9eb;
  --switch-on: #34c759;
  --segment: #e3e3e8;
  --segment-on: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --secondary: #98989d;
    --tertiary: #636366;
    --separator: rgba(84, 84, 88, .55);
    --field: #1c1c1e;
    --accent: #2997ff;
    --danger: #ff453a;
    --switch-off: #39393d;
    --switch-on: #30d158;
    --segment: #2c2c2e;
    --segment-on: #636366;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1c1c1e; --text: #f5f5f7; --secondary: #98989d; --tertiary: #636366;
  --separator: rgba(84, 84, 88, .55); --field: #1c1c1e; --accent: #2997ff; --danger: #ff453a;
  --switch-off: #39393d; --switch-on: #30d158; --segment: #2c2c2e; --segment-on: #636366;
}

:root { color-scheme: light; }
:root.is-dark { color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 620px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom));
}

/* En-tête */
.brand { display: flex; align-items: center; gap: 12px; margin: 12px 4px 28px; }
.brand-logo { height: 38px; width: auto; flex: none; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -.2px; }
.brand-sub { color: var(--secondary); font-size: 13px; }
h1 { font-size: 32px; line-height: 1.12; letter-spacing: -.6px; font-weight: 700; margin: 0 4px 32px; }

/* Groupes façon Réglages */
.group-title {
  color: var(--secondary); font-size: 13px; text-transform: uppercase; letter-spacing: .2px;
  margin: 0 16px 7px;
}
.group {
  background: var(--card); border-radius: 12px; overflow: hidden;
}
.group-note { color: var(--secondary); font-size: 13px; margin: 7px 16px 0; }
.group-note:empty { display: none; }
section { margin-bottom: 34px; }

.row {
  display: flex; align-items: center; min-height: 46px; padding: 0 16px; gap: 12px;
  position: relative;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px;
  background: var(--separator); transform: scaleY(.6);
}
.row label, .row .label { flex: 0 0 132px; font-size: 16px; }
.row input, .row select {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; padding: 12px 0; text-align: right;
}
.row input::placeholder { color: var(--tertiary); }
.row select { -webkit-appearance: none; appearance: none; cursor: pointer; color: var(--secondary); padding-right: 16px;
  background: no-repeat right center / 8px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13'%3E%3Cpath d='M1 1l5.5 5.5L1 12' fill='none' stroke='%23aeaeb2' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.row select.filled { color: var(--text); }
.row input[type="date"] { min-height: 46px; }
.row input[type="date"]::-webkit-date-and-time-value { text-align: right; }
.row.invalid label, .row.invalid .label { color: var(--danger); }

@media (max-width: 420px) {
  .row label, .row .label { flex-basis: 112px; font-size: 15px; }
}

/* Contrôle segmenté */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; background: var(--segment); border-radius: 9px;
  padding: 2px; margin: 10px 16px; gap: 2px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  text-align: center; font-size: 14px; font-weight: 500; padding: 7px 8px; border-radius: 7px; cursor: pointer;
}
.segmented input:checked + label { background: var(--segment-on); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); }
.invalid .segmented { box-shadow: 0 0 0 1.5px var(--danger); }

/* Interrupteur */
.switch-row { justify-content: space-between; padding-top: 10px; padding-bottom: 10px; }
.switch-row .label { flex: 1; font-size: 15px; }
.switch { position: relative; flex: none; width: 51px; height: 31px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute; inset: 0; border-radius: 31px; background: var(--switch-off); transition: background .2s;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .2s;
}
.switch input:checked + span { background: var(--switch-on); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.invalid .switch span { box-shadow: 0 0 0 1.5px var(--danger); }

/* Contrat */
details { position: relative; }
details + details::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px;
  background: var(--separator); transform: scaleY(.6);
}
summary {
  list-style: none; cursor: pointer; padding: 13px 40px 13px 16px; font-size: 16px; position: relative;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: ""; position: absolute; right: 18px; top: 50%; width: 7px; height: 7px; margin-top: -5px;
  border-right: 2px solid var(--tertiary); border-bottom: 2px solid var(--tertiary); transform: rotate(-45deg);
  transition: transform .2s;
}
details[open] summary::after { transform: rotate(45deg); margin-top: -6px; }
.article { padding: 0 16px 16px; color: var(--secondary); font-size: 15px; line-height: 1.5; }
.article p { margin: 0 0 8px; }
.article ul { margin: 0; padding-left: 18px; }
.article li { margin-bottom: 4px; }
.article strong { color: var(--text); font-weight: 600; }

/* Signature */
.pad-wrap { padding: 12px 16px 14px; }
.pad-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.pad-head span { font-size: 13px; color: var(--secondary); }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: 15px; padding: 4px 0; cursor: pointer; }
canvas.pad {
  display: block; width: 100%; aspect-ratio: 3 / 1; background: #fff; border-radius: 10px;
  border: 1px solid var(--separator); touch-action: none; cursor: crosshair;
}
.invalid canvas.pad { border-color: var(--danger); }

/* Bouton principal */
.primary {
  display: block; width: 100%; border: 0; border-radius: 12px; background: var(--accent); color: #fff;
  font: inherit; font-size: 17px; font-weight: 600; padding: 15px; cursor: pointer;
}
.primary:active { opacity: .7; }
.primary:disabled { opacity: .5; }
.secondary-btn {
  display: block; width: 100%; border: 0; border-radius: 12px; background: var(--segment); color: var(--accent);
  font: inherit; font-size: 17px; font-weight: 600; padding: 15px; cursor: pointer; margin-top: 10px;
}
.error { color: var(--danger); font-size: 14px; text-align: center; margin: 12px 0 0; min-height: 1em; }

/* Feuille de résultat */
dialog {
  border: 0; padding: 0; background: transparent; max-width: 100vw; width: 100%; margin: auto auto 0;
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.sheet {
  background: var(--bg); border-radius: 14px 14px 0 0; max-width: 620px; margin: 0 auto;
  padding: 26px 16px max(22px, env(safe-area-inset-bottom)); text-align: center;
}
@media (min-width: 660px) {
  dialog { margin: auto; }
  .sheet { border-radius: 14px; max-width: 420px; }
}
.sheet h2 { font-size: 22px; margin: 10px 0 6px; letter-spacing: -.3px; }
.sheet p { color: var(--secondary); font-size: 15px; margin: 0 0 22px; }
.check {
  width: 56px; height: 56px; border-radius: 50%; background: var(--switch-on); margin: 0 auto;
  display: grid; place-items: center;
}
.sheet .link { margin-top: 14px; }

.theme-btn {
  margin-left: auto; flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; padding: 0;
  background: var(--card); color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .sun { display: none; }
.is-dark .theme-btn .sun { display: block; }
.is-dark .theme-btn .moon { display: none; }

footer { text-align: center; color: var(--tertiary); font-size: 12px; margin-top: 40px; }
[hidden] { display: none !important; }

/* Champs supplémentaires */
.row textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; padding: 12px 0; resize: vertical; min-height: 76px; line-height: 1.4;
}
.row textarea::placeholder { color: var(--tertiary); }
.row.area { align-items: flex-start; }
.row.area label { padding-top: 12px; }
.row .value { flex: 1; text-align: right; color: var(--secondary); font-size: 16px; padding: 12px 0; }

/* Oui / Non dans une ligne */
.row.choice { padding-top: 8px; padding-bottom: 8px; }
.row.choice .label { flex: 1; font-size: 15px; }
.segmented.inline { margin: 0; flex: none; width: 128px; }
.segmented.inline label { padding: 5px 6px; font-size: 13px; }
.segmented.triple { grid-template-columns: 1fr 1fr 1fr; }
.invalid.row .segmented { box-shadow: 0 0 0 1.5px var(--danger); }

/* Liste de documents */
.doc-link {
  display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 40px 10px 16px;
  color: var(--text); text-decoration: none; position: relative;
}
.doc-link + .doc-link::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px;
  background: var(--separator); transform: scaleY(.6);
}
.doc-link::after {
  content: ""; position: absolute; right: 18px; top: 50%; width: 7px; height: 7px; margin-top: -4px;
  border-right: 2px solid var(--tertiary); border-bottom: 2px solid var(--tertiary); transform: rotate(-45deg);
}
.doc-link small { display: block; color: var(--secondary); font-size: 13px; margin-top: 2px; }
.doc-link:active { background: var(--segment); }

.group.invalid { box-shadow: 0 0 0 1.5px var(--danger); }

/* Photo d'identité */
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photo-row { justify-content: space-between; padding-top: 8px; padding-bottom: 8px; }
.photo-row .label { flex: 1; }
.photo-row img { width: 44px; height: 56px; object-fit: cover; border-radius: 6px; }
.photo-row .link { flex: none; }
.row.invalid .link { color: var(--danger); }
