/* ═══════════════════════════════════════════════════════════════
   SAMS — Identite visuelle (thème clair + sombre via tokens CSS)
   Palette fournie par le cahier des charges.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --navy:  #17287a;
  --red:   #cc1f1f;
  --royal: #2340d8;

  --paper: #f4f6fb;
  --card:  #ffffff;
  --ink:   #131a33;
  --muted: #64708f;
  --line:  #dfe4f2;

  --good:  #15924e; /* paye */
  --warn:  #d8891a; /* non paye */

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 18px rgba(23, 40, 122, .08), 0 2px 6px rgba(23, 40, 122, .06);
  --shadow-lg: 0 14px 40px rgba(23, 40, 122, .14);

  --discord: #5865F2;

  /* Harmonise les controles natifs (dropdown des select, scrollbars) */
  color-scheme: light;
}

/* Mode sombre complet */
:root[data-theme="dark"] {
  --paper: #0d1326;
  --card:  #161e3a;
  --ink:   #e8ecf8;
  --muted: #9aa6c9;
  --line:  #27335c;

  --good:  #35c478;
  --warn:  #f0a73e;

  --shadow: 0 6px 18px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .25);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, .5);

  /* Rend les menus deroulants natifs, scrollbars, etc. sombres */
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}

h1, h2, h3, .oswald {
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0;
}

.tabular { font-variant-numeric: tabular-nums; }

a { color: var(--royal); text-decoration: none; }

/* ── Barre d'accent tricolore ──────────────────────────────────── */
.accent-bar {
  height: 5px;
  background: linear-gradient(90deg,
    var(--red) 0 33.33%,
    var(--navy) 33.33% 66.66%,
    var(--royal) 66.66% 100%);
}

/* ── En-tete ───────────────────────────────────────────────────── */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.logo {
  width: 62px; height: 62px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  object-fit: contain;
  padding: 4px;
  flex: 0 0 auto;
}
.title-block { flex: 1 1 auto; min-width: 0; }
.title-block h1 { font-size: 30px; line-height: 1.05; }
.title-block h1 .t-fact { color: var(--red); }
.title-block h1 .t-lspd { color: var(--royal); }
.subtitle { color: var(--muted); font-size: 13.5px; margin-top: 3px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--navy); color: #fff;
  font-family: 'Oswald', sans-serif; text-transform: uppercase;
  letter-spacing: .08em; font-size: 12px;
  padding: 6px 12px; border-radius: 999px;
}

.header-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

/* Mini carte utilisateur */
.user-chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px 5px 5px;
}
.user-chip img, .user-chip .avatar-fallback {
  width: 30px; height: 30px; border-radius: 50%;
}
.user-chip .u-name { font-weight: 600; font-size: 13.5px; }
.user-chip .u-grade { font-size: 11px; color: var(--muted); }

/* ── Boutons ───────────────────────────────────────────────────── */
.btn {
  font-family: 'Inter', sans-serif;
  font-weight: 600; font-size: 14px;
  border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  padding: 9px 15px; border-radius: 999px;
  cursor: pointer; transition: .15s;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--royal); transform: translateY(-1px); }
.btn-primary { background: var(--royal); color: #fff; border-color: var(--royal); }
.btn-primary:hover { background: var(--navy); border-color: var(--navy); }
.btn-navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-red { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 7px 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.theme-toggle {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  cursor: pointer; font-size: 18px; line-height: 1;
  display: grid; place-items: center; transition: .15s;
}
.theme-toggle:hover { border-color: var(--royal); }

/* ── Layout ────────────────────────────────────────────────────── */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }

/* ── Cartes ────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }

/* ── Pastilles (pills) ─────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--paper); border: 1px solid var(--line);
}
.pill-good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.pill-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.pill-care { color: #fff; border: none; }

/* ── Onglets de semaines ───────────────────────────────────────── */
.weeks-tabs {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-bottom: 18px;
}
.week-tab {
  font-family: 'Oswald', sans-serif; text-transform: uppercase;
  letter-spacing: .05em; font-size: 13px; font-weight: 500;
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--muted); cursor: pointer; transition: .15s;
}
.week-tab:hover { border-color: var(--royal); color: var(--ink); }
.week-tab.active {
  background: var(--navy); color: #fff; border-color: var(--navy);
  box-shadow: var(--shadow);
}

/* ── Cartes statistiques ───────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  margin-bottom: 18px;
}
.stat { padding: 16px 18px; }
.stat .label {
  font-family: 'Oswald', sans-serif; text-transform: uppercase;
  letter-spacing: .07em; font-size: 12px; color: var(--muted);
}
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat.total .value { color: var(--navy); }
.stat.paid  .value { color: var(--good); }
.stat.due   .value { color: var(--warn); }
.stat.count .value { color: var(--royal); }
:root[data-theme="dark"] .stat.total .value { color: #7f93ff; }

/* ── Panneau d'ajout rapide ────────────────────────────────────── */
.add-panel { padding: 16px 18px; margin-bottom: 16px; }
.add-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1.3fr 1.1fr auto;
  gap: 10px; align-items: end;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-family: 'Oswald', sans-serif; text-transform: uppercase;
  letter-spacing: .06em; font-size: 11px; color: var(--muted);
}
input, select {
  font-family: 'Inter', sans-serif; font-size: 14px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  transition: .15s; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--royal); background: var(--card); box-shadow: 0 0 0 3px color-mix(in srgb, var(--royal) 18%, transparent); }
input::placeholder { color: var(--muted); }

/* Select stylise dans le theme (fleche personnalisee + couleurs tokens) */
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238892b0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 15px;
}
select:hover { border-color: var(--royal); }

/* ── Barre d'outils calendrier ─────────────────────────────────── */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  justify-content: space-between; margin-bottom: 14px;
}
.toolbar .left, .toolbar .right { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box .ic { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.search-box input { padding-left: 37px; min-width: 240px; }

/* ── Recap par soignant ────────────────────────────────────────── */
.recap { padding: 12px 16px; margin-bottom: 16px; }
.recap h3 { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.recap-list { display: flex; gap: 8px; flex-wrap: wrap; }
.recap-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px 5px 6px; font-size: 13px;
}
.recap-item .amount { font-weight: 700; }
.recap-item .cnt { color: var(--muted); font-size: 12px; }

/* ── Calendrier (7 colonnes) ───────────────────────────────────── */
.calendar {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px;
  align-items: start; /* chaque colonne a sa hauteur propre : un jour charge ne deforme plus les autres */
}
.day-col {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column;
  min-height: 160px; max-height: 560px; overflow: hidden;
}
.day-col.today { border-color: var(--royal); box-shadow: 0 0 0 2px color-mix(in srgb, var(--royal) 30%, transparent); }
.day-head {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.day-head .d-name {
  font-family: 'Oswald', sans-serif; text-transform: uppercase;
  letter-spacing: .05em; font-size: 13px;
}
.day-col.today .day-head .d-name { color: var(--royal); }
.day-head .d-head-right { display: flex; align-items: center; gap: 6px; }
.day-head .d-badge {
  font-size: 10px; background: var(--royal); color: #fff;
  padding: 2px 7px; border-radius: 999px; font-weight: 600;
}
.day-head .d-count {
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  background: var(--paper); border: 1px solid var(--line);
  min-width: 20px; text-align: center; padding: 1px 7px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.day-subtotal {
  padding: 7px 12px; font-size: 12px; color: var(--muted);
  display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line);
  flex: 0 0 auto;
}
.day-subtotal .due { color: var(--warn); font-weight: 600; }
/* Le corps defile a l'interieur de la colonne : une journee a 25 agents ne
   cree plus une liste interminable qui deforme le tableau. */
.day-body {
  padding: 10px; display: flex; flex-direction: column; gap: 9px;
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
}
.day-body::-webkit-scrollbar { width: 8px; }
.day-body::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 40%, transparent); border-radius: 999px; }
.day-body::-webkit-scrollbar-track { background: transparent; }
.day-body { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 40%, transparent) transparent; }
.day-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 14px 4px; }

/* ── Carte facture ─────────────────────────────────────────────── */
.invoice {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); padding: 9px; font-size: 13px;
  display: flex; flex-direction: column; gap: 8px;
}
.invoice.is-paid { background: color-mix(in srgb, var(--good) 8%, var(--paper)); }
.inv-top { display: flex; align-items: center; gap: 8px; }
.inv-avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  font-size: 12px; font-family: 'Oswald', sans-serif; letter-spacing: .02em;
}
.inv-agent { font-weight: 600; line-height: 1.2; word-break: break-word; }
.inv-amount {
  margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums;
  cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.inv-amount:hover { background: color-mix(in srgb, var(--royal) 12%, transparent); }
.inv-amount-input { width: 82px; font-size: 13px; padding: 4px 6px; }
.inv-mid { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inv-care { cursor: pointer; }
.inv-care-select { font-size: 12px; padding: 4px 6px; width: auto; }
.inv-actions { display: flex; gap: 6px; }
.inv-actions .btn { flex: 1; justify-content: center; }
.status-btn.paid  { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.status-btn.unpaid{ background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* ── Pied du calendrier ────────────────────────────────────────── */
.cal-footer {
  margin-top: 16px; padding: 14px 18px;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px;
}
.cal-footer .total { font-family: 'Oswald', sans-serif; font-size: 18px; letter-spacing: .04em; }
.cal-footer .pending { color: var(--warn); font-weight: 700; }
.cal-footer .settled { color: var(--good); font-weight: 700; }

/* ── Tableaux admin ────────────────────────────────────────────── */
.admin-nav {
  display: flex; gap: 10px; align-items: center; margin-bottom: 20px;
}
.section-title { font-size: 20px; margin: 26px 0 14px; display: flex; align-items: center; gap: 9px; }
.section-title .ic { width: 20px; height: 20px; color: var(--royal); }

/* Tableaux — lisibilite renforcee */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
thead th {
  font-family: 'Oswald', sans-serif; text-transform: uppercase;
  letter-spacing: .06em; font-size: 12px; color: var(--muted);
  text-align: left; padding: 13px 14px;
  background: var(--paper); border-bottom: 2px solid var(--line);
  position: sticky; top: 0; white-space: nowrap;
}
thead th:first-child { border-top-left-radius: var(--radius); }
thead th:last-child  { border-top-right-radius: var(--radius); }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--paper) 55%, transparent); }
tbody tr:hover td { background: color-mix(in srgb, var(--royal) 7%, transparent); }
tbody tr:last-child td { border-bottom: none; }
.cell-user { display: flex; align-items: center; gap: 11px; }
.cell-user img, .cell-user .avatar-fallback {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px;
  object-fit: cover;
}
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--muted); }
td select { max-width: 230px; }
td input { max-width: 100%; }
.col-actions { text-align: right; white-space: nowrap; }

/* ── Icones (SVG inline) ────────────────────────────────────────── */
.ic { width: 18px; height: 18px; display: inline-block; vertical-align: middle; flex: 0 0 auto; }
.btn .ic, .btn-icon .ic, .theme-toggle .ic { width: 16px; height: 16px; }
.theme-toggle .ic { width: 18px; height: 18px; }

/* ── Pastille de statut (lecture seule) ─────────────────────────── */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid transparent;
}
.status-pill.paid   { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); border-color: color-mix(in srgb, var(--good) 32%, transparent); }
.status-pill.unpaid { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); border-color: color-mix(in srgb, var(--warn) 32%, transparent); }
.status-pill .ic { width: 14px; height: 14px; }

/* Selects inline (dans une facture) : plus compacts */
.inv-care-select { background-position: right 7px center; padding-right: 26px; }

/* ── Page de connexion ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px; text-align: center;
  padding: 36px 30px; box-shadow: var(--shadow-lg);
}
.login-logo { width: 96px; height: 96px; border-radius: 50%; background:#fff; border:1px solid var(--line); padding:6px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 26px; margin: 18px 0 2px; }
.login-card h1 .t-fact { color: var(--red); }
.login-card h1 .t-lspd { color: var(--royal); }
.login-card .subtitle { margin-bottom: 26px; }
.btn-discord {
  width: 100%; justify-content: center;
  background: var(--discord); color: #fff; border-color: var(--discord);
  padding: 13px; font-size: 15px;
}
.btn-discord:hover { filter: brightness(1.08); }
.login-foot { margin-top: 20px; font-size: 12px; color: var(--muted); }

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ── Navigation principale (Facturation / Suivi Mutuel) ────────── */
.subnav { background: var(--card); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.main-nav { max-width: 1180px; margin: 0 auto; padding: 0 20px; display: flex; gap: 4px; flex-wrap: wrap; }
.main-nav .nav-link {
  font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .05em;
  font-size: 13.5px; font-weight: 500; color: var(--muted);
  padding: 13px 18px; border-bottom: 3px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 8px;
}
.main-nav .nav-link:hover { color: var(--ink); }
.main-nav .nav-link.active { color: var(--royal); border-bottom-color: var(--royal); }
.main-nav .nav-link .ic { width: 17px; height: 17px; }

/* ── Navbar admin (4 onglets) ──────────────────────────────────── */
.admin-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.admin-tab {
  font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .05em;
  font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  display: inline-flex; align-items: center; gap: 7px; transition: .15s;
}
.admin-tab:hover { border-color: var(--royal); color: var(--ink); }
.admin-tab.active { background: var(--navy); color: #fff; border-color: var(--navy); box-shadow: var(--shadow); }
.admin-tab .ic { width: 16px; height: 16px; }
.admin-section { display: none; }
.admin-section.active { display: block; }

/* ── Filtres ───────────────────────────────────────────────────── */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters select { min-width: 160px; width: auto; }

/* ── Soldes mutuelle ───────────────────────────────────────────── */
.bal-ok  { color: var(--good); font-weight: 700; font-variant-numeric: tabular-nums; }
.bal-neg { color: var(--warn); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Modale (formulaire souscription / option) ─────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(8, 12, 26, .55);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 60; overflow: auto;
}
.modal-overlay.open { display: flex; }
.modal-card { width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; display: grid; place-items: center; border-radius: 8px; }
.modal-close:hover { background: var(--paper); color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

textarea {
  font-family: 'Inter', sans-serif; font-size: 14px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  width: 100%; resize: vertical; min-height: 72px; transition: .15s;
}
textarea:focus { outline: none; border-color: var(--royal); background: var(--card); box-shadow: 0 0 0 3px color-mix(in srgb, var(--royal) 18%, transparent); }

/* ── Parametres mutuelle (listes modifiables) ──────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.opt-title { font-size: 15px; margin-bottom: 12px; }
.opt-list { display: flex; flex-direction: column; }
.opt-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.opt-row:last-child { border-bottom: none; }
.opt-row input { flex: 1; }
.opt-row .opt-rate { max-width: 120px; flex: 0 0 auto; }
.opt-add { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.opt-add .opt-new-label { flex: 1; min-width: 140px; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .calendar { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .add-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .calendar { grid-template-columns: 1fr; }
  .title-block h1 { font-size: 24px; }
  .header-actions { width: 100%; justify-content: space-between; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .wrap { padding: 16px 12px 50px; }
  .stats-grid { grid-template-columns: 1fr; }
  .add-grid { grid-template-columns: 1fr; }
  .user-chip .u-meta { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   WIKI — Documentation (navbar latérale, recherche, lecture)
   100 % basé sur les tokens → thèmes clair & sombre identiques.
   ═══════════════════════════════════════════════════════════════ */
.wiki-wrap { max-width: 1320px; }

/* ── Barre de recherche avancée (collante) ─────────────────────── */
.wiki-searchbar {
  padding: 14px 16px; margin-bottom: 18px;
  position: sticky; top: 10px; z-index: 30;
  display: flex; flex-direction: column; gap: 8px;
}
.wiki-search { width: 100%; }
.wiki-search input { padding-left: 42px; padding-right: 40px; min-width: 0; width: 100%; font-size: 15px; }
.wiki-search .ic { left: 14px; }
.wiki-search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 6px; border-radius: 8px; display: grid; place-items: center;
}
.wiki-search-clear:hover { background: var(--paper); color: var(--ink); }
.wiki-search-meta { font-size: 13px; color: var(--muted); min-height: 0; }
.wiki-search-meta:empty { display: none; }
.wiki-search-meta strong { color: var(--royal); }

/* ── Mise en page : sidebar + contenu ──────────────────────────── */
.wiki-layout {
  display: grid; grid-template-columns: 288px 1fr; gap: 20px;
  align-items: start; position: relative;
}

/* ── Navbar latérale ───────────────────────────────────────────── */
.wiki-sidebar {
  position: sticky; top: 92px;
  max-height: calc(100vh - 110px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding-right: 4px;
}
.wiki-navcat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  flex: 0 0 auto; /* ne pas rétrécir : laisse la sidebar défiler au lieu de couper les liens */
}
.wiki-navcat-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 12px 13px; background: transparent; border: none; cursor: pointer;
  color: var(--ink); text-align: left; transition: .15s;
}
.wiki-navcat-head:hover { background: color-mix(in srgb, var(--royal) 7%, transparent); }
.wiki-navcat-ic { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: color-mix(in srgb, var(--royal) 14%, transparent); color: var(--royal); flex: 0 0 auto; }
.wiki-navcat-ic .ic { width: 17px; height: 17px; }
.wiki-navcat-title { font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .04em; font-size: 13.5px; font-weight: 500; flex: 1 1 auto; }
.wiki-navcat-count { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.wiki-navcat-head .chev { color: var(--muted); transition: transform .2s; }
.wiki-navcat.open .wiki-navcat-head .chev { transform: rotate(90deg); }
.wiki-navcat-body { display: none; padding: 4px 8px 10px; }
.wiki-navcat.open .wiki-navcat-body { display: block; }
.wiki-navlink {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13.5px; line-height: 1.3; transition: .12s;
}
.wiki-navlink .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: 0 0 auto; transition: .12s; }
.wiki-navlink:hover { background: color-mix(in srgb, var(--royal) 8%, transparent); color: var(--ink); }
.wiki-navlink.active { background: color-mix(in srgb, var(--royal) 13%, transparent); color: var(--royal); font-weight: 600; }
.wiki-navlink.active .dot { background: var(--royal); }

/* ── Contenu ───────────────────────────────────────────────────── */
.wiki-content {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 30px 34px; min-height: 60vh; min-width: 0;
}
.wiki-breadcrumb {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--muted); margin-bottom: 16px;
}
.wiki-breadcrumb .ic { width: 15px; height: 15px; color: var(--royal); }
.wiki-breadcrumb .sep { opacity: .5; }
.wiki-breadcrumb .cur { color: var(--ink); font-weight: 600; }

.wiki-article-head { border-bottom: 2px solid var(--line); padding-bottom: 16px; margin-bottom: 22px; }
.wiki-article-head h1 { font-size: 30px; line-height: 1.1; color: var(--ink); }
.wiki-article-sub { color: var(--muted); font-size: 15px; margin-top: 6px; text-transform: none; letter-spacing: 0; font-family: 'Inter', sans-serif; }

.wiki-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.wiki-tag {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; cursor: pointer; transition: .12s; font-family: 'Inter', sans-serif;
}
.wiki-tag::before { content: '#'; opacity: .5; margin-right: 1px; }
.wiki-tag:hover { border-color: var(--royal); color: var(--royal); }

/* ── Corps de document (typographie) ───────────────────────────── */
.wiki-body { font-size: 15px; color: var(--ink); line-height: 1.65; }
.wiki-body > :first-child { margin-top: 0; }
.wiki-body p { margin: 0 0 14px; }
.wiki-lead { font-size: 16.5px; color: var(--ink); font-weight: 500; }
.wiki-h3 {
  font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .04em;
  font-size: 17px; color: var(--navy); margin: 26px 0 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
:root[data-theme="dark"] .wiki-h3 { color: #8ea2ff; }
.wiki-body h4 { font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .03em; font-size: 14.5px; color: var(--ink); margin: 0 0 10px; }
.wiki-note-inline { font-size: 13px; color: var(--muted); font-style: italic; }

/* Listes de définitions */
.wiki-dl { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0 0 8px; }
.wiki-dl dt {
  font-weight: 700; color: var(--royal); font-size: 14.5px;
  margin-top: 14px;
}
:root[data-theme="dark"] .wiki-dl dt { color: #8ea2ff; }
.wiki-dl dd { margin: 3px 0 0; color: var(--ink); }
.wiki-dl dt:first-child { margin-top: 0; }

/* Listes */
.wiki-list { margin: 0 0 14px; padding-left: 20px; }
.wiki-list li { margin-bottom: 6px; }
.wiki-list.tight li { margin-bottom: 2px; }
.wiki-list.ordered { list-style: decimal; }
.wiki-list strong { color: var(--ink); }

/* Encadrés (callouts) */
.wiki-callout {
  border: 1px solid var(--line); border-left: 4px solid var(--royal);
  background: color-mix(in srgb, var(--royal) 6%, var(--card));
  border-radius: var(--radius-sm); padding: 13px 16px; margin: 0 0 16px; font-size: 14.5px;
}
.wiki-callout.warn { border-left-color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, var(--card)); }
.wiki-callout.good { border-left-color: var(--good); background: color-mix(in srgb, var(--good) 9%, var(--card)); }
.wiki-callout .wiki-list { margin: 8px 0 0; }
.wiki-two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.wiki-two .wiki-callout { margin: 0; }

/* Cartes internes */
.wiki-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 50%, var(--card));
  padding: 16px 18px; margin: 0 0 16px;
}
.wiki-card > :last-child { margin-bottom: 0; }

/* Figures & galeries d'images */
.wiki-fig { margin: 0 0 16px; text-align: center; }
.wiki-fig img {
  max-width: 100%; height: auto; border-radius: var(--radius-sm);
  background: #fff; border: 1px solid var(--line); padding: 8px; box-shadow: var(--shadow);
}
.wiki-fig figcaption { margin-top: 7px; font-size: 12.5px; color: var(--muted); }
.wiki-fig.signature img { max-width: 240px; border: none; box-shadow: none; background: transparent; padding: 0; }
.wiki-fig.logo-pss { margin: 0 auto 22px; }
.wiki-fig.logo-pss img { max-width: 210px; border-radius: 50%; padding: 0; border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow); }
:root[data-theme="dark"] .wiki-fig.signature img { filter: invert(1) hue-rotate(180deg) brightness(1.4); }
.wiki-fig.inline { margin: 0; }
.wiki-fig.inline img { max-width: 150px; }
.wiki-logos { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; margin-bottom: 20px; }
.wiki-logos .wiki-fig.inline img { max-width: 110px; border: none; box-shadow: none; }
.wiki-gallery { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 12px; }
.wiki-gallery .wiki-fig.inline img { max-width: 160px; max-height: 150px; object-fit: contain; }
.wiki-gallery.meds .wiki-fig.inline img { max-width: 120px; }

/* Fiche médicament (molécule + texte) */
.wiki-med { display: flex; gap: 20px; align-items: flex-start; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 16px; background: color-mix(in srgb, var(--paper) 40%, var(--card)); }
.wiki-med .wiki-fig.med { flex: 0 0 150px; margin: 0; }
.wiki-med .wiki-fig.med img { max-width: 150px; }
.wiki-med-body { flex: 1 1 auto; min-width: 0; }
.wiki-med-body .wiki-h3 { margin-top: 0; }
.wiki-med-body p { margin-bottom: 7px; font-size: 14px; }

/* Étapes numérotées (guides) */
.wiki-steps { display: flex; flex-direction: column; gap: 14px; }
.wiki-step { display: flex; gap: 16px; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; background: color-mix(in srgb, var(--paper) 40%, var(--card)); }
.wiki-step-num {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; font-family: 'Oswald', sans-serif; font-size: 19px; font-weight: 700;
  background: var(--royal); color: #fff; box-shadow: var(--shadow);
}
.wiki-step .wiki-h3 { margin-top: 2px; border: none; padding: 0; }
.wiki-step p { font-size: 14px; }

/* Tableaux du wiki (réutilise les tokens) */
.wiki-table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 0; }
.wiki-table th {
  font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .05em;
  font-size: 11.5px; color: var(--muted); text-align: left; padding: 10px 12px;
  background: var(--paper); border-bottom: 2px solid var(--line); position: static; white-space: nowrap;
}
.wiki-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: top; }
.wiki-table td.k { font-weight: 600; color: var(--ink); white-space: nowrap; }
.wiki-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--paper) 50%, transparent); }
.wiki-table tbody tr:hover td { background: color-mix(in srgb, var(--royal) 7%, transparent); }
.wiki-table tbody tr:last-child td { border-bottom: none; }
.wiki-table.small td, .wiki-table.small th { padding: 7px 9px; font-size: 12.5px; text-align: center; }
.wiki-table.small td.k { text-align: left; }

/* Quiz */
.wiki-quiz { counter-reset: q; list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 12px; }
.wiki-quiz > li { counter-increment: q; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 13px 15px 13px 46px; position: relative; background: color-mix(in srgb, var(--paper) 40%, var(--card)); }
.wiki-quiz > li::before { content: counter(q); position: absolute; left: 12px; top: 13px; width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; font-family: 'Oswald', sans-serif; }
.wiki-quiz > li > p { margin: 0 0 8px; font-weight: 600; }
.wiki-quiz ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.wiki-quiz ul li { font-size: 14px; color: var(--muted); }
.wiki-details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px 14px; background: var(--paper); }
.wiki-details summary { cursor: pointer; font-weight: 600; color: var(--royal); padding: 8px 0; }
.wiki-corrige { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; letter-spacing: .02em; }

/* Surlignage recherche */
.wiki-body mark, .wiki-result mark, .wiki-result-title mark {
  background: color-mix(in srgb, var(--warn) 40%, transparent);
  color: inherit; border-radius: 3px; padding: 0 2px; font-weight: 600;
}

/* Navigation précédent / suivant */
.wiki-docnav { display: flex; justify-content: space-between; gap: 14px; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--line); }
.wiki-docnav-link { display: flex; flex-direction: column; gap: 3px; padding: 11px 15px; border: 1px solid var(--line); border-radius: var(--radius-sm); max-width: 48%; transition: .15s; }
.wiki-docnav-link:hover { border-color: var(--royal); transform: translateY(-1px); background: color-mix(in srgb, var(--royal) 6%, transparent); }
.wiki-docnav-link.next { text-align: right; margin-left: auto; align-items: flex-end; }
.wiki-docnav-link .dir { font-size: 11.5px; color: var(--muted); font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .04em; }
.wiki-docnav-link .t { font-weight: 600; font-size: 14px; color: var(--ink); }

/* ── Résultats de recherche ────────────────────────────────────── */
.wiki-results { display: flex; flex-direction: column; gap: 12px; }
.wiki-result { display: block; border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; transition: .15s; background: var(--card); }
.wiki-result:hover { border-color: var(--royal); box-shadow: var(--shadow); transform: translateY(-1px); }
.wiki-result-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.wiki-result-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--royal); text-transform: uppercase; letter-spacing: .04em; font-family: 'Oswald', sans-serif; }
.wiki-result-cat .ic { width: 14px; height: 14px; }
.wiki-result-occ { font-size: 11px; color: var(--muted); background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.wiki-result-title { font-family: 'Oswald', sans-serif; text-transform: none; letter-spacing: .01em; font-size: 17px; color: var(--ink); margin: 0; }
.wiki-result-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.wiki-result-snip { font-size: 13.5px; color: var(--ink); margin: 9px 0 10px; line-height: 1.55; }
.wiki-result-open { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--royal); }
.wiki-result-open .ic { width: 15px; height: 15px; }

/* ── Vide / Accueil ────────────────────────────────────────────── */
.wiki-empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.wiki-empty .ic { width: 42px; height: 42px; color: var(--line); margin-bottom: 10px; }
.wiki-empty h2 { font-size: 20px; color: var(--ink); margin-bottom: 8px; }

.wiki-hero { border-bottom: 2px solid var(--line); padding-bottom: 22px; margin-bottom: 24px; }
.wiki-hero h1 { font-size: 32px; color: var(--ink); }
.wiki-hero p { color: var(--muted); font-size: 15.5px; max-width: 760px; margin: 10px 0 0; line-height: 1.6; }
.wiki-hero p strong { color: var(--royal); }
.wiki-hero-search { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 12px 15px; border: 1px dashed var(--line); border-radius: var(--radius-sm); color: var(--muted); font-size: 13.5px; background: var(--paper); }
.wiki-hero-search .ic { color: var(--royal); flex: 0 0 auto; }

.wiki-cats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.wiki-catcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: color-mix(in srgb, var(--paper) 40%, var(--card)); transition: .15s; }
.wiki-catcard:hover { border-color: var(--royal); box-shadow: var(--shadow); }
.wiki-catcard-head { display: flex; align-items: center; gap: 13px; margin-bottom: 12px; }
.wiki-catcard-ic { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; box-shadow: var(--shadow); }
.wiki-catcard-ic .ic { width: 24px; height: 24px; }
.wiki-catcard-ic.ic-generale { background: var(--royal); }
.wiki-catcard-ic.ic-psychologie { background: var(--navy); }
.wiki-catcard-ic.ic-guides { background: var(--red); }
.wiki-catcard-head h2 { font-size: 18px; color: var(--ink); }
.wiki-catcard-owner { font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: 0; font-family: 'Inter', sans-serif; }
.wiki-catcard-desc { font-size: 14px; color: var(--muted); margin: 0 0 14px; line-height: 1.55; }
.wiki-catcard-docs { display: flex; flex-wrap: wrap; gap: 6px; }
.wiki-chip { font-size: 12.5px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; transition: .12s; }
.wiki-chip:hover { border-color: var(--royal); color: var(--royal); }
.wiki-chip.more { font-weight: 700; color: var(--muted); }

/* ── Bouton menu mobile ────────────────────────────────────────── */
.wiki-menu-btn {
  display: none; position: fixed; bottom: 20px; right: 20px; z-index: 45;
  align-items: center; gap: 8px; padding: 12px 18px; border-radius: 999px;
  background: var(--royal); color: #fff; border: none; cursor: pointer;
  font-family: 'Oswald', sans-serif; text-transform: uppercase; letter-spacing: .05em; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
}
.wiki-sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(8,12,26,.5); z-index: 49; }
.wiki-sidebar-overlay.show { display: block; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .wiki-layout { grid-template-columns: 1fr; }
  .wiki-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 300px; max-height: none;
    z-index: 50; background: var(--card); box-shadow: var(--shadow-lg);
    padding: 16px; transform: translateX(-105%); transition: transform .25s;
    overflow-y: auto; border-right: 1px solid var(--line);
  }
  .wiki-sidebar.open { transform: translateX(0); }
  .wiki-menu-btn { display: inline-flex; }
  .wiki-two { grid-template-columns: 1fr; }
  .wiki-cats { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .wiki-content { padding: 20px 16px 26px; }
  .wiki-article-head h1 { font-size: 24px; }
  .wiki-hero h1 { font-size: 25px; }
  .wiki-med { flex-direction: column; align-items: center; text-align: left; }
  .wiki-med .wiki-fig.med { flex: 0 0 auto; }
  .wiki-docnav { flex-direction: column; }
  .wiki-docnav-link, .wiki-docnav-link.next { max-width: 100%; text-align: left; align-items: flex-start; }
  .wiki-searchbar { position: static; }
}
