/* ─── Mode sombre ─────────────────────────────────────────────────────────────
   Notre thème est piloté par <html data-theme="dark"> (et non data-bs-theme).
   Couche 1 : on redéfinit les variables Bootstrap 5.3 que les composants lisent
   (tableaux, formulaires, texte secondaire, alertes, liens…), retintées vers
   notre palette verte — la plupart des composants Bootstrap s'adaptent alors
   automatiquement, sans !important.
   Couche 2 : quelques règles ciblées là où Bootstrap compile des couleurs
   littérales dans des utilitaires (!important côté Bootstrap).
   Chargé après site.css dans base.html. */

html[data-theme="dark"] {
  color-scheme: dark;

  /* Corps de page / texte */
  --bs-body-bg: #141a14;
  --bs-body-color: #dde8dd;
  --bs-body-color-rgb: 221, 232, 221;
  --bs-emphasis-color: #eef5ee;
  --bs-emphasis-color-rgb: 238, 245, 238;
  --bs-secondary-color: rgba(221, 232, 221, 0.75);
  --bs-secondary-color-rgb: 221, 232, 221;
  --bs-secondary-bg: #263026;
  --bs-secondary-bg-rgb: 38, 48, 38;
  --bs-tertiary-color: rgba(221, 232, 221, 0.5);
  --bs-tertiary-color-rgb: 221, 232, 221;
  --bs-tertiary-bg: #1c241c;
  --bs-tertiary-bg-rgb: 28, 36, 28;

  /* Emphase (titres, tableaux) */
  --bs-heading-color: inherit;

  /* Liens */
  --bs-link-color: #7fc79a;
  --bs-link-hover-color: #a3dbb7;
  --bs-link-color-rgb: 127, 199, 154;
  --bs-link-hover-color-rgb: 163, 219, 183;

  /* Code / surlignage */
  --bs-code-color: #a8d8a8;
  --bs-highlight-color: #dde8dd;
  --bs-highlight-bg: #664d03;

  /* Traits */
  --bs-border-color: rgba(255, 255, 255, 0.15);
  --bs-border-color-translucent: rgba(255, 255, 255, 0.15);

  /* Variantes « subtiles » (alertes, badges) — palette Bootstrap en version
     sombre, légèrement retintée */
  --bs-primary-text-emphasis: #74c08f;
  --bs-secondary-text-emphasis: #a7acb1;
  --bs-success-text-emphasis: #75b798;
  --bs-info-text-emphasis: #6edff6;
  --bs-warning-text-emphasis: #ffda6a;
  --bs-danger-text-emphasis: #ea868f;
  --bs-light-text-emphasis: #f8f9fa;
  --bs-dark-text-emphasis: #dee2e6;

  --bs-primary-bg-subtle: #031610;
  --bs-secondary-bg-subtle: #161719;
  --bs-success-bg-subtle: #051b11;
  --bs-info-bg-subtle: #032830;
  --bs-warning-bg-subtle: #332701;
  --bs-danger-bg-subtle: #2c0b0e;
  --bs-light-bg-subtle: #343a40;
  --bs-dark-bg-subtle: #1a1d20;

  --bs-primary-border-subtle: #0f5132;
  --bs-secondary-border-subtle: #41464b;
  --bs-success-border-subtle: #0f5132;
  --bs-info-border-subtle: #087990;
  --bs-warning-border-subtle: #997404;
  --bs-danger-border-subtle: #842029;
  --bs-light-border-subtle: #495057;
  --bs-dark-border-subtle: #343a40;

  /* Formulaires */
  --bs-form-valid-color: #75b798;
  --bs-form-valid-border-color: #75b798;
  --bs-form-invalid-color: #ea868f;
  --bs-form-invalid-border-color: #ea868f;
}

/* ─── Utilitaires Bootstrap compilés en littérales (portés par !important) ──── */

html[data-theme="dark"] .text-dark { color: var(--co-text) !important; }
html[data-theme="dark"] .text-success { color: #6fcf8f !important; }
html[data-theme="dark"] .badge.bg-light {
  background-color: #263226 !important;
  color: #c8ddc8 !important;
}
html[data-theme="dark"] .badge.bg-dark {
  background-color: #2c3830 !important;
  color: #c8ddc8 !important;
}

/* ─── Tableaux ────────────────────────────────────────────────────────────────
   .table / .form-control consomment déjà les variables ci-dessus ; il ne reste
   que les variantes qui figent leurs propres couleurs. */

html[data-theme="dark"] .table {
  --bs-table-bg: var(--co-surface);
}

html[data-theme="dark"] .table-light {
  --bs-table-color: var(--co-text);
  --bs-table-color-state: var(--co-text);
  --bs-table-color-type: var(--co-text);
  --bs-table-bg: var(--co-surface-3);
  --bs-table-bg-state: var(--co-surface-3);
  --bs-table-bg-type: var(--co-surface-3);
  --bs-table-border-color: var(--co-border);
  --bs-table-striped-color: var(--co-text);
  --bs-table-striped-bg: #1e271e;
  --bs-table-active-color: var(--co-text);
  --bs-table-active-bg: #242e24;
  --bs-table-hover-color: var(--co-text);
  --bs-table-hover-bg: #202a20;
}

/* ─── Boutons contour (couleurs figées par Bootstrap) ───────────────────────── */

html[data-theme="dark"] .btn-outline-secondary {
  color: #9aabb5;
  border-color: #9aabb5;
}
html[data-theme="dark"] .btn-outline-secondary:hover {
  background: #2e3e2e;
  border-color: #9aabb5;
  color: #dde8dd;
}
html[data-theme="dark"] .btn-outline-success {
  color: #7fc79a;
  border-color: #7fc79a;
}
html[data-theme="dark"] .btn-outline-success:hover {
  background: #1f7a4d;
  border-color: #1f7a4d;
  color: #fff;
}
html[data-theme="dark"] .btn-check:checked + .btn-outline-secondary,
html[data-theme="dark"] .btn-check:checked + .btn-outline-success {
  background: var(--co-green) !important;
  border-color: var(--co-green) !important;
  color: #fff !important;
}
html[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* ─── Barres de défilement ──────────────────────────────────────────────────── */

html[data-theme="dark"] ::-webkit-scrollbar       { width: 8px; height: 8px; }
html[data-theme="dark"] ::-webkit-scrollbar-track  { background: #0f1510; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb  { background: #2e3e2e; border-radius: 4px; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--co-green); }
