/* ============================================================
   Corex UI V2 — base list workspace (shared, universal).
   Full-width ERP surface: command header → toolbar (search/filters +
   pagination) → grid. One workspace gutter, no card-in-page look.
   ============================================================ */

/* Full-bleed: the list workspace owns its own internal gutter, so the
   module-main shell adds none (avoids gutter-inside-gutter). */
.module-main:has(> .cx-list-view) {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    padding: 0;
}

.cx-list-view {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: calc(100vh - var(--cx-header-height));
    color: var(--cx-color-text);
    background: var(--cx-color-surface);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    font-family: var(--cx-font-family);
}

/* Canonical list pages render no separate command-header/title band —
   context comes from the sidebar/nav. Everything lives in one toolbar row. */

/* One compact toolbar row: LEFT action | CENTER search/filters | RIGHT pagination */
.cx-list-toolbar {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: var(--cx-space-3);
    min-height: 40px;
    padding: 0 var(--cx-space-4);
    background: var(--cx-color-surface);
    border-block-end: 1px solid var(--cx-color-border);
}

/* LEFT — primary action group(s). Empty when the user lacks the create
   permission; the 1fr column still balances the trailing pager so the
   centre search stays mathematically centred. */
.cx-list-toolbar-start {
    grid-column: 1;
    display: flex;
    min-width: 0;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: var(--cx-space-2);
}

.cx-list-toolbar-center {
    grid-column: 2;
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: center;
    gap: var(--cx-space-2);
}

.cx-list-toolbar-group {
    display: flex;
    min-width: 0;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--cx-space-2);
}

.cx-list-toolbar-end {
    grid-column: 3;
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: var(--cx-space-3);
}

/* A list view embedded under a record header (e.g. inside a tab) is not the page workspace:
   it takes the height of its content instead of the viewport, so an empty grid stays compact. */
.cx-list-view--embedded {
    min-height: 0;
}

/* Grid fills the remaining workspace, no card frame */
.cx-list-view > .cx-data-grid {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    width: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.cx-list-view .cx-data-grid-toolbar {
    margin: 0;
    height: 40px;
    padding: 0 var(--cx-space-4);
    border-block-end: 1px solid var(--cx-color-border);
}

.cx-list-view .cx-data-grid-table-wrap {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.cx-list-view .cx-data-grid-cell {
    padding: 0 var(--cx-space-3);
}

.cx-list-view .cx-data-grid-loading,
.cx-list-view .cx-data-grid-empty,
.cx-list-view .cx-data-grid-error {
    padding: var(--cx-space-8) var(--cx-space-4);
}

.cx-list-view .cx-data-grid-selection {
    margin: 0;
    border-radius: 0;
}

/* Pagination relocated into the toolbar (top-right) — flat, inline */
.cx-data-grid-pagination--inline {
    padding: 0;
    border-block-start: 0;
    justify-content: flex-end;
    gap: var(--cx-space-2);
}

@media (max-width: 48rem) {
    .cx-list-view {
        min-height: 0;
    }

    .cx-list-toolbar {
        grid-template-columns: minmax(0, 1fr) auto;
        row-gap: var(--cx-space-2);
        padding-block: var(--cx-space-2);
    }

    .cx-list-toolbar::before {
        display: none;
    }

    .cx-list-toolbar-center {
        grid-column: 1 / -1;
        width: 100%;
        flex-wrap: wrap;
    }

    .cx-list-toolbar-end {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }
}
