/* Thème sombre : ajustements qui ne passent pas par les variables de couleur (couleurs.css).
   Écran uniquement : l'impression (reçus, factures) reste toujours en clair. */
@media screen {
  html[data-theme="dark"] {
    color-scheme: dark;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .35);
    --shadow-overlay: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 4px 12px -4px rgba(0, 0, 0, .45);
  }
  html[data-theme="dark"] body { background-color: var(--color-bg); color: var(--color-text); }

  /* Blanc utilisé comme fond de carte ou de page -> surface sombre (le texte blanc sur fond coloré reste blanc) */
  html[data-theme="dark"] .bg-white { background-color: var(--color-surface) !important; }
  html[data-theme="dark"] .bg-white\/90, html[data-theme="dark"] .bg-white\/95 { background-color: rgb(var(--tw-surface) / .92) !important; }
  html[data-theme="dark"] .text-black { color: var(--ink-900) !important; }
  html[data-theme="dark"] .border-white { border-color: var(--ink-200) !important; }
  html[data-theme="dark"] .ring-white { --tw-ring-color: var(--color-surface) !important; }
  html[data-theme="dark"] .bg-black.bg-opacity-50, html[data-theme="dark"] .bg-black\/60 { background-color: rgba(0, 0, 0, .65) !important; }

  /* Cadre */
  html[data-theme="dark"] #topbar { background: rgb(var(--tw-surface) / .88); }
  html[data-theme="dark"] .modal-overlay, html[data-theme="dark"] .drawer-overlay { background: rgba(0, 0, 0, .62); }
  /* Logo (texte noir) posé sur une pastille claire */
  html[data-theme="dark"] .sidebar-logo-full,
  html[data-theme="dark"] .login-marque-logo,
  html[data-theme="dark"] .login-logo-mobile { background: #fff; border-radius: 8px; padding: 3px 6px; }
  html[data-theme="dark"] .sidebar-logo-mini { background: #fff; }

  /* Écran de connexion */
  html[data-theme="dark"] .login-page { background: var(--color-bg); }
  html[data-theme="dark"] .login-atouts .ico { background: var(--color-surface); }

  /* Champs natifs (dates, listes) et contenus éditables */
  html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea {
    background-color: var(--color-surface); color: var(--ink-900); border-color: var(--ink-300);
  }
  html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: var(--ink-400); }
  html[data-theme="dark"] option { background-color: var(--color-surface); color: var(--ink-900); }

  /* SweetAlert */
  html[data-theme="dark"] .swal2-popup { background: var(--color-surface); color: var(--color-text); }
  html[data-theme="dark"] .swal2-title { color: var(--ink-900); }
  html[data-theme="dark"] .swal2-html-container { color: var(--ink-600); }
  html[data-theme="dark"] .swal2-input, html[data-theme="dark"] .swal2-textarea, html[data-theme="dark"] .swal2-select {
    background: var(--color-surface); color: var(--ink-900); border-color: var(--ink-300);
  }

  /* Tableaux : lignes paires et survol lisibles */
  html[data-theme="dark"] .table thead, html[data-theme="dark"] .table th { background: var(--ink-100); }
  html[data-theme="dark"] tbody tr.bg-gray-50, html[data-theme="dark"] tr.bg-white { background-color: var(--color-surface); }

  /* Cartes et images : éviter les éblouissements */
  html[data-theme="dark"] img:not([src*="logo"]) { filter: brightness(.92); }
  html[data-theme="dark"] .kpi-accent { background: linear-gradient(135deg, rgb(0 153 73), rgb(0 110 52)); }
}

/* ---------- Interrupteur de thème (barre supérieure) ---------- */
.theme-switch {
  position: relative; display: inline-flex; align-items: center; justify-content: space-between;
  width: 60px; height: 32px; padding: 0 7px; flex-shrink: 0;
  border: 1px solid var(--ink-200); border-radius: 999px; background: var(--ink-100);
  color: var(--ink-400); cursor: pointer; transition: background-color .2s ease, border-color .2s ease;
}
.theme-switch .ico { width: 15px; height: 15px; position: relative; z-index: 1; transition: color .2s ease; }
.theme-switch-knob {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--color-surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s ease;
}
.theme-switch .theme-soleil { color: var(--amber-500); }
.theme-switch[aria-checked="true"] .theme-switch-knob { transform: translateX(28px); }
.theme-switch[aria-checked="true"] .theme-soleil { color: var(--ink-400); }
.theme-switch[aria-checked="true"] .theme-lune { color: var(--brand-400); }
.theme-switch:hover { border-color: var(--ink-300); }
