:root {
  --accent: #7b1e2b;
  --accent-dark: #5e1520;
  --accent-soft: #f6ecee;
  --bg: #f4f1ee;
  --surface: #ffffff;
  --text: #24201f;
  --muted: #6d6563;
  --border: #e3ddd9;
  --ok: #1f7a4d;
  --ok-soft: #e7f4ed;
  --warn: #9a5b00;
  --warn-soft: #fdf3e2;
  --err: #b42318;
  --err-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(36, 32, 31, .06), 0 4px 16px rgba(36, 32, 31, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.topbar {
  background: var(--accent);
  color: #fff;
}
.topbar .inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { font-weight: 700; letter-spacing: .6px; font-size: 17px; }
.brand small { display: block; font-weight: 400; letter-spacing: 0; opacity: .8; font-size: 12px; }
.topbar .secure { font-size: 13px; opacity: .9; display: flex; align-items: center; gap: 6px; }

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

h1 { font-size: 22px; line-height: 1.3; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.message {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  white-space: pre-line;
}

.btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.secondary:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn.ghost:hover { color: var(--err); background: transparent; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.block { width: 100%; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Visionneuse PDF ---------- */
.viewer-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.viewer {
  background: #e9e4e0;
  border-radius: 8px;
  padding: 12px;
  max-height: 72vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.viewer .page {
  background: #fff;
  margin: 0 auto 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
  max-width: 100%;
}
.viewer .page:last-child { margin-bottom: 0; }
.viewer canvas { display: block; width: 100%; height: auto; }
.viewer .loading { text-align: center; padding: 40px 0; color: var(--muted); }

/* ---------- Signature ---------- */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps > li { position: relative; padding-left: 40px; margin-bottom: 22px; }
.steps > li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.steps > li.done::before { content: "✓"; background: var(--ok); }
.steps h3 { margin: 2px 0 8px; font-size: 15.5px; }

.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button {
  appearance: none; border: 1px solid var(--border); background: #fff; color: var(--muted);
  padding: 6px 12px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer;
}
.tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.pad-wrap { position: relative; border: 1.5px dashed #c9bfba; border-radius: 8px; background: #fff; }
.pad-wrap canvas { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; border-radius: 8px; }
.pad-hint { position: absolute; inset: auto 0 12px; text-align: center; color: #b3aaa6; font-size: 13px; pointer-events: none; }
.pad-line { position: absolute; left: 24px; right: 24px; bottom: 40px; border-bottom: 1px solid #e8e2de; pointer-events: none; }
.pad-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
input:focus, textarea:focus, select:focus, .btn:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

.code-input { font-size: 22px !important; letter-spacing: 8px; text-align: center; max-width: 220px; font-variant-numeric: tabular-nums; }

.alert { padding: 12px 14px; border-radius: 8px; margin: 10px 0; font-size: 14px; }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

.status-screen { text-align: center; padding: 40px 20px; }
.status-screen .icon {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto 16px; font-size: 30px;
}
.status-screen .icon.ok { background: var(--ok-soft); color: var(--ok); }
.status-screen .icon.err { background: var(--err-soft); color: var(--err); }
.status-screen .icon.warn { background: var(--warn-soft); color: var(--warn); }

.legal { font-size: 12px; color: var(--muted); margin-top: 14px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.layout .side { position: sticky; top: 16px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .layout .side { position: static; }
  .viewer { max-height: 62vh; }
}

.hidden { display: none !important; }

/* ---------- Admin ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #faf8f6; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.en_attente, .badge.consulte { background: var(--warn-soft); color: var(--warn); }
.badge.signee, .badge.signe { background: var(--ok-soft); color: var(--ok); }
.badge.refusee, .badge.refuse, .badge.annulee, .badge.expiree { background: var(--err-soft); color: var(--err); }

.signer-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
@media (max-width: 600px) { .signer-row { grid-template-columns: 1fr; } }

.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.timeline time { color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }

dialog {
  border: none; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(36, 32, 31, .45); }
dialog .card { margin: 0; border: none; box-shadow: none; }
