/* Shared interaction safeguards. Keep the existing colours, type and layouts. */

/* A two-colour indicator remains visible on both white panels and red menus. */
body :focus-visible {
    outline: 3px solid #173e61 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 3px #fff !important;
}

/* Navigation focuses these reading targets, not an interactive control.
   Keep the focus for assistive technology without framing the page title. */
body h1#viewTitle[tabindex="-1"]:focus,
body h1#adminViewTitle[tabindex="-1"]:focus {
    outline: none !important;
    box-shadow: none !important;
}

.session-card:has(input:focus-visible) {
    outline: 3px solid #173e61;
    outline-offset: 3px;
    box-shadow: 0 0 0 3px #fff;
}

.a11y-skip-link {
    position: fixed;
    z-index: 400;
    inset: max(12px, env(safe-area-inset-top)) auto auto 12px;
    max-width: calc(100% - 24px);
    padding: 12px 16px;
    border: 2px solid currentColor;
    border-radius: 9px;
    background: #fff;
    color: #222428;
    font-weight: 800;
    text-decoration: underline;
    transform: translateY(calc(-100% - 24px - env(safe-area-inset-top)));
}

.a11y-skip-link:focus {
    transform: none;
}

.a11y-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* Error text is visible, associated by JS, and never conveyed by colour alone. */
.a11y-field-error {
    display: block;
    width: 100%;
    margin: 2px 0 0;
    padding-inline-start: 0;
    color: #8d1420;
    font-size: .875rem;
    font-weight: 700;
    line-height: 1.5;
    overflow-wrap: anywhere;
    flex: 0 0 100%;
    grid-column: 1 / -1;
}

label:has(> .a11y-field-error) {
    flex-wrap: wrap;
}

.a11y-error-summary {
    scroll-margin-block: 6rem 2rem;
    margin: 0 0 20px;
    padding: 16px;
    border: 2px solid #a31320;
    border-radius: 12px;
    background: #fff0f2;
    color: #8d1420;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.a11y-error-summary:empty {
    display: none;
}

.a11y-error-summary h2,
.a11y-error-summary h3,
.a11y-error-summary p {
    margin: 0 0 8px;
    font-size: 1rem;
}

.a11y-error-summary ul {
    margin: 8px 0 0;
    padding-inline-start: 22px;
}

.a11y-error-summary a {
    color: inherit;
    font-weight: 750;
    text-decoration: underline;
    text-underline-offset: 3px;
}

body input[aria-invalid="true"]:not([type="checkbox"]):not([type="radio"]),
body select[aria-invalid="true"],
body textarea[aria-invalid="true"],
body [contenteditable="true"][aria-invalid="true"] {
    border-color: #a31320;
    border-width: 2px;
}

/* Let intrinsic content shrink and wrap instead of being clipped at zoom. */
:where(h1, h2, h3, h4, p, label, legend, button, a, summary, small, strong) {
    overflow-wrap: anywhere;
}

:is(.field-grid, .activity-field-grid, .admin-field-grid, .settings-grid,
    .switch-grid, .toggle-grid, .menu-setting-grid, .manual-person-grid,
    .payment-entry-grid, .admin-attendee-row, .builder-row, .booking-layout,
    .enrollment-layout, .admin-topbar, .admin-toolbar, .form-heading,
    .form-title, .participant-head, .panel-heading, .panel-head,
    .view-heading, .summary-row, .summary-total) > * {
    min-width: 0;
}

body :is(input, select, textarea, [contenteditable="true"]) {
    min-inline-size: 0;
    max-inline-size: 100%;
    scroll-margin-block: 7rem 3rem;
}

body :is(button, .button, .activity-button, .admin-button, .mini-button,
    .small-button, .header-join, .header-section-link) {
    max-inline-size: 100%;
}

.dashboard-export-actions .button,
.email-test-panel .button,
.user-create-panel .button,
.user-actions .mini-button,
.event-public-link .button,
.header-chip,
.header-join,
.header-section-link,
.module-nav a {
    white-space: normal;
}

.public-header__inner,
.activity-header__inner,
.header-actions,
.module-nav,
.admin-topbar,
.admin-toolbar,
.view-heading,
.panel-heading,
.panel-head,
.form-heading,
.form-title,
.participant-head,
.participant-admin-head,
.manual-person-head,
.menu-card__bottom,
.summary-row,
.summary-total,
.dashboard-export-actions,
.menu-setting-options,
.activity-footer {
    flex-wrap: wrap;
}

.brand-lockup,
.activity-brand,
.brand-section,
.activity-brand > span,
.module-nav,
.event-picker,
.activity-picker {
    min-width: 0;
    max-width: 100%;
}

.brand-logo,
.activity-brand > img,
.step-number,
.form-title > span,
.participant-index,
.option-card input,
.switch-card input,
.compact-check input,
.choice-options input,
.payment-choices input,
.admin-session-choices input {
    flex-shrink: 0;
}

.admin-toolbar {
    height: auto;
    min-height: 94px;
}

.step-number,
.form-title > span {
    height: auto;
    min-height: 42px;
}

.participant-index {
    height: auto;
    min-height: 28px;
}

.count-badge {
    height: auto;
    min-height: 30px;
}

/* Dialog contents scroll inside the current viewport, including short screens. */
.modal {
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-block-start: max(20px, env(safe-area-inset-top));
    padding-block-end: max(20px, env(safe-area-inset-bottom));
}

.modal-box {
    min-width: 0;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 18px;
}

.modal-title {
    padding-inline-end: 8px;
}

.modal-close {
    display: grid;
    place-items: center;
    width: auto;
    min-width: 36px;
    height: auto;
    min-height: 36px;
    padding: 0 8px;
    line-height: 1;
}

[data-a11y-drawer] {
    touch-action: pan-y pinch-zoom;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 12px;
}

body.a11y-drawer-open {
    overflow: hidden;
}

.a11y-drawer-backdrop {
    position: fixed;
    z-index: 29;
    inset: 0;
    background: rgba(20, 24, 28, .62);
}

.a11y-drawer-close {
    display: none;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid currentColor;
    border-radius: 9px;
    background: #fff;
    color: var(--red, #e31b2b);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

body.a11y-drawer-open .a11y-drawer-close {
    display: inline-flex;
}

.setup-page,
.login-screen,
.admin-login {
    min-height: 100svh;
}

/* The status filter must not squeeze the search input down to its icon. */
.list-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 230px);
    align-items: start;
}

.list-toolbar .search-field,
.search-field input {
    min-width: 0;
    width: 100%;
}

@media (max-width: 980px) {
    .list-toolbar {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Keep native mobile input zoom available; avoid its involuntary <16px zoom. */
@media (hover: none) and (pointer: coarse), (max-width: 820px) {
    body input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    body select,
    body textarea,
    body [contenteditable="true"] {
        font-size: max(16px, 1rem, 1em) !important;
    }

    body :is(button, .activity-card__link, .module-nav a,
        .admin-module-switch a) {
        min-height: 44px;
    }

    .modal-close,
    .mobile-menu {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 980px) {
    .enrollment-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .enrollment-form {
        order: 1;
    }

    .enrollment-summary {
        position: static;
        order: 2;
    }
}

@media (max-width: 900px) {
    .booking-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .booking-form {
        order: 1;
    }

    .booking-summary {
        position: static;
        order: 2;
    }
}

@media (max-width: 820px) {
    .admin-toolbar h1 {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    .event-picker {
        flex: 1 1 8rem;
        max-width: 100%;
    }

    .event-picker select,
    .activity-picker select {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .menu-stock strong,
    .menu-stock span {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    .modal {
        padding-block-start: max(8px, env(safe-area-inset-top));
        padding-block-end: max(8px, env(safe-area-inset-bottom));
    }

    .modal-box {
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    }
}

@media (max-width: 780px) {
    .admin-toolbar {
        min-height: 78px;
    }
}

/* A keyboard or landscape view must leave room to reach the active field. */
@media (max-width: 980px) and (max-height: 600px) {
    .admin-toolbar {
        position: relative;
    }
}

@media (max-width: 400px) {
    .dashboard-export-actions,
    .booking-detail-header,
    .attendee-card > div:first-child,
    .attendee-line,
    .waiting-item {
        display: flex;
        flex-wrap: wrap;
    }

    .dashboard-export-actions label,
    .dashboard-export-actions .button {
        width: 100%;
        min-width: 0;
    }

    .booking-always-visible {
        display: flex;
        flex-wrap: wrap;
    }

    .metric-grid,
    .stats-grid,
    .statistics-kpis,
    .payment-method-grid,
    .booking-facts {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (forced-colors: active) {
    body :focus-visible,
    .session-card:has(input:focus-visible) {
        outline-color: Highlight !important;
    }

    .a11y-error-summary,
    .a11y-field-error {
        border-color: CanvasText;
    }
}
