/* =====================================================
   Drawer — overlay panel (desktop) / bottom sheet (mobile)
   =====================================================

   Imported by components/ui/Drawer.tsx itself rather than by each page, the
   same way FlightMobileFilterBar owns flight-mobile-filters.css. A primitive
   that can be lazily loaded should not depend on a page having remembered to
   import its stylesheet.

   Deliberately small — Bootstrap utilities and the :root tokens do almost
   everything. What is here is only what Bootstrap has no equivalent for: the
   slide geometry, the two-breakpoint shape change, and the swipe transform.

   z-index sits above Modal (backdrop 1050 / dialog 1055) on purpose: a drawer
   opened from inside a modal — the flight-details popup on multi-city — must
   cover it, never slide underneath it.
   ===================================================== */

.ld-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1060;
    background: rgba(15, 39, 51, 0.5);
    opacity: 0;
    transition: opacity 0.28s ease;
}

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

.ld-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    z-index: 1061;
    background: var(--color-white);
    /* Never taller than the visual viewport. dvh, not vh: on mobile Safari a
       100vh panel hides its own footer behind the browser chrome. */
    max-height: 100dvh;
    transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
    /* The panel is the scroll container's ancestor, not a scroller itself —
       .ld-panel__body scrolls, so the sticky header stays put. */
    overflow: hidden;
}

/* ── Mobile: full-height sheet, slides up ─────────────────────────────── */

.ld-panel {
    left: 0;
    right: 0;
    bottom: 0;
    /* Clears the notch/Dynamic Island rather than sliding under it. On a device
       without one this is 0 and the sheet is genuinely full-screen. */
    top: env(safe-area-inset-top, 0px);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 32px rgba(15, 39, 51, 0.22);
    transform: translateY(100%);
}

.ld-panel.is-open { transform: translateY(0); }

/* ── Desktop: right-hand overlay ──────────────────────────────────────── */

@media (min-width: 768px) {
    .ld-panel {
        top: 0;
        bottom: 0;
        left: auto;
        right: 0;
        /* The ticket's "about 80% of the screen width", with a ceiling so the
           content does not stretch to an unreadable measure on a wide monitor. */
        width: min(80vw, 1120px);
        max-height: none;
        border-radius: 0;
        box-shadow: -12px 0 40px rgba(15, 39, 51, 0.22);
        transform: translateX(100%);
    }

    .ld-panel.is-open { transform: translateX(0); }
}

/* Motion here is spatial — it says where the panel came from — so under
   reduced-motion the panel still appears, it just stops travelling. */
@media (prefers-reduced-motion: reduce) {
    .ld-backdrop,
    .ld-panel { transition: none; }
}

/* ── Header ───────────────────────────────────────────────────────────── */

.ld-panel__head {
    flex: 0 0 auto;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 16px 12px;
    background: var(--color-white);
    border-bottom: 1px solid var(--review-flight-border, #dfe7ea);
    /* The whole header is the swipe surface on mobile; without this the browser
       claims the vertical drag for its own scroll before we see a touchmove. */
    touch-action: none;
}

@media (min-width: 768px) {
    .ld-panel__head {
        padding: 14px 24px;
        touch-action: auto;
    }
}

/* The grab handle. Presentational — the swipe it advertises is never the only
   way out (✕, Esc, backdrop and Back all close the drawer), which is what keeps
   this from being a gesture-only interaction. */
.ld-panel__grip {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--color-grey, #bdbdbd);
}

@media (min-width: 768px) {
    .ld-panel__grip { display: none; }
}

.ld-panel__titles {
    flex: 1 1 auto;
    min-width: 0;
    /* Clears the grip on mobile so a two-line title never collides with it. */
    padding-top: 8px;
}

@media (min-width: 768px) {
    .ld-panel__titles { padding-top: 0; }
}

.ld-panel__title {
    margin: 0;
    font-family: var(--font-family-inter);
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--color-dark);
    /* Long airport names wrap rather than truncate — the name is the one thing
       in this header nobody should have to hover to read. */
    overflow-wrap: anywhere;
}

.ld-panel__subtitle {
    margin: 2px 0 0;
    font-family: var(--font-family-inter);
    font-size: 0.8125rem;
    color: var(--color-content);
    overflow-wrap: anywhere;
}

.ld-panel__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* 44x44 — the icon inside is 18px; the rest is hit area. */
    width: 44px;
    height: 44px;
    margin-top: 2px;
    padding: 0;
    border: 1px solid var(--review-flight-border, #dfe7ea);
    border-radius: 999px;
    background: var(--color-white);
    color: var(--color-dark);
    cursor: pointer;
}

.ld-panel__close:hover { background: var(--bgColor-light); }

/* ── Body ─────────────────────────────────────────────────────────────── */

.ld-panel__body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Keeps the last row clear of the home indicator on a gesture-nav phone. */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    /* Anything focused low in the panel scrolls clear of the sticky header
       rather than landing behind it (WCAG 2.2 focus-not-obscured). */
    scroll-padding-top: 72px;
}

/* ── Focus ────────────────────────────────────────────────────────────── */

/* 2px at 3:1 against both surfaces, offset so it reads on a filled control. */
.ld-panel :focus-visible,
.ld-panel__close:focus-visible {
    outline: 2px solid var(--color-first);
    outline-offset: 2px;
}
