/*
 * HPC-AC Assessment UI completion v3.5
 * Purpose: finish the approved full-width, compact, task-oriented index/form/show
 * contract across the Assessment module and correct legacy layout collisions.
 * Loaded last; no build step required.
 */

body[data-assessment-module="1"] {
    --ac35-gap: .8rem;
    --ac35-card-pad: .85rem;
    --ac35-border: var(--sot-border, #d6e0ea);
    --ac35-border-strong: var(--sot-border-strong, #bdcad7);
    --ac35-surface: var(--sot-surface, #fff);
    --ac35-surface-soft: var(--sot-surface-soft, #f7f9fc);
    --ac35-text: var(--sot-text, #16263a);
    --ac35-muted: var(--sot-muted, #607086);
    --ac35-accent: var(--tenant-primary-color, var(--sot-accent, #334e8a));
    --ac35-radius: .7rem;
    --ac35-shadow: 0 4px 16px rgb(15 23 42 / .05);
}

body[data-assessment-module="1"] .hpc-main-content,
body[data-assessment-module="1"] .hpc-page-container {
    min-width: 0;
    width: 100%;
    max-width: none !important;
}

body[data-assessment-module="1"] .hpc-page-container {
    padding-inline: clamp(.65rem, 1.35vw, 1.35rem) !important;
}

/* Every Assessment data page uses the full content width. */
body[data-assessment-module="1"] :where(
    .hpc-master-page,
    .ui-page-root,
    .package-blueprint-page,
    .ac-page,
    .ac-foundation-matrix-page,
    .assessment-session-index,
    .assessment-session-show
) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: start;
    gap: var(--ac35-gap) !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0;
}

body[data-assessment-module="1"] :where(
    .hpc-master-page,
    .ui-page-root,
    .package-blueprint-page,
    .ac-page,
    .ac-foundation-matrix-page
) > * {
    grid-column: 1 / -1 !important;
    width: 100%;
    max-width: none;
    min-width: 0;
}

/* Compact headers: copy and actions share one row, without oversized whitespace. */
body[data-assessment-module="1"] :where(
    .as-card-header,
    .ui-page-header,
    .ui-primary-page-header,
    .ac-section-heading,
    .ui-section-header
) {
    align-items: flex-start;
    gap: .75rem 1rem;
}

body[data-assessment-module="1"] :where(
    .as-card-header,
    .ui-page-header,
    .ui-primary-page-header
) > :first-child {
    min-width: min(100%, 34rem);
    flex: 1 1 34rem;
}

body[data-assessment-module="1"] :where(
    .as-card-header,
    .ui-page-header,
    .ui-primary-page-header
) :where(h1, .ui-primary-page-heading) {
    max-width: 70rem;
    line-height: 1.2;
}

body[data-assessment-module="1"] :where(
    .as-card-header,
    .ui-page-header,
    .ui-primary-page-header
) :where(p, .page-description) {
    max-width: 86ch;
}

/* Full-width compact filter contract. */
body[data-assessment-module="1"] :where(
    .hpc-filter-bar,
    .ui-filter-grid,
    .assessment-session-filters,
    .ac-foundation-matrix-filters,
    .adw-filterbar,
    .erc-filters
) {
    display: grid !important;
    grid-template-columns: minmax(15rem, 2fr) repeat(4, minmax(8.5rem, 1fr)) auto !important;
    align-items: end !important;
    gap: .55rem !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0;
}

body[data-assessment-module="1"] :where(
    .hpc-filter-search,
    .ui-filter-search,
    .assessment-session-filter.is-search,
    .ac-foundation-matrix-filters__search,
    .erc-field--search
) {
    grid-column: auto !important;
    min-width: 0;
}

body[data-assessment-module="1"] :where(
    .hpc-filter-bar,
    .ui-filter-grid,
    .assessment-session-filters,
    .ac-foundation-matrix-filters,
    .adw-filterbar,
    .erc-filters
) :where(label, .ui-field, .adw-field, .erc-field) {
    display: grid;
    gap: .28rem;
    min-width: 0;
}

body[data-assessment-module="1"] :where(
    .hpc-filter-bar,
    .ui-filter-grid,
    .assessment-session-filters,
    .ac-foundation-matrix-filters,
    .adw-filterbar,
    .erc-filters
) :where(input, select, .hpc-combobox) {
    width: 100%;
    min-width: 0;
}

body[data-assessment-module="1"] :where(
    .hpc-filter-bar,
    .ui-filter-grid,
    .assessment-session-filters,
    .ac-foundation-matrix-filters,
    .adw-filterbar,
    .erc-filters
) > :where(button, .as-btn, .ui-button, .adw-button, .erc-button) {
    align-self: end;
    min-height: 2.35rem;
    white-space: nowrap;
}

/* Form pages: use available horizontal space and keep actions visible. */
body[data-assessment-module="1"][data-assessment-page-kind="form"] :where(
    .hpc-master-form,
    .hpc-session-form,
    form[data-hpc-validation-form="1"]
) {
    width: 100%;
    max-width: none;
}

body[data-assessment-module="1"] .hpc-master-form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: .7rem !important;
}

body[data-assessment-module="1"] .hpc-structured-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: .65rem !important;
}

body[data-assessment-module="1"] :where(.hpc-master-form-actions, .ui-sticky-action-bar) {
    position: sticky;
    bottom: .45rem;
    z-index: 35;
    align-items: center;
    border: 1px solid var(--ac35-border);
    border-radius: var(--ac35-radius);
    background: color-mix(in srgb, var(--ac35-surface) 94%, transparent);
    box-shadow: 0 8px 26px rgb(15 23 42 / .11);
    padding: .6rem .7rem;
    backdrop-filter: blur(10px);
}

/* Tables are comparison tools: full width, compact, readable, and not clipped. */
body[data-assessment-module="1"] :where(
    .ui-table-shell,
    .hpc-ui-table-region,
    .as-table-wrap,
    .table-shell,
    .overflow-x-auto
) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    scrollbar-gutter: stable;
}

body[data-assessment-module="1"] :where(table, .hpc-ui-table, .as-table) {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

body[data-assessment-module="1"] :where(.hpc-ui-table, .as-table) :where(th, td) {
    padding: .58rem .65rem !important;
    vertical-align: top;
    overflow-wrap: break-word;
    word-break: normal;
}

body[data-assessment-module="1"] :where(.hpc-ui-table, .as-table) th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--ac35-surface-soft);
}

body[data-assessment-module="1"] :where(.hpc-ui-table, .as-table) th:last-child,
body[data-assessment-module="1"] :where(.hpc-ui-table, .as-table) td:last-child {
    min-width: 9.5rem;
}

body[data-assessment-module="1"] :where(.as-action-row, .ui-action-group, .row-actions) {
    flex-wrap: wrap;
    overflow: visible !important;
}

/* Generic master-data details use the tabbed full-width command surface. */
body[data-assessment-module="1"] .hpc-detail-tabs {
    position: sticky;
    top: .25rem;
    z-index: 24;
    width: 100%;
    overflow-x: auto;
    background: var(--ac35-surface);
}

body[data-assessment-module="1"] .as-tab-panel {
    min-width: 0;
    padding: var(--ac35-card-pad);
}

body[data-assessment-module="1"] .hpc-detail-card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Assessment packages: one header/filter/results column, useful cards. */
body[data-assessment-module="1"] .package-blueprint-filters .ui-filter-grid {
    grid-template-columns: minmax(16rem, 2fr) repeat(4, minmax(8.5rem, 1fr)) auto !important;
}

body[data-assessment-module="1"] .package-blueprint-card-grid {
    grid-template-columns: repeat(3, minmax(17rem, 1fr)) !important;
    gap: .7rem !important;
}

body[data-assessment-module="1"] .package-blueprint-list-card {
    display: grid;
    grid-template-rows: auto minmax(2.8rem, auto) auto auto;
    gap: .5rem;
    min-width: 0;
}

/* Foundation matrix: never split hero/filter/content into narrow side columns. */
body[data-assessment-module="1"] .ac-foundation-matrix-page {
    grid-template-columns: minmax(0, 1fr) !important;
}

body[data-assessment-module="1"] .ac-foundation-matrix-stats {
    grid-template-columns: repeat(6, minmax(8.5rem, 1fr)) !important;
    gap: .55rem !important;
}

body[data-assessment-module="1"] .ac-foundation-matrix-stat {
    min-height: 5.35rem;
    padding: .65rem !important;
}

body[data-assessment-module="1"] .ac-foundation-matrix-stat > span {
    min-height: 0 !important;
}

body[data-assessment-module="1"] .ac-foundation-matrix-content {
    min-height: 24rem;
    overflow: visible !important;
}

body[data-assessment-module="1"] .ac-foundation-matrix-page .as-table-wrap {
    max-height: none !important;
    overflow: auto;
}

body[data-assessment-module="1"] .ac-foundation-matrix-gap-grid {
    grid-template-columns: repeat(3, minmax(15rem, 1fr)) !important;
}

/* Review handoff: queue + selected task, with governance below the detail. */
body[data-assessment-module="1"] .adw-review-handoff.adw-page,
body[data-assessment-module="1"] .adw-consensus-workspace.adw-page {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
}

body[data-assessment-module="1"] .adw-review-handoff .adw-commandbar,
body[data-assessment-module="1"] .adw-consensus-workspace .adw-commandbar {
    grid-template-columns: minmax(20rem, 1.1fr) minmax(32rem, 1.9fr) !important;
    width: 100%;
}

body[data-assessment-module="1"] .adw-review-handoff .adw-commandbar__actions--wide,
body[data-assessment-module="1"] .adw-commandbar__actions--wide {
    grid-column: 1 / -1;
}

body[data-assessment-module="1"] .adw-shell--review,
body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell {
    display: grid !important;
    grid-template-columns: minmax(19rem, 23rem) minmax(0, 1fr) !important;
    align-items: start;
    gap: .75rem;
}

body[data-assessment-module="1"] .adw-shell--review > .adw-rail,
body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell > .adw-rail {
    grid-column: 1;
    grid-row: 1 / span 2;
}

body[data-assessment-module="1"] .adw-shell--review > .adw-main,
body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell > .adw-main {
    grid-column: 2;
    grid-row: 1;
}

body[data-assessment-module="1"] .adw-shell--review > .adw-side,
body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell > .adw-side {
    grid-column: 2;
    grid-row: 2;
}

body[data-assessment-module="1"] :where(.adw-review-handoff, .adw-consensus-workspace) :where(.adw-rail, .adw-side) {
    position: static !important;
    top: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

body[data-assessment-module="1"] :where(.adw-review-handoff, .adw-consensus-workspace) .adw-main {
    overflow: visible !important;
    min-height: 20rem;
}

body[data-assessment-module="1"] .adw-action-stack {
    display: grid;
    gap: .45rem;
}

body[data-assessment-module="1"] .adw-checkbox {
    width: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
}

body[data-assessment-module="1"] .adw-empty--roomy { margin: 1rem; }
body[data-assessment-module="1"] .adw-empty--compact { margin: .7rem; }

/* Native progress elements replace unsafe inline width styles. */
body[data-assessment-module="1"] :where(
    progress.erc-progress,
    progress.afr-progress,
    progress.assessment-session-progress-track,
    .priority-exercise-progress progress
) {
    display: block;
    width: 100%;
    height: .42rem;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: var(--ac35-border);
    appearance: none;
}

body[data-assessment-module="1"] :where(progress.erc-progress, progress.afr-progress, progress.assessment-session-progress-track)::-webkit-progress-bar {
    background: var(--ac35-border);
    border-radius: 999px;
}

body[data-assessment-module="1"] :where(progress.erc-progress, progress.afr-progress, progress.assessment-session-progress-track)::-webkit-progress-value {
    background: var(--ac35-accent);
    border-radius: 999px;
}

body[data-assessment-module="1"] :where(progress.erc-progress, progress.afr-progress, progress.assessment-session-progress-track)::-moz-progress-bar {
    background: var(--ac35-accent);
    border-radius: 999px;
}

/* Results and work queues occupy the main width, not a narrow right rail. */
body[data-assessment-module="1"] [data-results-context-guard="1"] > .as-card,
body[data-assessment-module="1"] [data-index-contract="complete"] > .as-card {
    width: 100%;
    max-width: none;
}

/* Participant preview remains realistic but uses the available admin canvas. */
body[data-assessment-module="1"] .assessment-participant-preview-frame[data-viewport="desktop"] {
    max-width: none !important;
}

body[data-assessment-module="1"] .assessment-participant-preview-workspace.has-support-material {
    grid-template-columns: minmax(15rem, .72fr) minmax(28rem, 1.7fr) minmax(13.5rem, 15rem) !important;
}

body[data-assessment-module="1"] .assessment-participant-preview-support,
body[data-assessment-module="1"] .assessment-participant-preview-question-column,
body[data-assessment-module="1"] .assessment-participant-preview-rail {
    min-height: 30rem;
}

/* Toasts inform without hiding the operational surface. */
body[data-assessment-module="1"] .hpc-toast-region {
    width: min(26rem, calc(100vw - 1.25rem));
    max-height: min(70vh, 36rem);
    overflow-y: auto;
}

body[data-assessment-module="1"] .hpc-toast {
    border-radius: .7rem;
}

@media (max-width: 1480px) {
    body[data-assessment-module="1"] :where(
        .hpc-filter-bar,
        .ui-filter-grid,
        .assessment-session-filters,
        .ac-foundation-matrix-filters,
        .adw-filterbar,
        .erc-filters
    ) {
        grid-template-columns: minmax(15rem, 2fr) repeat(3, minmax(9rem, 1fr)) auto !important;
    }

    body[data-assessment-module="1"] .package-blueprint-card-grid {
        grid-template-columns: repeat(2, minmax(17rem, 1fr)) !important;
    }

    body[data-assessment-module="1"] .ac-foundation-matrix-stats {
        grid-template-columns: repeat(3, minmax(10rem, 1fr)) !important;
    }
}

@media (max-width: 1180px) {
    body[data-assessment-module="1"] :where(
        .hpc-filter-bar,
        .ui-filter-grid,
        .assessment-session-filters,
        .ac-foundation-matrix-filters,
        .adw-filterbar,
        .erc-filters
    ) {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }

    body[data-assessment-module="1"] :where(
        .hpc-filter-search,
        .ui-filter-search,
        .assessment-session-filter.is-search,
        .ac-foundation-matrix-filters__search,
        .erc-field--search
    ) {
        grid-column: span 2 !important;
    }

    body[data-assessment-module="1"] .hpc-master-form-grid,
    body[data-assessment-module="1"] .hpc-structured-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    body[data-assessment-module="1"] .hpc-master-field--wide,
    body[data-assessment-module="1"] .hpc-structured-field--wide {
        grid-column: 1 / -1 !important;
    }

    body[data-assessment-module="1"] .adw-review-handoff .adw-commandbar,
    body[data-assessment-module="1"] .adw-consensus-workspace .adw-commandbar {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-assessment-module="1"] .adw-shell--review,
    body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell {
        grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr) !important;
    }

    body[data-assessment-module="1"] .assessment-participant-preview-workspace.has-support-material {
        grid-template-columns: minmax(0, 1fr) minmax(13.5rem, 15rem) !important;
    }

    body[data-assessment-module="1"] .assessment-participant-preview-support {
        grid-column: 1 / -1;
        min-height: auto;
    }
}

@media (max-width: 820px) {
    body[data-assessment-module="1"] .hpc-page-container {
        padding-inline: .55rem !important;
    }

    body[data-assessment-module="1"] :where(
        .hpc-filter-bar,
        .ui-filter-grid,
        .assessment-session-filters,
        .ac-foundation-matrix-filters,
        .adw-filterbar,
        .erc-filters
    ) {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-assessment-module="1"] :where(
        .hpc-filter-search,
        .ui-filter-search,
        .assessment-session-filter.is-search,
        .ac-foundation-matrix-filters__search,
        .erc-field--search
    ) {
        grid-column: auto !important;
    }

    body[data-assessment-module="1"] .hpc-master-form-grid,
    body[data-assessment-module="1"] .hpc-structured-grid,
    body[data-assessment-module="1"] .hpc-detail-card-grid,
    body[data-assessment-module="1"] .package-blueprint-card-grid,
    body[data-assessment-module="1"] .ac-foundation-matrix-stats,
    body[data-assessment-module="1"] .ac-foundation-matrix-gap-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-assessment-module="1"] .adw-shell--review,
    body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-assessment-module="1"] .adw-shell--review > :where(.adw-rail, .adw-main, .adw-side),
    body[data-assessment-module="1"] .adw-consensus-workspace .adw-shell > :where(.adw-rail, .adw-main, .adw-side) {
        grid-column: 1 !important;
        grid-row: auto !important;
    }

    body[data-assessment-module="1"] .assessment-participant-preview-workspace,
    body[data-assessment-module="1"] .assessment-participant-preview-workspace.has-support-material {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-assessment-module="1"] .assessment-participant-preview-rail {
        order: -1;
        min-height: auto;
    }
}
