:root {
  --navy: #000fa0;
  --blue: #0070c0;
  --sky: #28a3dd;
  --ink: #1b1f3b;
  --muted: #5b6080;
  --line: #d6dbea;
  --bg: #f4f6fb;
  --card: #fff;
  --err: #c0262d;
  --ok: #137a3c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
@font-face { font-family: "Allura"; src: url("/fonts/allura.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Caveat"; src: url("/fonts/caveat-500.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Dancing Script"; src: url("/fonts/dancing-script-500.ttf") format("truetype"); font-weight: 500; font-display: swap; }
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--blue); }

.top { background: var(--card); border-bottom: 4px solid var(--sky); padding: 14px 16px; display: flex; justify-content: center; }
.top img { height: 44px; width: auto; }

main { max-width: 820px; margin: 0 auto; padding: 32px 16px 48px; }
h1 { color: var(--navy); font-size: clamp(1.4rem, 3.5vw, 1.9rem); line-height: 1.2; margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 24px; }
.req { color: var(--err); }

.keys { list-style: none; padding: 0; margin: 0 0 28px; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.keys li { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--sky); border-radius: 8px; padding: 10px 12px; display: grid; gap: 2px; }
.keys strong { color: var(--navy); }
.keys span { color: var(--muted); font-size: .85rem; }

fieldset { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 0 0 20px; min-width: 0; }
legend { font-weight: 700; color: var(--navy); font-size: 1.1rem; padding: 0 6px; display: flex; align-items: center; gap: 10px; }
.step { background: var(--blue); color: #fff; width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .9rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.field { margin-bottom: 16px; }
.field > label, .label { display: block; font-weight: 600; margin-bottom: 6px; }
input:not([type=radio]):not([type=checkbox]), textarea, select {
  width: 100%; font: inherit; color: inherit; padding: 10px 12px; border: 1px solid #b9c0d6; border-radius: 8px; background: #fff;
}
input[readonly] { background: var(--bg); color: var(--muted); }
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, .articles:focus-visible, canvas:focus-visible, .btn:focus-visible, .choice:focus-within, .check:focus-within {
  outline: 3px solid color-mix(in srgb, var(--sky) 60%, transparent); outline-offset: 2px;
}
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.choice { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--blue); background: #eef5fc; }
input[type=radio], input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--blue); margin: 0; flex: none; }

.articles { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 18px 12px; background: #fafbfe; color: var(--navy); font-size: .92rem; margin-bottom: 16px; }
.articles h3 { font-size: .95rem; margin: 18px 0 6px; }
.articles h4 { font-size: .9rem; margin: 12px 0 4px 16px; }
.articles p { margin: 0 0 8px; text-align: justify; }
.articles ul { margin: 0 0 8px; }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; cursor: pointer; flex-wrap: wrap; }
.check input { margin-top: 3px; }
.check > span { flex: 1; min-width: 0; }
.check .err { flex-basis: 100%; }

.pad { position: relative; border: 2px dashed #b9c0d6; border-radius: 10px; background: #fff; }
.pad canvas { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }
.pad-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #a3a9c2; pointer-events: none; }
.pad.inked .pad-hint { display: none; }
.pad .link { position: absolute; top: 6px; right: 8px; }
.signature-modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.typed-signature { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfe; }
.typed-signature > .hint { margin: 0 0 10px; }
.typed-signature-preview { display: block; width: 100%; height: 150px; margin-bottom: 16px; border: 0; border-radius: 8px; background: linear-gradient(110deg, #e7f2ff, #f1f7ff); }
.signature-styles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.signature-style { position: relative; display: grid; grid-template-columns: 16px 1fr; align-items: center; gap: 4px 8px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--navy); cursor: pointer; text-align: left; }
.signature-style:has(input:checked) { border-color: #456bff; box-shadow: inset 0 0 0 1px #456bff; background: #edf5ff; color: #000fa0; }
.signature-style:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 3px; }
.signature-style input { position: static; width: 14px; height: 14px; margin: 0; accent-color: #244cff; }
.signature-style span { font-family: inherit; font-size: .78rem; font-weight: 600; line-height: 1.3; }
.signature-style canvas { display: block; grid-column: 1 / -1; width: 100%; min-width: 0; height: 64px; }
.signature-caption { margin: 12px 0 6px; color: var(--navy); font-size: .8rem; font-weight: 600; }
.link { background: none; border: 0; color: var(--blue); font: inherit; text-decoration: underline; cursor: pointer; padding: 4px; }
.legal { color: var(--muted); font-size: .8rem; margin: 4px 0 0; }

.invalid input:not([type=radio]):not([type=checkbox]), .invalid textarea, .invalid select, .invalid .pad, .invalid .choice { border-color: var(--err); }
.check.invalid { background: #fdf1f1; }
.err { color: var(--err); font-size: .88rem; font-weight: 600; margin: 6px 0 0; }
.summary { border: 2px solid var(--err); background: #fdf1f1; border-radius: 10px; padding: 12px 16px; margin-bottom: 20px; color: var(--err); }
.summary ul { margin: 6px 0 0; padding-left: 20px; }
.summary a { color: var(--err); }

.btn { display: inline-block; font: inherit; font-weight: 700; border-radius: 10px; padding: 12px 22px; border: 0; cursor: pointer; text-decoration: none; background: var(--blue); color: #fff; }
.btn.primary { background: var(--navy); width: 100%; font-size: 1.05rem; padding: 15px 22px; text-align: center; }
.done .btn.primary { width: auto; }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .6; cursor: progress; }

.done { background: var(--card); border: 1px solid var(--line); border-top: 5px solid var(--ok); border-radius: 12px; padding: 24px; }
.done h2 { color: var(--ok); margin-top: 0; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.privacy-notice { margin: 4px 0 18px; padding: 14px 16px; border: 1px solid var(--line); border-left: 4px solid var(--sky); border-radius: 8px; background: var(--card); color: var(--muted); font-size: .82rem; }
.privacy-notice h2 { margin: 0 0 7px; color: var(--navy); font-size: .95rem; }
.privacy-notice p { margin: 5px 0; }
.turnstile-box { min-height: 34px; margin: 4px 0 14px; }
.turnstile-box .verify-status { text-align: center; }
.turnstile-box.invalid { padding: 10px; border: 1px solid var(--err); border-radius: 8px; background: #fdf1f1; }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 16px 32px; }

/* Facturation & contacts */
.hint.intro { margin: -4px 0 16px; }
.sub { color: var(--navy); font-size: 1rem; margin: 24px 0 4px; padding-top: 16px; border-top: 1px solid var(--line); }
.contact { border: 1px solid var(--line); border-left: 4px solid var(--sky); border-radius: 8px; padding: 12px 14px 0; margin-bottom: 12px; background: #fafbfe; }
.contact-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--navy); }
.btn.secondary { background: #fff; color: var(--blue); border: 1px solid var(--blue); padding: 9px 16px; }
.btn.danger { background: var(--err); }
.email-verification { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.email-verification label { display: block; margin: 10px 0 6px; font-weight: 600; }
.code-row { display: flex; gap: 8px; }
.code-row input { max-width: 160px; font-size: 1.15rem; font-weight: 700; letter-spacing: .18em; text-align: center; }
.verify-status { margin: 8px 0 0; color: var(--muted); font-size: .85rem; }
.verify-status.ok { color: var(--ok); font-weight: 700; }

/* Admin */
.admin main { max-width: 1500px; }
.admin-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.preview-banner { margin-bottom: 20px; padding: 11px 14px; border: 1px solid #e0a52b; border-radius: 9px; background: #fff8e7; color: #704900; }
.admin-heading .lead { margin-bottom: 0; }
.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--blue); border-radius: 10px; padding: 14px 16px; }
.stat span { display: block; color: var(--muted); font-size: .84rem; }
.stat strong { display: block; color: var(--navy); font-size: 1.65rem; line-height: 1.2; }
.stat.warning { border-top-color: #d58a00; }
.stat.success { border-top-color: var(--ok); }
.stat.danger { border-top-color: var(--err); }
button.stat { text-align: left; font: inherit; cursor: pointer; width: 100%; }
button.stat:hover, button.stat:focus-visible { background: #fdf1f1; }
.admin td.nw { white-space: nowrap; }
.count { background: var(--sky); color: #fff; border-radius: 999px; padding: 0 10px; font-size: 1rem; vertical-align: middle; }
.scroll { overflow: auto; max-height: calc(100vh - 315px); min-height: 280px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; background: var(--blue); color: #fff; white-space: nowrap; }
tr:nth-child(even) td { background: #fafbfe; }
.admin td > small { display: block; margin-top: 3px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px; }
.toolbar input[type=search] { flex: 1 1 320px; width: auto; }
.toolbar select { width: auto; flex: 0 1 220px; }
.reset-filters { margin-left: auto; }
th .sort { all: unset; cursor: pointer; display: inline-flex; gap: 4px; }
th .sort::after { content: "↕"; opacity: .5; }
th[aria-sort=ascending] .sort::after { content: "▲"; opacity: 1; }
th[aria-sort=descending] .sort::after { content: "▼"; opacity: 1; }
th .sort:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
tr[hidden] { display: none; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: .8rem; font-weight: 700; }
.badge.todo { background: #fff3d6; color: #8a5a00; }
.badge.ok { background: #e3f5ea; color: var(--ok); }
.badge.revoked { background: #f2f2f4; color: var(--muted); }
.badge.correction { background: #e8f1fb; color: #174f86; }
.badge.refused { background: #fbe8e8; color: var(--err); }
.admin small, .admin a.small { font-size: .78rem; color: var(--muted); }
dialog { border: 0; border-radius: 12px; padding: 24px; width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 40, .3); }
dialog::backdrop { background: rgba(10, 15, 60, .45); }
dialog h2 { color: var(--navy); margin-top: 0; }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.user-scroll { max-height: 310px; min-height: 120px; margin-bottom: 20px; }
.password-row { display: flex; gap: 8px; align-items: center; }
.password-row input { flex: 1; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: min(460px, 100%); margin: 0; padding: 32px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); box-shadow: 0 18px 50px rgba(0, 15, 80, .12); }
.login-card > img { display: block; margin-bottom: 26px; }
.login-card h1 { font-size: clamp(1.65rem, 5vw, 2.2rem); }
.login-card .btn.primary, .login-card form > .btn { width: 100%; }
.login-help { display: block; margin: 18px auto 0; }
.signer-preview { background: var(--bg); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.signer-preview img { max-height: 70px; max-width: 100%; display: block; }
.signer-preview p { margin: 0 0 6px; }
.opt { font-weight: 400; color: var(--muted); }
.stamp-preview { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.stamp-preview img { max-height: 90px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

.admin tbody tr:hover td { background: #eef5fc; }
.row-title { display: block; border: 0; padding: 0; background: none; color: var(--navy); font: inherit; font-weight: 750; text-align: left; text-decoration: underline; text-decoration-color: transparent; cursor: pointer; }
.row-title:hover, .row-title:focus-visible { color: var(--blue); text-decoration-color: currentColor; }
.status-note { color: var(--muted); white-space: nowrap; }
.status-note.notification-failed { color: var(--err); font-weight: 700; }
.decision-summary { padding: 12px 14px; border-radius: 8px; background: var(--bg); }
.row-actions { min-width: 210px; }
.row-actions .btn, .row-actions .original-link { margin: 0 6px 6px 0; }
.btn.compact { padding: 7px 10px; border-radius: 7px; font-size: .82rem; }
dialog.wide { width: min(900px, calc(100vw - 32px)); }
.detail-groups { display: grid; gap: 16px; }
.detail-section { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.detail-section h3 { margin: 0; padding: 9px 14px; background: var(--bg); color: var(--navy); font-size: .95rem; }
.detail { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 6px 16px; margin: 0; }
.detail-section .detail { padding: 12px 14px; }
.detail dt { font-weight: 700; color: var(--navy); }
.detail dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
#detailPdf { display: flex; gap: 10px; flex-wrap: wrap; }
.sig-imgs { display: flex; gap: 16px; align-items: center; }
.check.confirm { border: 1px solid var(--line); background: var(--bg); margin-top: 14px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(430px, calc(100vw - 40px)); padding: 13px 16px; border-radius: 9px; background: var(--ok); color: #fff; font-weight: 700; box-shadow: 0 10px 35px rgba(0, 0, 40, .25); }
.toast.error { background: var(--err); }
@media (max-width: 800px) {
  .admin-heading { align-items: stretch; flex-direction: column; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .scroll { max-height: none; overflow: visible; border: 0; background: transparent; }
  .admin table, .admin tbody { display: block; }
  .admin thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .admin tbody tr[data-s] { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
  .admin tbody tr[data-s] td { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
  .admin tbody tr[data-s] td::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
  .admin tbody tr[data-s] td:first-child, .admin tbody tr[data-s] td:last-child { grid-column: 1 / -1; }
  .admin tbody tr[data-s] td:last-child { border-bottom: 0; }
  .row-actions { min-width: 0; }
  #none { display: block; }
  #none[hidden] { display: none; }
  #none td { display: block; }
}
@media (max-width: 600px) {
  .detail { grid-template-columns: 1fr; }
  .detail dd { margin-bottom: 8px; }
  .stats { grid-template-columns: 1fr; }
  .toolbar > * { width: 100% !important; flex-basis: 100% !important; }
  .reset-filters { margin-left: 0; text-align: left; }
  dialog .actions { flex-direction: column-reverse; }
  dialog .actions .btn { width: 100%; text-align: center; }
  .signature-modes, .signature-styles { grid-template-columns: 1fr; }
}

.notice { border: 2px solid #174f86; background: #e8f1fb; border-radius: 10px; padding: 12px 16px; margin-bottom: 20px; color: #174f86; }
.notice.error { border-color: var(--err); background: #fdf1f1; color: var(--err); }

/* Contre-signature en masse */
th.sel, td.sel { width: 36px; text-align: center; }
.bulk-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 0 0 10px; padding: 10px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.bulk-bar[hidden] { display: none; }
.bulk-list { max-height: 240px; overflow: auto; margin: 0 0 12px; padding-left: 18px; }
.bulk-list li.bulk-error { color: #b42318; }

th.sel, td.sel { padding-left: 12px; padding-right: 4px; }
td.sel .sel-box { width: 20px; height: 20px; cursor: pointer; }
tr.selected td { background: #eef3ff; }

/* L'attribut hidden doit toujours masquer (sinon .btn { display: … } le contourne) */
[hidden] { display: none !important; }
