/**
 * Booking → payment → confirmation logo bridge.
 * Shares wallpaper/flip mechanics with post-reg-logo-sequence.css (§4.8).
 */

#booking-pay-logo-seq {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100svh;
    height: 100dvh;
    z-index: 2147483005;
    pointer-events: none;
    overflow: hidden;
    background: var(--gradient-sunrise-field);
}

/* Single Sun Road mark on the field. HTML, not a background tile: dusk sets
   background-image none on this root, and a tile would disappear. Hidden
   while the stage or the Stripe face owns the centre. */
#booking-pay-logo-seq .bplb-field-mark {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 12.5rem;
    height: 12.5rem;
    transform: translate(-50%, -50%);
    z-index: 1;
    pointer-events: none;
}

#booking-pay-logo-seq:has(.prls-stage) .bplb-field-mark,
#booking-pay-logo-seq.prls--flipped .bplb-field-mark,
#booking-pay-logo-seq.bplb--pay-revealed .bplb-field-mark {
    visibility: hidden;
}

/* Only while actively covering — wallpaper-only must not suppress shell/CRO.
 * html.ns-bplb-* class fallbacks for engines without reliable :has(). */
html:has(#booking-pay-logo-seq.bplb--active) #care-transition-shell,
html:has(#booking-pay-logo-seq.bplb--active) #care-transition-shell.cts-shell--visible,
html.ns-bplb-active #care-transition-shell,
html.ns-bplb-active #care-transition-shell.cts-shell--visible {
    opacity: 0 !important;
    pointer-events: none !important;
}

html:has(#booking-pay-logo-seq.bplb--active).ns-care-shell-pending::before,
html.ns-bplb-active.ns-care-shell-pending::before {
    opacity: 0 !important;
}

html:has(#booking-pay-logo-seq.bplb--active) #checkout-redirect-overlay,
html:has(#booking-pay-logo-seq.bplb--active) #checkout-redirect-overlay.is-visible,
html.ns-bplb-active #checkout-redirect-overlay,
html.ns-bplb-active #checkout-redirect-overlay.is-visible {
    display: none !important;
    opacity: 0 !important;
}

#booking-pay-logo-seq.bplb--active {
    pointer-events: auto;
}

/*
 * Card-rise must paint above logo-bridge / post-reg wallpaper (2147483005)
 * on Safari — leave→book, reschedule flip, and open-intake all share this stack.
 */
html.cpi-card-rising .pbs-card-rise-clone,
html:has(#booking-pay-logo-seq.bplb--active) .pbs-card-rise-clone,
html:has(#booking-pay-logo-seq.bplb--below-modal) .pbs-card-rise-clone,
html.ns-bplb-active .pbs-card-rise-clone,
html.ns-bplb-below-modal .pbs-card-rise-clone,
html:has(#post-reg-logo-seq.prls--welcome) .pbs-card-rise-clone,
html:has(#post-reg-logo-seq.prls--interactive) .pbs-card-rise-clone,
html:has(#post-reg-logo-seq.prls--below-modal) .pbs-card-rise-clone,
html.ns-prls-welcome .pbs-card-rise-clone,
html.ns-prls-interactive .pbs-card-rise-clone,
html.ns-prls-below-modal .pbs-card-rise-clone {
    z-index: 2147483010;
}

/*
 * Confirm Complete Now flip: same gradient + mark as html.bplb-confirm-wallpaper
 * so the field does not flash when leaving wallpaper-only, but the root is an
 * opaque full-bleed cover so confirmation chrome is not visible behind the card.
 */
#booking-pay-logo-seq.bplb--confirm-flip {
    background: var(--gradient-sunrise-field);
}

html:has(#booking-pay-logo-seq.bplb--confirm-flip) .bc-page,
html.ns-bplb-confirm-flip .bc-page {
    visibility: hidden;
    pointer-events: none;
}

/* Body-mounted typeaheads must sit above the confirm / wizard root. */
html:has(#booking-pay-logo-seq.bplb--confirm-flip) .pac-container,
html:has(#booking-pay-logo-seq.bplb--confirm-flip) .ta-dropdown,
html:has(#booking-pay-logo-seq.prls--wizard) .pac-container,
html:has(#booking-pay-logo-seq.prls--wizard) .ta-dropdown,
html:has(#post-reg-logo-seq.prls--wizard) .pac-container,
html:has(#post-reg-logo-seq.prls--wizard) .ta-dropdown,
html.ns-bplb-confirm-flip .pac-container,
html.ns-bplb-confirm-flip .ta-dropdown,
html.ns-bplb-wizard .pac-container,
html.ns-bplb-wizard .ta-dropdown,
html.ns-prls-wizard .pac-container,
html.ns-prls-wizard .ta-dropdown {
    z-index: 2147483010 !important;
}

/*
 * Passive confirmation: hide the full-viewport bridge root. Wallpaper paints
 * only inside #main-content (gaps behind cards). Sidebar + header keep normal
 * portal chrome — do not transparent them or cover them with a fixed field.
 */
#booking-pay-logo-seq.bplb--wallpaper-only {
    display: none !important;
    pointer-events: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/*
 * Leave→book / care-path: keep full-bleed branded field under --z-modal (400)
 * so PBM owns the stack without html.bplb-confirm-wallpaper trapping
 * #main-content modals under the sticky header.
 */
#booking-pay-logo-seq.bplb--below-modal {
    z-index: 350;
    pointer-events: none;
}

html.bplb-confirm-wallpaper #main-content {
    position: relative;
    background: var(--gradient-sunrise-field) !important;
    background-attachment: local;
}

/* Content column; transparent so the sunrise field shows
   between cards. Sidebar + .patient-portal-header are untouched. */
html.bplb-confirm-wallpaper .patient-portal-content {
    position: relative;
    z-index: 1;
    background: transparent !important;
    background-color: transparent !important;
}

/*
 * That z-index makes .patient-portal-content a stacking context, which traps
 * every overlay the page owns — a fixed #patientBookingModal at 2147483010
 * still paints at level 1, i.e. UNDER #booking-pay-logo-seq (2147483005).
 * Book on meet-your-provider opened the PBM beneath the wallpaper and left the
 * patient stranded (a reload dropped the class, which is why the second try
 * worked). While the field is up the page is fully covered, so releasing the
 * context is invisible to the page and hands the root stack back to overlays.
 */
html.bplb-confirm-wallpaper:has(#booking-pay-logo-seq.bplb--active) .patient-portal-content,
html.bplb-confirm-wallpaper.ns-bplb-active .patient-portal-content {
    z-index: auto;
}

html.bplb-confirm-wallpaper .bc-page {
    background: transparent !important;
    background-color: transparent !important;
}

#booking-pay-logo-seq .prls-stage {
    position: fixed;
    left: var(--prls-left, 50%);
    top: var(--prls-top, 50%);
    width: var(--prls-w, 12.5rem);
    height: var(--prls-h, 12.5rem);
    margin: 0;
    perspective: 1600px;
    overflow: visible;
    transition:
        left var(--prls-move-ms, 520ms) cubic-bezier(0.22, 1, 0.36, 1),
        top var(--prls-move-ms, 520ms) cubic-bezier(0.22, 1, 0.36, 1),
        width var(--prls-move-ms, 520ms) cubic-bezier(0.22, 1, 0.36, 1),
        height var(--prls-move-ms, 520ms) cubic-bezier(0.22, 1, 0.36, 1),
        opacity 360ms ease-out;
}

#booking-pay-logo-seq .prls-card {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    overflow: visible;
    transition: transform var(--prls-flip-ms, 680ms) cubic-bezier(0.4, 0.0, 0.2, 1);
}

#booking-pay-logo-seq.prls--flipped .prls-card {
    transform: rotateY(180deg);
}

/* Conceal: hide back-face during spinToLogo unflip (Safari mid-flip text leak). */
#booking-pay-logo-seq.prls--concealing .prls-face--back {
    opacity: 0 !important;
    visibility: hidden;
    pointer-events: none;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

#booking-pay-logo-seq .prls-face {
    position: absolute;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

#booking-pay-logo-seq .prls-face--front {
    inset: 0;
    background: transparent;
    /* Promote a compositor layer so Safari preserve-3d does not drop
       the circle clip and beam mask and leak the back face. */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

#booking-pay-logo-seq .prls-face--back {
    left: 50%;
    top: 50%;
    width: min(26rem, calc(100vw - 2rem));
    height: auto;
    min-height: 100%;
    transform: translate(-50%, -50%) rotateY(180deg);
    background: transparent;
    overflow: visible;
}

#booking-pay-logo-seq .prls-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 10px 28px color-mix(in srgb, var(--color-ink) 22%, transparent));
}

#booking-pay-logo-seq .bplb-pay-shell {
    width: min(22rem, calc(100vw - 2rem));
    min-height: 12rem;
    border-radius: 0.875rem;
    background: color-mix(in srgb, var(--color-paper) 92%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-ink) 12%, transparent);
    box-shadow: 0 16px 40px color-mix(in srgb, var(--color-ink) 12%, transparent);
    transition: opacity 120ms ease-out;
    /* Out of the render tree until the flip. Opacity 0 still composites
       on Safari preserve-3d and reads as a cream square behind the mark. */
    display: none;
    opacity: 0;
    visibility: hidden;
}

#booking-pay-logo-seq.prls--flipped .bplb-pay-shell {
    display: block;
    opacity: 1;
    visibility: visible;
}

/* Real Confirm/ECM open — hide timing shell ghost */
#booking-pay-logo-seq.bplb--pay-revealed .bplb-pay-shell {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/*
 * Unflip: the ghost must match the stage so it reads as the same card
 * shrinking into the mark. Default back-face width (26rem) is wider than
 * the 200px logo stage and looks like a new white rectangle appearing.
 */
#booking-pay-logo-seq.bplb--unflipping .prls-face--back {
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    transform: rotateY(180deg);
}

#booking-pay-logo-seq.bplb--unflipping .bplb-pay-shell {
    width: 100%;
    height: 100%;
    min-height: 0;
}

/*
 * Forward membership flip: lock the ghost to the stage so it grows with the
 * 200px mark instead of popping in as a 22rem white rectangle. The real
 * overlay starts pending (opacity 0, still laid out) and fades in mid-rotate.
 */
#booking-pay-logo-seq.bplb--payflipping .prls-face--back {
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    transform: rotateY(180deg);
}

#booking-pay-logo-seq.bplb--payflipping .bplb-pay-shell {
    width: 100%;
    height: 100%;
    min-height: 0;
}

#membershipConfirmModal.bplb-payflip-pending,
#embeddedCheckoutModal.bplb-payflip-pending,
#confirmPaymentModal.bplb-payflip-pending {
    opacity: 0;
    pointer-events: none;
}

#membershipConfirmModal.bplb-payflip-landed,
#embeddedCheckoutModal.bplb-payflip-landed,
#confirmPaymentModal.bplb-payflip-landed {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 220ms ease;
}

/* Transparent billing overlays while wallpaper owns the field */
html.bplb-pay-open #confirmPaymentModal,
html.bplb-pay-open #embeddedCheckoutModal,
html.bplb-pay-open #membershipConfirmModal,
#confirmPaymentModal[data-bplb-bridge="1"],
#embeddedCheckoutModal[data-bplb-bridge="1"],
#membershipConfirmModal[data-bplb-bridge="1"] {
    background: transparent !important;
}

/*
 * Condensed pay cards on wallpaper (pre-bridge compact sizes). Without these,
 * ECM max-height:100dvh + full-bleed field reads as a full-screen modal again.
 */
html.bplb-pay-open #confirmPaymentModal > div,
html.bplb-pay-open #membershipConfirmModal > div,
#confirmPaymentModal[data-bplb-bridge="1"] > div,
#membershipConfirmModal[data-bplb-bridge="1"] > div {
    width: 100% !important;
    max-width: 22rem !important;
    max-height: min(
        34rem,
        calc(
            100svh - 2rem
        )
    ) !important;
    max-height: min(
        34rem,
        calc(
            100dvh - 2rem
        )
    ) !important;
    /* visualViewport.height already excludes keyboard — prefer when set. */
    max-height: min(34rem, calc(var(--bplb-vv-height, 100dvh) - 2rem)) !important;
    /* Home-indicator floor only. The overlay is already the visual-viewport
     * band, so adding --bplb-vv-inset-bottom here charged the keyboard twice
     * and grew the Cancel region until the card form was squeezed out. */
    padding: max(0.875rem, env(safe-area-inset-top, 0px)) 1rem
        max(0.75rem, env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 0.875rem !important;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Single scrollport = panel; mount expands inside (no nested ECM scrollbar). */
html.bplb-pay-open #embeddedCheckoutModal [data-ecm-panel],
#embeddedCheckoutModal[data-bplb-bridge="1"] [data-ecm-panel] {
    width: 100% !important;
    max-width: 22rem !important;
    max-height: min(
        34rem,
        calc(
            100svh - 2rem
        )
    ) !important;
    max-height: min(
        34rem,
        calc(
            100dvh - 2rem
        )
    ) !important;
    max-height: min(34rem, calc(var(--bplb-vv-height, 100dvh) - 2rem)) !important;
    /* Home-indicator floor only — see the ConfirmPaymentModal note above. */
    padding: max(0.75rem, env(safe-area-inset-top, 0px)) 0.875rem
        max(0.625rem, env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 0.875rem !important;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

html.bplb-pay-open #embeddedCheckoutModal [data-ecm-mount],
#embeddedCheckoutModal[data-bplb-bridge="1"] [data-ecm-mount] {
    max-height: none !important;
    overflow: visible;
}

/*
 * Spin → logo handoff. The wallpaper is an opaque full-screen layer well above
 * these modals, so cutting both in the same frame let the patient see only the
 * wallpaper arrive — no sense of the queue/booking card becoming the logo.
 * Fade the panel out while the wallpaper fades in: opacity only, so it stays
 * cheap to composite on mobile Safari, and `visibility` is delayed to the end
 * so the ramp is actually visible before the panel goes inert.
 */
#patientBookingModal.bplb--booking-hidden,
#patientJoinQueueModal.bplb--booking-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transition: opacity 220ms ease, visibility 0s linear 220ms !important;
}

/*
 * prls--concealing is added at spin start and cleared once the fly settles, so
 * it scopes the fade to exactly the spin-in window — teardown and the payment
 * flip keep their own timing.
 */
#booking-pay-logo-seq.bplb--active.prls--concealing {
    transition: opacity 220ms ease;
}

@media (prefers-reduced-motion: reduce) {
    #patientBookingModal.bplb--booking-hidden,
    #patientJoinQueueModal.bplb--booking-hidden,
    #booking-pay-logo-seq.bplb--active.prls--concealing {
        transition: none !important;
    }
}

/* Confirmation landing: page fades in over wallpaper */
html.bplb-confirm-pending .bc-page,
html.bplb-confirm-pending .myp-shell {
    opacity: 0;
}

.bc-page.bplb-bc-page--reveal,
.myp-shell.bplb-bc-page--reveal {
    opacity: 1;
    transition: opacity 420ms ease-out;
}

/*
 * Membership pay / onboarding PBM sit on wallpaper after flipToPayment.
 * A grey overlay-host backdrop is what made the field look like a dimmed
 * portal page instead of the corporate card flip.
 */
html.bplb-pay-open #patientBookingModal,
html.myp-wallpaper-dest #patientBookingModal,
html.bplb-confirm-wallpaper #patientBookingModal {
    background: transparent !important;
    z-index: 2147483010;
}

html.bplb-pay-open #patientBookingModal .patient-overlay-backdrop,
html.myp-wallpaper-dest #patientBookingModal .patient-overlay-backdrop,
html.bplb-confirm-wallpaper #patientBookingModal .patient-overlay-backdrop,
html.bplb-pay-open #patientBookingModal.pbs-modal-rise-pending .patient-overlay-backdrop,
html.myp-wallpaper-dest #patientBookingModal.pbs-modal-rise-pending .patient-overlay-backdrop {
    background: transparent !important;
    opacity: 0 !important;
    animation: none !important;
}

#booking-pay-logo-seq.bplb--confirm-landing.bplb--fading,
#booking-pay-logo-seq.bplb--confirm-landing.bplb--fading .prls-stage {
    opacity: 0;
}

/* Field and mark leave with the page's 420ms reveal, not as a cut. */
#booking-pay-logo-seq.bplb--confirm-landing.bplb--fading {
    transition: opacity 420ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
    #booking-pay-logo-seq.bplb--confirm-landing.bplb--fading {
        transition: none;
    }
}

/*
 * Prep wizard flip — tall panel must sit in the viewport.
 * The stage stays a small centered logo box; face offsets are relative to that
 * stage, so translateY(-50%) + content height clips the header above the root
 * (overflow:hidden). Offset top/left by --prls-* so the face top-anchors.
 */
#booking-pay-logo-seq.prls--wizard .prls-face--back {
    /* Mirror post-reg: fixed resolves against the layout viewport, so a raised
     * keyboard strands the face unless the visual offset is added back. */
    top: calc(
        1rem
        + var(--prls-vv-offset-top, var(--bplb-vv-offset-top, 0px))
        - var(--prls-top, 0px)
    );
    left: calc(50vw - var(--prls-left, 0px));
    width: min(40rem, calc(100vw - 2rem));
    /* Join pattern: VV height only — no 100vh / safe-area re-subtract. */
    max-height: calc(100svh - 2rem);
    max-height: calc(100dvh - 2rem);
    /* visualViewport.height already excludes keyboard — do not re-subtract. */
    max-height: calc(var(--prls-vv-height, var(--bplb-vv-height, 100dvh)) - 2rem);
    min-height: 0;
    transform: translate(-50%, 0) rotateY(180deg);
    align-items: stretch;
    justify-content: flex-start;
    /* The face is the scroller. A card scrollport paints a gutter on the
       card edge and breaks sticky Next. Hide the rail. */
    overflow: auto;
    scrollbar-width: none;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    /* Home-indicator floor only: the face is anchored into the visual viewport
     * and capped at its height, so a keyboard inset here is dead scroll that
     * pushes the wizard footer off the visible band. */
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    scroll-padding-bottom: 7.5rem;
}

#booking-pay-logo-seq.prls--wizard .prls-face--back::-webkit-scrollbar {
    width: 0;
    height: 0;
}

#booking-pay-logo-seq.prls--wizard.prls--flipped .prls-stage {
    perspective: none;
}

#booking-pay-logo-seq.prls--wizard .prls-face--back #unifiedIntakeWizard,
#booking-pay-logo-seq.prls--wizard .prls-face--back .intake-wizard-panel {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

#booking-pay-logo-seq.prls--wizard #unifiedIntakeWizard.intake-wizard--post-reg-flip {
    display: block;
    background: transparent;
}

#booking-pay-logo-seq.prls--wizard #unifiedIntakeWizard.intake-wizard--post-reg-flip .wizard-wrapper {
    max-width: none;
    margin: 0;
    animation: none;
    /* Keep bottom padding — zeroing it put Continue under Safari chrome. */
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
}

/* The face scrolls. The linen card must not be a scrollport. */
#booking-pay-logo-seq.prls--wizard #unifiedIntakeWizard.intake-wizard--post-reg-flip .intake-wizard-panel {
    background: var(--color-linen);
    max-height: none;
    height: auto;
    overflow: visible;
    border-radius: 20px;
}

html.myp-wallpaper-dest .sidebar,
html.myp-wallpaper-dest #sidebarOverlay,
html.myp-wallpaper-dest #sidebarToggle,
html.myp-wallpaper-dest .patient-portal-header,
html.myp-wallpaper-dest #headerNorthstarPlusBadge,
html.myp-wallpaper-dest #scheduledUpcomingBanner,
html.myp-wallpaper-dest #scheduledCheckInBanner,
html.myp-wallpaper-dest #scheduledCheckedInWaitingBanner {
    display: none !important;
}

html.myp-wallpaper-dest #main-content {
    margin-left: 0;
    padding-top: var(--space-lg, 1.5rem);
}

@media (prefers-reduced-motion: reduce) {
    #booking-pay-logo-seq .prls-stage,
    #booking-pay-logo-seq .prls-card,
    .bc-page.bplb-bc-page--reveal,
    .myp-shell.bplb-bc-page--reveal {
        transition: none !important;
    }
}
