/* Novaloc Sign — feuille de styles unique */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --brand: #1d4ed8;
  --brand-2: #1e40af;
  --brand-soft: #eff4ff;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --info: #0369a1;
  --info-soft: #f0f9ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden, [hidden] { display: none !important; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ------------------------------------------------------------------ layout admin */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #0b1324; color: #cbd5e1; padding: 1.25rem .9rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1.25rem; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); display: grid; place-items: center; color: #fff; font-size: .95rem; }
.nav a { display: flex; align-items: center; gap: .6rem; color: #cbd5e1; padding: .55rem .7rem; border-radius: 8px; margin-bottom: 2px; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(59,130,246,.18); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar-foot { margin-top: auto; font-size: .82rem; padding: .5rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot button { background: none; border: 0; color: #93c5fd; padding: 0; cursor: pointer; font: inherit; }
.main { padding: 1.75rem 2rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.topbar { display: none; }

/* ------------------------------------------------------------------ composants */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); color: inherit; display: block; }
.stat:hover { text-decoration: none; border-color: var(--line-2); }
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.9rem; font-weight: 700; margin-top: .2rem; }
.stat.s-signed .value { color: var(--ok); }
.stat.s-viewed .value { color: var(--info); }
.stat.s-expired .value { color: var(--warn); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 1px solid transparent; border-radius: var(--radius-sm); padding: .6rem 1rem; font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; background: var(--brand); color: #fff; text-decoration: none; line-height: 1.2; min-height: 40px; }
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #065f46; }
.btn-sm { padding: .35rem .7rem; font-size: .84rem; min-height: 32px; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.02rem; min-height: 50px; }
.btn-block { width: 100%; }
form.inline { display: inline; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-draft { background: #f1f5f9; color: #475569; }
.b-sent { background: var(--brand-soft); color: var(--brand); }
.b-viewed { background: var(--info-soft); color: var(--info); }
.b-signed { background: var(--ok-soft); color: var(--ok); }
.b-expired { background: var(--warn-soft); color: var(--warn); }
.b-cancelled { background: var(--danger-soft); color: var(--danger); }
.b-countersign { background: #f5f3ff; color: #6d28d9; }
.stat.s-countersign .value { color: #6d28d9; }
.b-paid { background: var(--ok-soft); color: var(--ok); }
.b-due { background: #f1f5f9; color: #475569; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: .6rem .75rem; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; font-weight: 500; word-break: break-word; }

.flashes { margin-bottom: 1rem; }
.alert { border-radius: var(--radius-sm); padding: .75rem 1rem; margin-bottom: .6rem; border: 1px solid; font-size: .93rem; }
.alert-success { background: var(--ok-soft); border-color: #a7f3d0; color: #065f46; }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert-warning { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }
.alert-info, .alert-message { background: var(--info-soft); border-color: #bae6fd; color: #075985; }

/* ------------------------------------------------------------------ formulaires */
label, .label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; color: var(--ink-2); }
.field { margin-bottom: .9rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.field .error, .form-error { font-size: .82rem; color: var(--danger); margin-top: .25rem; font-weight: 600; }
.req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=tel], select, textarea {
  width: 100%; padding: .62rem .75rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); font: inherit; font-size: 16px; background: #fff; color: var(--ink); min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(29, 78, 216, .25); border-color: var(--brand); }
input[readonly], input:disabled { background: var(--surface-2); color: var(--ink-2); }
.has-error input, .has-error select { border-color: var(--danger); }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: .1rem 0 0; flex: none; accent-color: var(--brand); }
fieldset { border: 0; padding: 0; margin: 0; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 0 0 .8rem; }
.source-switch { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1.25rem; }
.source-switch label { border: 2px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; cursor: pointer; background: #fff; margin: 0; }
.source-switch input { position: absolute; opacity: 0; pointer-events: none; }
.source-switch label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.source-switch strong { display: block; font-size: .98rem; }
.source-switch span { font-weight: 400; color: var(--muted); font-size: .85rem; }
.locked { background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--radius-sm); padding: .8rem 1rem; font-size: .9rem; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.total-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem .9rem; }
.total-box .label { margin: 0; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.total-box .value { font-size: 1.15rem; font-weight: 700; }
.coherence { margin-top: .75rem; padding: .6rem .85rem; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600; }
.coherence.ok { background: var(--ok-soft); color: var(--ok); }
.coherence.ko { background: var(--danger-soft); color: var(--danger); }
.inst-table input, .inst-table select { min-height: 38px; padding: .45rem .55rem; }
.inst-table td { padding: .4rem .35rem; }
.inst-table .num { width: 42px; color: var(--muted); font-weight: 600; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: flex-end; position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 .25rem; }

.copy-box { display: flex; gap: .5rem; }
.copy-box input { font-family: var(--mono); font-size: .8rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.2rem; border-left: 2px solid var(--line); margin-left: .35rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; }
.timeline .t-when { font-size: .8rem; color: var(--muted); }
.timeline .t-what { font-weight: 600; font-size: .92rem; }
.pdf-frame { width: 100%; height: 75vh; min-height: 480px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f1f5f9; }

/* ------------------------------------------------------------------ pages publiques */
.public { min-height: 100vh; display: flex; flex-direction: column; }
.public-head { background: #fff; border-bottom: 1px solid var(--line); }
.public-head .inner { max-width: 960px; margin: 0 auto; padding: .85rem 1rem; display: flex; align-items: center; gap: .6rem; }
.public-head .brand { color: var(--ink); padding: 0; }
.public-main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.public-foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 1rem; }
.center-card { max-width: 440px; margin: 8vh auto 0; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 1.25rem; }
.auth-logo .brand { color: var(--ink); font-size: 1.25rem; }

.doc-pages { background: #e2e8f0; border-radius: var(--radius-sm); padding: .75rem; max-height: 80vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.doc-pages img { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); margin: 0 auto .75rem; max-width: 820px; min-height: 200px; }
.doc-pages img:last-child { margin-bottom: 0; }
.identity { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem 1rem; }
.identity div span { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.identity div strong { font-weight: 600; word-break: break-word; }
.sig-wrap { position: relative; border: 2px dashed var(--line-2); border-radius: var(--radius); background: #fff; touch-action: none; }
.sig-wrap.signed { border-style: solid; border-color: var(--brand); }
#signature-pad { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; border-radius: var(--radius); }
.sig-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; pointer-events: none; font-size: .95rem; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 48px; border-bottom: 1px solid #cbd5e1; pointer-events: none; }
.mention-model { background: var(--surface-2); border-left: 3px solid var(--brand); padding: .6rem .85rem; border-radius: 4px; font-style: italic; margin-bottom: .5rem; }
.legal { font-size: .8rem; color: var(--muted); }
.success-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 2rem; margin: 0 auto 1rem; }
.hero { text-align: center; padding: 10vh 1rem 2rem; }
.hero h1 { font-size: 2.2rem; }
.hero p { color: var(--muted); max-width: 560px; margin: .5rem auto 1.5rem; font-size: 1.05rem; }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 2rem; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .cols { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 23, 42, .45); }
  .topbar { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; background: #0b1324; color: #fff; position: sticky; top: 0; z-index: 20; }
  .topbar .brand { padding: 0; font-size: 1rem; }
  .menu-btn { background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 8px; padding: .35rem .6rem; font-size: 1.1rem; cursor: pointer; }
  .main { padding: 1.1rem 1rem 3rem; }
  .grid-2, .grid-3, .features { grid-template-columns: 1fr; }
  .totals { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; gap: .1rem; }
  dl.kv dd { margin-bottom: .55rem; }
  .source-switch { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .form-actions .btn { flex: 1; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 1.5rem; }
  h1 { font-size: 1.35rem; }
  .card { padding: 1rem; }
  #signature-pad { height: 200px; }
  .inst-table thead { display: none; }
  .inst-table tr { display: grid; grid-template-columns: 30px 1fr 1fr; gap: .35rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
  .inst-table td { border: 0; padding: 0; }
  .inst-table td.st { grid-column: 2 / 3; }
  .inst-table td.act { grid-column: 3 / 4; text-align: right; }
}

/* ------------------------------------------------------------------ utilitaires (version PHP) */
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.mt-05 { margin-top: .5rem; }
.mt-075 { margin-top: .75rem; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.nomargin { margin: 0; }
.center-wide { max-width: 560px; }
.errors-list { margin: .3rem 0 0; padding-left: 1.2rem; }
.filters { margin-bottom: 1rem; }
.filters input { flex: 2; min-width: 200px; }
.filters select { flex: 1; min-width: 150px; }
.checklist { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.checklist li { padding: .3rem 0; font-weight: 600; }
.checklist li.ok { color: var(--ok); }
.checklist li.ko { color: var(--danger); }
.doc-pages canvas.doc-page { display: block; width: 100%; height: auto; max-width: 820px; margin: 0 auto .75rem; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.doc-pages canvas.doc-page:last-child { margin-bottom: 0; }
.sig-preview { max-width: 100%; margin-top: .75rem; border: 1px solid var(--line); border-radius: 8px; }

/* ------------------------------------------------------------------ documents clients */
.doc-upload { background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--radius-sm); padding: .9rem 1rem; margin-bottom: 1rem; }
.doc-upload input[type=file] { width: 100%; font-size: .9rem; }
.doc-cat { margin: 1.1rem 0 .5rem; font-size: .95rem; }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-item { display: flex; gap: .85rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.doc-item:last-child { border-bottom: 0; }
.doc-thumb { flex: none; width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; text-decoration: none; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-thumb span { font-weight: 700; font-size: .78rem; color: var(--danger); }
.doc-info { min-width: 0; flex: 1; }
.doc-info strong { word-break: break-word; }
.doc-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .4rem; }
.select-sm { min-height: 32px; padding: .25rem .5rem; font-size: .84rem; width: auto; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: .55rem 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border-bottom: 0; }
