/* =========================================
   FILTERS BAR - HORIZONTAL MOBILE LAYOUT
   Scroll horizontal pour gagner de la place
   ========================================= */

/* Desktop - Garde le layout existant */
@media (min-width: 769px) {
    .filters-bar {
        display: flex;
        align-items: center;
        gap: 20px;
        margin-bottom: 30px;
        padding: 20px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 2px 10px rgba(0,0,0,.1);
    }
    
    .filters-bar > .filter-label:first-child {
        font-weight: 600;
        color: var(--text);
        white-space: nowrap;
        margin-right: 10px;
    }
    
    .filter-group {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .filter-group label {
        margin: 0;
        font-weight: 500;
        color: var(--text);
        white-space: nowrap;
        font-size: 0.95rem;
    }
    
    .filter-group select {
        width: 100%;
        padding: 10px 12px;
        border: 2px solid #e0e0e0;
        border-radius: 5px;
        font-size: 1rem;
        height: 42px;
    }
}

/* ========== MOBILE (<768px) - LAYOUT HORIZONTAL AVEC SCROLL ========== */
@media (max-width: 768px) {
    /* Container principal avec scroll */
    .filters-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 20px;
        padding: 12px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,.08);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch; /* Smooth scroll iOS */
        scroll-behavior: smooth;
        position: relative;
        /* Empêche le wrap */
        flex-wrap: nowrap;
        white-space: nowrap;
    }
    
    /* Indicateur de scroll (gradient) à droite */
    .filters-bar::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to right, transparent, rgba(255,255,255,0.9));
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    /* Montre l'indicateur quand il y a du scroll possible */
    .filters-bar.has-scroll::after {
        opacity: 1;
    }
    
    /* Label "Filtrer par" compact */
    .filters-bar > .filter-label:first-child {
        font-weight: 600;
        color: var(--text);
        white-space: nowrap;
        margin-right: 8px;
        font-size: 0.9rem;
        flex-shrink: 0;
        padding-right: 8px;
        border-right: 2px solid #e0e0e0;
    }
    
    /* Chaque groupe de filtre en ligne */
    .filter-group {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0; /* Empêche la compression */
    }
    
    /* Labels compacts */
    .filter-group label {
        margin: 0;
        font-weight: 500;
        color: #666;
        font-size: 0.85rem;
        white-space: nowrap;
        display: none; /* On cache les labels pour gagner de la place */
    }
    
    /* Select boxes optimisées pour mobile */
    .filter-group select {
        min-width: 120px; /* Largeur minimum */
        max-width: 150px; /* Largeur maximum */
        padding: 10px 35px 10px 12px;
        border: 2px solid #e0e0e0;
        border-radius: 8px;
        font-size: 0.9rem;
        height: 40px;
        background: #fff;
        color: var(--text);
        flex-shrink: 0;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232c5530' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 8px center;
        background-size: 18px;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .filter-group select:focus {
        outline: none;
        border-color: #2c5530;
        box-shadow: 0 0 0 3px rgba(44, 85, 48, 0.1);
    }
    
    /* Option sélectionnée en gras */
    .filter-group select:not([value=""]) {
        font-weight: 600;
        background-color: #f0f7f4;
        border-color: #2c5530;
    }
    
    /* Style de la scrollbar */
    .filters-bar::-webkit-scrollbar {
        height: 4px;
    }
    
    .filters-bar::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 2px;
    }
    
    .filters-bar::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 2px;
    }
    
    .filters-bar::-webkit-scrollbar-thumb:hover {
        background: #a1a1a1;
    }
}

/* ========== TRÈS PETIT MOBILE (<480px) ========== */
@media (max-width: 480px) {
    .filters-bar {
        padding: 10px;
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .filters-bar > .filter-label:first-child {
        font-size: 0.85rem;
        padding-right: 6px;
        margin-right: 6px;
    }
    
    .filter-group select {
        min-width: 100px;
        max-width: 130px;
        height: 38px;
        padding: 8px 30px 8px 10px;
        font-size: 0.85rem;
        background-size: 16px;
        background-position: right 6px center;
    }
}

/* ========== INDICATEUR VISUEL DE SCROLL ========== */
@media (max-width: 768px) {
    /* Flèche animée pour indiquer le scroll */
    .filters-bar[data-scrollable="true"]::before {
        content: '→';
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        background: #2c5530;
        color: white;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: bold;
        z-index: 10;
        animation: pulseArrow 2s infinite;
        box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    }
    
    @keyframes pulseArrow {
        0%, 100% { 
            transform: translateY(-50%) translateX(0);
            opacity: 1;
        }
        50% { 
            transform: translateY(-50%) translateX(3px);
            opacity: 0.7;
        }
    }
    
    /* Cache la flèche quand on a scrollé jusqu'au bout */
    .filters-bar.scrolled-end[data-scrollable="true"]::before {
        display: none;
    }
}

/* ========== AMÉLIORATION UX ========== */
@media (max-width: 768px) {
    /* Zone de touch optimisée */
    .filter-group select {
        min-height: 44px; /* Taille minimum recommandée Apple */
    }
    
    /* Espacement entre les filtres */
    .filter-group + .filter-group {
        margin-left: 8px;
    }
    
    /* Premier select avec placeholder explicite */
    #category-filter option:first-child {
        color: #999;
    }
    
    #brand-filter option:first-child {
        color: #999;
    }
    
    #price-filter option:first-child {
        color: #999;
    }
}

/* ========== MODE PAYSAGE MOBILE ========== */
@media (max-width: 768px) and (orientation: landscape) {
    .filters-bar {
        padding: 8px;
    }
    
    .filter-group select {
        height: 36px;
        font-size: 0.85rem;
    }
}

/* ========== FALLBACK POUR NAVIGATEURS SANS SCROLL SMOOTH ========== */
@supports not (-webkit-overflow-scrolling: touch) {
    @media (max-width: 768px) {
        .filters-bar {
            overflow-x: scroll;
        }
    }
}

/* ========== JAVASCRIPT HELPER (à ajouter) ========== */
/* 
   Script JS à ajouter pour détecter si le scroll est nécessaire :
   
   document.addEventListener('DOMContentLoaded', function() {
       const filtersBar = document.querySelector('.filters-bar');
       if (filtersBar && window.innerWidth <= 768) {
           // Vérifie si le contenu déborde
           if (filtersBar.scrollWidth > filtersBar.clientWidth) {
               filtersBar.setAttribute('data-scrollable', 'true');
               filtersBar.classList.add('has-scroll');
               
               // Détecte quand on arrive au bout du scroll
               filtersBar.addEventListener('scroll', function() {
                   const maxScroll = this.scrollWidth - this.clientWidth;
                   if (this.scrollLeft >= maxScroll - 5) {
                       this.classList.add('scrolled-end');
                   } else {
                       this.classList.remove('scrolled-end');
                   }
               });
           }
       }
   });
*/