/* ==========================================================================
   Page Produits (views/products/index.php)
   Feuille de style propre à la liste : les pages de détail ne la chargent pas.
   Le squelette de la page (grille sidebar + produits, hauteur de viewport
   fixe, encart promo) reste dans products-fixed-layout.css.

   Sommaire
     1. Utilitaires d'affichage mobile / bureau
     2. Cartes produit
     3. Tri bureau
     4. Colonne de filtres
     5. États : chargement, vide, erreur
     6. Pagination
     7. Barre d'actions mobile
     8. Tiroir de tri mobile
   ========================================================================== */


/* 1. Utilitaires d'affichage
   -------------------------------------------------------------------------- */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex !important;
    }

    .desktop-only {
        display: none !important;
    }
}


/* 2. Cartes produit
   L'action (panier) est une icône compacte posée sur l'image :
   la carte reste basse tout en gardant son action accessible.
   -------------------------------------------------------------------------- */
.product-card {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Image à ratio constant : hauteur de carte homogène quelle que soit la
   taille du visuel d'origine (évite les grilles en dents de scie). */
.product-card-image {
    position: relative;
    aspect-ratio: 4 / 5;
    overflow: hidden;
}

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

.product-card-body {
    padding: 0.6rem 0.7rem 0.7rem;
}

.product-card-body .product-name {
    display: -webkit-box;
    margin: 0.15rem 0 0.2rem;
    overflow: hidden;
    font-size: 0.9rem;
    line-height: 1.3;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.product-card-body .product-category {
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* Barre d'actions : calquée sur la zone de l'image (même ratio 4/5 que
   `.product-card-image`). Le panier est en bas à gauche de l'image. Au-dessus des badges produit (z-index 10) pour rester
   cliquable ; seuls les boutons captent le clic. */
.product-card-actions {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    aspect-ratio: 4 / 5;
    padding: 0.45rem;
    box-sizing: border-box;
    z-index: 15;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    pointer-events: none;
}

.product-card-actions > .product-card-cart {
    align-self: flex-end;
}

.product-card-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.14);
    color: #334155;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.product-card-action:hover {
    transform: scale(1.1);
}

.product-card-action:focus-visible {
    outline: 2px solid var(--primary-color, #d6336c);
    outline-offset: 2px;
}

.product-card-cart:hover {
    background: var(--primary-color, #d6336c);
    color: #fff;
}

[data-theme="dark"] .product-card-action {
    border-color: rgba(148, 163, 184, 0.25);
    background: rgba(30, 41, 59, 0.94);
    color: #e2e8f0;
}


/* 3. Tri bureau
   -------------------------------------------------------------------------- */
.products-sort {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.products-sort .sort-select {
    min-width: 150px;
}

.products-sort .btn {
    white-space: nowrap;
}

@media (min-width: 769px) {
    .products-sort {
        display: flex !important;
    }
}


/* 4. Colonne de filtres
   -------------------------------------------------------------------------- */

/* En-tête : visible aussi sur bureau, où il sert de titre au bloc. */
.products-sidebar-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.products-sidebar-title {
    color: var(--text-primary, #1a1a1a);
    font-size: 0.95rem;
    font-weight: 700;
}

.filters-close {
    display: none;
}

@media (max-width: 1024px) {
    .filters-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

.sidebar-reset-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.price-range-inputs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

.price-input {
    flex: 1;
    min-width: 0;
}

.price-range-separator,
.price-range-unit {
    color: var(--text-light, #9ca3af);
}

.price-range-unit {
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Tiroir de filtres mobile : boutons pleine largeur, libellé visible. Dans un
   tiroir plein écran, deux boutons réduits à une icône ne se distingueraient
   plus l'un de l'autre. */
@media (max-width: 768px) {
    .mobile-filter-btn,
    .sidebar-reset-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
        min-width: auto;
        padding: 0.75rem 1rem;
    }

    .mobile-filter-btn .filter-btn-text,
    .sidebar-reset-btn .filter-btn-text {
        display: inline;
    }

    .mobile-filter-btn svg,
    .sidebar-reset-btn svg {
        flex-shrink: 0;
        margin: 0;
    }
}


/* 5. États : chargement (squelette), vide, erreur
   -------------------------------------------------------------------------- */
.product-grid.is-loading {
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.product-card-skeleton {
    overflow: hidden;
    padding-bottom: 0.7rem;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
}

.product-card-skeleton .skeleton-image,
.product-card-skeleton .skeleton-line {
    background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%);
    background-size: 400% 100%;
    animation: products-skeleton 1.3s ease-in-out infinite;
}

.product-card-skeleton .skeleton-image {
    width: 100%;
    aspect-ratio: 4 / 5;
}

.product-card-skeleton .skeleton-line {
    height: 0.7rem;
    margin: 0.5rem 0.7rem 0;
    border-radius: 4px;
}

.product-card-skeleton .skeleton-line-sm {
    width: 40%;
}

.product-card-skeleton .skeleton-line-md {
    width: 60%;
}

@keyframes products-skeleton {
    0% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0 50%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .product-card-skeleton .skeleton-image,
    .product-card-skeleton .skeleton-line {
        animation: none;
    }
}

.products-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 3rem 1.5rem;
    color: var(--text-secondary, #64748b);
    text-align: center;
}

.products-state svg {
    margin-bottom: 0.25rem;
    opacity: 0.45;
}

.products-state h3 {
    margin: 0;
    color: var(--text-primary, #1f2937);
    font-size: 1.05rem;
}

.products-state p {
    margin: 0 0 0.5rem;
    font-size: 0.88rem;
}

.products-state-error svg {
    color: #dc2626;
    opacity: 0.7;
}


/* 6. Pagination
   Rendue en CSS, de façon identique pour le HTML initial (PHP) et pour le
   rendu AJAX : rien n'est injecté en JavaScript.
   -------------------------------------------------------------------------- */
.pagination-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.pagination .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.6rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #374151);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.pagination .page-link:hover:not(.active) {
    border-color: var(--primary-color, #d6336c);
    color: var(--primary-color, #d6336c);
}

.pagination .page-link.active {
    border-color: var(--primary-color, #d6336c);
    background: var(--primary-color, #d6336c);
    color: #fff;
    cursor: default;
}

.pagination .page-link svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.pagination .page-ellipsis {
    padding: 0 0.25rem;
    color: var(--text-secondary, #94a3b8);
}

.per-page-selector {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-left: auto;
    color: var(--text-secondary, #64748b);
    font-size: 0.83rem;
}

.per-page-selector select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 7px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #374151);
    font-size: 0.83rem;
    cursor: pointer;
}


/* 7. Barre d'actions mobile (Filtres / Trier)
   Sans elle, les filtres seraient inaccessibles sur téléphone. Masquée sur
   bureau par .mobile-only.
   -------------------------------------------------------------------------- */
.products-mobile-actions {
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-secondary, #f8fafc);
}

.products-mobile-actions button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 40px;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #374151);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.products-mobile-actions button:hover {
    background: var(--primary-color, #d6336c);
    color: #fff;
    transform: scale(1.03);
}

.products-mobile-actions button:active {
    transform: scale(0.97);
}


/* 8. Tiroir de tri mobile
   Panneau latéral glissant depuis la gauche, sous le header (jeton
   --site-header-height mesuré par le layout). Il porte `.mobile-only`, qui
   force `display: flex` sous 768px : d'où la direction en colonne.
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .mobile-sort-dropdown {
        position: fixed;
        top: var(--site-header-height, var(--header-height, 73px));
        left: -100%;
        z-index: 1000;
        flex-direction: column;
        width: min(320px, 88vw);
        max-width: 88vw;
        height: calc(100dvh - var(--site-header-height, var(--header-height, 73px)));
        overflow-y: auto;
        border-radius: 0 12px 12px 0;
        background: linear-gradient(to bottom, var(--bg-primary, #fff), var(--bg-secondary, #f8fafc));
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        backdrop-filter: blur(10px);
        transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-sort-dropdown.active {
        left: 0;
    }

    .mobile-sort-dropdown-content {
        position: relative;
        flex: 1 1 auto;
        min-width: 0;
        padding: 1.5rem 1.5rem 1rem;
    }

    .mobile-sort-dropdown-header {
        position: sticky;
        top: 0;
        z-index: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
        border-bottom: 2px solid var(--border-color, #e2e8f0);
        background: inherit;
    }

    .mobile-sort-dropdown h4 {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin: 0;
        color: var(--text-primary, #1e293b);
        font-size: 1.1rem;
        font-weight: 700;
    }

    .mobile-sort-dropdown h4::before {
        content: '📊';
        font-size: 1.2rem;
    }

    .mobile-sort-close {
        display: flex;
        flex-shrink: 0;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border: none;
        border-radius: 50%;
        background: var(--bg-secondary, #f8fafc);
        color: var(--text-secondary, #64748b);
        cursor: pointer;
        transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
    }

    .mobile-sort-close:hover {
        background: var(--primary-color, #d6336c);
        color: #fff;
        transform: scale(1.1);
    }

    .mobile-sort-options-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Option de tri : un filet de couleur apparaît à gauche au survol et sur
       l'option active. Le jeton primaire (et non l'accent) porte l'état actif :
       le texte blanc y reste lisible quelle que soit la palette. */
    .mobile-sort-option {
        position: relative;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        padding: 0.75rem;
        overflow: hidden;
        border: 2px solid var(--border-color, #e2e8f0);
        border-radius: 10px;
        background: var(--bg-primary, #fff);
        color: var(--text-primary, #1e293b);
        font-size: 0.9rem;
        font-weight: 500;
        text-align: left;
        cursor: pointer;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-sort-option::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 4px;
        height: 100%;
        background: var(--primary-color, #d6336c);
        transform: scaleY(0);
        transition: transform 0.3s ease;
    }

    .mobile-sort-option:hover {
        border-color: var(--primary-color, #d6336c);
        background: linear-gradient(135deg, var(--bg-primary, #fff), var(--bg-secondary, #f8fafc));
        box-shadow: 0 4px 15px color-mix(in srgb, var(--primary-color, #d6336c) 20%, transparent);
        transform: translateX(4px) scale(1.02);
    }

    .mobile-sort-option:hover::before {
        transform: scaleY(1);
    }

    .mobile-sort-option:active {
        transform: translateX(2px) scale(1);
    }

    .mobile-sort-option.active {
        border-color: var(--primary-color, #d6336c);
        background: linear-gradient(135deg, var(--primary-color, #d6336c), var(--primary-color-dark, #b32558));
        box-shadow: 0 6px 20px color-mix(in srgb, var(--primary-color, #d6336c) 40%, transparent);
        color: #fff;
        transform: translateX(2px);
    }

    .mobile-sort-option.active::before {
        background: #fff;
        transform: scaleY(1);
    }

    .mobile-sort-option svg {
        flex-shrink: 0;
        width: 18px;
        height: 18px;
        color: var(--primary-color, #d6336c);
        transition: all 0.3s ease;
    }

    .mobile-sort-option:hover svg {
        transform: scale(1.2) rotate(-5deg);
    }

    .mobile-sort-option.active svg {
        color: #fff;
        transform: scale(1.1);
    }

    .mobile-sort-option-text {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .mobile-sort-option-title {
        font-size: 0.95rem;
        font-weight: 600;
    }

    .mobile-sort-option-desc {
        font-size: 0.8rem;
        font-weight: 400;
        opacity: 0.7;
    }

    .mobile-sort-option.active .mobile-sort-option-desc {
        color: #fff;
        opacity: 0.9;
    }

    /* Fond assombri derrière le tiroir : invisible et inerte tant que le
       tiroir n'est pas ouvert. */
    .sort-overlay {
        position: fixed;
        inset: 0;
        z-index: 999;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sort-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}
