/**
 * Universal Smart Filter — Frontend Styles
 *
 * Mobile-first, page-builder agnostic.
 * Uses only .usf- prefixed classes to avoid conflicts.
 *
 * @package Universal_Smart_Filter
 * @since   1.0.0
 */

/* ==========================================================================
   # Wrapper — Universal Combined Container (backward compat)
   ========================================================================== */

.universal-smart-grid-wrapper {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    box-sizing: border-box;
}

/* ==========================================================================
   # Independent Filter Wrapper
   # Used when [usf_filters] is placed separately from [usf_product_grid].
   # Adapts to its parent container — works in sidebars, headers, full-width.
   ========================================================================== */

.usf-filter-buttons-wrapper {
    width: 100%;
    box-sizing: border-box;
}

/* ==========================================================================
   # Independent Grid Wrapper
   # Used when [usf_product_grid] is placed separately from [usf_filters].
   ========================================================================== */

.usf-product-grid-wrapper {
    width: 100%;
    box-sizing: border-box;
}

/* ==========================================================================
   # Filter Buttons — Mobile First
   # Default: horizontal wrap. Scrolls horizontally on overflow.
   ========================================================================== */

.usf-filter-buttons {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    margin-bottom: 24px;
    padding: 4px 0;
    list-style: none;
    scrollbar-width: thin;
}

/* Hide scrollbar on WebKit but keep functionality */
.usf-filter-buttons::-webkit-scrollbar {
    height: 4px;
}

.usf-filter-buttons::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* Vertical layout variant — add class .usf-vertical to .usf-filter-buttons-wrapper */
.usf-filter-buttons-wrapper.usf-vertical .usf-filter-buttons {
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-x: visible;
    overflow-y: auto;
    max-height: 80vh;
}

/* Horizontal wrap variant — add class .usf-wrap to .usf-filter-buttons-wrapper */
.usf-filter-buttons-wrapper.usf-wrap .usf-filter-buttons {
    flex-wrap: wrap;
    overflow-x: visible;
}

.usf-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    justify-content: center;
}

/* Buttons with category image — stack image above text */
.usf-filter-btn.usf-has-img {
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 5px 2px;
    white-space: normal;
    text-align: center;
}

/* Category thumbnail image inside filter button */
.usf-filter-img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 50%;
    display: block;
    flex-shrink: 0;
}

/* Filter label text (when image present) */
.usf-filter-label {
    font-size: 12px;
    line-height: 1.2;
}

/* Vertical layout: image + text side by side */
.usf-filter-buttons-wrapper.usf-vertical .usf-filter-btn.usf-has-img {
    flex-direction: column;
    text-align: center;
    gap: 4px;
    border-radius: 20px;
}

.usf-filter-btn:hover {
    border-color: #333;
    background: #f8f8f8;
    color: #111;
}

.usf-filter-btn:focus-visible {
    box-shadow: 0 0 0 2px #0073aa;
    border-color: #0073aa;
}

/* Active state */
.usf-filter-btn.usf-active {
    background: #333;
    border-color: #333;
    color: #fff;
}

.usf-filter-btn.usf-active:hover {
    background: #555;
    border-color: #555;
}

/* Product count badge */
.usf-count {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.7;
    display: none;
}

/* ==========================================================================
   # Product Grid — Responsive Columns
   ========================================================================== */

.usf-product-grid {
    position: relative;
    min-height: 200px;
    transition: opacity 0.3s ease;
}

/* Loading state — handled via JS inline styles + this class */
.usf-product-grid.usf-loading {
    pointer-events: none;
}

/* No products / Error messages */
.usf-no-products,
.usf-error {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 16px;
}

.usf-error {
    color: #c00;
}

/* Notice for non-archive pages */
.usf-notice {
    text-align: center;
    padding: 20px;
    color: #999;
    font-style: italic;
}

/* ==========================================================================
   # WooCommerce Product List Override (scoped)
   # Ensures grid layout works inside our wrapper regardless of theme.
   ========================================================================== */

.usf-product-grid ul.products {
    display: grid;
    gap: 20px;
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Mobile: 2 columns default */
.usf-product-grid ul.products {
    grid-template-columns: repeat(2, 1fr);
}

/* Column overrides via data-attribute driven classes */
.usf-columns-1 ul.products {
    grid-template-columns: 1fr;
}

.usf-columns-2 ul.products {
    grid-template-columns: repeat(2, 1fr);
}

/* ==========================================================================
   # Tablet Breakpoint (600px+)
   ========================================================================== */
@media ( min-width: 600px ) {
    .usf-filter-btn {
        padding: 10px 20px;
        font-size: 14px;
    }

    .usf-columns-3 ul.products,
    .usf-columns-4 ul.products {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ==========================================================================
   # Desktop Breakpoint (900px+)
   ========================================================================== */
@media ( min-width: 900px ) {
    .universal-smart-grid-wrapper {
        padding: 0 20px;
    }

    .usf-filter-buttons {
        gap: 10px;
        margin-bottom: 32px;
    }

    .usf-filter-btn {
        padding: 10px 24px;
        font-size: 15px;
    }

    .usf-columns-3 ul.products {
        grid-template-columns: repeat(3, 1fr);
    }

    .usf-columns-4 ul.products {
        grid-template-columns: repeat(4, 1fr);
    }

    .usf-product-grid ul.products {
        gap: 24px;
    }
}

/* ==========================================================================
   # Large Desktop (1200px+)
   ========================================================================== */
@media ( min-width: 1200px ) {
    .usf-filter-buttons {
        gap: 12px;
    }

    .usf-product-grid ul.products {
        gap: 30px;
    }
}

/* ==========================================================================
   # Product Card Scoped Resets
   # Prevents theme bleed-through within the grid wrapper.
   ========================================================================== */

.usf-product-grid ul.products li.product {
    margin: 0;
    padding: 0;
    float: none;
    width: 100% !important;
}

.usf-product-grid ul.products li.product img {
    width: 100%;
    height: auto;
    display: block;
}
