:root {
    /* Color Palette from rent.php */
    --dark-dashboard-1: #1C2526;
    --dark-dashboard-2: #2E3A3B;
    --accent-cyan: #33C1CF;
    --hover-cyan: #069BAA;
    --text-light: #D3D8D9;
    --metallic-accent: #3F4E50;
    --content-bg-1: #f5f7fa;
    --content-bg-2: #e4e9f0;
    --offer-bg: #FFF5B7;
    --timer-red: #940924;
    --success-green: #28A745;
    --border-gray: #E0E0E0;
    --card-bg: #2A3738;
    --card-border: #4A5A5C;
}

/* Remove conflicting main styles - let header3.css handle it */
/* main { 
    padding: 20px 0 10px; 
} */

/* Prevent body scroll when filter is open - MOBILE ONLY */
@media (max-width: 767px) {
    body.filter-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

.search-results-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    gap: 24px;
    position: relative;
}

.error {
    color: var(--timer-red);
    font-size: 1rem;
    margin: 20px 0;
    text-align: center;
    background: rgba(148, 9, 36, 0.1);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--card-border);
}

/* Mobile Filter Toggle Button */
.filter-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 40px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: var(--accent-cyan);
    border: 1px solid var(--accent-cyan);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    margin-bottom: 15px;
}

.filter-toggle-btn:hover {
    background: var(--hover-cyan);
    border-color: var(--hover-cyan);
    box-shadow: 0 4px 12px rgba(51, 193, 207, 0.3);
}

.filter-toggle-btn.has-filters {
    background: var(--success-green);
    border-color: var(--success-green);
}

.filter-toggle-btn.has-filters:hover {
    background: #1e7e34;
}

/* Desktop Filter Toggle */
.desktop-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 14px;
    color: var(--text-light);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.desktop-filter-toggle:hover {
    background: var(--metallic-accent);
    border-color: var(--accent-cyan);
}

/* Filter Overlay - MOBILE ONLY */
.filter-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    overscroll-behavior: contain;
}

.filter-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Filter Section - OPTIMIZED HEIGHT */
.filter-section {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    background: var(--card-bg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    border-left: 1px solid var(--card-border);
}

.filter-section.active {
    right: 0;
}

/* Filter Header */
.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--card-border);
    background: rgba(42, 55, 56, 0.95);
    backdrop-filter: blur(5px);
    flex-shrink: 0;
}

.filter-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-cyan);
    margin: 0;
}

.filter-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.filter-close:hover {
    background: var(--metallic-accent);
    color: var(--accent-cyan);
}

/* Filter Form - OPTIMIZED FOR BETTER SCROLLING */
.filter-form {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* Remove touch gestures that cause issues */
.filter-form * {
    touch-action: manipulation;
}

/* Filter Groups - COMPACT */
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filter-group h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-cyan);
    margin: 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--card-border);
}

/* Sort Options - COMPACT */
.sort-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(42, 55, 56, 0.5);
}

.radio-option:hover {
    border-color: var(--accent-cyan);
    background: var(--metallic-accent);
}

.radio-option input[type="radio"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent-cyan);
    margin: 0;
}

.radio-option span {
    color: var(--text-light);
    font-size: 13px;
}

/* Filter Items - COMPACT */
.filter-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-item label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    margin: 0;
}

.filter-item input,
.filter-item select {
    padding: 10px;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text-light);
    transition: all 0.3s ease;
}

.filter-item input:focus,
.filter-item select:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 3px rgba(51, 193, 207, 0.3);
}

.filter-item input::placeholder {
    color: rgba(211, 216, 217, 0.6);
}

/* Price Range */
.price-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.price-range input {
    flex: 1;
    min-width: 0;
}

.price-range span {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 500;
    flex-shrink: 0;
}

/* Filter Actions - NON-STICKY */
.filter-actions {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--card-border);
    background: rgba(42, 55, 56, 0.95);
    backdrop-filter: blur(5px);
    flex-shrink: 0;
}

.clear-btn,
.apply-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
}

.clear-btn {
    background: var(--card-bg);
    color: var(--text-light);
    border: 1px solid var(--card-border);
}

.clear-btn:hover {
    background: var(--metallic-accent);
    border-color: var(--accent-cyan);
}

.apply-btn {
    background: var(--accent-cyan);
    color: white;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(51, 193, 207, 0.2);
}

.apply-btn:hover {
    background: var(--hover-cyan);
    box-shadow: 0 4px 12px rgba(51, 193, 207, 0.3);
    transform: translateY(-1px);
}

/* Main Content */
.main-content {
    flex: 1;
    min-width: 0;
}

/* Results Header */
.results-header {
    margin-bottom: 24px;
}

.results-title {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--accent-cyan);
    margin-bottom: 8px;
}

.result-count {
    font-size: 0.9rem;
    color: var(--text-light);
    opacity: 0.7;
}

/* City info styles */
.city-info {
    background: rgba(51, 193, 207, 0.1);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid rgba(51, 193, 207, 0.3);
}

.city-priority-badge {
    background: var(--accent-cyan);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
}

/* Product Grid */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

/* Product Card */
.product-card {
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--card-border);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.product-card.priority-city {
    border-left: 3px solid var(--accent-cyan);
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.product-link {
    text-decoration: none;
    color: inherit;
    display: block;
    flex: 1;
}

.product-image {
    width: 100%;
    height: 220px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: var(--card-bg);
    position: relative;
    transition: opacity 0.3s ease;
    border-bottom: 1px solid var(--card-border);
}

.product-image.error {
    background-image: url('../images/book-placeholder.jpg') !important;
}

.product-image:not(.loaded) {
    opacity: 0.7;
}

.product-type-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 4px;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.product-type-badge.rental {
    background: var(--success-green);
}

.product-type-badge.2nd_hand {
    background: #f59e0b;
}

.product-type-badge.new_book {
    background: var(--accent-cyan);
}

.product-title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    margin: 15px;
    margin-bottom: 8px;
    line-height: 1.4;
    height: 48px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.shipping-info {
    font-size: 12px;
    color: #666;
    margin: 0 15px 8px;
}

.shipping-info.local {
    color: var(--accent-cyan);
    font-weight: 600;
}

/* Product Price */
.product-price {
    margin: 0 15px 15px;
}

.price-dropdown {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-cyan);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    background: var(--card-bg) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24"><path fill="%2333C1CF" d="M7 10l5 5 5-5z"/></svg>') no-repeat right 10px center;
    background-size: 12px;
    cursor: pointer;
    appearance: none;
    transition: all 0.3s ease;
}

.price-dropdown:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 5px rgba(51, 193, 207, 0.3);
}

.price-display {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-cyan);
}

/* No Results */
.no-results {
    text-align: center;
    padding: 60px 20px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--card-border);
    margin: 40px 0;
}

.no-results-icon {
    font-size: 48px;
    color: var(--metallic-accent);
    margin-bottom: 16px;
}

.no-results h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 8px;
}

.no-results p {
    color: var(--text-light);
    opacity: 0.7;
    margin-bottom: 24px;
}

.category-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 24px;
}

.category-suggestion {
    padding: 6px 12px;
    background: var(--metallic-accent);
    color: var(--text-light);
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.3s ease;
    border: 1px solid var(--card-border);
}

.category-suggestion:hover {
    background: var(--accent-cyan);
    color: white;
    border-color: var(--accent-cyan);
}

.clear-filters-link {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 16px;
    background: var(--card-bg);
    border: 1px solid var(--accent-cyan);
    border-radius: 6px;
    color: var(--accent-cyan);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.clear-filters-link:hover {
    background: var(--accent-cyan);
    color: white;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 40px 0;
    flex-wrap: wrap;
}

.pagination-btn,
.pagination-number {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 12px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    color: var(--text-light);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.pagination-btn:hover,
.pagination-number:hover {
    background: var(--metallic-accent);
    border-color: var(--accent-cyan);
}

.pagination-number.active {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: white;
}

.pagination-ellipsis {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    color: var(--text-light);
    font-weight: 500;
    opacity: 0.6;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.md\:hidden {
    /* Don't set display: none globally - let responsive rules handle it */
}

.md\:block {
    display: block !important;
}

/* Responsive Design */
@media (min-width: 768px) {
    .filter-toggle-btn {
        display: none !important;
    }
    
    .md\:hidden {
        display: none !important;
    }
    
    .md\:block {
        display: block !important;
    }
    
    /* DESKTOP - FILTER OPENS BY DEFAULT & PROPER HEIGHT */
    .filter-section {
        position: static;
        width: 320px;
        height: fit-content;
        max-height: calc(100vh - 120px);
        background: rgba(42, 55, 56, 0.8);
        backdrop-filter: blur(5px);
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        display: flex;
        transition: none;
        flex-shrink: 0;
        border: 1px solid var(--card-border);
        z-index: auto;
        overscroll-behavior: auto;
    }
    
    .filter-overlay {
        display: none;
    }
    
    .search-results-container {
        flex-direction: row;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
    
    /* Reset body scroll lock on desktop */
    body.filter-open {
        overflow: auto;
        position: static;
        width: auto;
        height: auto;
    }
}

@media (min-width: 1024px) {
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
}

@media (max-width: 767px) {
    .filter-toggle-btn {
        display: inline-flex !important;
        position: relative;
        z-index: 10;
        background: var(--accent-cyan);
        color: white;
        border: none;
        padding: 10px 15px;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        align-items: center;
        margin-bottom: 15px;
        box-shadow: 0 2px 8px rgba(51, 193, 207, 0.3);
    }
    
    .md\:hidden {
        display: block !important;
    }
    
    /* Remove conflicting padding - let header3.css handle it */
    /* main { 
        padding: 20px 0 60px;
    } */
    
    .search-results-container {
        flex-direction: column;
        padding: 10px;
        margin-top: 0;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 15px;
    }
    
    .product-card { 
        padding: 0; 
    }
    
    .product-image { 
        height: 180px; 
    }
    
    .product-title { 
        font-size: 15px;
        font-weight: 600;
        height: 42px; 
        margin: 10px;
        margin-bottom: 8px;
    }
    
    .product-price {
        margin: 0 10px 10px;
    }
    
    .price-dropdown { 
        font-size: 14px;
        font-weight: 700;
        padding: 8px;
    }
    
    .results-title {
        font-size: 1.5rem;
        margin-top: 0;
    }
    
    .results-header {
        margin-bottom: 16px;
        margin-top: 0;
    }
    
    .pagination {
        gap: 4px;
    }
    
    .pagination-btn,
    .pagination-number {
        min-width: 36px;
        height: 36px;
        font-size: 13px;
    }
    
    /* Mobile specific optimizations */
    .filter-section {
        padding-top: env(safe-area-inset-top, 0);
        touch-action: pan-y;
    }
    
    .filter-header {
        padding-top: calc(16px + env(safe-area-inset-top, 0));
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* Loading States */
.filter-section.loading {
    pointer-events: none;
    opacity: 0.7;
}

.apply-btn.loading {
    background: var(--metallic-accent) !important;
    cursor: not-allowed;
}

.apply-btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}