/**
 * Page-owned People and Administration layout repairs.
 * Controls, routes and behaviour remain owned by their existing modules.
 */

/* These forms already declare columns and gaps but the bundled base never
 * establishes a grid formatting context. Restore only the affected forms. */
body.hasp-staff-portal-page.hasp-section-staff_directory .hasp-workplace-form > .hasp-form-grid,
body.hasp-staff-portal-page.hasp-section-m365_integration .hasp-workplace > .hasp-form > .hasp-form-grid,
body.hasp-staff-portal-page.hasp-section-automated_notifications .hasp-notifications .hasp-panel form > .hasp-form-grid,
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-settings-grid > .hasp-panel form > .hasp-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin: 0 0 18px;
}

body.hasp-staff-portal-page.hasp-section-staff_directory .hasp-workplace-form > .hasp-form-grid > label,
body.hasp-staff-portal-page.hasp-section-m365_integration .hasp-workplace > .hasp-form > .hasp-form-grid > label,
body.hasp-staff-portal-page.hasp-section-automated_notifications .hasp-notifications .hasp-panel form > .hasp-form-grid > label,
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-settings-grid > .hasp-panel form > .hasp-form-grid > label {
    min-width: 0;
    margin-bottom: 0;
}

/* The assignment form's historical tablet rule leaves a zero-width third
 * track. A deliberate two-field row keeps the action on its own next row. */
@media (min-width: 601px) and (max-width: 920px) {
    body.hasp-staff-portal-page.hasp-section-roles .hasp-user-role-panel .hasp-assign-role {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    body.hasp-staff-portal-page.hasp-section-roles .hasp-user-role-panel .hasp-assign-role > .hasp-btn {
        grid-column: 1 / -1;
    }
}

/* QR artwork must also fit inside a card after the surrounding theme adds
 * its gutters. Preserve the generated square without changing QR content. */
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-qr-panel #hasp-team-recognition-qr {
    width: min(272px, 100%);
    height: auto;
    aspect-ratio: 1;
}
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-qr-panel #hasp-team-recognition-qr > canvas,
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-qr-panel #hasp-team-recognition-qr > img,
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-qr-panel #hasp-team-recognition-qr > svg {
    width: min(240px, 100%) !important;
    height: auto !important;
    aspect-ratio: 1;
}

/* Text values in record details can contain long email addresses or URLs. */
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-detail-grid > .hasp-panel,
body.hasp-staff-portal-page.hasp-section-security .hasp-2fa-enrol-layout > div {
    min-width: 0;
}
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-detail dd,
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-review > p,
body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-delivery-status {
    overflow-wrap: anywhere;
}

/* Audit uses a page-local inline style whose fixed desktop minimum tracks
 * exceed the space beside the sidebar. A named content container lets this
 * page adapt to the actual column, including a theme's narrower wrapper. */
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-workspace {
    container: hasp-audit / inline-size;
}
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-search > .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

@container hasp-audit (max-width: 1120px) {
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters > .hasp-audit-search {
        grid-column: span 2 !important;
    }
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
        grid-column: 3 / -1 !important;
        min-width: 0 !important;
    }
}
@container hasp-audit (max-width: 760px) {
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters > .hasp-audit-search,
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
        grid-column: 1 / -1 !important;
    }
}
@container hasp-audit (max-width: 520px) {
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters > .hasp-audit-search,
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
        grid-column: auto !important;
    }
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions .hasp-btn {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* Older browsers still receive the deliberate viewport fallback. Container
 * rules above refine this further when an outer theme restricts the column. */
@supports not (container-type: inline-size) {
    @media (max-width: 1450px) {
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters {
            grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        }
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters > .hasp-audit-search {
            grid-column: span 2 !important;
        }
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
            grid-column: 3 / -1 !important;
            min-width: 0 !important;
        }
    }
    @media (max-width: 760px) {
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters {
            grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        }
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
            grid-column: 1 / -1 !important;
        }
    }
    @media (max-width: 520px) {
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters {
            grid-template-columns: minmax(0, 1fr) !important;
        }
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filters > .hasp-audit-search,
        body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-filter-actions {
            grid-column: auto !important;
        }
    }
}

@media (max-width: 920px) {
    body.hasp-staff-portal-page.hasp-section-staff_directory .hasp-workplace-form > .hasp-form-grid,
    body.hasp-staff-portal-page.hasp-section-m365_integration .hasp-workplace > .hasp-form > .hasp-form-grid,
    body.hasp-staff-portal-page.hasp-section-automated_notifications .hasp-notifications .hasp-panel form > .hasp-form-grid,
    body.hasp-staff-portal-page.hasp-section-team_recognition .hasp-recognition-settings-grid > .hasp-panel form > .hasp-form-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Audit records need readable columns; only the table scrolls on small screens. */
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-table-wrap {
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
}
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-table {
    display: table;
    min-width: 980px;
    table-layout: auto;
}
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-table th {
    white-space: nowrap;
    overflow-wrap: normal;
}
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-table--empty {
    min-width: 0;
}
body.hasp-staff-portal-page.hasp-section-audit .hasp-audit-table--empty thead {
    display: none;
}

/* Empty registers convey their message without making staff scroll an empty table. */
body.hasp-staff-portal-page.hasp-section-staff_directory .hasp-workplace .hasp-table--empty,
body.hasp-staff-portal-page.hasp-section-automated_notifications .hasp-notifications .hasp-notification-table--empty {
    display: table;
    min-width: 0 !important;
    width: 100% !important;
}
body.hasp-staff-portal-page.hasp-section-staff_directory .hasp-workplace .hasp-table--empty thead,
body.hasp-staff-portal-page.hasp-section-automated_notifications .hasp-notifications .hasp-notification-table--empty thead {
    display: none;
}
