/* WikiPost — design system v2.
   Direction : SaaS moderne et sobre. Couleurs pleines (pas de dégradés),
   sidebar navy, icônes colorées par module, cartes arrondies à ombres douces.
   Aucune dépendance externe. */

:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --border: #e5e9f0;
  --text: #101828;
  --muted: #667085;
  --navy: #0d1b31;
  --navy-2: #13294b;
  --accent: #1d5bd6;
  --accent-2: #3b82f6;
  --accent-dark: #1747a8;
  --accent-soft: #e8effc;
  --amber: #b45309;      --amber-soft: #fef3e2;
  --green: #15803d;      --green-soft: #e7f6ec;
  --red: #b42318;        --red-soft: #fdecea;
  --violet: #6d28d9;     --violet-soft: #f1eafd;
  --cyan: #0e7490;       --cyan-soft: #e0f5fa;
  --pink: #be185d;       --pink-soft: #fce7f1;
  --orange: #c2410c;     --orange-soft: #feefe6;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 22px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, .08), 0 16px 44px rgba(16, 24, 40, .12);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

.icon {
  width: 16px; height: 16px; flex: none;
  vertical-align: -3px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Structure ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface);
  color: var(--text);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px;
}
.brand-name { font-weight: 700; font-size: 16px; color: var(--text); line-height: 1.15; letter-spacing: -.01em; }
.brand-sub { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 1px; }

.nav { padding: 10px 10px 16px; flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #d6dce6 transparent; }
.nav-section {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); font-weight: 700;
  padding: 16px 10px 7px;
}
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px;
  border-radius: 10px;
  color: #344054; margin-bottom: 2px;
  font-size: 13.5px; font-weight: 500;
  transition: background .12s ease;
}
.nav a:hover { background: #f2f5f9; text-decoration: none; color: var(--text); }
.nav a.active {
  background: var(--accent-soft);
  color: var(--accent-dark); font-weight: 600;
}

/* Pastille d'icône colorée par module */
.mod-ic {
  width: 26px; height: 26px; flex: none;
  border-radius: 7px;
  display: grid; place-items: center;
}
.mod-ic .icon { width: 15px; height: 15px; }
.mi-blue   { background: #e8effc; color: #1d5bd6; }
.mi-sky    { background: #e0f3fc; color: #0284c7; }
.mi-green  { background: #e5f6eb; color: #16a34a; }
.mi-amber  { background: #fdf2df; color: #d97706; }
.mi-violet { background: #f1ebfd; color: #7c3aed; }
.mi-teal   { background: #dff5f2; color: #0d9488; }
.mi-orange { background: #feeee2; color: #ea580c; }
.mi-cyan   { background: #ddf5fa; color: #0891b2; }
.mi-pink   { background: #fce8f2; color: #db2777; }
.mi-red    { background: #fdeaea; color: #dc2626; }
.mi-yellow { background: #fdf6dc; color: #ca8a04; }
.mi-slate  { background: #eef1f5; color: #64748b; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 13px 16px; font-size: 11.5px; color: var(--muted);
}
.sidebar-footer a { color: var(--accent); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: none;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.topbar .crumb { font-size: 12px; color: var(--muted); margin-top: 1px; }

.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}

main { padding: 26px 28px 48px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- Hero ---------- */

.hero {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--navy);
  color: #fff;
  padding: 30px 32px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.hero > * { position: relative; z-index: 1; }
.hero .pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 600;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 14px;
}
.hero .pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 8px #4ade80; }
.hero h2 { font-size: 26px; font-weight: 800; margin: 0 0 8px; letter-spacing: -.02em; line-height: 1.2; }
.hero p { margin: 0 0 18px; color: #b9c9de; max-width: 640px; font-size: 14px; line-height: 1.55; }
.hero .toolbar { gap: 10px; }
.hero .btn { border: none; }
.hero .btn.light { background: #fff; color: var(--navy); font-weight: 600; }
.hero .btn.light:hover { background: #e8effc; }
.hero .btn.ghost {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.22);
  color: #fff;
}
.hero .btn.ghost:hover { background: rgba(255,255,255,.18); }

/* ---------- Composants ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-head h2 { font-size: 14.5px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.card-body { padding: 20px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid #d6dce6;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px; font-weight: 500; line-height: 1.3;
  transition: all .13s ease;
}
.btn:hover { background: #f5f7fa; border-color: #c3ccda; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff; font-weight: 600;
}
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--red); border-color: #efc4c0; }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.icon-only { padding: 7px; }
.btn.sm.icon-only { padding: 5.5px; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d6dce6;
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3.5px rgba(59,130,246,.14); }
textarea.input { resize: vertical; min-height: 70px; }

.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: #344054; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Tuiles de stats ---------- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex; align-items: flex-start; gap: 14px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-ic {
  width: 42px; height: 42px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
}
.stat-ic .icon { width: 20px; height: 20px; }
.st-blue   { background: var(--accent-soft); color: var(--accent); }
.st-green  { background: var(--green-soft);  color: var(--green); }
.st-amber  { background: var(--amber-soft);  color: var(--amber); }
.st-violet { background: var(--violet-soft); color: var(--violet); }
.st-cyan   { background: var(--cyan-soft);   color: var(--cyan); }
.st-pink   { background: var(--pink-soft);   color: var(--pink); }
.st-orange { background: var(--orange-soft); color: var(--orange); }
.st-red    { background: var(--red-soft);    color: var(--red); }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.1; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700;
  padding: 11px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f7faff; }
tbody tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }

.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }

.empty { text-align: center; padding: 52px 16px; color: var(--muted); }
.empty .icon { width: 34px; height: 34px; opacity: .35; margin-bottom: 12px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.blue   { background: var(--accent-soft); color: var(--accent-dark); }
.badge.green  { background: var(--green-soft);  color: var(--green); }
.badge.amber  { background: var(--amber-soft);  color: var(--amber); }
.badge.red    { background: var(--red-soft);    color: var(--red); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
.badge.gray   { background: #f0f2f5; color: var(--muted); }
.badge.plain::before { display: none; }

/* ---------- Onglets ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 18px; }
.tabs button {
  border: none; background: none;
  padding: 13px 15px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  border-bottom: 2.5px solid transparent; margin-bottom: -1px;
  transition: color .12s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 20px 30px; }
.timeline li::before {
  content: ""; position: absolute; left: 6px; top: 4px;
  width: 11px; height: 11px; border-radius: 50%;
  background: #cbd5e1;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1.5px #cbd5e1;
}
.timeline li:first-child::before { background: var(--accent-2); box-shadow: 0 0 0 1.5px var(--accent-2), 0 0 10px rgba(59,130,246,.5); }
.timeline li::after {
  content: ""; position: absolute; left: 11px; top: 19px; bottom: -2px;
  width: 1.5px; background: #e2e8f0;
}
.timeline li:last-child::after { display: none; }
.timeline .tl-status { font-weight: 600; }
.timeline .tl-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Modales & toasts ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(13, 27, 49, .55);
  backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 100;
}
.modal-overlay.open { display: flex; animation: fade-in .15s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 490px;
  box-shadow: 0 24px 70px rgba(13, 27, 49, .35);
  animation: modal-in .18s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal.wide { max-width: 660px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15.5px; font-weight: 700; }
.modal-head .btn { border: none; }
.modal-body { padding: 20px; max-height: 68vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: #f8fafc; border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

#toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--navy); color: #fff;
  padding: 11px 18px; border-radius: 12px;
  font-size: 13px; max-width: 380px;
  box-shadow: 0 8px 26px rgba(13, 27, 49, .35);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Connexion ---------- */

.login-page {
  min-height: 100vh; display: grid; place-items: center;
  background: var(--navy);
  padding: 16px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: 18px;
  padding: 38px 34px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .4);
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 30px; }
.login-brand .brand-mark { width: 46px; height: 46px; font-size: 17px; border-radius: 13px; }
.login-brand h1 { font-size: 21px; margin: 0; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; }
.login-brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.login-error {
  background: var(--red-soft); color: var(--red);
  border-radius: 10px; padding: 10px 14px;
  font-size: 13px; margin-bottom: 16px; display: none;
}
.login-error.visible { display: block; }
.login-foot { margin-top: 26px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Pages publiques ---------- */

.public-page { min-height: 100vh; background: var(--bg); }
.public-header {
  background: var(--navy);
  color: #fff;
  padding: 22px 20px;
}
.public-header .inner, .public-main { max-width: 660px; margin: 0 auto; width: 100%; }
.public-header .inner { display: flex; align-items: center; gap: 13px; }
.public-header .brand-mark { width: 38px; height: 38px; }
.public-header h1 { font-size: 17px; margin: 0; font-weight: 700; }
.public-header p { margin: 1px 0 0; font-size: 12px; color: #93a8c4; }
.public-main { padding: 24px 20px 48px; }

.verdict {
  display: flex; align-items: center; gap: 15px;
  padding: 20px;
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow);
}
.verdict.ok { background: var(--green-soft); color: var(--green); border: 1px solid #b5e3c4; }
.verdict.bad { background: var(--red-soft); color: var(--red); border: 1px solid #f2c0bc; }
.verdict .icon { width: 28px; height: 28px; }

.kv { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.kv td { padding: 9px 4px; border-bottom: 1px solid #eef1f5; }
.kv td:first-child { color: var(--muted); width: 42%; }
.kv tr:last-child td { border-bottom: none; }

/* ---------- Signature ---------- */

.sig-pad {
  border: 1.5px dashed #c3ccda;
  border-radius: 12px;
  background: #fff;
  display: block; width: 100%; height: 150px;
  touch-action: none; cursor: crosshair;
}

/* ---------- Graphiques (SVG maison) ---------- */

.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding-top: 8px; }
.chart-bars .bar {
  flex: 1; min-width: 6px;
  background: var(--accent);
  border-radius: 4px 4px 2px 2px;
  position: relative;
  transition: opacity .12s;
}
.chart-bars .bar:hover { opacity: .75; }
.chart-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 7px; }

.hbar { margin-bottom: 12px; }
.hbar .hbar-label { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.hbar .hbar-track { height: 9px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.hbar .hbar-fill { height: 100%; border-radius: 999px; background: var(--accent); }

/* ---------- Scanner ---------- */

.scan-box {
  border: 2px dashed #c3ccda;
  border-radius: var(--radius-lg);
  padding: 26px;
  text-align: center;
  background: #f8fafc;
}
.scan-box.active { border-color: var(--accent-2); background: var(--accent-soft); }
#scanVideo { width: 100%; max-width: 420px; border-radius: 12px; background: #000; }

/* ---------- Impression ---------- */

.print-area { display: none; }

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { display: block !important; position: absolute; inset: 0; padding: 24px; background: #fff; }
  .no-print { display: none !important; }
}

.doc {
  border: 1.5px solid #101828;
  border-radius: 4px;
  padding: 20px;
  max-width: 640px;
  font-size: 13px;
  color: #000;
  background: #fff;
}
.doc-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid #101828; padding-bottom: 10px; margin-bottom: 12px; }
.doc-title { font-weight: 800; font-size: 15px; letter-spacing: .02em; }
.doc-code { font-family: ui-monospace, Consolas, monospace; font-size: 16px; font-weight: 700; }
.doc table { font-size: 12.5px; }
.doc .qr { text-align: center; }
.doc .qr img { width: 130px; height: 130px; }

.stamp-sheet { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stamp-cell {
  border: 1px dashed #555; padding: 8px; text-align: center;
  font-size: 10.5px; break-inside: avoid;
}
.stamp-cell img { width: 92px; height: 92px; }
.stamp-cell .val { font-weight: 800; font-size: 13px; }
.stamp-cell .ser { font-family: ui-monospace, Consolas, monospace; font-size: 9px; }

/* ---------- Mobile : sidebar en tiroir + topbar compacte ---------- */

.menu-btn { display: none; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(13, 27, 49, .55);
  z-index: 55;
}
.sidebar-backdrop.show { display: block; }

@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: min(300px, 84vw); height: 100vh; height: 100dvh;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 8px 0 30px rgba(13, 27, 49, .18);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { padding: 0 14px; height: 56px; }
  .topbar h1 { font-size: 15px; }
  .topbar .crumb { display: none; }
  .user-chip { gap: 7px; }
  .user-chip .uname, .user-chip .badge { display: none; }

  main { padding: 14px 14px 40px; }
  .hero { padding: 22px 20px; }
  .hero h2 { font-size: 21px; }
  .hero p { font-size: 13.5px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 13px; gap: 10px; }
  .stat .value { font-size: 19px; }
  .stat-ic { width: 34px; height: 34px; border-radius: 9px; }
  .card-head { padding: 13px 14px; }
  .card-body { padding: 14px; }
  th, td { padding: 9px 10px; }
  .modal-body { max-height: 74vh; }
}

@media (max-width: 420px) {
  .hero .toolbar .btn { flex: 1 1 100%; justify-content: center; }
}
