/*
 * <ui-data-grid> — unified data grid built on semantic <table>.
 *
 * Структура:
 *   .ui-dg-card
 *     ├── .ui-dg-toolbar         (title / search / actions / add)
 *     └── .ui-dg-body
 *         ├── FLAT mode:
 *         │   └── <table.ui-dg-table>
 *         │       ├── <colgroup>            (widths via <col style="width:…">)
 *         │       ├── <thead.ui-dg-head>    (sticky)
 *         │       └── <tbody.ui-dg-tbody>
 *         │
 *         └── GROUPED mode:
 *             └── .ui-dg-cardgroup (per group)
 *                 ├── .ui-dg-master              (label + optional chart)
 *                 └── .ui-dg-cardrows            (per-group scroll container)
 *                     └── <table.ui-dg-table>
 *                         ├── <colgroup>
 *                         ├── <thead.ui-dg-head-inner>  (sticky inside cardrows)
 *                         └── <tbody.ui-dg-tbody>
 *
 * Width sync between cardgroup tables: JS keeps every <col>:nth-child(i)
 * with the same width across all tables, so all cardgroup columns visually
 * line up despite each having its own <colgroup>.
 *
 * Light DOM. Themed via /shared/design/tokens.css.
 */

ui-data-grid {
    display: flex;                 /* flex column chain → cardrows can be
                                      flex-allocated when parent constrains
                                      height (inner scroll); otherwise
                                      grows to content (page scrolls). */
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    /* Bind to parent height: when the host lives in a flex column parent
       (e.g. `<div class="flex-1 min-h-0">`), `flex: 1 1 auto` makes the
       host fill the parent's allocated track instead of taking its own
       content size. `max-height: 100%` guards block-parent cases where
       the parent has an explicit height — the host never overflows.
       Combined with body's `overflow-y: auto` (grouped mode) and
       cardrows' `overflow-y: auto` (flat mode), expanding rows produce
       an INNER scrollbar instead of pushing the host past the parent. */
    flex: 1 1 auto;
    max-height: 100%;
    overflow: hidden;
    box-sizing: border-box;
    container-type: inline-size;
    font-size: var(--ui-font-size-xs, 11px);
}

ui-data-grid > .ui-dg-card {
    background: var(--ui-color-bg, #fff);
    border: 2px solid var(--ui-divider);
    border-radius: var(--ui-radius-lg, 10px);
    box-shadow: var(--ui-shadow-sm);
    display: flex; flex-direction: column;
    width: 100%;
    min-width: 0;
    flex: 1 1 auto;                /* fills host when parent is constrained */
    min-height: 0;
    box-sizing: border-box;
    /* Clip children to the rounded border so the heading row's square
       corners don't overlay the rounded card corners. `clip` (not
       `hidden`) does NOT establish a scroll containing block, so sticky
       <thead> still works against the outer scroll ancestor. */
    overflow: clip;
}
ui-data-grid[no-card] > .ui-dg-card {
    background: transparent; border: 0; box-shadow: none; border-radius: 0;
}

/* ── Toolbar ─────────────────────────────────────────────────────────── */
ui-data-grid .ui-dg-toolbar {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: var(--ui-spacing-2, 8px);
    padding: var(--ui-spacing-2, 8px) var(--ui-spacing-3, 12px);
    border-bottom: 1px solid var(--ui-border-color, #e2e8f0);
    background: var(--ui-color-bg-alt, #f8fafc);
    flex-shrink: 0;
}
ui-data-grid .ui-dg-title {
    font-size: var(--ui-font-size-sm, 12px);
    font-weight: 600;
    color: var(--ui-color-text-muted, #64748b);
}
ui-data-grid .ui-dg-count {
    background: rgba(37, 99, 235, .13);
    color: var(--ui-color-primary-hover);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: var(--ui-font-size-xs, 11px);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
ui-data-grid .ui-dg-search {
    flex: 1 1 180px; min-width: 140px;
    position: relative;
}
ui-data-grid .ui-dg-search > input {
    width: 100%;
    padding: 5px 8px 5px 26px;
    font-size: var(--ui-font-size-xs, 11px);
    border: 1px solid var(--ui-border-color, #e2e8f0);
    border-radius: var(--ui-radius-md, 7px);
    background: var(--ui-color-bg, #fff);
    outline: none;
}
ui-data-grid .ui-dg-search > input:focus {
    border-color: var(--ui-color-primary, #2563eb);
    box-shadow: 0 0 0 1px var(--ui-color-primary, #2563eb);
}
ui-data-grid .ui-dg-search > svg {
    position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
    width: 12px; height: 12px;
    color: var(--ui-color-text-faint, #94a3b8);
    pointer-events: none;
}
ui-data-grid .ui-dg-actions { display: flex; align-items: center; gap: 6px; }

/* ── Body ────────────────────────────────────────────────────────────── */
ui-data-grid .ui-dg-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
    padding: 0;                    /* content fills card edge-to-edge */
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    position: relative;            /* anchor for .ui-dg-loading overlay */
}
/* Flat mode body: flex column → cardhead (flex-shrink) + cardrows
   (flex-1 with internal scroll). When the host's parent constrains
   height, cardrows scrolls; otherwise body grows to content. */
ui-data-grid[mode="flat"] .ui-dg-body,
ui-data-grid:not([mode]) .ui-dg-body {
    display: flex;
    flex-direction: column;
}
/* Grouped mode body: cardgroups stack vertically. The body itself
   scrolls when the cumulative cardgroup heights (expanded masters +
   their cardrows + collapsed masters) exceed the host-allocated
   height. This keeps the grid container at a fixed visual size — when
   a cardgroup expands, instead of pushing the grid taller, a vertical
   scrollbar appears on the body and rows scroll within. Per-cardgroup
   cardrows are also bounded by 60vh so a single huge group still gets
   its own internal scroll. */
ui-data-grid[mode="grouped"] .ui-dg-body {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    /* No scrollbar-gutter: stable — only consumes gutter when actually
       scrolling. Cardgroups inside re-flow when body's scrollbar
       appears/disappears (cardhead paddings recomputed via JS). */
}

/* ── Loading overlay ────────────────────────────────────────────────── */
/* Ensure the body keeps vertical space even when there's no data — the
   overlay is absolute and wouldn't otherwise contribute to body height. */
ui-data-grid[loading] .ui-dg-body { min-height: 120px; }

ui-data-grid .ui-dg-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
    z-index: 10;
    pointer-events: all;           /* block row clicks during fetch */
    color: var(--ui-color-primary, #2563eb);
}
ui-data-grid .ui-dg-loading .ui-dg-spinner {
    width: 28px;
    height: 28px;
    animation: ui-dg-spin 0.85s linear infinite;
}
ui-data-grid .ui-dg-loading .ui-dg-loading-label {
    font-size: var(--ui-font-size-xs, 11px);
    color: var(--ui-color-text-muted, #64748b);
    font-weight: 500;
}
@keyframes ui-dg-spin {
    to { transform: rotate(360deg); }
}

/* ── Table ───────────────────────────────────────────────────────────── */
ui-data-grid table.ui-dg-table {
    width: 100%;
    table-layout: fixed;         /* <col> widths are authoritative */
    border-collapse: separate;
    border-spacing: 0;
    font-size: inherit;
}

/* Heading row — sticky inside the cardrows scroll container so the
   header stays visible while body rows scroll. thead and tbody live in
   the SAME <table>, so columns auto-align — no JS width-sync needed
   between separate head/body tables. */
ui-data-grid table.ui-dg-table > thead > tr > th.ui-dg-hc {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 6px 8px;
    background: var(--ui-neutral-300);
    color: var(--ui-color-text, #0f172a);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    border-right: 1px solid var(--ui-divider);          /* 50% grey column divider */
    border-bottom: 1px solid var(--ui-divider);
}
ui-data-grid table.ui-dg-table > thead.ui-dg-head-inner > tr > th.ui-dg-hc {
    /* Lighter background for per-cardgroup heading. Sticky is inherited
       above; here we just override colours. */
    background: var(--ui-neutral-200);
    border-top: 1px solid var(--ui-divider);
    border-bottom: 1px solid var(--ui-divider);
}
ui-data-grid table.ui-dg-table > thead > tr > th.ui-dg-hc:last-child {
    border-right: 0;
}
ui-data-grid table.ui-dg-table > thead > tr > th.ui-dg-hc[data-sortable] {
    cursor: pointer;
}
ui-data-grid table.ui-dg-table > thead > tr > th.ui-dg-hc[data-sortable]:hover {
    color: var(--ui-color-primary, #2563eb);
}
ui-data-grid table.ui-dg-table > thead > tr > th.ui-dg-hc[data-sort-active] {
    color: var(--ui-color-primary, #2563eb);
}
ui-data-grid table.ui-dg-table > thead > tr > th.ui-dg-hc[data-sort-active]::after {
    content: attr(data-sort-arrow);
    margin-left: 4px;
    font-size: 9px;
}

/* Cells */
ui-data-grid table.ui-dg-table > tbody > tr.ui-dg-row > td.ui-dg-cell {
    padding: 6px 8px;
    border-right: 1px solid var(--ui-divider);          /* 50% grey column divider */
    border-bottom: 1px solid rgba(128, 128, 128, .25);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}
ui-data-grid table.ui-dg-table > tbody > tr.ui-dg-row > td.ui-dg-cell:last-child {
    border-right: 0;
}
ui-data-grid table.ui-dg-table > tbody > tr.ui-dg-row:last-child > td.ui-dg-cell {
    border-bottom: 0;
}

/* ── Density: compact ─────────────────────────────────────────────────
   Differs from default ONLY in row vertical padding (2px vs 6px).
   Heading, font, line-height stay identical to default. */
ui-data-grid[density="compact"] table.ui-dg-table > tbody > tr.ui-dg-row > td.ui-dg-cell {
    padding-top: 2px;
    padding-bottom: 2px;
}

/* Actions / CRUD column — FORCED fixed width, tight auto-fit by JS to
   render ALL icons fully without any extra slack. JS measures the row
   with the MOST slots across all actions cells and sets
   --ui-dg-actions-width on the host as:
       max(N) * 22px (icon button) + (max(N)-1) * 2px (gap) + 4px (cell padding)
   So 1 icon = 26px, 2 = 50px, 3 = 74px, 4 = 98px. Hard rule across
   the ecosystem (CLAUDE.md / shared README §3). */
ui-data-grid table.ui-dg-table > colgroup > col[data-col-actions="1"] {
    width: var(--ui-dg-actions-width, 72px);
    min-width: var(--ui-dg-actions-width, 72px);
    max-width: var(--ui-dg-actions-width, 72px);
}
ui-data-grid th.ui-dg-hc[data-fit-content="1"],
ui-data-grid td.ui-dg-cell[data-col-actions="1"] {
    width: var(--ui-dg-actions-width, 72px);
    min-width: var(--ui-dg-actions-width, 72px);
    max-width: var(--ui-dg-actions-width, 72px);
    padding: 2px 2px;
    text-align: center;
    white-space: nowrap;
}
ui-data-grid th.ui-dg-hc[data-fit-content="1"] > .ui-dg-hc-label {
    visibility: hidden;
    font-size: 0;
}
ui-data-grid th.ui-dg-hc[data-fit-content="1"]::after {
    content: '';
}
ui-data-grid td.ui-dg-cell[data-col-actions="1"] {
    text-align: center;
}

/* Ряд CRUD-иконок внутри грида. Базовый `.ui-actions-row` (inline-flex)
   определён один раз в design/controls.css; грид добавляет модификатор
   `.ui-actions-row--grid` — жёсткая сетка 22px, от которой считается
   ширина actions-колонки. Аудит 2026-09-13 §3.7. ───────────────────── */
.ui-actions-row--grid {
    display: inline-grid;
    grid-auto-flow: column;
    grid-auto-columns: 22px;
    gap: 2px;
    justify-items: center;
    align-items: center;
}
.ui-actions-row--grid > span[aria-hidden] {
    display: block;
    width: 22px;
    height: 22px;
}
/* Компактный (22×22) вариант иконочной кнопки — ТОЛЬКО внутри CRUD-колонки:
   её ширина считается как N×22 + (N−1)×2 + 4, поэтому размер здесь жёсткий.
   Селектор намеренно ограничен `.ui-actions-row--grid`: глобальное определение
   `.ui-icon-btn` живёт в design/controls.css в единственном экземпляре
   («one concept = one place»). Без этого ограничения data-grid.css,
   подключаемый последним, перебивал бы слой контролов на всех страницах. */
.ui-actions-row--grid .ui-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    color: var(--ui-color-text-muted, #64748b);
    transition: background .12s ease, color .12s ease;
    line-height: 1;
}
.ui-actions-row--grid .ui-icon-btn > svg { width: 14px; height: 14px; }
.ui-actions-row--grid .ui-icon-btn:hover { background: rgba(0, 0, 0, .06); color: var(--ui-color-primary, #2563eb); }
.ui-actions-row--grid .ui-icon-btn:focus-visible { outline: 2px solid var(--ui-color-primary, #2563eb); outline-offset: 1px; }
.ui-actions-row--grid .ui-icon-btn.is-danger:hover { color: var(--ui-color-danger-hover); background: rgba(220, 38, 38, .08); }

/* Global CRUD normalizer — every <button>/<a> inside an actions cell
   (component OR slot-mode) gets coerced into the .ui-icon-btn visual:
   22×22, neutral grey at rest, primary-tint on hover. Pages can opt
   into per-action color tints by adding .is-danger to a button. This
   means even legacy pages that pass raw <table> through admin-gridview
   and render bespoke action buttons inside `td.col-actions` /
   `td[data-i18n="col_actions"]` end up visually identical to the
   canonical grids. */
ui-data-grid td.ui-dg-cell[data-col-actions="1"] > button,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] > a,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] .ui-actions-row--grid > button,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] .ui-actions-row--grid > a,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child.col-actions > button,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child.col-actions > a,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child[data-i18n="col_actions"] > button,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child[data-i18n="col_actions"] > a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    color: var(--ui-color-text-muted, #64748b);
    transition: background .12s ease, color .12s ease;
    line-height: 1;
    flex: 0 0 auto;
}
ui-data-grid td.ui-dg-cell[data-col-actions="1"] > button > svg,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] > a > svg,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] .ui-actions-row--grid > button > svg,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] .ui-actions-row--grid > a > svg,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child.col-actions > button > svg,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child.col-actions > a > svg,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child[data-i18n="col_actions"] > button > svg,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child[data-i18n="col_actions"] > a > svg {
    width: 14px;
    height: 14px;
}
ui-data-grid td.ui-dg-cell[data-col-actions="1"] > button:hover,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] > a:hover,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] .ui-actions-row--grid > button:hover,
ui-data-grid td.ui-dg-cell[data-col-actions="1"] .ui-actions-row--grid > a:hover,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child.col-actions > button:hover,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child.col-actions > a:hover,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child[data-i18n="col_actions"] > button:hover,
ui-data-grid table:not(.ui-dg-table) tbody td:last-child[data-i18n="col_actions"] > a:hover {
    background: rgba(0, 0, 0, .06);
    color: var(--ui-color-primary, #2563eb);
}

/* ── Slot-mode (legacy <x-admin-gridview>) — same CRUD rule for raw
       <table> grids the page provides itself. ──────────────────────── */
ui-data-grid table:not(.ui-dg-table):has(thead th:last-child[data-i18n="col_actions"]) thead th:last-child,
ui-data-grid table:not(.ui-dg-table):has(thead th:last-child[data-i18n="col_actions"]) tbody td:last-child,
ui-data-grid table:not(.ui-dg-table):has(thead th:last-child.col-actions) thead th:last-child,
ui-data-grid table:not(.ui-dg-table):has(thead th:last-child.col-actions) tbody td:last-child {
    width: var(--ui-dg-actions-width, 72px);
    min-width: var(--ui-dg-actions-width, 72px);
    max-width: var(--ui-dg-actions-width, 72px);
    white-space: nowrap;
    text-align: center !important;
    padding-left: 2px !important;
    padding-right: 2px !important;
}
ui-data-grid table:not(.ui-dg-table):has(thead th:last-child[data-i18n="col_actions"]) tbody td:last-child > div,
ui-data-grid table:not(.ui-dg-table):has(thead th:last-child.col-actions) tbody td:last-child > div {
    justify-content: center !important;
}

/* ── Column resize handle ────────────────────────────────────────────── */
ui-data-grid th.ui-dg-hc { position: relative; }
ui-data-grid .ui-dg-resizer {
    position: absolute;
    top: 0; right: -3px; bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 4;
    background: transparent;
    transition: background .12s ease;
}
ui-data-grid .ui-dg-resizer:hover,
ui-data-grid .ui-dg-resizer.is-active {
    background: var(--ui-color-primary, #2563eb);
    opacity: .35;
}
ui-data-grid.is-resizing { cursor: col-resize; user-select: none; }
ui-data-grid.is-resizing * { cursor: col-resize !important; }

/* Rows ──────────────────────────────────────────────────────────────── */
ui-data-grid tr.ui-dg-row.is-clickable { cursor: pointer; }
ui-data-grid tr.ui-dg-row:hover > td.ui-dg-cell {
    background: rgba(59, 130, 246, .04);
}

/* Cell alignment by column data-align (cells follow data type — number=right,
   text=left). Heading cells остаются центрированы. */
ui-data-grid td.ui-dg-cell[data-align="right"]  { text-align: right; }
ui-data-grid td.ui-dg-cell[data-align="center"] { text-align: center; }
ui-data-grid td.ui-dg-cell[data-align="left"]   { text-align: left; }

/* ── Grouped mode — card per group ───────────────────────────────────── */
ui-data-grid .ui-dg-cardgroup {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 5px;
    border: 0;
    border-top: 1px solid var(--ui-border-color, #e2e8f0);
    border-radius: 0;
    background: var(--ui-color-bg, #fff);
    box-shadow: none;
    overflow: clip;                /* see note on .ui-dg-card */
}
ui-data-grid .ui-dg-cardgroup:first-of-type { border-top: 0; }
ui-data-grid .ui-dg-cardgroup:last-of-type { margin-bottom: 0; }

ui-data-grid .ui-dg-master {
    padding: 8px 12px;
    background: var(--ui-neutral-200);
    border-bottom: 1px solid var(--ui-neutral-300);
    cursor: pointer;
    user-select: none;
    display: flex; flex-direction: column; gap: 6px;
    font-weight: 500;
    color: var(--ui-color-text, #0f172a);
    /* Keep master content strictly inside the cardgroup (which is inside
       the host's `overflow: hidden` box). Without min-width:0 the flex
       children below can push the master wider than its track; without
       overflow:hidden a long chip/label still bleeds visually. */
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}
ui-data-grid .ui-dg-master:hover { background: var(--ui-neutral-300); }
ui-data-grid .ui-dg-master > .ui-dg-master-head {
    display: flex; align-items: center; gap: 8px;
    min-height: 22px;
    /* Flex row must collapse on narrow widths so the label below can
       ellipsize instead of forcing horizontal overflow. */
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}
/* Long label / chip → ellipsis. The label is the only flexible child
   (chevron/chip/count are fixed-size). Need min-width:0 to allow it
   to shrink past its intrinsic content width inside flex.
   `.ui-dg-master-content` opts out — page-supplied custom headers
   (via headerRenderer + this wrapper class) get the full remaining
   row width and handle their own per-cell overflow. */
ui-data-grid .ui-dg-master > .ui-dg-master-head > span:not(.ui-chip):not(.ui-dg-master-count):not(.ui-dg-master-content) {
    min-width: 0;
    flex: 0 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
ui-data-grid .ui-dg-master > .ui-dg-master-head > .ui-dg-master-content {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
ui-data-grid .ui-dg-master > .ui-dg-master-head > .ui-chip {
    flex: 0 0 auto;
    max-width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
ui-data-grid .ui-dg-master > ui-activity-chart {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 60px;
    padding-top: 2px;
    box-sizing: border-box;
    overflow: hidden;
}
ui-data-grid .ui-dg-master .ui-dg-chevron {
    width: 12px; height: 12px;
    flex: 0 0 auto;
    transition: transform .15s ease;
    transform: rotate(90deg);
}
ui-data-grid .ui-dg-cardgroup.is-collapsed .ui-dg-master {
    border-bottom: 0;
}
ui-data-grid .ui-dg-cardgroup.is-collapsed .ui-dg-master .ui-dg-chevron {
    transform: rotate(0deg);
}
ui-data-grid .ui-dg-master .ui-dg-master-count {
    color: var(--ui-color-text-faint, #94a3b8);
    font-size: 10px; font-weight: 400;
    margin-left: 2px;
    flex: 0 0 auto;
}

ui-data-grid .ui-dg-cardrows {
    width: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    /* No scrollbar-gutter: stable — gutter only when scrollbar exists;
       cardhead padding is added by JS to match (see _updateScrollGutters). */
}
/* Thin 50% grey divider on the LEFT edge of the vertical scrollbar —
   visually separates the rows region from the scrollbar zone, same
   colour as column dividers. WebKit pseudo-elements (Chrome/Edge/
   Safari/Opera) — covers ~all admin users. */
ui-data-grid .ui-dg-cardrows::-webkit-scrollbar {
    width: 14px;
}
ui-data-grid .ui-dg-cardrows::-webkit-scrollbar-track {
    background: transparent;
    border-left: 1px solid var(--ui-divider);
}
ui-data-grid .ui-dg-cardrows::-webkit-scrollbar-thumb {
    background: var(--ui-neutral-300);
    border-radius: 7px;
    border: 3px solid transparent;
    background-clip: content-box;
}
ui-data-grid .ui-dg-cardrows::-webkit-scrollbar-thumb:hover {
    background: var(--ui-neutral-400);
    background-clip: content-box;
}
/* Same treatment on the grouped-mode body scrollbar (cardgroups list). */
ui-data-grid[mode="grouped"] .ui-dg-body::-webkit-scrollbar {
    width: 14px;
}
ui-data-grid[mode="grouped"] .ui-dg-body::-webkit-scrollbar-track {
    background: transparent;
    border-left: 1px solid var(--ui-divider);
}
ui-data-grid[mode="grouped"] .ui-dg-body::-webkit-scrollbar-thumb {
    background: var(--ui-neutral-300);
    border-radius: 7px;
    border: 3px solid transparent;
    background-clip: content-box;
}
ui-data-grid[mode="grouped"] .ui-dg-body::-webkit-scrollbar-thumb:hover {
    background: var(--ui-neutral-400);
    background-clip: content-box;
}
ui-data-grid .ui-dg-cardrows > table.ui-dg-table-body {
    width: 100%;
}
/* Flat mode: cardrows is direct child of body — fills body's flex space,
   scrollbar appears INSIDE cardrows when content overflows the parent-
   allocated height. No max-height; height comes from the flex chain. */
ui-data-grid .ui-dg-body > .ui-dg-cardrows {
    flex: 1 1 auto;
    min-height: 0;
}
/* Grouped mode: cardrows lives inside each cardgroup — bounded by 60vh
   so each group has its own independent scroll region. */
ui-data-grid .ui-dg-cardgroup > .ui-dg-cardrows {
    max-height: 60vh;
}

/* Collapsed cardgroup hides the cardrows entirely */
/* hide-empty-groups: a card without rows is just its master line. */
ui-data-grid[hide-empty-groups] .ui-dg-cardgroup.is-empty > .ui-dg-cardrows { display: none; }
ui-data-grid .ui-dg-cardgroup.is-collapsed > .ui-dg-cardrows {
    display: none;
}

/* ── Empty / loading state ──────────────────────────────────────────── */
ui-data-grid .ui-dg-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--ui-color-text-faint, #94a3b8);
    font-size: var(--ui-font-size-sm, 12px);
}
ui-data-grid tr.ui-dg-empty-row > td.ui-dg-empty {
    border-right: 0;
}

/* ── Adaptive: hide columns by data-priority on narrow containers.
       Both the <col> AND the matching cells are hidden — table-layout: fixed
       redistributes the freed width across the remaining columns. ──── */
@container (max-width: 1280px) {
    ui-data-grid col[data-priority="low"]    { display: none; }
    ui-data-grid th.ui-dg-hc[data-priority="low"],
    ui-data-grid td.ui-dg-cell[data-priority="low"] { display: none; }
}
@container (max-width: 1024px) {
    ui-data-grid col[data-priority="medium"] { display: none; }
    ui-data-grid th.ui-dg-hc[data-priority="medium"],
    ui-data-grid td.ui-dg-cell[data-priority="medium"] { display: none; }
}

/* group-by hides the redundant column whose value is already shown as
   the cardgroup label. Same mechanism as priority hiding above. */
ui-data-grid col[data-hidden="1"],
ui-data-grid th.ui-dg-hc[data-hidden="1"],
ui-data-grid td.ui-dg-cell[data-hidden="1"] { display: none; }
