/* ==========================================================================
   Slot: phone bottom sheets for every dropdown.
   Driven by /js/mobile-sheet.js, which adds .m-sheet to a dropdown's panel
   while it is open on a phone. Same shell as the Appointments page sheets:
   18px top corners, grab handle, dimmed backdrop, slide-up, 48px rows.
   !important is deliberate: each dropdown positions itself with inline
   left/top/width (or its own CSS), and the sheet has to win over all of it.
   ========================================================================== */

.m-sheet-scrim { display: none; }

@media (max-width: 767.98px) {
    .m-sheet-scrim.on {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1059;
        background: rgba(15, 23, 42, .36);
        animation: mSheetFade .18s ease-out;
    }

    .m-sheet {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        height: auto !important;
        max-height: 85dvh !important;
        margin: 0 !important;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        background: #fff !important;
        border: 0 !important;
        border-radius: 18px 18px 0 0 !important;
        box-shadow: 0 -8px 24px rgba(15, 23, 42, .08) !important;
        padding: 22px 10px calc(12px + env(safe-area-inset-bottom)) !important;
        z-index: 1060 !important;
        /* Only the sheet's own motion: the dropdown's fade/slide/scale transitions and
           open animations would otherwise play on top of (or instead of) the slide-up. */
        transition: none !important;
        animation: mSheetUp .22s ease-out !important;
    }
    /* Closing: slide down and fade the backdrop, then mobile-sheet.js restores the
       panel with .m-sheet-reset so its own closing transition can't play either. */
    .m-sheet.m-sheet-out {
        animation: mSheetDown .18s ease-in forwards !important;
        pointer-events: none !important;
    }
    .m-sheet-scrim.on.out { animation: mSheetFadeOut .18s ease-in forwards; pointer-events: none; }

    /* Grab handle. Overrides any arrow/caret a dropdown drew on ::before. */
    .m-sheet::before {
        content: '' !important;
        display: block !important;
        position: absolute !important;
        top: 7px !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translateX(-50%) !important;
        width: 36px !important;
        height: 4px !important;
        border: 0 !important;
        border-radius: 2px !important;
        background: #E5E7EB !important;
        box-shadow: none !important;
    }
    .m-sheet::after { display: none !important; }

    /* List menus: thumb-sized rows. */
    /* Rows keep their own display (a filtered-out row stays hidden); flex rows
       centre via align-items, block rows via align-content. */
    .m-sheet-list :is(button, a, [role="option"], .sdd-opt):not(.m-sheet-keep) {
        min-height: 48px;
        font-size: 15px !important;
        border-radius: 10px;
        align-items: center;
        align-content: center;
    }

    /* SuperAdmin console is dark: its sheets use the console tokens, not white
       (its rows are light text, unreadable on #fff). */
    :is(.menu, .dd-menu, .dsel-menu, .el-src-menu, .bc-menu).m-sheet {
        background: var(--panel-3, #1E2A42) !important;
        border-top: 1px solid var(--line-strong, rgba(148,163,184,.26)) !important;
        box-shadow: 0 -12px 32px rgba(0, 0, 0, .5) !important;
        /* Stops under the console top bar (--head-h, measured by sa-console.js), like
           the console's modal sheets: the bar is never covered. */
        max-height: calc(100dvh - var(--head-h, 104px) - 10px) !important;
    }
    :is(.menu, .dd-menu, .dsel-menu, .el-src-menu, .bc-menu).m-sheet::before {
        background: var(--line-strong, rgba(148,163,184,.26)) !important;
    }
    /* The light backdrop lifts a dark page instead of dimming it; use the console's
       modal backdrop. It starts under the top bar so the bar stays readable. */
    .m-sheet-scrim.on:has(+ :is(.menu, .dd-menu, .dsel-menu, .el-src-menu, .bc-menu).m-sheet) {
        background: linear-gradient(to bottom, transparent var(--head-h, 104px), rgba(5, 10, 20, .72) var(--head-h, 104px));
    }
    /* Console topbars are position:sticky. Locking body too makes body their scroll
       container, so the bar jumps back to the top of the page (off screen). Locking
       html alone still stops the page scrolling. */
    html.m-sheet-lock:has(:is(.menu, .dd-menu, .dsel-menu, .el-src-menu, .bc-menu).m-sheet) body {
        overflow: visible !important;
    }

    /* Ancestors that would pin the sheet to themselves instead of the screen
       (set by mobile-sheet.js only while a sheet is open). */
    .m-sheet-host {
        transform: none !important;
        filter: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        perspective: none !important;
        contain: none !important;
        will-change: auto !important;
    }

    /* Page behind a sheet doesn't scroll. */
    html.m-sheet-lock,
    html.m-sheet-lock body { overflow: hidden !important; }
    /* Keep the width steady where scrollbars take space, or the lock itself fires
       resize and dropdowns that close on resize would shut the sheet at once. */
    html.m-sheet-lock { scrollbar-gutter: stable; }
}

@keyframes mSheetUp { from { translate: 0 100%; } to { translate: 0 0; } }
@keyframes mSheetDown { from { translate: 0 0; } to { translate: 0 100%; } }
@keyframes mSheetFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mSheetFadeOut { from { opacity: 1; } to { opacity: 0; } }
/* Outside the media query on purpose: also covers the frame where a rotated or
   resized screen drops back to a dropdown. */
.m-sheet-reset,
.m-sheet-reset * { transition: none !important; animation: none !important; }
@media (prefers-reduced-motion: reduce) {
    .m-sheet, .m-sheet.m-sheet-out, .m-sheet-scrim.on, .m-sheet-scrim.on.out { animation: none !important; }
}
