/* A page's own list of tabs (a vertical TabButtons in .page > .side-menu: Reports, Orders, Menus, Management) goes
   on top of the page below the compact breakpoint, as one sideways-scrolling row, and the page content takes the
   full width under it. The navigation's .side-menu is not inside a .page, and the menu editor's holds no tabs, so
   neither is matched. TabButtons is shared with the POS, which keeps its vertical list; this file is the Portal's.
   TabButtons' Scroll keeps the row's selected tab in view (SelectedSelector). */
@media (max-width: 1023.98px) {
    .page:has(> .side-menu .side-tab-buttons) {
        flex-direction: column;
    }

    /* The content under the row shrinks to the page rather than holding it open at its own minimum size. */
    .page:has(> .side-menu .side-tab-buttons) > :not(.side-menu) {
        min-width: 0;
        min-height: 0;
    }

    /* Edge to edge, out over the page's padding (base.css), so a tab cut off at the edge shows the row scrolls. */
    .page > .side-menu:has(.side-tab-buttons) {
        flex: none;
        min-width: 0;
        margin: 0 -1.2rem;
        overflow: visible;
    }

    /* Scroll's content is absolutely placed, which gives the row no height of its own; in flow it has its tabs'. */
    .page > .side-menu:has(.side-tab-buttons) .scroll-wrapper {
        flex: none;
    }

    .page > .side-menu:has(.side-tab-buttons) .scroll-content {
        position: static;
        overflow: visible;
    }

    /* The row scrolls itself, with no scrollbar, and its width comes from the page alone: without the containment
       its tabs' full width would hold every ancestor up to the layout open past the window. The spacers inset the
       first and last tabs inside the scrolled content, where trailing padding is not reliably kept. */
    .page > .side-menu .side-tab-buttons {
        flex-direction: row !important;
        gap: .8rem;
        contain: inline-size;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }

    .page > .side-menu .side-tab-buttons::-webkit-scrollbar {
        display: none;
    }

    .page > .side-menu .side-tab-buttons::before,
    .page > .side-menu .side-tab-buttons::after {
        content: "";
        flex: 0 0 .4rem;
    }

    /* Each tab keeps its whole label on one line; the row scrolls instead of the tabs shrinking. */
    .page > .side-menu .side-tab-buttons .tab-button {
        flex: none;
        width: auto;
        margin-bottom: 0;
    }

    .page > .side-menu .side-tab-buttons .tab-button-content > span {
        max-width: none;
        white-space: nowrap;
    }

    /* A control a page keeps on its own line over the content (the Orders search, .page-tabs-trailing) moves to the
       end of the tab row: on its own line under the row it is a band holding one button between the tabs and the
       content. The column around it is unwrapped so the control and the panel are the grid's own items. */
    /* !important because a page can carry MudBlazor's d-flex (MenuHome's does), whose display is !important too. */
    .page:has(> .side-menu .side-tab-buttons):has(> * > .page-tabs-trailing) {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .page:has(> .side-menu .side-tab-buttons) > :has(> .page-tabs-trailing) {
        display: contents !important;
    }

    .page:has(> .side-menu .side-tab-buttons):has(> * > .page-tabs-trailing) > .side-menu {
        grid-area: 1 / 1;
        margin-right: 0;
    }

    .page:has(> .side-menu .side-tab-buttons) > * > .page-tabs-trailing {
        grid-area: 1 / 2;
        align-self: center;
        margin: 0 !important;
    }

    .page:has(> .side-menu .side-tab-buttons) > :has(> .page-tabs-trailing) > :not(.page-tabs-trailing) {
        grid-area: 2 / 1 / 3 / 3;
        min-width: 0;
        min-height: 0;
    }
}
