/* The date range drawer (DateRangeDrawer around DateRangePicker) lists its presets in a column beside the calendars.
   Below the compact breakpoint the presets are one sideways-scrolling row above the calendars, which take the full
   width under it. Both components are Cluster.Blazor's and shared with the POS, which keeps the column; this file is
   the Portal's. Each selector outweighs the components' scoped rules, which load after it. */
@media (max-width: 1023.98px) {
    /* The theme sizes a right drawer to its content and pins it to the window's right edge, so content wider than the
       window puts the drawer's left edge, where the presets start, off the window. The drawer is the window's width
       instead, and its content scrolls down inside it rather than being cut off at the bottom; a window tall enough
       scrolls only the calendars (below). Padding rather than margin, so the edge-to-edge row below stays inside
       what the drawer scrolls. */
    .drawer-body > .drawer-container:has(> .date-range-wrapper) {
        flex: none;
        width: 100vw;
        min-width: 0;
        margin: 0;
        padding: 1.6rem;
        overflow-y: auto;
    }

    .drawer-body > .drawer-container > .date-range-wrapper {
        flex-direction: column;
        min-width: 0;
    }

    /* The list is the row: it scrolls sideways, with no scrollbar, edge to edge out over the drawer's padding, so an
       option cut off at the edge shows the row scrolls. The wrapper is the drawer's height and the calendars are
       usually taller, and a box that scrolls may shrink to nothing in a flex column, so the row keeps its height and
       the drawer or the calendars' panel scrolls instead. */
    .drawer-container > .date-range-wrapper > .date-range-list {
        flex: none;
        min-width: 0;
        margin: 0 -1.6rem;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .drawer-container > .date-range-wrapper > .date-range-list::-webkit-scrollbar {
        display: none;
    }

    /* Scroll's content is absolutely placed, which gives it no size of its own; in flow it is as wide and as tall as
       its options, which is what the list scrolls across. */
    .drawer-container > .date-range-wrapper > .date-range-list .scroll-wrapper {
        flex: none;
    }

    .drawer-container > .date-range-wrapper > .date-range-list .scroll-content {
        position: static;
        overflow: visible;
    }

    /* !important because the options' column comes from MudBlazor's flex-column. The spacers, with the options' gap,
       inset the first and last options by the drawer's padding, in line with the calendars; trailing padding is not
       reliably kept inside scrolled content. */
    .drawer-container > .date-range-wrapper > .date-range-list .scroll-content > div {
        flex-direction: row !important;
    }

    .drawer-container > .date-range-wrapper > .date-range-list .scroll-content > div::before,
    .drawer-container > .date-range-wrapper > .date-range-list .scroll-content > div::after {
        content: "";
        flex: 0 0 .8rem;
    }

    /* Each option keeps its label's full width, so the label stays on one line; the row scrolls instead of the
       options shrinking. */
    .drawer-container > .date-range-wrapper > .date-range-list .date-range-option {
        flex: none;
    }

    /* MudBlazor raises the month switch's buttons to z-index 1 and DateRangePicker's read-only overlay, which takes
       every tap on the calendars when a custom range is not allowed, to 5. Isolated, the calendars keep those layers
       to themselves, so the footer after them paints over them, and takes the taps, where they scroll under it. */
    .drawer-container > .date-range-wrapper > .date-range-calendar > .date-range-calendar-content {
        isolation: isolate;
    }

    /* The footer (Clear and Apply, DateRangeDrawer's content after the calendars) stays at the bottom of what scrolls,
       the drawer or the calendars' panel, while the calendars scroll under it, so Apply is in view however far they
       are scrolled. A sticky box stops at its scroller's padding, so it is offset by that padding (1.6rem, the
       drawer's and the panel's alike) to reach the scroller's edge, and its own padding keeps Apply that far inside.
       It covers what scrolls under it with the calendars' background, and runs down over their bottom padding so at
       rest it ends where they do. */
    .drawer-container > .date-range-wrapper > .date-range-calendar > .date-range-calendar-content + * {
        position: sticky;
        bottom: -1.6rem;
        margin-bottom: -1.6rem;
        padding: 1.6rem 0;
        background: var(--bg-tertiary);
    }
}

/* In a window tall enough, the drawer holds still under its header with the presets at its top, and only the
   calendars' panel scrolls. Under 500px tall (a phone held sideways) the presets and the footer would leave the
   calendars a strip of a row or two, so there the whole drawer scrolls (above). */
@media (max-width: 1023.98px) and (min-height: 500px) {
    .drawer-body > .drawer-container:has(> .date-range-wrapper) {
        overflow: hidden;
    }

    .drawer-container > .date-range-wrapper > .date-range-calendar {
        overflow-y: auto;
    }
}

/* MudBlazor sets two months side by side from 600px. A month's weeks are seven 40px days with 5px each side, 290px,
   so two months, their gap and the calendar's and the drawer's padding need about 655px, and the picker clips what
   does not fit. Below that, with room to spare, the months stack, as MudBlazor stacks them under 600px. */
@media (max-width: 679.98px) {
    .drawer-container > .date-range-wrapper .date-range-calendar-content .mud-picker-calendar-content {
        grid-template-columns: auto;
    }
}
