body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #f9f9f9;
    color: #333;
}

.search-container {
    display: flex;
    margin: 2rem auto;
    padding: 0 1rem;
    gap: 2rem;
}

/* Results Header Layout */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.results-title {
    font-size: .9rem;
    color: #333;
    margin: 0;
}

.sort-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sort-label {
    font-size: 0.9rem;
    color: #666;
    white-space: nowrap;
}

.sort-select {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background-color: #fff;
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1rem;
}

.sort-select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .results-title {
        font-size: 1.1rem;
    }

    .sort-container {
        width: 100%;
    }

    .sort-select {
        flex: 1;
    }
}

/* Sidebar Filters */
.filters-sidebar {
    width: 250px;
    flex-shrink: 0;
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

    /* Sticky Magic: Keeps it in view while scrolling products */
    position: sticky;
    top: 2rem;
    /* Adjust this if you have a fixed top navbar (e.g., top: 80px) */

    /* Limit height to viewport minus top/bottom margins */
    max-height: calc(100vh - 4rem);

    /* Internal scrolling for the sidebar */
    overflow-y: auto;
    overflow-x: hidden;

    /* Clean, thin scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

/* Webkit (Chrome/Safari) Scrollbar Styling */
.filters-sidebar::-webkit-scrollbar {
    width: 6px;
}

.filters-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.filters-sidebar::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 20px;
}

/* Force hidden items to stay hidden */
.filter-section label.hidden,
.color-option.hidden {
    display: none !important;
}

.filter-section {
    margin-bottom: 2rem;
}

.filter-section h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    font-weight: 600;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
}

.filter-section label {
    display: block;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.filter-section input[type="radio"],
.filter-section input[type="checkbox"] {
    margin-right: 0.5rem;
}

.custom-price {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.custom-price input {
    width: 100%;
    padding: 0.4rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.custom-price button {
    padding: 0.4rem 0.8rem;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.custom-price button:hover {
    background: #555;
}

.show-all-btn {
    background: none;
    border: none;
    color: #007bff;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    text-decoration: underline;
    display: none;
}

/* Main Results Area */
.results-area {
    flex: 1;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
}

.product-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.product-card:hover {
    transform: translateY(-4px);
}

.product-card img {
    width: 100%;
    height: 220px;
    object-fit: cover;
}

.product-card .info {
    padding: 1rem;
}

.product-card h3 {
    font-size: 0.95rem;
    margin: 0 0 0.5rem 0;
    font-weight: 500;
    line-height: 1.4;
}

.product-card .price {
    font-weight: 600;
    color: #d32f2f;
}

.product-card .original-price {
    text-decoration: line-through;
    color: #999;
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.discount-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #d32f2f;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
}

.pagination button {
    padding: 0.5rem 0.8rem;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .pagination button {
        padding-inline: .3rem;
    }
}



.pagination button:hover:not(:disabled) {
    background: #f0f0f0;
}

.pagination button.active {
    background: #333;
    color: #fff;
    border-color: #333;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#loading {
    text-align: center;
    padding: 2rem;
    display: none;
}

.error {
    color: #d32f2f;
    text-align: center;
    grid-column: 1 / -1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .search-container {
        flex-direction: column;
    }

    .filters-sidebar {
        width: 100%;
    }
}

.toggle-btn {
    background: none;
    border: none;
    color: #007bff;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    text-decoration: underline;
    padding: 0;
}

.toggle-btn:hover {
    color: #0056b3;
}

.material-item.hidden {
    display: none;
}

/* Loader Styles */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    grid-column: 1 / -1;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f0f0f0;
    border-top: 4px solid #333;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loader-container p {
    color: #666;
    font-size: 0.95rem;
}

.material-item.hidden,
.origin-item.hidden {
    display: none;
}


/* Material toggle button */
.toggle-btn {
    background: none;
    border: none;
    color: #007bff;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    text-decoration: underline;
    padding: 0;
}

.toggle-btn:hover {
    color: #0056b3;
}

.material-item.hidden {
    display: none;
}

.filter-section label {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.filter-section input[type="radio"] {
    margin-right: 0.5rem;
    margin-top: 2px;
    /* Aligns radio button with text */
}

.color-option {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.color-swatch {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #ddd;
    margin-right: 8px;
    flex-shrink: 0;
    display: inline-block;
}

/* Checkerboard pattern for transparent/clear colors */
.color-swatch.transparent {
    background: repeating-conic-gradient(#ccc 0% 25%, white 0% 50%) 50% / 16px 16px;
}

/* Reuse your existing hidden class */
.color-option.hidden {
    display: none;
}

/* =========================================
   DESKTOP DEFAULTS (Hide mobile elements)
   ========================================= */
.mobile-filter-btn,
.filters-header,
.filters-footer,
.filter-backdrop {
    display: none;
}

/* =========================================
   MOBILE STYLES (Max width 768px)
   ========================================= */
@media (max-width: 768px) {

    /* Show the mobile filter button at the top of results */
    .mobile-filter-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;

        /* Make it stretch edge-to-edge on mobile */
        width: calc(100% + 2rem);
        margin: 0 -1rem 1rem -1rem;
        padding: 0.85rem;
        background: #fff;
        border: none;
        border-bottom: 1px solid #eee;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;

        /* Sticky Magic */
        position: sticky;
        top: 0;
        /* ⚠️ If you have a fixed top navbar, change this to match its height (e.g., top: 60px;) */
        z-index: 900;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .product-card img {
        height: auto;
        aspect-ratio: 1 / 1;
        /* Forces perfect square images on mobile */
        object-fit: cover;
    }

    .product-card .info {
        padding: 0.5rem;
    }

    .product-card h3 {
        font-size: 0.85rem;
        line-height: 1.3;
        margin-bottom: 0.25rem;
        /* Truncate to 2 lines to keep cards same height */
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .product-card .price {
        font-size: 0.9rem;
    }

    .product-card .original-price {
        font-size: 0.75rem;
    }

    /* Transform sidebar into a slide-in drawer */
    .filters-sidebar {
        position: fixed;
        top: 0;
        right: -100%;
        /* Hidden off-screen by default */
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: #fff;
        z-index: 1001;
        transition: right 0.3s ease-in-out;
        display: flex;
        flex-direction: column;
        box-shadow: -4px 0 15px rgba(0, 0, 0, 0.15);
    }

    .filters-sidebar.active {
        right: 0;
        /* Slide in */
    }

    /* Header with X button */
    .filters-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 1.25rem;
        border-bottom: 1px solid #eee;
        flex-shrink: 0;
        background: #fff;
    }

    .filters-header h3 {
        margin: 0;
        font-size: 1.2rem;
        font-weight: 600;
    }

    .close-filters-btn {
        background: none;
        border: none;
        font-size: 2rem;
        cursor: pointer;
        color: #333;
        line-height: 1;
        padding: 0;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Scrollable content area */
    .filters-content {
        flex: 1;
        overflow-y: auto;
        padding: 1rem 1.25rem;
        -webkit-overflow-scrolling: touch;
        /* Smooth scrolling on iOS */
    }

    /* Footer with Done button */
    .filters-footer {
        display: block;
        padding: 1rem 1.25rem;
        border-top: 1px solid #eee;
        flex-shrink: 0;
        background: #fff;
    }

    .apply-filters-btn {
        width: 100%;
        padding: 0.9rem;
        background: #333;
        color: #fff;
        border: none;
        border-radius: 8px;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.2s;
    }

    .apply-filters-btn:active {
        background: #555;
    }

    /* Dark backdrop */
    .filter-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease-in-out;
    }

    .filter-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Adjust main layout */
    .search-container {
        flex-direction: column;
        padding: 0 1rem 1rem 1rem;
    }

    .results-area {
        margin-top: 0;
    }
}