/*
 * Espace client (tableau de bord, commandes, téléchargements, profil, détails) :
 * mode sombre « noir pur ». Chargée en dernier dans <head>, elle ne s'applique
 * que si le système est en sombre et prend le pas sur les styles de chaque page.
 */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --cd-bg: #000000;
        --cd-surface: #0b0b0b;
        --cd-raised: #151515;
        --cd-hover: #1f1f1f;
        --cd-border: #2a2a2a;
        --cd-border-strong: #3a3a3a;
        --cd-text: #f5f5f5;
        --cd-text-2: #d4d4d4;
        --cd-muted: #a3a3a3;

        /* Variables propres aux pages (tableau de bord, profil, détails…).
           --white / --gray-50 / --gray-100 servent aussi de couleur de texte : on ne les remappe pas. */
        --gray-200: var(--cd-border);
        --gray-300: var(--cd-border-strong);
        --gray-500: var(--cd-muted);
        --gray-600: var(--cd-muted);
        --gray-800: var(--cd-text-2);
        --gray-900: var(--cd-text);
        --bg-primary: var(--cd-bg);
        --bg-secondary: var(--cd-surface);
        --bg-tertiary: var(--cd-raised);
        --text-primary: var(--cd-text);
        --text-secondary: var(--cd-text-2);
        --text-muted: var(--cd-muted);
        --border-color: var(--cd-border);
        --glass-bg: var(--cd-surface);
        --glass-border: var(--cd-border);
        --primary-50: rgba(129, 128, 255, 0.14);
        --primary-100: rgba(129, 128, 255, 0.2);
    }

    /* ---------- Fond et texte de base ---------- */
    html,
    html body {
        background: var(--cd-bg) !important;
        background-image: none !important;
        color: var(--cd-text);
    }

    html .gradient-bg { background: var(--cd-bg) !important; }

    /* Pendant la correction initiale (client-dark.js) : couleurs appliquées sans animation */
    html.edx-dark-fixing *,
    html.edx-dark-fixing *::before,
    html.edx-dark-fixing *::after { transition: none !important; }

    /* ---------- Surfaces (cartes, barres, menus, modales) ---------- */
    html .glass,
    html .glass-dark,
    html .glass-card,
    html .section-header,
    html .header-container,
    html .mobile-nav,
    html .search-suggestions,
    html .empty-state,
    html nav,
    html header,
    html .bg-white,
    html .bg-white\/90,
    html .bg-white\/95,
    html .bg-gray-50,
    html .bg-slate-50,
    html .bg-gray-900,
    html .bg-slate-900,
    html .dark\:bg-gray-800,
    html .dark\:bg-gray-800\/90,
    html .dark\:bg-gray-800\/50,
    html .dark\:bg-gray-900,
    html .dark\:bg-slate-800,
    html .dark\:bg-slate-900 {
        background-color: var(--cd-surface) !important;
        background-image: none !important;
        border-color: var(--cd-border) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        box-shadow: none !important;
    }

    html .bg-gray-100,
    html .bg-gray-200,
    html .bg-slate-100,
    html .bg-slate-200,
    html .bg-gray-50\/50,
    html .bg-gray-800,
    html .bg-slate-800,
    html .dark\:bg-gray-700,
    html .dark\:bg-gray-700\/50,
    html .dark\:bg-slate-700,
    html .dark\:bg-gray-600 {
        background-color: var(--cd-raised) !important;
        background-image: none !important;
    }

    html .empty-state { border: 2px dashed var(--cd-border-strong) !important; }

    html .order-card:hover,
    html .search-suggestion-item:hover,
    html .hover\:bg-gray-50:hover,
    html .hover\:bg-gray-100:hover,
    html .dark\:hover\:bg-gray-700:hover,
    html .dark\:hover\:bg-gray-600:hover {
        background-color: var(--cd-hover) !important;
        box-shadow: 0 0 0 1px var(--cd-border-strong) !important;
    }

    html .mobile-overlay,
    html .modal-backdrop { background: rgba(0, 0, 0, 0.8) !important; }

    /* Bordures */
    html [class*="border-gray-"],
    html [class*="border-slate-"],
    html [class*="divide-gray-"] > * + *,
    html .border,
    html hr {
        border-color: var(--cd-border) !important;
    }

    /* ---------- Texte ---------- */
    html .text-gray-900, html .text-gray-800, html .text-gray-700,
    html .text-slate-900, html .text-slate-800, html .text-slate-700,
    html .text-blue-900, html .text-indigo-900, html .text-purple-900,
    html .dark\:text-white, html .dark\:text-gray-100, html .dark\:text-gray-200,
    html h1, html h2, html h3, html h4 {
        color: var(--cd-text) !important;
    }

    html .text-gray-600, html .text-gray-500,
    html .text-slate-600, html .text-slate-500,
    html .dark\:text-gray-300 {
        color: var(--cd-text-2) !important;
    }

    html .text-gray-400, html .text-slate-400,
    html .dark\:text-gray-400, html .dark\:text-gray-500 {
        color: var(--cd-muted) !important;
    }

    /* Textes colorés éclaircis pour rester lisibles sur noir (contraste AA) */
    html .text-blue-500, html .text-blue-600, html .text-blue-700, html .text-blue-800,
    html .text-primary, html .text-primary-500, html .text-primary-600 { color: #7cb4ff !important; }
    html .text-indigo-500, html .text-indigo-600, html .text-indigo-700 { color: #a5b4fc !important; }
    html .text-purple-500, html .text-purple-600, html .text-purple-700,
    html .text-violet-600 { color: #d0a8ff !important; }
    html .text-pink-500, html .text-pink-600, html .text-rose-800 { color: #f9a8d4 !important; }
    html .text-green-500, html .text-green-600, html .text-green-700, html .text-green-800,
    html .text-emerald-600, html .text-emerald-700, html .text-emerald-800, html .text-emerald-900,
    html .text-teal-600, html .text-teal-700 { color: #4ade80 !important; }
    html .text-red-500, html .text-red-600, html .text-red-700, html .text-red-800 { color: #fca5a5 !important; }
    html .text-yellow-600, html .text-yellow-800,
    html .text-amber-500, html .text-amber-600, html .text-amber-700, html .text-amber-800, html .text-amber-900,
    html .text-orange-500, html .text-orange-600, html .text-orange-800 { color: #fcd34d !important; }

    /* ---------- Pastilles et encadrés teintés (fonds clair -50/-100) ---------- */
    html .bg-blue-50, html .bg-blue-100, html .bg-indigo-50, html .bg-indigo-100,
    html .bg-primary-50, html .bg-primary-100,
    html .dark\:bg-blue-900\/20, html .dark\:bg-blue-900\/30, html .dark\:bg-indigo-900\/20 {
        background-color: rgba(59, 130, 246, 0.16) !important;
        border-color: rgba(96, 165, 250, 0.35) !important;
    }
    html .bg-green-50, html .bg-green-100, html .bg-emerald-50, html .bg-emerald-100, html .bg-teal-100,
    html .dark\:bg-green-900\/20, html .dark\:bg-emerald-900\/20, html .dark\:bg-teal-900\/20 {
        background-color: rgba(34, 197, 94, 0.15) !important;
        border-color: rgba(74, 222, 128, 0.35) !important;
    }
    html .bg-red-50, html .bg-red-100, html .bg-rose-50,
    html .dark\:bg-red-900\/20, html .dark\:bg-rose-900\/20 {
        background-color: rgba(239, 68, 68, 0.16) !important;
        border-color: rgba(248, 113, 113, 0.35) !important;
    }
    html .bg-yellow-50, html .bg-yellow-100, html .bg-amber-50, html .bg-amber-100,
    html .bg-orange-100, html .dark\:bg-yellow-900\/20, html .dark\:bg-amber-900\/20,
    html .dark\:bg-orange-900\/20 {
        background-color: rgba(245, 158, 11, 0.16) !important;
        border-color: rgba(252, 211, 77, 0.35) !important;
    }
    html .bg-purple-50, html .bg-purple-100, html .bg-violet-100, html .bg-pink-100,
    html .dark\:bg-purple-900\/20, html .dark\:bg-pink-900\/20 {
        background-color: rgba(168, 85, 247, 0.16) !important;
        border-color: rgba(216, 180, 254, 0.35) !important;
    }
    html [class*="border-blue-1"], html [class*="border-blue-2"], html [class*="border-indigo-"],
    html [class*="border-pink-"], html [class*="border-purple-"] { border-color: rgba(129, 140, 248, 0.35) !important; }
    html [class*="border-green-"], html [class*="border-emerald-"], html [class*="border-teal-"] { border-color: rgba(74, 222, 128, 0.35) !important; }
    html [class*="border-yellow-"], html [class*="border-amber-"] { border-color: rgba(252, 211, 77, 0.35) !important; }
    html [class*="border-red-"], html [class*="border-rose-"] { border-color: rgba(248, 113, 113, 0.4) !important; }

    /* Le texte dans les encadrés teintés reste clair */
    html .text-green-200, html .text-emerald-200, html .dark\:text-green-200, html .dark\:text-green-400 { color: #86efac !important; }
    html .text-yellow-200, html .text-amber-200, html .dark\:text-yellow-200, html .dark\:text-yellow-400 { color: #fde68a !important; }
    html .text-red-200, html .dark\:text-red-400 { color: #fca5a5 !important; }

    /* Dégradés pastel (from-*-50 → to-*-50) : on les neutralise */
    html .from-blue-50, html .from-blue-100, html .from-amber-50, html .from-violet-50,
    html .from-pink-50, html .from-indigo-50, html .from-emerald-50, html .from-purple-50 {
        background-image: none !important;
        background-color: var(--cd-surface) !important;
    }

    /* ---------- Boutons : couleurs pleines, texte blanc, focus visible ---------- */
    html .bg-blue-500, html .bg-blue-600, html .bg-blue-700 { background-color: #2563eb !important; color: #fff !important; }
    html .bg-indigo-600, html .bg-indigo-700, html .bg-primary, html .bg-primary-500 { background-color: #5b5bf0 !important; color: #fff !important; }
    html .bg-purple-600, html .bg-purple-700 { background-color: #9333ea !important; color: #fff !important; }
    html .bg-green-500, html .bg-green-600, html .bg-green-700, html .bg-emerald-500 { background-color: #15803d !important; color: #fff !important; }
    html .bg-red-500, html .bg-red-600 { background-color: #dc2626 !important; color: #fff !important; }
    html .bg-yellow-500, html .bg-yellow-600, html .bg-yellow-700,
    html .bg-amber-500, html .bg-orange-500, html .bg-orange-600 { background-color: #f59e0b !important; color: #000 !important; }
    html .bg-pink-600, html .bg-pink-700 { background-color: #db2777 !important; color: #fff !important; }
    html .bg-teal-700, html .bg-teal-800 { background-color: #0f766e !important; color: #fff !important; }
    html .bg-gray-500, html .bg-gray-600, html .bg-gray-700 { background-color: #3f3f46 !important; color: #fff !important; }

    html a[class*="bg-"]:hover,
    html button[class*="bg-"]:hover { filter: brightness(1.15); }

    html button:focus-visible,
    html a:focus-visible,
    html input:focus-visible,
    html select:focus-visible,
    html textarea:focus-visible {
        outline: 2px solid #7cb4ff !important;
        outline-offset: 2px;
    }

    /* Boutons « secondaires » clairs (bg-gray-100 text-gray-700…) */
    html button.bg-gray-100, html a.bg-gray-100,
    html button.bg-gray-200, html a.bg-gray-200,
    html button.bg-white, html a.bg-white {
        background-color: var(--cd-raised) !important;
        color: var(--cd-text) !important;
        border: 1px solid var(--cd-border-strong) !important;
    }

    /* ---------- Formulaires ---------- */
    html input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    html select,
    html textarea {
        background-color: var(--cd-surface) !important;
        color: var(--cd-text) !important;
        border-color: var(--cd-border-strong) !important;
    }
    html input::placeholder,
    html textarea::placeholder { color: #8a8a8a !important; }

    /* ---------- Éléments propres aux pages ---------- */
    /* Menus burger : fond noir, textes blancs (les icônes gardent leur couleur) */
    html .mobile-nav,
    html #mobileNav,
    html #mobileMenu { background: #000 !important; border-color: var(--cd-border) !important; }
    html .mobile-nav a,
    html .mobile-nav button,
    html .mobile-nav span,
    html #mobileNav a,
    html #mobileNav span,
    html #mobileMenu a,
    html #mobileMenu span,
    html .mobile-nav-item { color: #fff !important; }
    html .mobile-nav a:hover,
    html #mobileNav a:hover,
    html #mobileMenu a:hover,
    html .mobile-nav-item:hover { background: var(--cd-hover) !important; }
    html .edx-update-notice-close { background: var(--cd-raised) !important; color: #fff !important; border: 1px solid var(--cd-border-strong) !important; }

    /* Mes téléchargements : cartes mobiles forcées en blanc par la page */
    html .mobile-download-card,
    html .mobile-grid-card {
        background: var(--cd-surface) !important;
        border-color: var(--cd-border) !important;
        box-shadow: none !important;
    }
    html .mobile-card-meta { color: var(--cd-muted) !important; }
    html .mobile-card-progress { background: var(--cd-border-strong) !important; }

    /* Tableau de bord : surfaces et liens définis via var(--white) / var(--primary-color) */
    html .main-container { background: var(--cd-bg) !important; }
    html .stat-card,
    html .section-card,
    html .notification,
    html .modal:not(.fixed) { background: var(--cd-surface) !important; box-shadow: none !important; }
    html .download-item,
    html .order-item { background: var(--cd-raised) !important; }
    html .download-item:hover,
    html .order-item:hover,
    html .modal-close { background: var(--cd-hover) !important; }
    html .logo-text p, html .mobile-menu-btn, html .section-link, html .empty-action,
    html .notification-icon, html .modal-icon, html .stat-icon.blue { color: #7cb4ff !important; }
    html .btn-success { background: #15803d !important; color: #fff !important; }

    html .type-badge { background: var(--cd-raised) !important; color: var(--cd-text) !important; border: 1px solid var(--cd-border-strong); }
    html .stat-icon { background: var(--cd-raised) !important; }
    html .status-active, html .status-paid { background: rgba(34, 197, 94, 0.16) !important; color: #86efac !important; }
    html .status-expired, html .status-rejected { background: rgba(239, 68, 68, 0.16) !important; color: #fca5a5 !important; }
    html .status-pending, html .status-exhausted { background: rgba(245, 158, 11, 0.16) !important; color: #fde68a !important; }

    /* Les bandeaux en dégradé vif gardent leur couleur et un texte blanc */
    html [class*="bg-gradient-to-"][class*="from-blue-5"],
    html [class*="bg-gradient-to-"][class*="from-blue-6"],
    html [class*="bg-gradient-to-"][class*="from-purple-"],
    html [class*="bg-gradient-to-"][class*="from-green-"],
    html [class*="bg-gradient-to-"][class*="from-emerald-5"],
    html [class*="bg-gradient-to-"][class*="from-indigo-5"],
    html [class*="bg-gradient-to-"][class*="from-pink-5"],
    html [class*="bg-gradient-to-"][class*="from-red-5"],
    html [class*="bg-gradient-to-"][class*="from-amber-"] {
        color: #fff;
    }

    html .shadow, html .shadow-sm, html .shadow-md, html .shadow-lg, html .shadow-xl,
    html .shadow-glass { box-shadow: none !important; }
}
