:root {
  --navy: #14213d;
  --navy-2: #1d2d52;
  --gold: #c9a227;
  --gold-ink: #241a00;
  --bg: #f3f1ec;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #6b6f7d;
  --line: #e4e0d6;
  --ok: #217a4b;
  --warn: #9a6a00;
  --err: #b3261e;
  --paper: #ffffff;
  --paper-ink: #16181d;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1422;
    --card: #171e31;
    --ink: #e8e9ee;
    --muted: #9aa0b4;
    --line: #29324c;
    --ok: #4cc38a;
    --warn: #e0b13a;
    --err: #f2867e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: inherit; }
h1, h2 { font-family: var(--serif); font-weight: 700; letter-spacing: .01em; }
h1 { font-size: 1.9rem; margin: 0 0 .2rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .88rem; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }
.alert { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); padding: .7rem 1rem; border-radius: 10px; }

/* ---- barre du haut ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem max(16px, calc((100vw - 1320px) / 2)); background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; font-family: var(--serif); font-size: 1.45rem; font-weight: 700; }
.brand img { width: 34px; height: 34px; }
.top-actions { display: flex; align-items: center; gap: .7rem; }
.top-actions form { margin: 0; }
.user { display: flex; align-items: center; gap: .45rem; font-size: .9rem; opacity: .9; }
.user img { width: 28px; height: 28px; border-radius: 50%; }
@media (max-width: 640px) { .user span { display: none; } }

/* ---- boutons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: 600 .92rem var(--sans); padding: .55rem 1rem; border-radius: 9px; border: 1px solid transparent; cursor: pointer; text-decoration: none; background: none; color: inherit; white-space: nowrap; }
.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-gold { background: var(--gold); color: var(--gold-ink); }
.btn-gold:hover { filter: brightness(1.06); }
.btn-ghost { border-color: var(--line); }
.topbar .btn-ghost { border-color: rgb(255 255 255 / 30%); color: #fff; }
.btn-ghost:hover { border-color: var(--gold); }
.btn-danger { border-color: var(--line); color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 12%, transparent); }
.btn-discord { background: #5865f2; color: #fff; width: 100%; padding: .8rem; }

/* ---- liste ---- */
.page { max-width: 1320px; margin: 0 auto; padding: 1.6rem 16px 4rem; }
.page-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.2rem; }
.new-types { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .6rem; flex: 1; max-width: 900px; }
@media (max-width: 900px) { .new-types { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) { .new-types { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.type-card { display: flex; flex-direction: column; gap: .15rem; padding: .7rem .85rem; border-radius: 12px; background: var(--card); border: 1px solid var(--line); text-decoration: none; }
.type-card strong { font-family: var(--serif); font-size: 1.25rem; color: var(--gold); }
.type-card span { font-size: .78rem; color: var(--muted); line-height: 1.3; }
.type-card:hover { border-color: var(--gold); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
input[type=search] { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; margin-bottom: .8rem; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.list td { padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tbody tr[data-id] { cursor: pointer; }
.list tbody tr[data-id]:hover { background: color-mix(in srgb, var(--gold) 8%, transparent); }
.badge { font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 99px; background: color-mix(in srgb, var(--navy) 12%, transparent); }
@media (prefers-color-scheme: dark) { .badge { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); } }
.statut { font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; }
.statut-brouillon { background: color-mix(in srgb, var(--muted) 18%, transparent); }
.statut-finalise { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.statut-signe { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }

/* ---- éditeur ---- */
.editor { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 1.5rem; max-width: 1520px; margin: 0 auto; padding: 1.4rem 16px 4rem; align-items: start; }
@media (max-width: 1100px) { .editor { grid-template-columns: minmax(0, 1fr); } }
.pane-preview { position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow: auto; border-radius: 12px; padding-bottom: 12px; }
@media (max-width: 1100px) { .pane-preview { position: static; max-height: none; } }
.preview-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .4rem; }
.contract-form fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem 1rem; margin: 0 0 1rem; background: var(--card); }
.contract-form legend { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; padding: 0 .4rem; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem .8rem; }
.grid + .grid { margin-top: .8rem; padding-top: .8rem; border-top: 1px dashed var(--line); }
@media (max-width: 520px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.grid > span { display: contents; }
.grid > span[hidden] { display: none; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
label.wide, .grid > span.wide > label { grid-column: 1 / -1; }
label.check { flex-direction: row; align-items: center; gap: .45rem; color: var(--ink); font-weight: 500; font-size: .9rem; }
input, select, textarea { font: 400 .95rem var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; width: 100%; min-width: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: transparent; }
label.check input { width: auto; accent-color: var(--gold); }
.type-switch { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .4rem; }
@media (max-width: 520px) { .type-switch { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.annexe-row { display: flex; flex-direction: column; gap: .5rem; padding: .7rem 0; border-top: 1px dashed var(--line); }
.annexe-row-head { display: flex; gap: .6rem; align-items: flex-end; }
.annexe-row-head label { flex: 1; }
.type-switch label { position: relative; }
.type-switch input { position: absolute; opacity: 0; }
.type-switch span { display: block; text-align: center; padding: .5rem; border-radius: 8px; border: 1px solid var(--line); color: var(--ink); font-weight: 600; cursor: pointer; }
.type-switch input:checked + span { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.type-switch input:focus-visible + span { outline: 2px solid var(--gold); }
#checks { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.check-item { font-size: .86rem; padding: .55rem .75rem; border-radius: 9px; border-left: 4px solid; }
.check-err { border-color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); }
.check-warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.check-ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.form-actions { display: flex; gap: .6rem; }

/* ---- lecture ---- */
.reader { max-width: 900px; margin: 0 auto; padding: 1.2rem 16px 4rem; }
.reader-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.spacer { flex: 1; }
.meta { text-align: center; margin-top: 1rem; }

/* ---- profil et administration ---- */
.page.narrow { max-width: 760px; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
a.user { text-decoration: none; border-radius: 99px; padding: .15rem .55rem .15rem .15rem; }
a.user:hover { background: rgb(255 255 255 / 10%); }
.add-user { margin-bottom: 1rem; }
.add-user h2 { margin: 0 0 .7rem; font-size: 1.3rem; }
.grid-3 { grid-template-columns: 1.2fr 1.2fr .8fr; }
@media (max-width: 640px) { .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.users td { vertical-align: middle; }
.who { display: flex; align-items: center; gap: .6rem; }
.who img, .who-ph { width: 32px; height: 32px; border-radius: 50%; flex: none; background: var(--line); }
.who strong, .who span { display: block; }
input.inline { padding: .3rem .45rem; min-width: 150px; }
.users select { width: auto; padding: .3rem .45rem; }

/* ---- liens de signature (lecture) ---- */
.links { margin-bottom: 1rem; }
.links-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.links-head h2 { margin: 0; font-size: 1.3rem; }
.link-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: .6rem; align-items: center; padding: .55rem 0; border-top: 1px solid var(--line); margin-top: .55rem; }
@media (max-width: 640px) { .link-row { grid-template-columns: minmax(0, 1fr) auto; } .link-row input { grid-column: 1 / -1; grid-row: 2; } }
.link-who strong { display: block; font-size: .9rem; }
.link-row input { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; }
.link-ok { color: var(--ok); font-size: .82rem; font-weight: 600; }
.statut-sig { font-size: .72rem; color: var(--muted); margin-left: .3rem; }

/* ---- page publique de signature ---- */
.topbar-note { font-size: .82rem; opacity: .8; }
.sign-page { max-width: 900px; margin: 0 auto; padding: 1.4rem 16px 4rem; }
.sign-intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.sign-intro p { margin: .3rem 0 0; max-width: 620px; }
.sign-kicker { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.sign-card { margin-top: 1.4rem; display: flex; flex-direction: column; gap: .8rem; border-top: 4px solid var(--gold); }
.sign-card h2 { margin: 0; font-size: 1.5rem; }
.pad-label { display: flex; justify-content: space-between; align-items: center; font-size: .82rem; font-weight: 600; color: var(--muted); }
.pad { width: 100%; height: 190px; background: #fffdf4; border: 1.5px dashed #b9a463; border-radius: 10px; touch-action: none; cursor: crosshair; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); padding: .7rem 1.1rem; border-radius: 10px; color: #fff; font-weight: 600; box-shadow: 0 8px 30px rgb(0 0 0 / 25%); z-index: 10; max-width: calc(100vw - 32px); }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--err); }

/* ---- connexion ---- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 30% 20%, var(--navy-2), var(--navy) 70%); }
.login-card { background: var(--card); border-radius: 18px; padding: 2.4rem 2rem; width: min(400px, 100%); text-align: center; box-shadow: 0 25px 70px rgb(0 0 0 / 35%); }
.login-logo { width: 74px; height: 74px; }
.login-card h1 { font-size: 2.2rem; margin: .6rem 0 .2rem; }
.login-card p { margin: 0 0 1.4rem; }
.login-card .login-alt { margin: 1.1rem 0 0; font-size: .9rem; }
.login-alt a { color: var(--gold); text-decoration: none; }
.login-alt a:hover { text-decoration: underline; }
.gen-intro { margin: .2rem 0 1rem; font-size: .92rem; }

/* ---- impression : seul le contrat (styles A4 dans contract.css) ---- */
@media print {
  .no-print, .topbar, .reader-bar, .meta, .pane-form, .preview-label, .toast { display: none !important; }
  .reader, .editor, .sign-page, .pane-preview { display: block; max-width: none; padding: 0; margin: 0; }
  .pane-preview { position: static; max-height: none; overflow: visible; }
}
