/* Mobile-First Advanced Search CSS */
/* Z-index hierarchy: Above all modal systems */

/* Search Toggle Button */
.search-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    color: #666;
    transition: color 0.2s ease;
    z-index: 2;
}

.search-toggle:hover {
    color: #333;
    background-color: #f0f0f0;
}

.search-toggle:active {
    transform: translateY(-50%) scale(0.95);
}

.search-toggle .search-icon {
    display: block;
    width: 20px;
    height: 20px;
}

/* Search Container Modifications */
.search-container {
    position: relative;
}

.search-container #search-input {
    padding-right: 40px; /* Make room for toggle button */
}

/* Advanced Search Overlay */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1080; /* Above all modal systems including filter backdrop (1040) */
    display: none;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.search-overlay.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
    padding-top: 2rem;
}

.search-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.search-overlay-content {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Search Overlay Header */
.search-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e0e0e0;
    background: #f9f9f9;
}

.search-overlay-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #333;
}

.search-overlay-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #666;
    transition: all 0.2s ease;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-overlay-close:hover {
    background-color: #e0e0e0;
    color: #333;
}

.search-overlay-close:active {
    transform: scale(0.95);
}

/* Search Overlay Body */
.search-overlay-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.search-overlay-input-container {
    position: relative;
    margin-bottom: 1.5rem;
}

#search-overlay-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px; /* Prevent iOS zoom */
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    outline: none;
    transition: border-color 0.2s ease;
}

#search-overlay-input:focus {
    border-color: #4a90e2;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

/* Search Results */
.search-results {
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 6px;
    margin-bottom: 4px;
}

.search-result-item:hover {
    background-color: #f8f9fa;
}

.search-result-item:active {
    background-color: #e9ecef;
    transform: scale(0.98);
}

.search-result-item.highlighted {
    background-color: #e7f3ff;
    border-color: #4a90e2;
}

.search-result-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.search-result-category {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 4px;
}

.search-result-description {
    font-size: 0.85rem;
    color: #888;
    line-height: 1.4;
}

/* Search Placeholder */
.search-placeholder {
    text-align: center;
    padding: 2rem 1rem;
    color: #666;
}

.search-placeholder.hidden {
    display: none;
}

.search-placeholder-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.search-placeholder p {
    margin: 0 0 1.5rem 0;
    font-size: 1.1rem;
    line-height: 1.5;
}

.search-placeholder-tips {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    text-align: left;
    max-width: 300px;
    margin: 0 auto;
}

.search-placeholder-tips p {
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    color: #333;
}

.search-placeholder-tips ul {
    margin: 0;
    padding-left: 1.2rem;
}

.search-placeholder-tips li {
    margin-bottom: 0.3rem;
    color: #666;
    font-size: 0.9rem;
}

/* Search Recent */
.search-recent {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
}

.search-recent h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: #333;
}

.search-recent-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.search-recent-item {
    background: #f0f0f0;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.9rem;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-recent-item:hover {
    background: #e0e0e0;
    color: #333;
}

.search-recent-item:active {
    transform: scale(0.95);
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .search-overlay {
        padding: 0.5rem;
        padding-top: 1rem;
    }
    
    .search-overlay-content {
        max-height: 90vh;
        border-radius: 8px;
    }
    
    .search-overlay-header {
        padding: 0.75rem 1rem;
    }
    
    .search-overlay-header h2 {
        font-size: 1.1rem;
    }
    
    .search-overlay-body {
        padding: 1rem;
    }
    
    .search-placeholder {
        padding: 1.5rem 0.5rem;
    }
    
    .search-placeholder-icon {
        font-size: 2.5rem;
    }
    
    .search-placeholder p {
        font-size: 1rem;
    }
    
    .search-placeholder-tips {
        padding: 0.75rem;
    }
}

/* iOS Safari Specific */
@supports (-webkit-touch-callout: none) {
    .search-overlay {
        /* Account for iOS safe areas */
        padding-top: env(safe-area-inset-top, 1rem);
        padding-bottom: env(safe-area-inset-bottom, 1rem);
    }
    
    #search-overlay-input {
        /* Prevent iOS zoom */
        font-size: 16px;
        -webkit-appearance: none;
        border-radius: 8px;
    }
    
    .search-overlay-body {
        /* Smooth scrolling on iOS */
        -webkit-overflow-scrolling: touch;
        /* Prevent bounce */
        overscroll-behavior: contain;
    }
}

/* Touch Optimizations */
@media (hover: none) and (pointer: coarse) {
    .search-toggle {
        min-width: 44px;
        min-height: 44px;
    }
    
    .search-overlay-close {
        min-width: 44px;
        min-height: 44px;
    }
    
    .search-result-item {
        padding: 16px;
        min-height: 44px;
    }
    
    .search-recent-item {
        min-height: 32px;
        padding: 8px 16px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
    .search-overlay {
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
}

/* Accessibility */
.search-overlay[aria-hidden="true"] {
    display: none;
}

.search-overlay:not([aria-hidden="true"]) {
    display: flex;
}

/* Focus Management */
.search-overlay-content:focus-within {
    outline: none;
}

#search-overlay-input:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

/* Ensure proper layering above filter system */
body.mobile-filters-open .search-overlay {
    z-index: 1080; /* Above filter backdrop (1040) and filter panel (1050) */
}

/* Animation */
.search-overlay {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.search-overlay.active {
    opacity: 1;
}

.search-overlay-content {
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.search-overlay.active .search-overlay-content {
    transform: translateY(0);
}