/**
 * Product List Page (PLP) Styles
 *
 * @package Flaman_Storefront
 */

/* =====================================================
   PLP Header (inside toolbar, left-aligned)
   ===================================================== */

.plp-header {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-sm);
    min-width: calc(280px + var(--spacing-lg));
    flex-shrink: 0;
}

.plp-header-title {
    font-family: var(--font-primary);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--flaman-headings);
    margin: 0;
    line-height: 1.3;
    white-space: nowrap;
}

.plp-header-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* =====================================================
   PLP Layout
   ===================================================== */

.flaman-plp {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--spacing-2xl);
    margin: 0 0 var(--spacing-xl);
    width: 100%;
    max-width: 100%;
}

/* =====================================================
   Sidebar & Filters
   ===================================================== */

.plp-sidebar {
    position: sticky;
    top: calc(var(--spacing-xl) + 150px);
    align-self: start;
    height: fit-content;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.plp-sidebar .sidebar-section {
    margin-bottom: 0;
    border-radius: 7px;
}

.plp-sidebar .price-filter input[type="number"] {
    border-radius: 7px;
}

/* Price Filter */
.price-filter {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.price-filter input[type="number"] {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-family: var(--font-primary);
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--background);
    color: var(--flaman-headings);
}

.price-filter input[type="number"]:focus {
    outline: none;
    border-color: var(--flaman-red);
}

.price-filter span {
    color: var(--text-secondary);
    font-size: 14px;
}

.price-filter .apply-price-filter {
    width: 100%;
    margin-top: var(--spacing-xs);
}

/* Filter Checkbox (Brands, etc.) */
.filter-checkbox {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) 0;
}

.filter-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--flaman-red);
    flex-shrink: 0;
}

.filter-checkbox label {
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--flaman-headings);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.filter-checkbox label:hover {
    color: var(--flaman-red);
}

.filter-checkbox .count {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 12px;
}

/* Filter Actions */
.filter-actions {
    padding: var(--spacing-md) var(--spacing-lg);
}

.clear-filters {
    width: 100%;
}

/* Mobile Filter Drawer Header */
.filter-drawer-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--flaman-blue);
    color: var(--background);
    font-family: var(--font-primary);
    font-weight: 600;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.filter-drawer-close {
    background: none;
    border: none;
    color: var(--background);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-drawer-close:hover {
    opacity: 0.8;
}

/* =====================================================
   Product List Content
   ===================================================== */

.plp-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-self: start;
}

/* Toolbar — title + controls on one line */
.plp-toolbar {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
}

.plp-toolbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.plp-toolbar-controls .plp-sort {
    margin-left: 0;
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: 6px;
}

.view-toggle button {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    border: 1px solid #DBE1E5;
    border-radius: 7px;
    cursor: pointer;
    color: #DBE1E5;
    transition: all var(--transition-fast);
    padding: 0;
}

.view-toggle button:hover {
    border-color: #C4161C;
    color: #C4161C;
}

.view-toggle button.active {
    color: #C4161C;
    border-color: #DBE1E5;
    background: var(--background);
}

.view-toggle svg {
    display: block;
}

/* In Stock Toggle */
.plp-stock-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    margin-left: auto;
}

.plp-stock-toggle input {
    display: none;
}

.plp-stock-toggle__slider {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--flaman-secondary-3);
    border-radius: 10px;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.plp-stock-toggle__slider::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.plp-stock-toggle input:checked + .plp-stock-toggle__slider {
    background: var(--flaman-red);
}

.plp-stock-toggle input:checked + .plp-stock-toggle__slider::after {
    transform: translateX(16px);
}

.plp-stock-toggle__label {
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 600;
    color: var(--flaman-headings);
    white-space: nowrap;
}

/* Sorting */
.plp-sort .flaman-select__native {
    padding: 0 32px 0 14px !important;
    font-size: 16px; /* Prevents Chrome mobile auto-zoom on focus */
}

.plp-sort-icon {
    display: none;
}

/* Products Wrapper */
.products-wrapper {
    min-height: 400px;
    width: 100%;
    max-width: 100%;
    overflow: visible;
}

.products-wrapper[data-view="grid"] .products {
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    max-width: 100%;
}

.products-wrapper[data-view="list"] .products {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
}

/* Loading State */
.products-wrapper.loading {
    opacity: 0.5;
    pointer-events: none;
}

.loading-spinner {
    text-align: center;
    padding: var(--spacing-2xl);
}

.loading-spinner:after {
    content: "";
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* No Products Found */
.plp-content:has(.no-products-found) {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
}

.no-products-found {
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-lg);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.no-products-found__title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--flaman-headings);
    margin: 0 0 8px;
}

.no-products-found__message {
    font-size: var(--text-sm);
    max-width: 420px;
    margin: 0 0 24px;
    line-height: 1.6;
}

.no-products-found__btn {
    display: inline-block;
    padding: 10px 24px;
    font-size: var(--text-sm);
    font-weight: 600;
    border-radius: 8px;
    text-decoration: none;
}

/* =====================================================
   Mobile Filter Toggle
   ===================================================== */

.mobile-filter-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    background: var(--background);
    color: var(--flaman-headings);
    border: 1px solid #DBE1E5;
    border-radius: 7px;
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    margin-right: auto;
}

.mobile-filter-toggle:hover {
    border-color: #C4161C;
    color: #C4161C;
}

.mobile-filter-toggle svg {
    flex-shrink: 0;
}

/* =====================================================
   Active Filters Display (inline in toolbar)
   ===================================================== */

.active-filters {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.active-filters.has-filters {
    display: flex;
}

/* Active filters inside sidebar drawer on mobile */
.plp-sidebar .active-filters {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.active-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 36px;
    padding: 0 12px;
    background: var(--flaman-red);
    color: #fff;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.active-filter-tag button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 0 0 0 2px;
    font-size: 14px;
    line-height: 1;
    transition: color var(--transition-fast);
}

.active-filter-tag button:hover {
    color: #fff;
}

/* =====================================================
   Responsive Design
   ===================================================== */

@media (max-width: 1024px) {
    .plp-toolbar {
        gap: var(--spacing-md);
    }

    .flaman-plp {
        grid-template-columns: 240px 1fr;
        gap: var(--spacing-lg);
    }

    .products-wrapper[data-view="grid"] .products {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Stock toggle: hide label at smaller widths */
    .plp-stock-toggle__label {
        display: none;
    }

    /* Sort: collapse to icon-only button */
    .plp-sort.flaman-select {
        width: 36px;
        height: 36px;
        padding: 0;
        justify-content: center;
        overflow: hidden;
    }

    .plp-sort-icon {
        display: block;
        flex-shrink: 0;
        pointer-events: none;
    }

    .plp-sort .flaman-select__native {
        position: absolute;
        top: 0;
        right: 0;
        width: 220px !important;
        height: 100% !important;
        opacity: 0;
        cursor: pointer;
        padding: 0 32px 0 14px !important;
        background-image: none !important;
    }
}

@media (max-width: 768px) {
    .plp-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .plp-header {
        width: 100%;
    }

    .active-filters,
    .active-filters.has-filters {
        display: none;
    }

    .plp-sidebar .active-filters.has-filters {
        display: flex;
    }

    .plp-stock-toggle__label {
        display: inline;
    }

    .plp-toolbar-controls {
        width: 100%;
    }

    .flaman-plp {
        grid-template-columns: 1fr;
    }

    .plp-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        overflow-y: auto;
        z-index: 1000;
        transition: left var(--transition-base);
        background: var(--background);
        box-shadow: var(--shadow-lg);
    }

    .plp-sidebar.open {
        left: 0;
    }

    .filter-drawer-header {
        display: flex;
    }

    .plp-sidebar .sidebar-section {
        margin-bottom: 0;
        border: none;
        border-radius: 0;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-filter-toggle {
        display: flex;
    }

    .view-toggle {
        display: none;
    }

    .filter-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .filter-overlay.active {
        display: block;
    }

    .products-wrapper[data-view="grid"] .products {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .plp-sidebar {
        width: 90%;
    }
}
