/* ============================================================
   SignaDrive — feuille de style
   Mobile-first, responsive, thème sombre + clair auto
   ============================================================ */
:root {
  --bg: #0b1120;
  --bg-2: #0f172a;
  --surface: #111c33;
  --surface-2: #16233f;
  --border: #233251;
  --text: #e8eefc;
  --text-dim: #9fb0cf;
  --primary: #3b82f6;
  --primary-2: #6366f1;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 30px rgba(0,0,0,.35);
  --sidebar-w: 248px;
  font-synthesis: none;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef2f9; --bg-2: #e6ecf6; --surface: #ffffff; --surface-2: #f4f7fc;
    --border: #dbe3f0; --text: #10203b; --text-dim: #5b6b86; --shadow: 0 10px 28px rgba(20,40,80,.12);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ===================== Sidebar ===================== */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 14px; }
.brand__logo { width: 38px; height: 38px; border-radius: 10px; }
.brand__name { display: block; font-weight: 800; font-size: 18px; letter-spacing: .2px; }
.brand__tag { display: block; font-size: 11.5px; color: var(--text-dim); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav__item {
  display: flex; align-items: center; gap: 11px;
  background: transparent; border: 0; color: var(--text-dim);
  padding: 11px 12px; border-radius: var(--radius-sm); font-size: 14.5px; font-weight: 600;
  text-align: left; transition: .15s;
}
.nav__item:hover { background: var(--surface); color: var(--text); }
.nav__item.is-active { background: linear-gradient(90deg, rgba(59,130,246,.22), rgba(99,102,241,.14)); color: #fff; }
.nav__ico { width: 20px; text-align: center; opacity: .9; }
.sidebar__foot { margin-top: auto; font-size: 11.5px; color: var(--text-dim); display: flex; align-items: center; gap: 7px; padding: 10px 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }

/* ===================== Main ===================== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.icon-btn { display: none; background: var(--surface); border: 1px solid var(--border); color: var(--text); width: 40px; height: 40px; border-radius: 10px; font-size: 18px; }
.search { flex: 1; }
.search input {
  width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 10px 14px; border-radius: 10px; outline: none;
}
.search input:focus { border-color: var(--primary); }
.views { padding: 22px 20px 40px; }

/* ===================== Boutons ===================== */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 15px; border-radius: 10px; font-weight: 700; font-size: 14px; transition: .15s;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn--primary { background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-color: transparent; color: #fff; }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn--block { width: 100%; justify-content: center; }
.btn--sm { padding: 7px 11px; font-size: 13px; }

/* ===================== Titres de vue ===================== */
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head h1 { font-size: 24px; margin: 0 0 4px; }
.view-head p { margin: 0; color: var(--text-dim); font-size: 14px; }

/* ===================== Cartes & grilles ===================== */
.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat__label { color: var(--text-dim); font-size: 13px; font-weight: 600; }
.stat__value { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.stat__ico { font-size: 20px; opacity: .85; }

.quick-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.action-tile {
  flex: 1; min-width: 200px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; text-align: left; transition: .15s;
}
.action-tile:hover { border-color: var(--primary); transform: translateY(-2px); }
.action-tile h3 { margin: 10px 0 4px; font-size: 16px; }
.action-tile p { margin: 0; color: var(--text-dim); font-size: 13px; }
.action-tile .emoji { font-size: 26px; }

/* ===================== Listes ===================== */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.row:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 44px;
  display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 700; }
.row__sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.row__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { font-size: 11.5px; font-weight: 800; padding: 4px 9px; border-radius: 999px; letter-spacing: .3px; }
.badge--ok { background: rgba(34,197,94,.16); color: #4ade80; }
.badge--warn { background: rgba(245,158,11,.16); color: #fbbf24; }
.badge--draft { background: rgba(159,176,207,.16); color: var(--text-dim); }

.empty { text-align: center; color: var(--text-dim); padding: 60px 20px; }
.empty .emoji { font-size: 44px; display: block; margin-bottom: 12px; }

/* ===================== Formulaires ===================== */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.col-2 { grid-column: span 2; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.field input, .field select, .field textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 12px; border-radius: 10px; outline: none; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 70px; }
.section-title { font-size: 13px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .6px; margin: 22px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ===================== Signature pad ===================== */
.sigpad-wrap { position: relative; }
.sigpad {
  width: 100%; height: 220px; background: #fff; border: 2px dashed var(--border);
  border-radius: var(--radius); touch-action: none; display: block;
}
.sigpad.is-signed { border-style: solid; border-color: var(--ok); }
.sigpad-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; pointer-events: none; font-size: 14px; }
.sigpad-tools { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* Signature enregistrée, affichée en miniature */
.sig-thumb { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.sig-thumb img { display: block; max-width: 100%; height: 70px; object-fit: contain; }

/* ===================== Bloc signataire sur le contrat ===================== */
.signatory {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: stretch;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: var(--surface-2);
}
.signatory__id .who { font-weight: 800; font-size: 16px; }
.signatory__id .role { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.signatory__sign { display: flex; flex-direction: column; }

/* ===================== Scan permis ===================== */
.scan-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px; text-align: center;
  background: var(--surface-2); transition: .15s; cursor: pointer;
}
.scan-zone:hover, .scan-zone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
.scan-zone .emoji { font-size: 34px; }
.scan-preview { margin-top: 14px; display: none; }
.scan-preview img { max-width: 100%; max-height: 240px; border-radius: 10px; border: 1px solid var(--border); }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 12px; display: none; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--primary)); transition: width .3s; }

/* ===================== Modale ===================== */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(2,6,18,.66); backdrop-filter: blur(3px); }
.modal__box {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; width: min(760px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow);
}
.modal__content { padding: 24px; }
.modal__content h2 { margin: 0 0 4px; font-size: 20px; }
.modal__close { position: absolute; top: 12px; right: 14px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); width: 34px; height: 34px; border-radius: 9px; font-size: 20px; line-height: 1; z-index: 2; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

/* ===================== Toasts ===================== */
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); min-width: 240px; max-width: 360px;
  animation: slideIn .25s ease; font-size: 14px;
}
.toast--ok { border-left-color: var(--ok); }
.toast--warn { border-left-color: var(--warn); }
.toast--danger { border-left-color: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } }

/* ===================== Divers ===================== */
.hint { font-size: 12.5px; color: var(--text-dim); }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.spacer { height: 10px; }
.muted { color: var(--text-dim); }
.text-center { text-align: center; }

/* ===================== Documents : signer un upload ===================== */
.sign-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.pager { display: flex; align-items: center; gap: 8px; }
.doc-stage {
  overflow: auto; text-align: center; padding: 16px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); max-height: 78vh;
}
.doc-page-wrap { position: relative; display: inline-block; background: #fff; box-shadow: var(--shadow); line-height: 0; }
#docCanvas { display: block; }
.overlay-layer { position: absolute; top: 0; left: 0; pointer-events: none; }
.placement {
  position: absolute; pointer-events: auto; border: 1.5px dashed var(--primary);
  border-radius: 4px; background: rgba(59,130,246,.06); cursor: move; touch-action: none;
}
.placement img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; -webkit-user-drag: none; }
.pl-del {
  position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border: 0; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 15px; line-height: 1; cursor: pointer; pointer-events: auto; box-shadow: var(--shadow);
}
.pl-resize {
  position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; background: var(--primary);
  border: 2px solid #fff; border-radius: 3px; cursor: nwse-resize; pointer-events: auto; touch-action: none;
}
.sig-pick { cursor: pointer; text-align: left; }
.sig-pick:hover { border-color: var(--primary); }

/* ===================== Responsive ===================== */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .25s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .form-grid { grid-template-columns: 1fr; }
  .field.col-2 { grid-column: span 1; }
  .signatory { grid-template-columns: 1fr; }
  .views { padding: 16px 14px 40px; }
  .quick-actions .action-tile { min-width: 100%; }
}
@media print {
  .sidebar, .topbar, .toasts { display: none !important; }
}
