/*
 * Phones and tablets (Kevin, 11 Oct): the app is used on tablets and phones a lot.
 * The original stacked everything into one column below 1024px: the icon side bar
 * and the menu panel each took a full screen above the page. Here the slim icon
 * rail stays on the left, the page gets the rest of the width, and the labelled
 * menu panel opens over the page from the rail's toggle (responsive-script).
 * Loaded on every page, after brand.css.
 */
@media (max-width: 1024px) {
    .portal-shell,
    .portal-shell.is-collapsed,
    .portal-shell.nav-panel-collapsed,
    .portal-sidebar-initial-collapsed .portal-shell {
        grid-template-columns: 52px minmax(0, 1fr);
    }

    .portal-sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        height: 100dvh;
        padding: 0;
        margin: 0;
    }

    /* The menu panel: closed unless opened, and then over the page, not beside it. */
    .portal-shell .nav-panel {
        display: none;
    }

    .portal-shell.nav-panel-open .nav-panel {
        display: block;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 52px;
        width: min(270px, calc(100vw - 52px));
        z-index: 80;
        overflow-y: auto;
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.18);
    }

    .portal-shell.nav-panel-open::after {
        content: '';
        position: fixed;
        inset: 0 0 0 52px;
        z-index: 70;
        background: rgba(0, 0, 0, 0.25);
    }

    .portal-content {
        min-width: 0;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Top bar: bleeds over the page padding (matched to it), and its tabs scroll sideways if they don't fit. */
    .topbar {
        gap: 0.5rem;
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .topbar-left {
        min-width: 0;
        overflow-x: auto;
    }

    .cv-tabs {
        flex-wrap: nowrap;
    }
}

@media (max-width: 640px) {
    .portal-content {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .topbar {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Tab labels hidden on phones: the icons stay, and screen readers still hear the name. */
    .cv-tab span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* Every page's tables and pop-over panels (manifest, customers, waivers, back office). */
@media (max-width: 1024px) {
    .manifest-content,
    .manifest-group,
    .manifest-venue-group {
        min-width: 0;
    }

    /* A table that can't fit scrolls sideways inside its box, not the whole page. */
    .manifest-table-wrap {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Filters / Columns panels fit the screen (they were laid out wider, pushing the page sideways). */
    .manifest-filters-popover,
    .manifest-columns-popover {
        position: fixed;
        top: 3.25rem;
        left: 0.5rem;
        right: 0.5rem;
        width: auto;
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
    }
}

@media (max-width: 1024px) {
    /* The Filters button on Customers / Signed Waivers: its summary shortens instead of overflowing. */
    .manifest-filters-picker,
    .manifest-filters-trigger {
        max-width: 100%;
        min-width: 0;
    }

    .manifest-filters-bar {
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
    }

    .manifest-filters-bar > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (max-width: 640px) {
    /* Dashboard: the four number cards two to a row (they were 69px wide). */
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ---- Accessibility (UI audit, 11 Oct) ---- */

/* Read by screen readers, not shown (each page's heading, names of icon-only buttons). */
.portal-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* "Skip to main content": the first stop for the keyboard, shown only when it has focus. */
.portal-skip-link {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 1000;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    background: #111111;
    color: #FFFFFF;
    font-weight: 700;
    text-decoration: none;
    transform: translateY(-200%);
}

.portal-skip-link:focus {
    transform: none;
    outline: 2px solid #C8102E;
    outline-offset: 2px;
}

#portal-main:focus {
    outline: none;
}

/* A clear focus ring: white on the black side bar, red elsewhere (it was a faint grey line). */
.portal-sidebar a:focus-visible,
.portal-sidebar button:focus-visible {
    outline: 2px solid #FFFFFF;
    outline-offset: -3px;
}

.portal-content input:focus-visible,
.portal-content select:focus-visible,
.portal-content textarea:focus-visible,
.portal-content button:focus-visible,
.portal-content summary:focus-visible,
.portal-content a:focus-visible,
.nav-panel a:focus-visible,
.nav-panel button:focus-visible {
    outline: 2px solid #C8102E !important;
    outline-offset: 1px;
}

/* The Text size setting reaches the manifest, whose cells are sized in rem (14 / 16 / 18 px): the session
   headers and tables only. Not the booking pop-ups (the page puts them beside the tables): zoomed, their
   full-screen size outgrew a phone at 18 px and the close button went off-screen (release review, 11 Oct). */
.manifest-shell .manifest-group-header,
.manifest-shell .manifest-group-meta,
.manifest-shell .manifest-table {
    zoom: var(--portal-user-text-scale, 1);
}
