/* ==========================================
   Search Overlay & Results
   ========================================== */

/* Search icon in nav */
.nav-search-btn {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
    margin-left: 0.25rem;
}

.nav-search-btn:hover {
    color: #fff;
}

.nav-search-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Search overlay */
.search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: min(20vh, 160px);
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.search-overlay.closing {
    opacity: 0;
}

/* Search container */
.search-container {
    width: 90%;
    max-width: 640px;
    transform: translateY(-10px);
    transition: transform 0.2s ease;
}

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

/* Search input wrapper */
.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #1a1a2e;
    border: 1px solid rgba(59, 130, 246, 0.4);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(59, 130, 246, 0.1);
}

.search-input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.search-input-icon {
    padding: 0 0 0 1rem;
    color: #666;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.search-input-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: #fff;
    font-size: 1.1rem;
    padding: 1rem;
    font-family: inherit;
}

.search-input::placeholder {
    color: #666;
}

.search-input-clear {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 0.75rem 1rem;
    font-size: 1.2rem;
    display: none;
    transition: color 0.2s;
}

.search-input-clear:hover {
    color: #ccc;
}

.search-input-clear.visible {
    display: block;
}

/* Mobile close/cancel button */
.search-close-btn {
    display: none;
    background: none;
    border: none;
    color: #3b82f6;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.75rem 1rem;
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.search-kbd {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding-right: 1rem;
    color: #555;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.search-kbd kbd {
    background: #333;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: inherit;
    font-size: 0.7rem;
    color: #888;
}

/* Autocomplete suggestions */
.search-suggestions {
    margin-top: 0.5rem;
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    overflow: hidden;
    max-height: 420px;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: none;
}

.search-suggestions.visible {
    display: block;
}

.search-suggestions::-webkit-scrollbar {
    width: 6px;
}

.search-suggestions::-webkit-scrollbar-track {
    background: transparent;
}

.search-suggestions::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

/* Section headers */
.search-section-header {
    padding: 0.6rem 1rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
}

/* Individual suggestion item */
.search-suggestion {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.search-suggestion:last-child {
    border-bottom: none;
}

.search-suggestion:hover,
.search-suggestion.highlighted {
    background: rgba(59, 130, 246, 0.1);
}

.search-suggestion-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #222;
}

.search-suggestion-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #222;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #888;
}

.search-suggestion-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
}

.search-suggestion-info {
    flex: 1;
    min-width: 0;
}

.search-suggestion-name {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-suggestion-name mark {
    background: none;
    color: #3b82f6;
    font-weight: 600;
}

.search-suggestion-meta {
    color: #888;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-suggestion-rating {
    color: #f59e0b;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.search-suggestion-badge {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

/* Footer hint */
.search-footer {
    padding: 0.5rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #555;
    font-size: 0.7rem;
}

.search-footer-keys {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.search-footer-keys span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.search-footer-keys kbd {
    background: #333;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 1px 5px;
    font-family: inherit;
    font-size: 0.65rem;
    color: #777;
}

/* ==========================================
   Search Results Page
   ========================================== */

.search-results-page {
    padding: 2rem 0;
    min-height: 60vh;
}

.search-results-header {
    margin-bottom: 2rem;
}

.search-results-header h1 {
    font-size: 1.5rem;
    color: #fff;
    margin: 0 0 0.5rem;
}

.search-results-header h1 span {
    color: #3b82f6;
}

.search-results-count {
    color: #888;
    font-size: 0.9rem;
}

/* Search bar on results page */
.search-results-bar {
    margin-bottom: 2rem;
}

.search-results-bar .search-input-wrapper {
    max-width: 640px;
}

/* Filters row */
.search-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.search-filter-btn {
    background: #222;
    border: 1px solid #333;
    border-radius: 20px;
    padding: 0.4rem 0.9rem;
    color: #ccc;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.search-filter-btn:hover {
    border-color: #3b82f6;
    color: #fff;
}

.search-filter-btn.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: #3b82f6;
    color: #3b82f6;
}

/* Results grid */
.search-results-grid {
    display: grid;
    gap: 1rem;
}

/* Individual result card */
.search-result-card {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    gap: 1rem;
    transition: border-color 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.search-result-card:hover {
    border-color: #3b82f6;
}

.search-result-logo {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
    background: #222;
}

.search-result-body {
    flex: 1;
    min-width: 0;
}

.search-result-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.search-result-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
}

.search-result-rating {
    color: #f59e0b;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.search-result-desc {
    color: #999;
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0.25rem 0 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-result-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.search-result-tag {
    background: #222;
    color: #888;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
}

/* No results */
.search-no-results {
    text-align: center;
    padding: 3rem 1rem;
}

.search-no-results h2 {
    color: #fff;
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
}

.search-no-results p {
    color: #888;
    margin: 0 0 1.5rem;
}

.search-popular-terms {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.search-popular-term {
    background: #222;
    border: 1px solid #333;
    border-radius: 20px;
    padding: 0.4rem 1rem;
    color: #ccc;
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.search-popular-term:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

/* Mobile */
@media (max-width: 768px) {
    /* Position search button in header bar, before lang switcher and hamburger */
    .nav-search-btn {
        order: 2 !important;
        margin-left: auto !important;
        margin-right: 0.25rem !important;
        padding: 0.4rem !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* Re-order lang switcher and hamburger after search */
    header .language-switcher {
        order: 3 !important;
        margin-left: 0 !important;
    }

    header .hamburger {
        order: 4 !important;
    }

    .nav-search-btn svg {
        width: 22px;
        height: 22px;
    }

    .search-overlay {
        padding-top: 1rem;
    }

    .search-container {
        width: 95%;
    }

    .search-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 0.85rem 0.75rem;
    }

    .search-kbd {
        display: none;
    }

    .search-close-btn {
        display: block !important;
    }

    .search-suggestions {
        max-height: 60vh;
    }

    .search-suggestion {
        padding: 0.75rem 1rem;
    }

    .search-suggestion-logo {
        width: 32px;
        height: 32px;
    }

    .search-footer-keys {
        display: none;
    }

    .search-result-card {
        padding: 1rem;
    }

    .search-result-logo {
        width: 44px;
        height: 44px;
    }

    .search-results-page {
        padding: 1rem 0;
    }

    .search-results-header h1 {
        font-size: 1.2rem;
    }

    .search-filters {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 0.25rem;
    }

    .search-filters::-webkit-scrollbar {
        display: none;
    }
}
