/* ARA Signature : feuille de style unique, écrite à la main, sans dépendance externe. */

:root {
    --ink: #1c2733;
    --muted: #5d6b79;
    --line: #d9e0e7;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --brand: #1f4e79;
    --brand-dark: #163a5b;
    --ok: #1e7a46;
    --ok-bg: #e6f4ec;
    --wait: #8a5a00;
    --wait-bg: #fdf3dc;
    --bad: #b42318;
    --bad-bg: #fdecea;
    --info-bg: #eaf1f8;
    --radius: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
p { margin: 0 0 .75rem; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.mono { font-family: var(--mono); letter-spacing: .02em; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .9rem; }
.hidden { display: none; }

/* --- Barre du haut (back office et administration) -------------------------------------------- */

.topbar { background: var(--brand); color: #fff; }
.topbar-inner {
    max-width: 1200px; margin: 0 auto; padding: .6rem 1rem;
    display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.brand:hover { color: #fff; }
.menu { display: flex; flex-wrap: wrap; gap: .25rem 1rem; flex: 1; }
.menu a { color: #fff; text-decoration: none; padding: .2rem 0; border-bottom: 2px solid transparent; }
.menu a:hover { border-bottom-color: #fff; color: #fff; }
.menu-sep { border-left: 1px solid rgba(255, 255, 255, .45); margin: .2rem 0; }
.who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; flex-wrap: wrap; }
.who .link, .who a { color: #fff; }

.container { max-width: 1200px; width: 100%; margin: 0 auto; padding: 1.25rem 1rem 2rem; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* --- Blocs ---------------------------------------------------------------------------------------- */

.panel, .card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1.25rem; margin-bottom: 1.25rem;
}
.card { max-width: 640px; margin: 2rem auto; }
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.centered { text-align: center; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }
.columns > .panel { margin-bottom: 0; }
.columns + .panel, .columns + section { margin-top: 1.25rem; }

.notice {
    border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem;
    background: var(--info-bg); border: 1px solid #c7d8ea;
}
.notice p:last-child { margin-bottom: 0; }
.notice.success { background: var(--ok-bg); border-color: #b9e0c9; color: #12502d; }
.notice.error { background: var(--bad-bg); border-color: #f5c2bd; color: #7a1a12; }
.notice.warning { background: var(--wait-bg); border-color: #f1d9a3; color: #5e3d00; }

.badge {
    display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
    background: #eef1f4; color: var(--muted); vertical-align: middle; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.wait { background: var(--wait-bg); color: var(--wait); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

dl.facts { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stat-value { display: block; font-size: 1.8rem; font-weight: 700; color: var(--brand); }
.stat-label { color: var(--muted); font-size: .9rem; }

.timeline { padding-left: 1.25rem; margin: 0 0 1rem; }
.timeline li { margin-bottom: .3rem; }
.proof-text { white-space: pre-wrap; font-family: var(--mono); font-size: .85rem; background: var(--bg); padding: 1rem; border-radius: var(--radius); overflow-x: auto; }
details summary { cursor: pointer; color: var(--brand); }

/* --- Formulaires ---------------------------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: .35rem; max-width: 560px; min-width: 0; }
.wide-form { max-width: 760px; }
.form label { font-weight: 600; margin-top: .5rem; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0 0 1rem; display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.form legend { font-weight: 700; padding: 0 .35rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="search"],
input[type="url"], input[type="number"], input[type="date"], input[type="month"], input:not([type]), select, textarea {
    font: inherit; color: inherit; width: 100%;
    padding: .5rem .65rem; border: 1px solid #b8c3ce; border-radius: 6px; background: #fff;
    min-height: 40px;
}
textarea { min-height: 8rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
    outline: 3px solid #9cc3e6; outline-offset: 1px; border-color: var(--brand);
}
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
input[type="file"] { font: inherit; padding: .4rem 0; }

label.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; margin-top: .35rem; cursor: pointer; }
label.check input { width: 1.25rem; height: 1.25rem; margin-top: .15rem; flex: none; }
.field-error { color: var(--bad); font-size: .9rem; margin: .1rem 0 0; }

.color-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.color-row input[type="color"] { width: 4rem; height: 40px; padding: 2px; border: 1px solid #b8c3ce; border-radius: 6px; background: #fff; cursor: pointer; }
.color-row label.check { margin-top: 0; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > div { flex: 1 1 220px; display: flex; flex-direction: column; gap: .35rem; }
.row > .short { flex: 0 1 120px; }

button, .button {
    font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .5rem 1rem; min-height: 40px; border-radius: 6px; border: 1px solid #b8c3ce;
    background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; text-align: center;
}
button:hover, .button:hover { background: #eef2f6; color: var(--ink); }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover, .button.primary:hover { background: var(--brand-dark); color: #fff; }
button.danger, .button.danger { border-color: #e8a49d; color: var(--bad); }
button.danger:hover, .button.danger:hover { background: var(--bad-bg); }
button.small, .button.small { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: none; padding: 0; min-height: 0; color: var(--brand); text-decoration: underline; cursor: pointer; }
button.link:hover { background: none; }
.wide { width: 100%; }

form.inline { display: inline; margin: 0; }
/* Un panneau qui suit un formulaire (paramètres, puis mail d'essai) ne colle pas à son bouton. */
form + .panel { margin-top: 1.5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1rem; }
.actions.stacked { flex-direction: column; align-items: stretch; }
.actions.stacked form.inline, .actions.stacked form.inline button { display: block; width: 100%; }
.row-actions { white-space: nowrap; }
.row-actions form.inline + form.inline { margin-left: .35rem; }

.search { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search input { flex: 1 1 240px; width: auto; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .75rem 1rem; margin-bottom: 1rem; align-items: start; }
.filters > div { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.filters select, .filters input { width: 100%; box-sizing: border-box; }
.filters label { font-weight: 600; font-size: .9rem; }
.filter-actions { grid-column: 1 / -1; flex-direction: row !important; flex-wrap: wrap; gap: .5rem !important; }

/* --- Listes --------------------------------------------------------------------------------------- */

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { background: #f8fafb; font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tfoot th { background: #f8fafb; border-top: 2px solid var(--line); border-bottom: none; }
.table.numbers td:nth-last-child(-n+4), .table.numbers th:nth-last-child(-n+4) { text-align: right; }

.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* --- Pages du signataire : ordinateur d'abord (signataires professionnels), une colonne sous 800 px ------- */

.signer-body { background: #f1f4f7; }
.signer-header {
    background: #fff; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem;
}
.signer-logo { max-height: 48px; max-width: 160px; object-fit: contain; }
.signer-org { font-weight: 700; font-size: 1.05rem; }
.signer { max-width: 1200px; width: 100%; margin: 0 auto; padding: 1rem; flex: 1; }

.signing-title { margin-bottom: .75rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.narrow-signing { max-width: 560px; margin: 0 auto; }

.steps { display: flex; gap: .5rem; padding: 0; margin: 0 0 1rem; list-style: none; counter-reset: step; font-size: .85rem; }
.steps li { flex: 1; min-width: 0; counter-increment: step; color: var(--muted); border-top: 4px solid var(--line); padding-top: .35rem; }
.steps li::before { content: counter(step) ". "; font-weight: 700; }
.steps li.current { color: var(--ink); border-top-color: var(--brand); font-weight: 600; }
.steps li.done { border-top-color: var(--ok); }

.signing-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.signing-grid .panel { margin-bottom: 0; }

.pdf-frame { display: none; width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* Page de signature sans PDF à lire (mandat) : formulaire large à gauche, récapitulatif à droite. */
.signing-intro { margin-bottom: 1rem; }
.signing-intro h1 { font-size: 1.5rem; font-weight: 600; max-width: 52rem; }
.signing.form-only { max-width: 1180px; margin: 0 auto; }
.signing-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }
.signing-layout .panel { margin-bottom: 0; }
.recap { position: sticky; top: 1rem; font-size: .95rem; }
.recap h2 { font-size: 1.05rem; }
dl.facts.stacked { grid-template-columns: 1fr; gap: 0; }
dl.facts.stacked dd { margin-bottom: .6rem; }
details.references { margin-top: .75rem; border-top: 1px solid var(--line); padding-top: .6rem; }
details.references summary { font-size: .9rem; }
details.references dl { margin-top: .6rem; }

.signing .form { max-width: none; }
.signing-form fieldset { padding: 1rem 1.25rem 1.25rem; }
.signer-name { font-weight: 600; margin-bottom: .25rem; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { margin-top: .25rem; }
.form-actions { display: flex; justify-content: flex-end; margin-top: .5rem; }
button.submit { min-width: 17rem; }

/* Fichier à joindre : le champ lui-même est la zone de dépôt (glisser-déposer natif du navigateur, sans script). */
input[type="file"].dropzone {
    display: block; width: 100%; padding: 1.4rem 1rem; cursor: pointer;
    border: 2px dashed #9fb3c8; border-radius: var(--radius); background: #f7fafc; color: var(--muted);
}
input[type="file"].dropzone:hover, input[type="file"].dropzone:focus { border-color: var(--brand); background: #eef4fa; }
input[type="file"].dropzone[aria-invalid="true"] { border-color: var(--bad); }
input[type="file"].dropzone::file-selector-button {
    font: inherit; margin-right: 1rem; padding: .45rem .9rem; cursor: pointer;
    border: 1px solid #b8c3ce; border-radius: 6px; background: #fff; color: var(--ink);
}
.file-current { margin: .25rem 0 0; padding: .5rem .75rem; border-radius: 6px; background: var(--ok-bg); color: #12502d; }

.code-input { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; font-family: var(--mono); }
.secondary-actions { display: flex; flex-direction: column; gap: .75rem; margin-top: 1.25rem; align-items: flex-start; }
.big-check { font-size: 3rem; color: var(--ok); margin: 0; line-height: 1; }

@media (min-width: 900px) {
    .signing-grid { grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); align-items: start; }
    .pdf-frame { display: block; }
    h1 { font-size: 1.8rem; }
}

@media (max-width: 800px) {
    /* Zone de dépôt : le bouton sur sa ligne, le nom du fichier (ou « Aucun fichier… ») en entier dessous. */
    input[type="file"].dropzone { padding: 1rem; }
    input[type="file"].dropzone::file-selector-button { display: block; margin: 0 0 .6rem; }

    /* Une colonne : le récapitulatif passe sous le formulaire ; commandes à la taille du doigt. */
    .signing-layout, .field-grid { grid-template-columns: minmax(0, 1fr); }
    .recap { position: static; }
    .form-actions { justify-content: stretch; }
    button.submit { width: 100%; min-width: 0; }
    input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="search"],
    input[type="url"], input[type="number"], input[type="date"], input[type="month"], select, button, .button { min-height: 44px; }
    .signing-intro h1 { font-size: 1.3rem; }
}

@media (max-width: 600px) {
    .container, .signer { padding: .75rem; }
    .panel, .card { padding: 1rem; }
    .card { margin: 1rem auto; }
    dl.facts { grid-template-columns: 1fr; gap: 0; }
    dl.facts dd { margin-bottom: .5rem; }
    .steps { font-size: .75rem; }
    .actions > * { flex: 1 1 100%; }
}

/* Page publique du cachet de scellement. */
.narrow-text { max-width: 820px; margin-left: auto; margin-right: auto; }
.fingerprint { word-break: break-all; }
.steps-list { padding-left: 1.25rem; }
.steps-list li { margin-bottom: .5rem; }

/* Double authentification : QR code, clé, codes de secours. */
.qr { display: block; width: 220px; height: 220px; margin: .75rem 0; border: 1px solid var(--line); background: #fff; }
.key { display: inline-block; margin: .35rem 0; padding: .35rem .6rem; background: #f3f5f8; border-radius: var(--radius); word-break: break-all; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem 1.5rem; list-style: none; padding: 0; margin: .75rem 0 0; font-size: 1.05rem; }
