/* Lot 5.3 - Dark mode polish (UX 2026-05-13)
   Corrections ciblees sur les pages qui ne respectent pas correctement le
   `body.theme-dark` (zones avec couleurs hardcodees dans le HTML ou JS).

   Strategie : selectors specifiques sous `body.theme-dark` qui forcent les
   bonnes couleurs sur les zones identifiees comme cassees :
   - Modales / overlays a fond blanc fige
   - Tables avec background hardcoded #fff
   - Inputs / textareas
   - Boutons outline (texte invisible en dark)
   - Tooltips / popovers
   - Code blocks et pre
   - SVG icones (stroke / fill)
   - Alertes / notifications (warning, success, danger)
   - Smart folders et widgets dashboard avec couleurs cles
*/

/* ============================================================ */
/* Modales : background blanc force a la couleur du theme       */
/* ============================================================ */
body.theme-dark .modal,
body.theme-dark .modal-overlay .modal,
body.theme-dark .modal-content,
body.theme-dark .drive-modal,
body.theme-dark .gdrive-config-modal {
  background: var(--bg-card, #1f2937) !important;
  color: var(--text, #f3f4f6);
  border-color: var(--border, #374151);
}

body.theme-dark .modal-header,
body.theme-dark .modal-footer {
  background: var(--bg-card, #1f2937);
  border-color: var(--border, #374151);
}

body.theme-dark .modal-close {
  color: var(--text-light, #9ca3af);
}

body.theme-dark .modal-overlay {
  background: rgba(0, 0, 0, 0.7) !important;
}

/* ============================================================ */
/* Tableaux : fond blanc force                                   */
/* ============================================================ */
body.theme-dark table,
body.theme-dark thead,
body.theme-dark tbody,
body.theme-dark th,
body.theme-dark td {
  background: transparent !important;
  color: var(--text, #f3f4f6);
}

body.theme-dark table thead tr,
body.theme-dark th[style*="background:#f"],
body.theme-dark th[style*="background: #f"] {
  background: rgba(255, 255, 255, 0.04) !important;
  color: var(--text-light, #d1d5db) !important;
  border-bottom: 2px solid var(--border, #374151);
}

body.theme-dark tbody tr {
  border-bottom: 1px solid var(--border, #374151);
}

body.theme-dark tbody tr:hover,
body.theme-dark tbody tr[style*="background:#f9fafb"]:hover {
  background: rgba(255, 255, 255, 0.05) !important;
}

/* ============================================================ */
/* Inputs / textareas / selects                                  */
/* ============================================================ */
body.theme-dark input[type="text"],
body.theme-dark input[type="number"],
body.theme-dark input[type="date"],
body.theme-dark input[type="email"],
body.theme-dark input[type="password"],
body.theme-dark input[type="search"],
body.theme-dark textarea,
body.theme-dark select {
  background: var(--bg-input, #1a1f2e) !important;
  color: var(--text, #f3f4f6) !important;
  border-color: var(--border, #374151) !important;
}

body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder {
  color: var(--text-light, #6b7280) !important;
}

body.theme-dark input:focus,
body.theme-dark textarea:focus,
body.theme-dark select:focus {
  border-color: var(--accent, #4f9cff) !important;
  outline: 2px solid rgba(79, 156, 255, 0.2);
}

/* ============================================================ */
/* Boutons outline : texte invisible en dark                     */
/* ============================================================ */
body.theme-dark .btn-outline {
  color: var(--text, #f3f4f6) !important;
  border-color: var(--border, #374151) !important;
  background: transparent;
}

body.theme-dark .btn-outline:hover {
  background: rgba(255, 255, 255, 0.05) !important;
  border-color: var(--accent, #4f9cff) !important;
}

body.theme-dark .btn-ghost {
  color: var(--text-light, #d1d5db);
}

/* ============================================================ */
/* Alertes (warning/success/danger) : fonds clairs trop blancs   */
/* ============================================================ */
body.theme-dark .alert-warning,
body.theme-dark [style*="background:#fef3c7"],
body.theme-dark [style*="background: #fef3c7"] {
  background: rgba(254, 243, 199, 0.15) !important;
  color: #fcd34d !important;
}

body.theme-dark .alert-success,
body.theme-dark [style*="background:#d1fae5"],
body.theme-dark [style*="background: #d1fae5"] {
  background: rgba(16, 185, 129, 0.15) !important;
  color: #6ee7b7 !important;
}

body.theme-dark .alert-danger,
body.theme-dark [style*="background:#fee2e2"],
body.theme-dark [style*="background: #fee2e2"] {
  background: rgba(239, 68, 68, 0.15) !important;
  color: #fca5a5 !important;
}

body.theme-dark .alert-info,
body.theme-dark [style*="background:#dbeafe"],
body.theme-dark [style*="background: #dbeafe"] {
  background: rgba(59, 130, 246, 0.15) !important;
  color: #93c5fd !important;
}

/* ============================================================ */
/* Smart folders + widgets dashboard avec couleurs hardcoded     */
/* ============================================================ */
body.theme-dark .sf-section,
body.theme-dark [style*="background:#f3f4f6"],
body.theme-dark [style*="background: #f3f4f6"] {
  background: var(--bg-card, #1f2937) !important;
  color: var(--text, #f3f4f6);
}

body.theme-dark [style*="background:#f9fafb"],
body.theme-dark [style*="background: #f9fafb"] {
  background: rgba(255, 255, 255, 0.02) !important;
}

/* ============================================================ */
/* Tooltips / popovers                                           */
/* ============================================================ */
body.theme-dark .tooltip,
body.theme-dark [data-tip]:hover::after {
  background: var(--bg-card, #1f2937) !important;
  color: var(--text, #f3f4f6) !important;
  border: 1px solid var(--border, #374151);
}

/* ============================================================ */
/* Code blocks et pre (apercu de contenu doc)                    */
/* ============================================================ */
body.theme-dark code,
body.theme-dark pre {
  background: rgba(255, 255, 255, 0.06) !important;
  color: #e5e7eb !important;
  border: 1px solid var(--border, #374151);
}

body.theme-dark pre {
  padding: 8px 12px;
  border-radius: 4px;
}

/* ============================================================ */
/* SVG icones : invertir stroke si force #000 / #1a1a1a          */
/* ============================================================ */
body.theme-dark svg[stroke="#000"],
body.theme-dark svg[stroke="#1a1a1a"],
body.theme-dark svg[stroke="#1a2744"] {
  stroke: var(--text, #f3f4f6);
}

body.theme-dark .nav-item svg {
  stroke: currentColor;
}

/* ============================================================ */
/* Badges : ajuster contraste                                    */
/* ============================================================ */
body.theme-dark .badge,
body.theme-dark span[style*="background:#fef3c7"] {
  filter: brightness(1.1);
}

/* ============================================================ */
/* Cartes / containers avec fond clair hardcoded                 */
/* ============================================================ */
body.theme-dark [style*="background:#fff"],
body.theme-dark [style*="background: #fff"],
body.theme-dark [style*="background:#ffffff"],
body.theme-dark [style*="background: #ffffff"] {
  background: var(--bg-card, #1f2937) !important;
  color: var(--text, #f3f4f6);
}

/* ============================================================ */
/* Onboarding tour - bulle reste lisible en dark                 */
/* ============================================================ */
body.theme-dark .gd-onb-bubble {
  background: var(--bg-card, #1f2937) !important;
  color: var(--text, #f3f4f6) !important;
  border: 1px solid var(--accent, #4f9cff);
}

/* ============================================================ */
/* Drive modal et pages admin                                    */
/* ============================================================ */
body.theme-dark #gdrive-files-list,
body.theme-dark #aw-list,
body.theme-dark #as-list,
body.theme-dark .aw-list,
body.theme-dark .as-list {
  color: var(--text, #f3f4f6);
}

/* Bordures et separateurs */
body.theme-dark hr,
body.theme-dark [style*="border-bottom:1px solid var(--border)"],
body.theme-dark [style*="border:1px solid var(--border)"] {
  border-color: var(--border, #374151) !important;
}

/* ============================================================ */
/* Bouton qw-pin (sidebar primary) reste accent en dark          */
/* ============================================================ */
body.theme-dark .qw-pin-primary {
  background: rgba(79, 156, 255, 0.15) !important;
  color: var(--accent, #4f9cff) !important;
}

/* ============================================================ */
/* prefers-reduced-motion respect                                 */
/* ============================================================ */
@media (prefers-reduced-motion: reduce) {
  body.theme-dark * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
