/* ============================================
   MOBILE FAB & OVERLAY
   Floating action button for mobile search toggle
   ============================================ */

/* Mobile Search FAB */
.mobile-search-fab {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent-color), transparent 70%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    cursor: pointer;
    opacity: 0.4;
    transition: all 0.2s ease;
}

.mobile-search-fab:hover {
    transform: scale(1.05);
    opacity: 1;
    background: color-mix(in srgb, var(--accent-color), transparent 40%);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 20px var(--accent-glow);
}

.mobile-search-fab:active {
    transform: scale(0.95);
}

.mobile-search-fab svg {
    width: 24px;
    height: 24px;
    color: white;
}

/* Ensure close button is hidden on desktop by default */
.mobile-search-close {
    display: none;
}

@media (max-width: 768px) {
    .mobile-search-fab {
        display: flex;
        bottom: 60px; /* clears main tabs (52px) + small gap */
        /* Override base transition so bottom movement matches the tab animation */
        transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, transform 0.2s ease;
    }

    .mobile-search-fab.has-subtabs {
        bottom: 106px; /* clears main tabs + subtabs (~40px) + gap */
    }

    .mobile-search-fab.podcast-active {
        bottom: 156px; /* Lowered 8px (164 - 8) */
    }

    .mobile-search-fab.has-subtabs.podcast-active {
        bottom: 192px; /* Lowered 8px (200 - 8) */
    }

    /* Drop to screen edge when tabs are hidden — stays accessible, no orphaned float */
    .mobile-search-fab[data-tabs-hidden] {
        bottom: 20px;
    }

    .mobile-search-fab[data-tabs-hidden].podcast-active {
        bottom: 106px; /* Lowered 8px (114 - 8) */
    }

    /* Hide FAB while the search drawer is open — X button is the only exit */
    .mobile-search-backdrop.visible + .mobile-search-fab {
        display: none;
    }
}

/* Mobile Search Overlay Backdrop */
.mobile-search-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 450;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-search-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

/* Mobile Search Panel Overlay State */
@media (max-width: 768px) {
    .search-panel.mobile-overlay {
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 48px; /* sit above the fixed bottom nav so its tabs stay tappable */
        right: 0;
        width: 100vw !important;
        max-width: none;
        height: auto !important;
        transform: translateX(-100%);
        opacity: 0;
        visibility: hidden;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s, visibility 0.3s;
        z-index: 500;
        border-radius: 0;
        box-shadow: none;
        overflow-y: auto;
    }

    .search-panel.mobile-overlay.open {
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
    }

    /* FIX: Override global collapsed styles that hide content */
    .search-panel.mobile-overlay.collapsed * {
        visibility: visible !important;
    }

    .search-panel.mobile-overlay.collapsed {
        width: 100vw !important;
        max-width: none;
        padding: 0;
        /* Respect layout but ensure width holds */
    }

    /* Close button for mobile search overlay */
    .mobile-search-close {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--button-bg);
        border: 1px solid var(--button-border);
        color: var(--text-color);
        display: none;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 10;
        transition: background 0.2s ease;
        position: relative; /* Remove absolute positioning */
        top: 0;
        right: 0;
    }

    .mobile-search-close:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    .search-panel.mobile-overlay .mobile-search-close {
        display: flex;
    }

    .mobile-search-close svg {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
    }
}

/* ── Mobile: Search is a full top-level tab (not a drawer) ──────────────────────
   In-flow content that scrolls the window — so the app header scrolls away like every other
   tab — with the SEARCH/GLOSSARY toggle as a fixed sub-tab bar and the main nav below it. */
@media (max-width: 768px) {
    .search-panel.mobile-overlay {
        position: static !important;
        display: none !important;
        width: 100% !important;
        max-width: none !important;
        height: auto !important;
        top: auto !important;
        bottom: auto !important;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        overflow: visible !important;
        z-index: auto !important;
        box-shadow: none;
        border-radius: 0;
        /* Clear the fixed sub-tab + nav bars so the last results aren't hidden behind them. */
        padding-bottom: var(--mobile-bottom-bars) !important;
    }
    .search-panel.mobile-overlay.open {
        display: flex !important;
    }

    /* SEARCH / GLOSSARY toggle -> fixed sub-tab slot, matching other tabs' sub-tabs. */
    .search-panel.mobile-overlay .search-header {
        position: fixed;
        left: 0;
        right: 0;
        bottom: var(--mobile-nav-height);
        top: auto;
        height: auto;
        border-top: 1px solid var(--glass-border);
        border-bottom: none;
        z-index: 199;
        margin: 0;
        padding: 4px 8px;
        background: var(--panel-bg-opaque);
        box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.2);
        transform: translateY(0);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .search-panel.mobile-overlay .search-header.tabs-nav-hidden {
        transform: translateY(calc(100% + 60px));
    }

    /* The drawer close button is redundant now that the nav is always visible. */
    .search-panel.mobile-overlay .mobile-search-close {
        display: none !important;
    }

    /* Results flow naturally; the window is the scroll container. */
    .search-panel.mobile-overlay .search-results-wrapper {
        flex: none !important;
        overflow: visible !important;
        min-height: 0 !important;
        height: auto !important;
    }

    /* While Search is open, collapse the underlying tab's content (its fixed nav still shows). */
    .main-layout:has(.search-panel.mobile-overlay.open) .panel-content {
        display: none !important;
    }
    .main-layout:has(.search-panel.mobile-overlay.open) .right-panel {
        min-height: 0 !important;
        padding-bottom: 0 !important;
    }
}

/* The Search tab footer only shows on mobile (desktop search is the persistent side panel). */
.search-mobile-footer {
    display: none;
}

@media (max-width: 768px) {
    /* Sort row: give the asc/desc toggle its full width; the dropdown takes the leftover space
       (its labels are short), instead of the dropdown hogging the row and clipping the toggle. */
    .advanced-sort-control .sort-control-select {
        flex: 1 1 0;
        width: auto;          /* override .filter-group select { width: 100% } */
        min-width: 0;
    }
    .advanced-sort-control .sort-direction-toggle {
        flex: 0 0 auto;
    }
    .advanced-sort-control .sort-direction-toggle .toggle-btn {
        min-width: 52px;
    }

    /* SEARCH / GLOSSARY sub-tabs match the shared .sub-tab-bar / .lib-tab-btn look: gradient
       active pill, and icon-only when inactive (active expands to show its label). */
    .search-panel.mobile-overlay .search-mode-tabs--mobile {
        background: transparent;
        padding: 0;
        margin: 0;
        gap: 4px;
        width: 100%;
    }
    .search-panel.mobile-overlay .search-mode-tab {
        flex: 0 0 auto;
        padding: 6px 8px;
        gap: 4px;
        font-size: 13px;
        font-weight: 500;
        border-radius: 6px;
    }
    .search-panel.mobile-overlay .search-mode-tab--active {
        flex: 1 1 auto;
        padding: 6px 12px;
        background: var(--accent-gradient);
    }
    .search-panel.mobile-overlay .search-mode-tab:not(.search-mode-tab--active) span {
        display: none;
    }

    /* Footer at the bottom of the Search tab content, like every other tab. */
    .search-mobile-footer {
        display: block;
        margin-top: 12px;
    }
}
