/* Optimisation de l'affichage des produits sur mobile quand il y en a beaucoup */

/* ===== VARIABLES POUR MOBILE ===== */
:root {
    --mobile-card-height: 280px;
    --mobile-image-height: 160px;
    --mobile-card-padding: 0.75rem;
    --mobile-font-size-small: 0.8rem;
    --mobile-font-size-normal: 0.9rem;
    --mobile-button-height: 36px;
    --mobile-spacing: 0.5rem;
}

/* ===== OPTIMISATION GRILLE PRODUITS MOBILE ===== */
@media (max-width: 767.98px) {
    
    /* Réduire l'espacement entre les cartes */
    .row .col-12.mb-4,
    .row .col-sm-6.mb-4,
    .row .col-md-6.mb-4,
    .row .col-lg-4.mb-4 {
        margin-bottom: var(--mobile-spacing) !important;
    }
    
    /* Optimiser les cartes de produits */
    .product-card {
        height: var(--mobile-card-height);
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .product-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    /* Optimiser les images */
    .product-card .card-img-top {
        height: var(--mobile-image-height) !important;
        object-fit: cover;
        object-position: center;
    }
    
    .product-card .image-placeholder {
        height: var(--mobile-image-height) !important;
        font-size: 1.5rem;
    }
    
    /* Optimiser le contenu des cartes */
    .product-card .card-body {
        padding: var(--mobile-card-padding);
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: calc(var(--mobile-card-height) - var(--mobile-image-height));
    }
    
    /* Optimiser les titres */
    .product-card .card-title {
        font-size: var(--mobile-font-size-normal);
        line-height: 1.2;
        margin-bottom: 0.25rem;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 2.4em; /* 2 lignes max */
    }
    
    /* Optimiser le texte de l'équipe */
    .product-card .card-text {
        font-size: var(--mobile-font-size-small);
        margin-bottom: 0.5rem;
        color: #6c757d;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Optimiser les prix */
    .product-card .price {
        font-size: 1rem;
        font-weight: 700;
        color: #28a745;
        margin-bottom: 0.5rem;
    }
    
    .product-card .price-old {
        font-size: 0.8rem;
        color: #6c757d;
        text-decoration: line-through;
    }
    
    /* Optimiser les boutons */
    .product-card .btn {
        font-size: var(--mobile-font-size-small);
        padding: 0.4rem 0.6rem;
        min-height: var(--mobile-button-height);
        border-radius: 6px;
    }
    
    .product-card .btn-group-vertical .btn {
        margin-bottom: 0.25rem;
    }
    
    /* Optimiser les badges de promotion */
    .product-card .badge-sale {
        top: 6px;
        right: 6px;
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
        border-radius: 4px;
    }
    
    /* ===== MODE LISTE COMPACTE POUR BEAUCOUP D'ARTICLES ===== */
    
    /* Bouton pour basculer entre grille et liste */
    .view-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1000;
        background: #007bff;
        color: white;
        border: none;
        border-radius: 50%;
        width: 50px;
        height: 50px;
        box-shadow: 0 4px 12px rgba(0,123,255,0.3);
        transition: all 0.3s ease;
    }
    
    .view-toggle:hover {
        background: #0056b3;
        transform: scale(1.1);
    }
    
    /* Mode liste compacte */
    .list-view .row {
        display: block !important;
    }
    
    .list-view .col-12,
    .list-view .col-sm-6,
    .list-view .col-md-6,
    .list-view .col-lg-4 {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
        flex: none !important;
    }
    
    .list-view .product-card {
        height: 80px !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
    }
    
    .list-view .product-card .card-img-top {
        width: 60px;
        height: 60px;
        object-fit: cover;
        border-radius: 6px;
        margin: 0.5rem;
    }
    
    .list-view .product-card .image-placeholder {
        width: 60px;
        height: 60px;
        font-size: 1rem;
        margin: 0.5rem;
    }
    
    .list-view .product-card .card-body {
        flex: 1;
        padding: 0.5rem;
        height: auto;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    
    .list-view .product-card .card-title {
        font-size: 0.85rem;
        margin-bottom: 0;
        -webkit-line-clamp: 1;
        height: auto;
        flex: 1;
        margin-right: 0.5rem;
    }
    
    .list-view .product-card .card-text {
        display: none;
    }
    
    .list-view .product-card .price {
        font-size: 0.9rem;
        margin-bottom: 0;
        margin-right: 0.5rem;
    }
    
    .list-view .product-card .btn {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
        min-height: 32px;
        min-width: 60px;
    }
    
    .list-view .product-card .btn-group-vertical {
        display: none;
    }
    
    /* ===== PAGINATION INFINIE POUR MOBILE ===== */
    
    .infinite-scroll-loading {
        text-align: center;
        padding: 2rem;
        color: #6c757d;
    }
    
    .infinite-scroll-loading .spinner-border {
        width: 2rem;
        height: 2rem;
    }
    
    /* ===== OPTIMISATION PERFORMANCE ===== */
    
    /* Lazy loading pour les images */
    .product-card img {
        loading: lazy;
    }
    
    /* Réduire les animations sur mobile pour les performances */
    .product-card {
        will-change: transform;
    }
    
    /* ===== AMÉLIORATION UX POUR BEAUCOUP D'ARTICLES ===== */
    
    /* Indicateur de position dans la liste */
    .scroll-indicator {
        position: fixed;
        top: 50%;
        right: 10px;
        transform: translateY(-50%);
        background: rgba(0,0,0,0.7);
        color: white;
        padding: 0.5rem;
        border-radius: 20px;
        font-size: 0.8rem;
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .scroll-indicator.show {
        opacity: 1;
    }
    
    /* Bouton retour en haut */
    .back-to-top {
        position: fixed;
        bottom: 80px;
        right: 20px;
        background: #28a745;
        color: white;
        border: none;
        border-radius: 50%;
        width: 45px;
        height: 45px;
        z-index: 1000;
        opacity: 0;
        transform: translateY(20px);
        transition: all 0.3s ease;
    }
    
    .back-to-top.show {
        opacity: 1;
        transform: translateY(0);
    }
    
    /* ===== OPTIMISATION FILTRES MOBILE ===== */
    
    .mobile-filters {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #dee2e6;
        padding: 1rem;
        z-index: 1000;
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }
    
    .mobile-filters.show {
        transform: translateY(0);
    }
    
    .mobile-filters .btn {
        margin: 0.25rem;
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    /* ===== OPTIMISATION RECHERCHE MOBILE ===== */
    
    .mobile-search {
        position: sticky;
        top: 0;
        background: white;
        padding: 0.5rem;
        border-bottom: 1px solid #dee2e6;
        z-index: 100;
    }
    
    .mobile-search .form-control {
        font-size: 1rem;
        padding: 0.75rem;
        border-radius: 25px;
    }
    
    /* ===== OPTIMISATION PERFORMANCE ===== */
    
    /* Réduire les reflows/repaints */
    .product-card * {
        backface-visibility: hidden;
        perspective: 1000px;
    }
    
    /* Optimiser les transitions */
    .product-card,
    .product-card * {
        transition: transform 0.2s ease, opacity 0.2s ease;
    }
}

/* ===== OPTIMISATION POUR TRÈS PETITS ÉCRANS ===== */
@media (max-width: 480px) {
    :root {
        --mobile-card-height: 260px;
        --mobile-image-height: 140px;
        --mobile-card-padding: 0.5rem;
        --mobile-font-size-small: 0.75rem;
        --mobile-font-size-normal: 0.85rem;
        --mobile-button-height: 32px;
    }
    
    .product-card .card-title {
        font-size: 0.8rem;
    }
    
    .product-card .price {
        font-size: 0.9rem;
    }
    
    .product-card .btn {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }
}

/* ===== MODE ÉCONOMIE D'ÉNERGIE ===== */
@media (prefers-reduced-motion: reduce) {
    .product-card,
    .product-card *,
    .view-toggle,
    .back-to-top,
    .scroll-indicator {
        transition: none !important;
        animation: none !important;
    }
}
