/* Search bar layout & polish overrides
 * Loaded after styles.css so these win without !important wars.
 */

.filter-bar {
    /* Pin to the very top of the viewport so the search bar is always at the top
     * regardless of DOM order. */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    margin: 0;
    z-index: 40;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Reserve safe horizontal gutters for the menu (left) and theme toggle (right) */
    padding-left: clamp(1rem, 12vw, 9rem);
    padding-right: clamp(1rem, 14vw, 11rem);
}

/* Ensure the Menu / Themes / Genres / Theme-toggle buttons sit above the
 * fixed search bar, just like they do over the Menu button. */
.app-menu-button,
.theme-toggle,
.menu-toggle {
    z-index: 60 !important;
}

/* Push the games grid down so the fixed bar doesn't cover the first row. */
.games-grid.visible {
    padding-top: clamp(4.5rem, 7vh, 6rem) !important;
}

.filter-bar .search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 640px;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid var(--primary);
    border-radius: 999px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    overflow: hidden;
}

.filter-bar .search-wrap:focus-within {
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px var(--glow-color-40), 0 0 18px var(--glow-color-60);
    transform: translateY(-1px);
}

.filter-bar .search-icon {
    position: absolute;
    left: 1.1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    opacity: 0.8;
    pointer-events: none;
    font-size: 1rem;
}

.filter-bar input#searchInput {
    flex: 1;
    width: 100%;
    max-width: none;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    padding: 0.7rem 7rem 0.7rem 2.85rem;
    margin: 0;
    display: block;
    line-height: 1.2;
    box-shadow: none;
}

.filter-bar input#searchInput::placeholder {
    color: var(--primary);
    opacity: 0.55;
}

.filter-bar input#searchInput:focus {
    outline: none;
    box-shadow: none;
}

/* Hide native clear UI on Chrome/Edge/Safari since we provide our own */
.filter-bar input#searchInput::-webkit-search-cancel-button,
.filter-bar input#searchInput::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

.filter-bar .search-clear {
    position: absolute;
    right: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.filter-bar .search-clear:hover,
.filter-bar .search-clear:focus-visible {
    background: var(--primary);
    color: var(--background);
    outline: none;
    transform: translateY(-50%) scale(1.05);
}

.filter-bar .search-clear[hidden] {
    display: none;
}

.filter-bar .search-count {
    position: absolute;
    right: 3rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.78rem;
    color: var(--text);
    opacity: 0.6;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.02em;
}

.filter-bar .search-count:empty {
    display: none;
}

/* Responsive: relax gutters and stack count below on small screens */
@media (max-width: 900px) {
    .filter-bar {
        padding-left: 4.5rem;
        padding-right: 4.5rem;
    }
}

@media (max-width: 600px) {
    .filter-bar {
        padding: 0.7rem 0.9rem 0.7rem 4.5rem;
    }
    .filter-bar input#searchInput {
        font-size: 0.95rem;
        padding: 0.6rem 2.6rem 0.6rem 2.6rem;
    }
    .filter-bar .search-icon {
        left: 0.95rem;
        font-size: 0.95rem;
    }
    .filter-bar .search-count {
        display: none;
    }
    .filter-bar .search-clear {
        width: 30px;
        height: 30px;
        right: 0.4rem;
    }
}
