/* A mobile-only shell: header/footer stay visible; only the body scrolls. */
.mobile-bottom-sheet { display: none; }
@media (max-width: 991.98px) {
    .offcanvas.mobile-bottom-sheet-host,
    [data-bottom-sheet-host].mobile-bottom-sheet-host:not(.modal-content) {
        position: fixed !important;
        inset: auto 0 var(--storefront-keyboard-offset, 0px) !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: min(var(--mobile-sheet-min, 66.667dvh), calc(var(--storefront-sheet-height, 100dvh) - 12px)) !important;
        max-height: min(var(--mobile-sheet-max, 88dvh), calc(var(--storefront-sheet-height, 100dvh) - 12px)) !important;
        border: 0 !important;
        border-radius: 22px 22px 0 0 !important;
        background: #fff;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transform: translateY(100%) !important;
        transition: transform 180ms cubic-bezier(.2,.8,.2,1) !important;
    }
    /* The storefront theme places its shared backdrop at 10499. */
    .offcanvas.mobile-bottom-sheet-host { z-index: 10500 !important; }
    .offcanvas.mobile-bottom-sheet-host:is(.show, .showing):not(.hiding),
    [data-bottom-sheet-host][data-bottom-sheet-open]:not(.hiding) { transform: translateY(0) !important; }
    .mobile-bottom-sheet {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-height: min(var(--mobile-sheet-min, 66.667dvh), calc(var(--storefront-sheet-height, 100dvh) - 12px));
        max-height: min(var(--mobile-sheet-max, 88dvh), calc(var(--storefront-sheet-height, 100dvh) - 12px));
        overflow: hidden;
        background: var(--mobile-sheet-bg, #fff);
        direction: rtl;
    }
    .mobile-bottom-sheet__handle { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; padding: 10px 0 0; touch-action: none; cursor: grab; }
    .mobile-bottom-sheet__handle span { width: 34px; height: 3px; border-radius: 999px; background: #d5d5d5; }
    .mobile-bottom-sheet__header, .mobile-bottom-sheet__footer { flex: 0 0 auto; }
    .mobile-bottom-sheet__body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
    .mobile-bottom-sheet__footer { padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--mobile-sheet-bg, #fff); }
    [data-bottom-sheet-slot][hidden], [data-bottom-sheet-unused] { display: none !important; }

    /* Existing controls retain their classes, IDs, listeners and owning forms. */
    .mobile-bottom-sheet--adapted > .mobile-bottom-sheet__footer { max-height: 35dvh; overflow: auto; overscroll-behavior: contain; }
    .mobile-bottom-sheet--adapted > .mobile-bottom-sheet__body > :is(.offcanvas-body,.modal-body,.smb-nav,.smb2-scroll,.storefront-select-content) {
        height: auto !important; min-height: 0 !important; max-height: none !important; overflow: visible !important;
    }
    .offcanvas.product-list-sheet.mobile-bottom-sheet-host { min-height: min(66.667dvh, calc(var(--storefront-sheet-height, 100dvh) - 12px)) !important; --mobile-sheet-bg: var(--product-list-bg, #fff); }
    #smb-drawer.mobile-bottom-sheet-host { padding-bottom: 0 !important; --mobile-sheet-bg: var(--smb-bg, #1a1a2a); }
    #smb-drawer.mobile-bottom-sheet-host .mobile-bottom-sheet__handle span { background: var(--smb-text, #d5d5d5); }
    #smb-drawer.livm-panel.mobile-bottom-sheet-host { --mobile-sheet-bg: #fff; opacity: 1; }
    #smb-drawer.livm-panel.mobile-bottom-sheet-host .mobile-bottom-sheet__header,
    #smb-drawer.livm-panel.mobile-bottom-sheet-host .mobile-bottom-sheet__body,
    #smb-drawer.livm-panel.mobile-bottom-sheet-host .mobile-bottom-sheet__footer { padding: 12px 16px; }
    #smb-drawer.livm-panel.mobile-bottom-sheet-host .livm-panel-title { margin-bottom: 0; }
    .livm-backdrop:not([hidden]) { background: #0006; }

    /* Bootstrap still owns focus, backdrop, Escape and modal lifecycle. */
    .modal:has(.modal-content[data-bottom-sheet-host]) .modal-dialog {
        position: fixed !important; inset: auto 0 var(--storefront-keyboard-offset, 0px) !important;
        margin: 0 !important; width: 100% !important; max-width: 100% !important;
        min-height: 0 !important; height: auto !important; transform: none !important;
    }
    .modal-content[data-bottom-sheet-host] { padding: 0 !important; overflow: hidden; border-radius: 22px 22px 0 0 !important; }
    .modal-content[data-bottom-sheet-host] > .mobile-bottom-sheet { width: 100%; }
    .modal .modal-content[data-bottom-sheet-host]::before,
    .storefront-select-panel[data-bottom-sheet-host] .storefront-select-header::before { display: none !important; }
    .modal-content[data-bottom-sheet-host] .variant-picker-footer { margin: 0 !important; padding: 16px 20px; }
    .modal-content[data-bottom-sheet-host] > form.mobile-bottom-sheet {
        display: flex !important; flex-direction: column; overflow: hidden; margin: 0;
        min-height: min(var(--mobile-sheet-min, 66.667dvh), calc(var(--storefront-sheet-height, 100dvh) - 12px)) !important;
        max-height: min(var(--mobile-sheet-max, 88dvh), calc(var(--storefront-sheet-height, 100dvh) - 12px)) !important;
    }
    .modal-content[data-bottom-sheet-host] .mobile-bottom-sheet__body > .product-section-box { margin: 20px; }
}
@media (max-width: 991.98px) and (prefers-reduced-motion: reduce) {
    .offcanvas.mobile-bottom-sheet-host { transition-duration: .01ms !important; }
}
