/**
 * E-commerce Mobile Optimizations
 * Grille 2 colonnes, badges, ajout rapide, swipe, bottom sheet
 * 
 * @package UMOA
 * @version 1.0
 */

/* ============================================================================
   GRILLE PRODUITS - 2 COLONNES MOBILE, 4 COLONNES DESKTOP
   ============================================================================ */

/* Grille standard pour produits/articles */
.product-grid,
.products-grid-modern,
.articles-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 colonnes sur mobile */
    gap: 12px;
    padding: 12px;
}

/* Tablette */
@media (min-width: 768px) and (max-width: 1023px) {
    .product-grid,
    .products-grid-modern,
    .articles-grid {
        grid-template-columns: repeat(3, 1fr); /* 3 colonnes sur tablette */
        gap: 16px;
        padding: 16px;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .product-grid,
    .products-grid-modern,
    .articles-grid {
        grid-template-columns: repeat(4, 1fr); /* 4 colonnes sur desktop */
        gap: 20px;
        padding: 20px;
    }
}

/* ============================================================================
   CARTE PRODUIT - STYLE MODERNE
   ============================================================================ */

.product-card,
.product-card-modern,
.article-card {
    background: white;
    border-radius: 12px; /* Capsules compactes */
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 420px; /* Hauteur maximale fixe pour uniformiser */
    height: 100%;
}

.product-card:active,
.product-card-modern:active,
.article-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Image produit avec ratio 1:1 */
.product-image,
.product-image-modern,
.article-image {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 240px;
    max-width: 100%;
    overflow: hidden;
    background: #f5f5f5;
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    border: none;
}

.product-image img,
.product-image-modern img,
.article-image img {
    width: 100%;
    height: 100%;
    max-height: 240px;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease;
    display: block;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    border: none;
    max-width: 100% !important;
    max-height: 100% !important;
}

/* ============================================================================
   DESKTOP OPTIMIZATIONS - Images produits avec ratio et contraintes
   ============================================================================ */

@media (min-width: 1024px) {
    /* Images produits - Respect du ratio et contraintes desktop */
    .product-image,
    .product-image-modern,
    .article-image {
        aspect-ratio: 1 / 1; /* Force le ratio carré */
        max-height: 400px; /* Limite la hauteur maximale sur desktop */
        max-width: 400px; /* Limite aussi la largeur pour maintenir le ratio */
        width: 100%;
    }
    
    /* S'assurer que les images dans les conteneurs produits respectent le ratio */
    .product-image img,
    .product-image-modern img,
    .article-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
        max-height: none;
        box-sizing: border-box;
        padding: 0;
        margin: 0;
        border: none;
        max-width: 100% !important;
    }
}

/* Lazy loading placeholder */
.product-image img[loading="lazy"],
.product-image-modern img[loading="lazy"],
.article-image img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================================================
   BADGES PROMOTION/STOCK
   ============================================================================ */

.product-badge,
.product-badge-modern,
.article-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 4px 6px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    z-index: 10;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    line-height: 1.2;
    display: inline-block;
    white-space: nowrap;
}

/* Badge promotion */
.badge-promo,
.badge-sale,
.badge-discount {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    color: white;
}

/* Badge nouveau */
.badge-new,
.badge-nouveau {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white;
}

/* Badge stock faible */
.badge-stock-low,
.badge-stock {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
}

/* Badge négociable */
.badge-negotiable,
.badge-negotiable-modern {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
    padding: 3px 5px;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.6), 0 0 20px rgba(16, 185, 129, 0.4);
    animation: badge-glow-negotiable 2s ease-in-out infinite alternate;
}

@keyframes badge-glow-negotiable {
    0% {
        box-shadow: 0 0 10px rgba(16, 185, 129, 0.6), 0 0 20px rgba(16, 185, 129, 0.4);
    }
    100% {
        box-shadow: 0 0 15px rgba(16, 185, 129, 0.8), 0 0 30px rgba(16, 185, 129, 0.6);
    }
}

/* Badge épuisé */
.badge-out-of-stock {
    background: linear-gradient(135deg, #6B7280 0%, #4B5563 100%);
    color: white;
}

/* Badge multiple - empiler */
.product-badges {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 10;
}

/* ============================================================================
   BOUTON AJOUT RAPIDE (STICKY)
   ============================================================================ */

.product-quick-add {
    display: none !important;
    visibility: hidden !important;
}

/* Bouton quick-add masqué - ne s'affiche plus */
.product-card:hover .product-quick-add,
.product-card-modern:hover .product-quick-add,
.article-card:hover .product-quick-add,
.product-card:active .product-quick-add,
.product-card-modern:active .product-quick-add,
.article-card:active .product-quick-add {
    display: none !important;
    visibility: hidden !important;
}

.product-quick-add:active {
    transform: scale(0.9);
    box-shadow: 0 2px 6px rgba(74, 144, 226, 0.3);
}

.product-quick-add svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}

/* Sur mobile, également masqué */
@media (max-width: 768px) {
    .product-quick-add {
        display: none !important;
        visibility: hidden !important;
    }
}

/* État loading */
.product-quick-add.loading {
    pointer-events: none;
    opacity: 0.6;
}

.product-quick-add.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* État succès */
.product-quick-add.success {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
}

.product-quick-add.success::after {
    content: '✓';
    position: absolute;
    font-size: 18px;
    font-weight: bold;
}

/* ============================================================================
   GALERIE SWIPE (MOBILE)
   ============================================================================ */

.product-image-swipe {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.product-image-swipe-container {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.product-image-swipe-slide {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    position: relative;
}

.product-image-swipe-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Indicateurs de pagination */
.product-image-swipe-indicators {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 12;
}

.product-image-swipe-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
}

.product-image-swipe-indicator.active {
    background: white;
    width: 20px;
    border-radius: 10px;
}

/* Compteur d'images */
.product-image-count {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    z-index: 12;
    backdrop-filter: blur(4px);
}

/* Desktop - Afficher miniatures */
@media (min-width: 769px) {
    .product-image-swipe {
        display: block;
    }
    
    .product-image-swipe-container {
        flex-direction: column;
    }
    
    .product-image-swipe-slide {
        flex: none;
    }
    
    .product-image-swipe-indicators {
        display: none;
    }
}

/* ============================================================================
   BOTTOM SHEET (FILTRAGE/TRI)
   ============================================================================ */

.filter-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 3000;
    max-height: 90vh;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.filter-bottom-sheet.active {
    transform: translateY(0);
}

.filter-bottom-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
}

.filter-bottom-sheet-overlay.active {
    opacity: 1;
    visibility: visible;
}

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

.filter-bottom-sheet-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #333;
}

.filter-bottom-sheet-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    border: none;
    background: #f5f5f5;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 10;
}

.filter-bottom-sheet-close:active {
    background: #e0e0e0;
    transform: scale(0.95);
}

.filter-bottom-sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
}

.filter-section {
    margin-bottom: 24px;
}

.filter-section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-color);
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-option {
    display: flex;
    align-items: center;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-option:active {
    background: #f9f9f9;
    transform: scale(0.98);
}

.filter-option input[type="checkbox"],
.filter-option input[type="radio"] {
    margin-right: 12px;
    width: 20px;
    height: 20px;
    accent-color: #4A90E2;
}

.filter-option label {
    flex: 1;
    cursor: pointer;
    font-size: 0.9375rem;
    color: #333;
}

.filter-bottom-sheet-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 12px;
    flex-shrink: 0;
    background: white;
}

.filter-bottom-sheet-footer .btn {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    font-weight: 600;
}

/* Bouton fixe Filtrer/Trier */
.filter-trigger-btn {
    position: fixed;
    bottom: calc(var(--mobile-bottom-height, 64px) + 16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4A90E2 0%, #1E3A8A 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(74, 144, 226, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2000;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.filter-trigger-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.filter-trigger-btn svg {
    width: 24px;
    height: 24px;
}

/* Badge sur le bouton */
.filter-trigger-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #EF4444;
    color: white;
    border-radius: 10px;
    min-width: 20px;
    height: 20px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid white;
}

/* Desktop - Masquer le bouton fixe */
@media (min-width: 769px) {
    .filter-trigger-btn {
        display: none;
    }
    
    .filter-bottom-sheet {
        display: none;
    }
}

/* ============================================================================
   INFO PRODUIT
   ============================================================================ */

.product-info,
.product-info-modern,
.article-info {
    padding: 8px; /* Réduit de 12px à 8px */
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Change de space-between à flex-start */
    gap: 1px; /* Réduit à 1px pour respecter la grille */
    min-height: 80px; /* Hauteur minimale pour garantir la visibilité des informations */
    overflow: visible;
}

.product-title,
.product-title-modern,
.article-info h3 {
    font-size: 0.875rem; /* 14px Desktop */
    font-weight: 600;
    color: #333;
    margin: 0;
    line-height: 1.3; /* Réduit l'interligne */
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limite à 2 lignes maximum */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 2.6em; /* Réduit la hauteur minimale */
    flex-shrink: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.product-price,
.product-price-modern,
.article-price {
    font-size: 1.125rem;
    font-weight: 700;
    color: #4A90E2;
    margin: 4px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

.product-price-old {
    font-size: 0.875rem;
    color: #999;
    text-decoration: line-through;
    margin-right: 8px;
}

.product-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: #999;
    margin-top: auto;
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 768px) {
    /* ============================================================
       MARKETPLACE PREMIUM - OPTIMISATIONS MOBILE
       ============================================================ */
    
    /* Cards plus compactes avec hauteur réduite (sauf page boutique où le contenu ne doit pas être coupé) */
    .product-card,
    .product-card-modern,
    .article-card {
        max-height: 380px; /* Hauteur réduite sur mobile */
        overflow: hidden; /* Empêche tout débordement */
    }
    .shop-container .product-card,
    .shop-content .product-card {
        max-height: none; /* Laisser la carte s'adapter au contenu (titre, prix, localisation visibles) */
    }
    
    /* Padding uniforme pour toutes les capsules */
    .product-info,
    .product-info-modern,
    .article-info {
        padding: 8px; /* Réduit de 10px à 8px */
        gap: 1px; /* Réduit à 1px pour respecter la grille */
        display: flex;
        flex-direction: column;
        flex: 1;
        justify-content: flex-start; /* Change de space-between à flex-start */
        min-height: 75px; /* Hauteur minimale pour garantir la visibilité */
        overflow: visible;
    }
    
    /* Titre avec limitation de hauteur pour éviter le débordement */
    .product-title,
    .product-title-modern,
    .article-info h3 {
        font-size: 0.75rem; /* 12px Mobile */
        line-height: 1.3; /* Réduit l'interligne */
        margin: 0;
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limite à 2 lignes maximum */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        min-height: 2.6em; /* Réduit la hauteur minimale */
        flex-shrink: 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
        hyphens: auto;
    }
    
    /* MASQUAGE INTELLIGENT - Éléments secondaires masqués sur mobile */
    .product-category,
    .product-category-modern,
    .product-description,
    .product-meta,
    .product-meta-modern,
    .article-category {
        display: none !important; /* Masque catégorie, description et métadonnées */
    }
    
    /* Marketplace moderne : garder catégorie + meta visibles comme sur desktop */
    .product-card-modern .product-category-modern,
    .product-card-modern .product-meta-modern {
        display: block !important;
    }
    .product-card-modern .product-meta-modern {
        display: flex !important;
    }
    
    /* Optimisation des prix - Une seule ligne */
    .product-price,
    .product-price-modern,
    .article-price {
        font-size: 0.9375rem; /* Taille réduite sur mobile (15px) */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0; /* Supprime toutes les marges */
        flex-shrink: 0;
        line-height: 1.1; /* Réduit l'interligne */
    }
    
    /* Prix avec promotion - Affichage compact */
    .price-with-discount {
        display: flex;
        flex-direction: row; /* Sur une seule ligne */
        align-items: baseline;
        gap: 6px;
        flex-wrap: nowrap;
        width: 100%;
        line-height: 1.2;
    }
    
    .price-original {
        font-size: 0.75rem; /* 12px - Plus petit pour le prix barré */
        color: #999;
        text-decoration: line-through;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .price-final {
        font-size: 0.9375rem; /* 15px - Prix final */
        font-weight: 700;
        color: #b12704;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
        min-width: 0;
    }
    
    .price-savings {
        display: none !important; /* Masque le texte d'économie sur mobile */
    }
    
    /* Optimisations pour les badges */
    .product-badge,
    .product-badge-modern,
    .article-badge {
        font-size: 10px;
        padding: 2px 5px;
        top: 8px;
        right: 8px;
    }
    
    .product-image img,
    .product-image-modern img,
    .article-image img {
        object-fit: cover;
        object-position: center;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        padding: 0;
        margin: 0;
        border: none;
        max-width: 100% !important;
        max-height: 100% !important;
    }
}

/* Très petits écrans */
@media (max-width: 480px) {
    .product-card,
    .product-card-modern,
    .article-card {
        max-height: 360px;
        overflow: hidden; /* Empêche tout débordement */
    }
    
    /* Padding uniforme réduit pour très petits écrans */
    .product-info,
    .product-info-modern,
    .article-info {
        padding: 6px; /* Réduit de 8px à 6px */
        gap: 2px; /* Réduit de 4px à 2px */
        min-height: 70px; /* Hauteur minimale pour garantir la visibilité sur mobile */
        overflow: visible;
        justify-content: flex-start; /* Évite les espaces vides */
    }
    
    .product-image,
    .product-image-modern,
    .article-image {
        max-height: 200px;
        box-sizing: border-box;
        padding: 0;
        margin: 0;
        border: none;
    }
    
    .product-image img,
    .product-image-modern img,
    .article-image img {
        max-height: 200px;
        object-fit: cover;
        object-position: center;
        box-sizing: border-box;
        padding: 0;
        margin: 0;
        border: none;
        max-width: 100% !important;
        max-height: 100% !important;
    }
    
    .product-title,
    .product-title-modern,
    .article-info h3 {
        font-size: 0.75rem; /* 12px */
        line-height: 1.25;
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limite à 2 lignes maximum */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        min-height: 2.8em; /* Hauteur fixe pour 2 lignes */
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
        hyphens: auto;
    }
    
    /* Éléments secondaires toujours masqués */
    .product-category,
    .product-category-modern,
    .product-description,
    .product-meta,
    .product-meta-modern,
    .article-category {
        display: none !important;
    }
    
    /* Marketplace moderne : garder catégorie + meta visibles (aligné desktop) */
    .product-card-modern .product-category-modern,
    .product-card-modern .product-meta-modern {
        display: block !important;
    }
    .product-card-modern .product-meta-modern {
        display: flex !important;
    }
    
    .product-price,
    .product-price-modern,
    .article-price {
        font-size: 0.875rem; /* 14px */
    }
    
    .price-with-discount .price-original {
        font-size: 0.6875rem; /* 11px */
    }
    
    .price-with-discount .price-final {
        font-size: 0.875rem; /* 14px */
    }
    
    .product-badge,
    .product-badge-modern,
    .article-badge {
        font-size: 9px;
        padding: 2px 4px;
    }
}

/* ============================================================================
   UTILITAIRES
   ============================================================================ */

/* Masquer sur desktop */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

/* Masquer sur mobile */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}

