/**
 * Styles pour la modal de filtres avancés et la barre d'outils de filtres/tri
 */

/* Barre d'outils de filtres et tri */
.filters-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.filters-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Bouton de filtres avancés */
.btn-advanced-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: #f0f0f0;
    border: 2px solid transparent;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #555;
}

.btn-advanced-filters:hover {
    background-color: #e5e5e5;
    color: #333;
}

/* État actif quand des filtres sont sélectionnés */
.btn-advanced-filters.has-filters {
    background-color: rgba(255, 107, 107, 0.15);
    border-color: var(--primary-color, #FF6B6B);
    color: var(--primary-color, #FF6B6B);
}

.btn-advanced-filters.has-filters .filter-icon {
    fill: var(--primary-color, #FF6B6B);
}

.btn-advanced-filters .filters-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: white !important;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    min-width: 25px;
    height: 25px;
    opacity: 0;
    transition: opacity 0.3s ease;
    line-height: 1;
}

.btn-advanced-filters .filters-count.visible {
    opacity: 1 !important;
}

/* Compteur de résultats */
#results-counter {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Conteneur du sélecteur de tri */
.sort-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sort-label {
    font-weight: 500;
    color: var(--text-color);
    font-size: 0.95rem;
}

.sort-select {
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background-color: white;
    color: var(--text-color);
    font-size: 0.95rem;
    min-width: 160px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 35px;
}

.sort-select:hover {
    border-color: #d0d0d0;
}

.sort-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(255, 60, 60, 0.1);
}

/* Mode sombre pour la barre d'outils */
.dark-mode .btn-advanced-filters {
    background-color: #3a4550;
    color: #bbb;
}

.dark-mode .btn-advanced-filters:hover {
    background-color: #4a5560;
    color: #fff;
}

.dark-mode .btn-advanced-filters.has-filters {
    background-color: rgba(255, 107, 107, 0.2);
    border-color: var(--primary-color, #FF6B6B);
    color: var(--primary-color, #FF6B6B);
}


.dark-mode #results-counter {
    color: var(--primary-color-light, #ff6b6b);
}

.dark-mode .sort-label {
    color: #f0f0f0;
}

.dark-mode .sort-select {
    background-color: #2a2a2a;
    border-color: #444;
    color: #f0f0f0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23f0f0f0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

.dark-mode .sort-select:hover {
    border-color: #555;
}

.dark-mode .sort-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(255, 60, 60, 0.2);
}

/* Modal - Centrée avec taille limitée */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    height: 85vh;
    max-height: 85vh;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow: hidden;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: relative;
}

.modal-overlay {
    display: none;
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: block;
    opacity: 1;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.modal-title-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
    padding-top: 15px;
}

.modal-title {
    margin: 0;
    font-size: 1.4rem;
    color: var(--text-color);
    position: relative;
    padding-bottom: 10px; /* Espace pour le trait rouge */
}

/* Le ::after est défini dans commun.css via l'harmonisation des H2 */
/* On s'assure juste qu'il est bien visible dans la modale */
.modal-header .modal-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 50px;
    height: 3px;
    background-color: var(--primary-color, #FF6B6B);
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: #888;
    transition: color 0.2s;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal:hover {
    color: #000;
    background-color: #f0f0f0;
}

.modal-body {
    padding: 20px;
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0; /* Important pour que le flex fonctionne correctement */
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
    background-color: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
    flex-shrink: 0;
}

.btn-apply-filters, .btn-reset-filters {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-apply-filters {
    background-color: var(--primary-color);
    color: white;
    border: none;
    min-width: 80px;
}

.btn-apply-filters:hover {
    background-color: var(--primary-color-dark, #e83c3c);
}

.btn-reset-filters {
    background-color: transparent;
    color: var(--text-color);
    border: 1px solid #e0e0e0;
}

.btn-reset-filters:hover {
    background-color: #f0f0f0;
}

/* Style des filtres à l'intérieur de la modal */
.modal .filters-container {
    overflow: hidden;
    margin: 0 0 20px 0;
    border: 1px solid #eee !important;
    border-radius: var(--border-radius);
}

.modal .filters-container:last-child {
    margin-bottom: 0;
}

.modal .filters-header {
    background-color: #f9f9f9;
    border-bottom: 1px solid #eee;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Compteur de filtres actifs dans chaque section */
.modal .filters-count {
    display: none; /* Masqué par défaut */
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 50%;
    min-width: 25px;
    height: 25px;
    line-height: 1;
}

/* Afficher uniquement quand il contient du texte (non vide) */
.modal .filters-count:not(:empty) {
    display: inline-flex;
}

.modal .filters-body {
    padding: 15px;
}

/* Style uniforme pour tous les boutons de filtres */
.modal .filter-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    margin: 5px;
    border-radius: 25px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background-color: #3a3a3a;
    color: #f0f0f0;
    pointer-events: auto;
    user-select: none;
}

.modal .filter-button:hover {
    background-color: #4a4a4a;
    transform: none;
}

/* État actif/sélectionné */
.modal .filter-button.active {
    background-color: #ff6b6b !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

.modal .filter-button.active:hover {
    background-color: #ff5252 !important;
}

/* Conteneur de boutons unifié - s'applique à tous les types de filtres */
.modal .filters-body > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Icônes dans les boutons d'allergènes - masquées dans la modal */
.modal .allergen-button svg {
    width: 0;
    height: 0;
    display: none;
    pointer-events: none; /* Les SVG ne doivent pas intercepter les clics */
}

/* Étoiles pour les notes */
.modal .star-icon {
    color: #ffc107;
    margin-right: 4px;
}

/* Mode sombre pour la modal */
.dark-mode .modal {
    background-color: #222;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.dark-mode .modal-footer {
    background-color: #222;
    border-top-color: #444;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.dark-mode .modal .filter-button {
    background-color: #3a3a3a;
    color: #f0f0f0;
}

.dark-mode .modal .filter-button:hover {
    background-color: #4a4a4a;
}

.dark-mode .modal .filter-button.active {
    background-color: #ff6b6b !important;
    color: white !important;
}

.dark-mode .modal-header, .dark-mode .modal-footer {
    border-color: #333;
}

.dark-mode .modal-title {
    color: #f0f0f0;
}

.dark-mode .close-modal {
    color: #aaa;
}

.dark-mode .close-modal:hover {
    color: #f0f0f0;
    background-color: #333;
}

.dark-mode .btn-reset-filters {
    color: #f0f0f0;
    border-color: #444;
}

.dark-mode .btn-reset-filters:hover {
    background-color: #333;
}

.dark-mode .modal .filters-container {
    border: 1px solid #444 !important;
}

.dark-mode .modal .filters-header {
    background-color: #2a2a2a !important;
    border-color: #333;
}

/* Responsive - Pour ingredient.php, ustensile.php et categories.php */
@media (min-width: 321px) and (max-width: 480px) {
    /* Disposition en 2 lignes - identique à categories.php */
    /* Note: categories.php a ses propres règles dans page-categories-recettes.css qui écrasent celles-ci */
    /* Ces règles s'appliquent donc principalement à ingredient.php et ustensile.php */

    body:not(.categories-recettes-page) .filters-toolbar,
    .ingredient-recettes-section .filters-toolbar,
    .ustensile-recettes-section .filters-toolbar {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        align-items: center !important;
        padding: 0px !important;
        margin-bottom: 10px !important;
    }

    body:not(.categories-recettes-page) .filters-left,
    .ingredient-recettes-section .filters-left,
    .ustensile-recettes-section .filters-left {
        flex: 0 0 100% !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 8px !important;
        order: 0 !important;
    }

    /* Ligne 1 : Compteur de résultats seul */
    #results-counter {
        font-weight: 700 !important;
        order: -1 !important;
        margin-bottom: 8px !important;
    }

    /* Ligne 2 gauche : Bouton filtres */
    body:not(.categories-recettes-page) .filters-left .btn-advanced-filters,
    .ingredient-recettes-section .filters-left .btn-advanced-filters,
    .ustensile-recettes-section .filters-left .btn-advanced-filters {
        flex: 0 0 auto !important;
        order: 0 !important;
        padding: 6px 10px !important;
        font-size: 0.85rem !important;
    }

    /* Ligne 2 droite : Tri */
    body:not(.categories-recettes-page) .sort-container,
    .ingredient-recettes-section .sort-container,
    .ustensile-recettes-section .sort-container {
        flex: 1 1 auto !important;
        order: 1 !important;
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        margin-top: -42px !important;
        max-width: calc(100% - 120px) !important;
        margin-left: auto !important;
        gap: 0px !important;
        position: relative !important;
        bottom: 6px !important;
    }

    body:not(.categories-recettes-page) .sort-controls,
    .ingredient-recettes-section .sort-controls,
    .ustensile-recettes-section .sort-controls {
        display: flex !important;
        gap: 0px !important;
        max-width: 100% !important;
    }

    body:not(.categories-recettes-page) .sort-select,
    .ingredient-recettes-section .sort-select,
    .ustensile-recettes-section .sort-select {
        min-width: 0 !important;
        max-width: 160px !important;
        width: 100% !important;
        font-size: 0.85rem !important;
        padding: 0 28px 0 8px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 10px center !important;
        background-size: 10px 10px !important;
    }

    body:not(.categories-recettes-page) .sort-direction-btn,
    .ingredient-recettes-section .sort-direction-btn,
    .ustensile-recettes-section .sort-direction-btn {
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }

    body:not(.categories-recettes-page) .btn-advanced-filters,
    .ingredient-recettes-section .btn-advanced-filters,
    .ustensile-recettes-section .btn-advanced-filters {
        font-size: 0.85rem !important;
    }

    /* Mode sombre : Triangle blanc pour le select */
    .dark-mode body:not(.categories-recettes-page) .sort-select,
    .dark-mode .ingredient-recettes-section .sort-select,
    .dark-mode .ustensile-recettes-section .sort-select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%23f0f0f0' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
        background-size: 10px 10px !important;
    }

    .btn-apply-filters, .btn-reset-filters {
        flex: 1;
        text-align: center;
    }
}

@media (max-width: 320px) {
    .filters-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        padding: 0 5px;
        align-items: center;
        position: relative;
    }

    .filters-left {
        flex: 0 0 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 5px;
        order: 0;
    }

    .filters-left #results-counter {
        flex: 0 0 100%;
        font-weight: 700;
        order: -1;
        margin-bottom: 5px;
    }

    .filters-left .btn-advanced-filters {
        flex: 0 0 auto;
        order: 0;
        padding: 5px 8px !important;
        font-size: 0.8rem !important;
    }

    .sort-container {
        flex: 1 1 auto;
        order: 1;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        margin-top: -38px;
        max-width: calc(100% - 100px);
        margin-left: auto;
        gap: 0px !important;
        position: relative;
        bottom: 4px;
    }

    .sort-controls {
        display: flex;
        gap: 0px;
        max-width: 100%;
    }

    .sort-select {
        min-width: 0 !important;
        max-width: 130px !important;
        width: 100%;
        font-size: 0.8rem !important;
        padding: 0 24px 0 6px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sort-direction-btn {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        flex-shrink: 0;
    }
}

/* Override pour tablettes et grands mobiles */
@media (min-width: 481px) and (max-width: 768px) {
    .filters-toolbar {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    .filters-left {
        flex: 0 1 auto;
    }
    
    .sort-container {
        width: auto !important;
        flex: 0 0 auto;
    }
    
    .sort-select {
        flex-grow: 0 !important;
        /* min-width géré dans sort-width-fix.css */
    }
}

/* Pour s'assurer que le contenu scrolle correctement sur tous les navigateurs */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Optimisations tablettes */
@media (max-width: 768px) {
    .modal .filter-button {
        padding: 9px 16px;
        font-size: 0.9rem;
        margin: 4px;
    }
    
    .modal .filters-body {
        padding: 12px;
    }
}

/* Optimisations smartphones */
@media (max-width: 768px) {
    .modal {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
        position: fixed;
    }
    
    .modal-content {
        display: flex;
        flex-direction: column;
        height: 100vh;
        max-height: 100vh;
        position: relative;
    }
    
    .modal-header {
        padding: 12px 15px;
        position: relative;
        flex-shrink: 0;
        background-color: white;
        z-index: 11;
        border-bottom: 1px solid #eee;
    }
    
    .modal-title {
        font-size: 1.1rem;
    }
    
    .modal-body {
        flex: 1 1 auto;
        padding: 0 12px 30px 12px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        /* Important : ne pas utiliser de padding-bottom trop grand */
        min-height: 0; /* Nécessaire pour Firefox */
    }
    
    .modal-footer {
        position: relative; /* Changé de absolute à relative */
        bottom: auto;
        left: 0;
        right: 0;
        display: flex;
        justify-content: center;
        gap: 15px;
        padding: 12px 15px;
        border-top: 1px solid #eee;
        background-color: white;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        z-index: 10;
        flex-shrink: 0; /* Empêche le footer de se réduire */
    }
    
    .modal .filter-button {
        padding: 8px 14px;
        font-size: 0.85rem;
        margin: 3px;
    }
    
    .modal .filters-container {
        margin-bottom: 15px;
    }
    
    .btn-apply-filters, .btn-reset-filters {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    /* Amélioration de l'ergonomie tactile */
    .close-modal {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }
}

/* Ajustement pour iOS Safari et navigateurs mobiles */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .modal {
            height: 100vh;
            height: -webkit-fill-available; /* Pour iOS Safari */
        }
        
        .modal-content {
            height: 100vh;
            height: -webkit-fill-available;
        }
        
        .modal-footer {
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }
    }
}

/* Mode sombre pour tablettes et écrans moyens */
@media (max-width: 768px) {
    .dark-mode .modal-header {
        background-color: #222 !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    }

    .dark-mode .modal-footer {
        background-color: #222;
        box-shadow: 0 -2px 4px rgba(0,0,0,0.3);
    }
}

/* Ajustements supplémentaires pour petits écrans */
@media (max-width: 480px) {
    .modal-header {
        padding: 10px 12px;
    }

    .modal-title {
        font-size: 1rem;
    }
    
    .modal-body {
        padding: 10px;
    }
    
    .modal-footer {
        padding: 10px 12px;
        gap: 10px;
    }
    
    .btn-apply-filters, .btn-reset-filters {
        flex: 1;
        padding: 12px 15px;
        font-size: 0.95rem;
        min-width: 0; /* Permet aux boutons de se réduire si nécessaire */
    }
    
    /* Amélioration de l'ergonomie tactile */
    .close-modal {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }
    
    .modal .filter-button {
        padding: 8px 14px;
        font-size: 0.85rem;
        margin: 3px;
    }
    
    .modal .filters-container {
        margin-bottom: 15px;
    }
}

/* Mode sombre pour mobile */
@media (max-width: 480px) {
    .dark-mode .modal-header,
    .dark-mode .modal-footer {
        background-color: #222;
    }

    .dark-mode .modal-header {
        box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    }

    .dark-mode .modal-footer {
        box-shadow: 0 -2px 4px rgba(0,0,0,0.3);
    }
}

/* ============================================
   ACCORDÉON MOBILE (≤480px)
   ============================================ */

/* Bouton accordéon - Masqué par défaut sur desktop */
.modal .accordion-toggle {
    display: none;
    background-color: #f9f9f9; /* Même couleur que .filters-header */
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-color);
    transition: transform 0.3s ease;
    min-width: 32px;
    min-height: 32px;
    z-index: 10;
}

.modal .accordion-toggle svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* Afficher le bouton accordéon uniquement sur mobile ET si nécessaire */
@media (max-width: 480px) {
    .modal .accordion-toggle {
        display: none; /* Masqué par défaut */
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        /* background hérite de la règle globale (#f9f9f9 ou #2a2a2a en dark mode) */
        border: none;
        padding: 8px;
        cursor: pointer;
        color: var(--text-color);
        transition: transform 0.3s ease;
        min-width: 32px;
        min-height: 32px;
    }

    /* Afficher le bouton uniquement si la classe .has-overflow est présente */
    .modal .filters-container.has-overflow .accordion-toggle {
        display: inline-flex !important;
    }

    /* Transition douce pour la rotation de la flèche (ouverture ET fermeture) */
    .modal .accordion-toggle {
        transition: transform 0.4s ease;
    }

    /* Rotation de la flèche quand ouvert */
    .modal .filters-container.expanded .accordion-toggle {
        transform: rotate(180deg);
    }

    /* État par défaut des filtres avec overflow : fermé (2 lignes complètes) */
    .modal .filters-container.has-overflow .filters-body {
        max-height: 127px !important; /* Aligné sur la hauteur de "Note moyenne" (127px) */
        overflow: hidden !important;
        transition: max-height 0.5s ease;
    }

    /* Quand le filtre est étendu, afficher tout */
    .modal .filters-container.has-overflow.expanded .filters-body {
        max-height: 3000px !important;
        overflow: visible !important;
        transition: max-height 0.5s ease;
    }

    /* Espacement du header avec le bouton accordéon */
    .modal .filters-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
        flex-wrap: nowrap !important;
    }

    .modal .filters-header .filters-title {
        flex: 1 1 auto !important;
    }

    .modal .filters-header .filters-count {
        flex: 0 0 auto !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* S'assurer que les conteneurs de boutons utilisent flexbox */
    .modal .filters-body > div {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* Uniformiser tous les boutons de filtres */
    .modal .filter-button {
        height: auto !important;
        min-height: 40px !important;
        padding: 10px 18px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }

    /* Désactiver les effets hover sur mobile pour éviter les bugs */
    .modal .filter-button:hover {
        background-color: #3a3a3a !important;
        transform: none !important;
    }

    .modal .filter-button.active:hover {
        background-color: #ff6b6b !important;
        transform: none !important;
    }

    .dark-mode .modal .filter-button:hover {
        background-color: #4a4a4a !important;
        transform: none !important;
    }

    .dark-mode .modal .filter-button.active:hover {
        background-color: #ff6b6b !important;
        transform: none !important;
    }
}

/* Mode sombre pour le bouton accordéon */
.dark-mode .modal .accordion-toggle {
    color: #fff;
    background-color: #2a2a2a !important; /* Même couleur que .filters-header en mode dark */
}

.dark-mode .modal .accordion-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* ============================================
   SOUS-MODALES DE FILTRES
   ============================================ */

.sub-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background-color, #fff);
    z-index: 10;
    overflow-y: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.sub-modal-header {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color, #ddd);
    position: sticky;
    top: 0;
    background: var(--background-color, #fff);
    z-index: 1;
}

.sub-modal-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--primary-color, #ff6b6b);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    transition: opacity 0.2s;
}

.sub-modal-back:hover {
    opacity: 0.7;
}

.sub-modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-color, #333);
}

.sub-modal-body {
    padding: 1rem;
}

/* Animation de la sous-modale */
.sub-modal.show {
    display: block !important;
    animation: slideInRight 0.3s ease;
}

.sub-modal.hide {
    animation: slideOutRight 0.3s ease;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Boutons de filtres temporels */
.time-filter-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.time-button {
    padding: 0.75rem 1rem;
    text-align: center;
}

/* Mode sombre */
.dark-mode .sub-modal {
    background: var(--dark-background, #1a1a1a);
}

.dark-mode .sub-modal-header {
    background: var(--dark-background, #1a1a1a);
    border-bottom-color: var(--dark-border, #333);
}

.dark-mode .sub-modal-title {
    color: var(--dark-text, #ecf0f1);
}
