/**
 * BWG YGL Mobile Styles
 *
 * Mobile-specific overrides and map/list toggle support.
 * Load after bwgygl.css.
 */

/* ========== MOBILE TOGGLE BUTTON ========== */
.bwgygl-mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9000;
    background: var(--navy);
    border: none;
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.bwgygl-mobile-toggle-inner {
    display: flex;
    gap: 4px;
}

.bwgygl-mobile-toggle-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: white;
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.bwgygl-mobile-toggle-btn:hover {
    background: var(--navy-light);
}

.bwgygl-mobile-toggle-btn.active {
    background: var(--gold);
    color: white;
}

.bwgygl-mobile-toggle-icon {
    font-size: 16px;
}

/* ========== MOBILE RESULTS/PAGINATION BAR ========== */
.bwgygl-mobile-results-bar {
    display: none;
}

/* ========== FILTERS MODAL (defaults — hidden on desktop) ========== */
.bwgygl-filters-trigger {
    display: none;
}

.bwgygl-filters-modal-header,
.bwgygl-filters-modal-footer,
.bwgygl-filters-modal-backdrop {
    display: none;
}

/* ========== MOBILE BREAKPOINT ========== */
@media (max-width: 968px) {
    /* Show toggle button */
    .bwgygl-mobile-toggle {
        display: block;
    }

    /* Hide header info bar */
    .bwgygl-header-top {
        display: none;
    }

    /* Hide original results summary on mobile (we use mobile bar instead) */
    /* !important needed to override JS inline style (summaryDiv.style.display = 'block') */
    .bwgygl-results-summary {
        display: none !important;
    }

    /* ========== FILTERS MODAL ========== */
    /* Hide inline filter bar on mobile — shown via modal instead */
    .bwgygl-filter-bar {
        display: none;
    }

    /* Hide filter bar icon on mobile */
    .bwgygl-filter-bar-icon {
        display: none;
    }

    /* Trigger button: visible on mobile */
    .bwgygl-filters-trigger {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 16px;
        background: var(--navy);
        border: 2px solid var(--gold);
        border-radius: 24px;
        color: var(--cream);
        font-family: 'Montserrat', sans-serif;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        flex-shrink: 0;
        margin: 10px 16px;
    }

    .bwgygl-filters-trigger-icon {
        font-size: 16px;
    }

    .bwgygl-filters-trigger-badge {
        background: var(--gold);
        color: var(--navy);
        border-radius: 50%;
        min-width: 20px;
        height: 20px;
        font-size: 11px;
        font-weight: 700;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
    }

    /* When modal is open: filter bar becomes fullscreen fixed overlay */
    .bwgygl-filter-bar.bwgygl-filters-modal-open {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9500;
        background: white;
        overflow-y: auto;
        padding: 70px 16px 100px;
        gap: 12px;
        flex-wrap: nowrap;
    }

    /* Inside modal: pills stack vertically, full width */
    .bwgygl-filter-bar.bwgygl-filters-modal-open .bwgygl-filter-pill {
        width: 100%;
        justify-content: space-between;
        flex-shrink: 0;
        padding: 14px 16px;
        font-size: 15px;
    }

    /* Sort control: restore pill appearance in mobile modal */
    .bwgygl-filter-bar.bwgygl-filters-modal-open .bwgygl-filter-pill.bwgygl-sort-control {
        border-color: var(--cream-dark);
        background: white;
        color: var(--text-dark);
        padding: 14px 16px;
        font-size: 15px;
    }

    /* Dropdowns inside modal: fixed and centered in viewport, content
       scrolls internally, Clear/Done footer stays pinned at bottom.
       z-index must beat .bwgygl-filter-backdrop.active (9999). */
    .bwgygl-filter-bar.bwgygl-filters-modal-open .bwgygl-filter-dropdown.open {
        position: fixed;
        top: 50%;
        left: 16px;
        right: 16px;
        bottom: auto;
        transform: translateY(-50%);
        max-height: calc(100vh - 140px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 10001;
        margin-top: 0;
        min-width: auto;
        width: auto;
    }

    .bwgygl-filter-bar.bwgygl-filters-modal-open .bwgygl-dropdown-content {
        flex: 1;
        overflow-y: auto;
    }

    .bwgygl-filter-bar.bwgygl-filters-modal-open .bwgygl-dropdown-footer {
        flex-shrink: 0;
    }

    /* Modal backdrop */
    .bwgygl-filters-modal-backdrop.bwgygl-filters-modal-visible {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9400;
    }

    /* Modal header */
    .bwgygl-filters-modal-header.bwgygl-filters-modal-visible {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 9600;
        padding: 16px 20px;
        background: white;
        border-bottom: 1px solid var(--cream-dark);
    }

    .bwgygl-filters-modal-title {
        font-size: 18px;
        font-weight: 600;
        color: var(--text-dark);
    }

    .bwgygl-filters-modal-close {
        background: none;
        border: none;
        font-size: 28px;
        cursor: pointer;
        color: var(--text-light);
        padding: 4px 8px;
        line-height: 1;
    }

    /* Modal footer */
    .bwgygl-filters-modal-footer.bwgygl-filters-modal-visible {
        display: flex;
        gap: 12px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 9600;
        padding: 16px 20px;
        background: white;
        border-top: 1px solid var(--cream-dark);
    }

    .bwgygl-filters-modal-clear {
        flex: 1;
        padding: 14px;
        background: white;
        border: 2px solid var(--cream-dark);
        border-radius: 8px;
        font-family: 'Montserrat', sans-serif;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        color: var(--text-dark);
    }

    .bwgygl-filters-modal-apply {
        flex: 2;
        padding: 14px;
        background: var(--navy);
        border: none;
        border-radius: 8px;
        font-family: 'Montserrat', sans-serif;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        color: white;
    }

    .bwgygl-filters-modal-apply:active {
        background: var(--navy-light);
    }

    /* Prevent body scroll when modal is open */
    body.bwgygl-filters-modal-active {
        overflow: hidden;
    }

    /* Hide map/list toggle when filters modal is open (toggle is on
       document.body, outside the .bwgygl-root stacking context) */
    body.bwgygl-filters-modal-active .bwgygl-mobile-toggle {
        display: none;
    }

    /* Elevate plugin root above site header/footer when filters modal is
       open.  Themes set isolation:isolate on .bwgygl-root which traps child
       z-indexes — this breaks them out. */
    body.bwgygl-filters-modal-active .bwgygl-root {
        position: relative;
        z-index: 10000;
    }

    /* Boost wrapper above everything (including toggle at 9000) when
       modal is open.  Backdrop, filter bar, header & footer are all inside
       this stacking context so their relative z-indexes work correctly. */
    body.bwgygl-filters-modal-active .bwgygl-stacked-search-bar-wrapper {
        z-index: 10000;
    }

    /* FIX: Use position:fixed for dropdowns on mobile to escape overflow:auto clipping */
    .bwgygl-filter-dropdown.open {
        position: fixed;
        top: 120px; /* Below header + filter bar */
        left: 16px;
        right: 16px;
        bottom: auto;
        max-height: calc(100vh - 200px); /* Leave room for header and toggle */
        overflow-y: auto;
        z-index: 10000;
        margin-top: 0;
    }

    .bwgygl-filter-backdrop.active {
        z-index: 9999;
    }

    /* Mobile results/pagination bar - shows between filters and list */
    .bwgygl-mobile-results-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--cream-dark);
        padding: 10px 16px;
        font-size: 13px;
        color: var(--text-light);
        border-bottom: 1px solid var(--cream-dark);
    }

    .bwgygl-mobile-results-bar .bwgygl-mobile-count {
        font-weight: 500;
    }

    .bwgygl-mobile-results-bar .bwgygl-mobile-pagination {
        display: flex;
        gap: 6px;
    }

    .bwgygl-mobile-results-bar .bwgygl-mobile-pagination button {
        padding: 6px 10px;
        background: white;
        border: 1px solid var(--cream-dark);
        border-radius: 4px;
        color: var(--text-dark);
        font-size: 12px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .bwgygl-mobile-results-bar .bwgygl-mobile-pagination button:hover:not(:disabled) {
        background: var(--gold);
        border-color: var(--gold);
        color: var(--navy);
    }

    .bwgygl-mobile-results-bar .bwgygl-mobile-pagination button:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }

    .bwgygl-mobile-results-bar .bwgygl-mobile-pagination button.active {
        background: var(--navy);
        border-color: var(--navy);
        color: white;
    }

    /* ========== SPLIT LAYOUT - MAP ONLY ========== */
    /* position:fixed overlay — works regardless of DOM nesting in WordPress */

    /* Filter bar column: fixed below site header */
    .bwgygl-mobile-map-only .bwgygl-results-column {
        position: fixed;
        top: var(--bwgygl-header-offset, 0px);
        left: 0;
        right: 0;
        z-index: 8500;
        width: 100%;
        height: auto;
        overflow: visible;
    }

    .bwgygl-mobile-map-only .bwgygl-results-scroll {
        display: none;
    }

    .bwgygl-mobile-map-only .bwgygl-mobile-results-bar {
        display: none;
    }

    /* Map: fixed fullscreen below site header */
    .bwgygl-mobile-map-only .bwgygl-map-column {
        position: fixed;
        top: var(--bwgygl-header-offset, 0px);
        left: 0;
        right: 0;
        bottom: 60px;
        z-index: 8000;
        width: 100%;
        height: auto;
        min-height: 0;
    }

    /* ========== SPLIT LAYOUT - LIST ONLY ========== */
    .bwgygl-mobile-list-only .bwgygl-map-column {
        display: none;
    }

    .bwgygl-mobile-list-only .bwgygl-results-column {
        width: 100%;
        height: calc(100vh - 70px);
    }

    /* ========== STACKED LAYOUT - UNIFY WITH SPLIT ON MOBILE ========== */
    /* Make stacked search bar look like split layout */
    .bwgygl-stacked-search-bar-wrapper {
        padding: 0;
    }

    .bwgygl-stacked-search-bar {
        background: white;
        border-radius: 0;
        padding: 0;
        flex-direction: column;
        gap: 0;
    }

    .bwgygl-stacked-search-bar .bwgygl-filter-bar:not(.bwgygl-filters-modal-open) {
        background: white;
        padding: 12px 16px;
        border-bottom: 2px solid var(--cream-dark);
    }

    /* Reset filter pill colors for stacked (they were navy-themed) */
    .bwgygl-stacked-search-bar .bwgygl-filter-pill {
        background: white;
        border-color: var(--cream-dark);
        color: var(--text-dark);
    }

    .bwgygl-stacked-search-bar .bwgygl-filter-pill:hover {
        border-color: var(--navy);
        background: var(--cream);
        color: var(--text-dark);
    }

    .bwgygl-stacked-search-bar .bwgygl-filter-pill.active {
        border-color: var(--gold);
        background: var(--gold);
        color: var(--navy);
    }

    .bwgygl-stacked-search-bar .bwgygl-filter-pill.open {
        border-color: var(--navy);
        background: var(--cream);
        color: var(--text-dark);
    }

    /* Utility bar: hide sort on mobile (accessible via filter modal) */
    .bwgygl-utility-sort {
        display: none;
    }

    .bwgygl-utility-bar {
        background: var(--cream-dark);
        justify-content: center;
        padding: 6px 12px;
        border-top: none;
    }

    .bwgygl-utility-info {
        flex-direction: column;
        align-items: center;
        gap: 6px;
    }

    .bwgygl-stacked-count {
        color: var(--text-light);
        font-weight: 500;
    }

    .bwgygl-stacked-pagination button {
        background: white;
        border: 1px solid var(--cream-dark);
        color: var(--text-dark);
    }

    .bwgygl-stacked-pagination button:hover:not(:disabled) {
        background: var(--gold);
        border-color: var(--gold);
        color: var(--navy);
    }

    .bwgygl-stacked-pagination button.active {
        background: var(--navy);
        border-color: var(--navy);
        color: white;
    }

    /* ========== STACKED LAYOUT - MAP ONLY ========== */
    /* position:fixed overlay — works regardless of DOM nesting in WordPress */

    /* Filter bar: fixed below any site header.
       Themes set --bwgygl-header-offset to their fixed header height.
       White background masks the map (z-index 8000) which may be above
       the site header in stacking order. */
    .bwgygl-mobile-map-only .bwgygl-stacked-search-bar-wrapper {
        position: fixed;
        top: var(--bwgygl-header-offset, 0px);
        left: 0;
        right: 0;
        z-index: 8500;
        background: white;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    }

    /* Lock body scroll in map-only mode — the map is a position:fixed overlay,
       so page scrolling only moves the site header and looks broken. */
    body.bwgygl-mobile-map-only {
        overflow: hidden;
    }

    /* Elevate the plugin root above surrounding page content (e.g. Elementor
       hero sections) so the fixed map overlay is visible.  Must stay BELOW
       the site header — Elementor default sticky z-index is 99, so we use
       50 to stay safely underneath.  Needed because themes may set
       isolation:isolate on .bwgygl-root, which traps child z-indexes. */
    .bwgygl-mobile-map-only .bwgygl-root {
        position: relative;
        z-index: 50;
    }

    /* Compact filter trigger in map-only mode */
    .bwgygl-mobile-map-only .bwgygl-filters-trigger {
        margin: 4px 12px;
    }

    /* Push map controls below the filter bar overlay in map-only mode.
       Controls are relative to the map container (already offset by header),
       so only need to clear the compact filter bar (~52px). */
    .bwgygl-mobile-map-only .leaflet-top {
        top: 85px;
    }

    .bwgygl-mobile-map-only .bwgygl-search-area-btn {
        top: 90px;
    }

    /* Map: fixed, fills viewport below header, above toggle button */
    .bwgygl-mobile-map-only .bwgygl-stacked-map-wrapper {
        position: fixed;
        top: var(--bwgygl-header-offset, 0px);
        left: 0;
        right: 0;
        bottom: 60px;
        z-index: 8000;
        padding: 0;
    }

    .bwgygl-mobile-map-only .bwgygl-stacked-map-wrapper .bwgygl-map-column {
        height: 100%;
        border-radius: 0;
    }

    /* Cards: hidden in map-only mode */
    .bwgygl-mobile-map-only .bwgygl-stacked-cards-wrapper {
        display: none;
    }

    /* Hide utility bar in stacked map-only */
    .bwgygl-mobile-map-only .bwgygl-utility-bar {
        display: none;
    }

    /* ========== STACKED LAYOUT - LIST ONLY ========== */
    .bwgygl-mobile-list-only .bwgygl-stacked-map-wrapper {
        display: none;
    }

    .bwgygl-mobile-list-only .bwgygl-stacked-search-bar-wrapper {
        position: sticky;
        top: var(--bwgygl-header-offset, 0px);
        z-index: 2000;
    }

    /* ========== SPACING ADJUSTMENT FOR TOGGLE ========== */
    /* Add bottom padding to avoid toggle button overlapping content */
    .bwgygl-results-scroll,
    .bwgygl-stacked-cards-wrapper {
        padding-bottom: 80px;
    }
}
