/*
 * Filters and sort on a phone.
 *
 * Only below lg. On desktop both live in the left column, which is a perfectly
 * good home for them; this exists because below lg that column is ordered after
 * the whole flight list, putting every filter behind a scroll past every
 * result.
 */

.flight-mobile-filterbar,
.fmf-backdrop,
.fmf-sheet {
    display: none;
}

@media (max-width: 991.98px) {
    .flight-mobile-filterbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        /* Above the results and the pinned search chrome (1025), below the
           edit drawer (1040) — a drawer open over this bar must cover it. */
        z-index: 1030;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        /* Clears the home indicator on iOS, and collapses to nothing on
           anything without one. */
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        background: var(--color-white);
        border-top: 1px solid var(--bs-border-color);
        box-shadow: 0 -4px 16px rgba(15, 39, 51, 0.08);
    }

    /*
     * Chips scroll sideways rather than wrapping.
     *
     * The set is open-ended — it grows with however many airlines a route has
     * — and a bar that wraps to a second row on a narrow phone eats the
     * results it exists to refine. `min-width: 0` is what actually lets it
     * shrink: a flex item defaults to min-content, so without it the row
     * widens to fit every chip and pushes the button off screen.
     */
    .flight-mobile-filterbar__chips {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        gap: 6px;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .flight-mobile-filterbar__chips::-webkit-scrollbar { display: none; }

    .fmf-chip {
        flex: 0 0 auto;
        min-height: 36px;
        padding: 6px 12px;
        border: 1px solid var(--bs-border-color);
        border-radius: 999px;
        background: var(--color-white);
        color: var(--color-text-black, #13253a);
        font-family: var(--font-family-inter);
        font-size: 0.8125rem;
        font-weight: 500;
        white-space: nowrap;
        cursor: pointer;
    }

    .fmf-chip.is-on {
        border-color: var(--color-first);
        background: var(--color-blue-light, #eef4f7);
        color: var(--color-first);
        font-weight: 600;
    }

    .flight-mobile-filterbar__open {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        /* 44px: the touch-target floor. */
        min-height: 44px;
        padding: 8px 14px;
        border: 0;
        border-radius: 999px;
        background: var(--color-second);
        /*
         * `--color-white-same`, not `--color-white`.
         *
         * `--color-white` is `light-dark(#fff, #333)`, so in dark mode the
         * label turned dark — on a button whose background does not follow the
         * theme the same way. This is the token the codebase already uses for
         * text that has to stay white on a coloured button.
         */
        color: var(--color-white-same, #fff);
        font-family: var(--font-family-inter);
        font-size: 0.875rem;
        font-weight: 600;
        letter-spacing: 0.01em;
        white-space: nowrap;
        cursor: pointer;
    }

    .fmf-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 999px;
        /* Same reasoning as the label above — both sit on the button. */
        background: var(--color-white-same, #fff);
        color: var(--color-second);
        font-size: 0.6875rem;
        font-weight: 700;
    }

    /* ── The drawer ───────────────────────────────────────────────────── */

    .fmf-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1044;
        background: rgba(15, 39, 51, 0.45);
        opacity: 0;
        transition: opacity 0.26s ease;
    }

    .fmf-backdrop.is-open { opacity: 1; }

    .fmf-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1045;
        /* Not the full screen: the strip of results left showing says the list
           is still there and this is a refinement of it. */
        max-height: 88vh;
        background: var(--color-white);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -12px 32px rgba(15, 39, 51, 0.22);
        transform: translateY(100%);
        transition: transform 0.26s cubic-bezier(0.22, 0.61, 0.36, 1);
    }

    .fmf-sheet.is-open { transform: translateY(0); }

    @media (prefers-reduced-motion: reduce) {
        .fmf-backdrop,
        .fmf-sheet { transition: none; }
    }

    .fmf-sheet__head {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        padding: 14px 16px 10px;
        flex: 0 0 auto;
    }

    .fmf-sheet__title {
        font-family: var(--font-family-inter);
        font-size: 1rem;
        font-weight: 600;
        color: var(--color-text-black, #13253a);
    }

    /* Updates as filters are ticked — the number moving is the feedback that
       a tick landed, which is what lets Apply be a confirmation. */
    .fmf-sheet__count {
        font-family: var(--font-family-inter);
        font-size: 0.75rem;
        color: var(--color-grey, #7c7c7c);
        margin-top: 2px;
    }

    .fmf-sheet__close {
        width: 44px;
        height: 44px;
        margin: -10px -8px 0 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 0;
        background: transparent;
        color: var(--color-text-black, #13253a);
        cursor: pointer;
    }

    .fmf-sheet__tabs {
        display: flex;
        border-bottom: 1px solid var(--bs-border-color);
        flex: 0 0 auto;
    }

    .fmf-tab {
        flex: 1 1 50%;
        min-height: 44px;
        border: 0;
        border-bottom: 2px solid transparent;
        background: transparent;
        font-family: var(--font-family-inter);
        font-size: 0.875rem;
        font-weight: 500;
        color: var(--color-grey, #7c7c7c);
        cursor: pointer;
    }

    .fmf-tab.is-active {
        border-bottom-color: var(--color-first);
        color: var(--color-first);
        font-weight: 600;
    }

    .fmf-sheet__body {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px 16px;
    }

    /*
     * The filter panel, freed of the desktop column's mechanics.
     *
     * `.flight-filter-panel` is capped at `100vh - 88px` with `overflow-y:
     * hidden`, unlocked only once useStickyPinned adds `.is-pinned` — a
     * sensible arrangement for a sticky column, and completely wrong inside a
     * drawer, where that class never arrives. Left alone it would cut the
     * filters off at an arbitrary height with no way to scroll them.
     *
     * The drawer body is the scroll container; this just has to get out of
     * its way.
     */
    .fmf-sheet__body .flight-filter-panel {
        max-height: none;
        overflow-y: visible;
        position: static;
        top: auto;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
    }

    .fmf-sort-list {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .fmf-sort {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 52px;
        padding: 10px 4px;
        border: 0;
        border-bottom: 1px solid var(--bs-border-color);
        background: transparent;
        text-align: start;
        cursor: pointer;
    }

    .fmf-sort__label {
        font-family: var(--font-family-inter);
        font-size: 0.9375rem;
        font-weight: 500;
        color: var(--color-text-black, #13253a);
    }

    .fmf-sort__hint {
        font-family: var(--font-family-inter);
        font-size: 0.8125rem;
        color: var(--color-grey, #7c7c7c);
    }

    .fmf-sort.is-active .fmf-sort__label,
    .fmf-sort.is-active .fmf-sort__hint {
        color: var(--color-first);
        font-weight: 600;
    }

    .fmf-sheet__foot {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 16px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--bs-border-color);
        flex: 0 0 auto;
    }

    .fmf-clear {
        flex: 0 0 auto;
        min-height: 44px;
        padding: 8px 14px;
        border: 1px solid var(--bs-border-color);
        border-radius: 8px;
        background: transparent;
        color: var(--color-text-black, #13253a);
        font-family: var(--font-family-inter);
        font-size: 0.875rem;
        font-weight: 500;
        cursor: pointer;
    }

    .fmf-clear:disabled {
        opacity: 0.45;
        cursor: default;
    }

    .fmf-apply {
        flex: 1 1 auto;
        min-height: 44px;
        border: 0;
        border-radius: 8px;
        background: var(--color-second);
        color: var(--color-white-same, #fff);
        font-family: var(--font-family-inter);
        font-size: 0.9375rem;
        font-weight: 600;
        cursor: pointer;
    }

    /*
     * Room at the very bottom of the page for the fixed bar.
     *
     * On the FOOTER, not the results section — the footer comes after it, so
     * padding there left the footer's last line sitting under the bar with no
     * way to scroll it clear. Padding the footer also keeps its own background
     * running behind the bar; padding the body instead would have shown a
     * strip of page colour under a dark footer.
     *
     * The height is measured and published by FlightMobileFilterBar rather
     * than guessed, because the chip row wraps to a second line on a narrow
     * phone and a literal would be wrong exactly when it matters. The class is
     * only on the body while that bar is mounted, so every other page keeps
     * its normal footer.
     */
    body.has-flight-filterbar footer {
        padding-bottom: calc(var(--flight-filterbar-h, 60px) + 12px) !important;
    }

    /* The last card still needs to clear the bar before the footer begins. */
    body.has-flight-filterbar .flight-list {
        padding-bottom: calc(var(--flight-filterbar-h, 60px) + 12px);
    }
}
