/* ==========================================================================
   DataGridView — styles
   ==========================================================================
   A self-contained design system for the RSC DataGridView. Everything is driven
   by CSS custom properties declared on .dg; override any token from your own
   stylesheet, e.g.:

       .my-panel .dg { --dg-primary: #7c3aed; --dg-row-height: 40px; }

   Theming is resolved three ways, in order of precedence (later wins):
     1. The component's Theme parameter → data-theme="light|dark|system".
     2. The operating-system setting via @media (prefers-color-scheme) when
        data-theme="system".
     3. An application-level theme: :root[data-theme="dark"] .dg.

   Density is resolved through data-density="compact|comfortable|spacious",
   which overrides the row-height/padding tokens — no duplicated styles.

   Layout uses logical properties throughout (padding-inline, inset-inline-start,
   border-inline-end, ...) so the grid mirrors correctly under dir="rtl".

   Link the stylesheet once from the host page:

       <link rel="stylesheet" href="_content/RSC/DataGrid/datagridview.css" />
   ========================================================================== */

/* ------------------------------------------------------------------ Design tokens */

.dg {
    --dg-primary: #0f766e;
    --dg-primary-hover: #115e59;
    --dg-primary-soft: rgba(15, 118, 110, 0.10);
    --dg-primary-soft-strong: rgba(15, 118, 110, 0.18);
    --dg-primary-contrast: #ffffff;

    /* Surfaces */
    --dg-background: #ffffff;
    --dg-surface: #ffffff;
    --dg-surface-alt: #f8fafc;
    --dg-header-bg: #f8fafc;
    --dg-hover: #f1f5f9;
    --dg-selected: rgba(15, 118, 110, 0.10);
    --dg-selected-hover: rgba(15, 118, 110, 0.16);

    /* Borders */
    --dg-border: #e2e8f0;
    --dg-border-strong: #cbd5e1;

    /* Text */
    --dg-text: #0f172a;
    --dg-muted-text: #64748b;
    --dg-disabled-text: #94a3b8;

    /* Semantic */
    --dg-danger: #dc2626;
    --dg-danger-soft: rgba(220, 38, 38, 0.10);
    --dg-warning: #d97706;
    --dg-success: #16a34a;

    /* Focus */
    --dg-focus: rgba(15, 118, 110, 0.35);

    /* Shape & typography */
    --dg-radius: 10px;
    --dg-radius-sm: 6px;
    --dg-font-family: inherit;
    --dg-font-size: 13.5px;
    --dg-font-size-sm: 12.5px;

    /* Rows & cells */
    --dg-row-height: 44px;
    --dg-cell-padding-x: 14px;
    --dg-header-height: 44px;

    /* Shadows */
    --dg-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --dg-shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);

    /* Controls & extras */
    --dg-control-bg: #ffffff;
    --dg-control-border: #cbd5e1;
    --dg-chip-bg: rgba(15, 118, 110, 0.08);
    --dg-skeleton: #e2e8f0;
    --dg-overlay-bg: rgba(15, 23, 42, 0.35);
    --dg-z-overlay: 40;
    --dg-z-popover: 41;

    /* Grouping */
    --dg-group-background: #f1f5f9;
    --dg-group-background-end: #e9eef5;
    --dg-group-hover: #e3eaf3;
    --dg-group-border: #e2e8f0;
    --dg-group-chip-border: #cbd5e1;
    --dg-group-indent: 24px;
    --dg-group-header-height: 44px;
    --dg-group-level-indicator: #cbd5e1;

    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Never let the grid force its parent (and the page) wider than the viewport: the
       table scrolls inside .dg__scroll, and min-width:0 lets flex/grid parents shrink us. */
    min-width: 0;
    max-width: 100%;
    font-family: var(--dg-font-family);
    font-size: var(--dg-font-size);
    line-height: 1.5;
    color: var(--dg-text);
    background: var(--dg-background);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    box-shadow: var(--dg-shadow-sm);
    -webkit-font-smoothing: antialiased;
    text-align: start;
}

/* ------------------------------------------------------------------ Density */

.dg[data-density="compact"] {
    --dg-row-height: 34px;
    --dg-header-height: 38px;
    --dg-group-header-height: 38px;
    --dg-font-size: 12.5px;
    --dg-font-size-sm: 12px;
    --dg-cell-padding-x: 10px;
}

.dg[data-density="spacious"] {
    --dg-row-height: 58px;
    --dg-header-height: 50px;
    --dg-group-header-height: 52px;
    --dg-font-size: 14.5px;
    --dg-cell-padding-x: 18px;
}

/* ------------------------------------------------------------------ Dark theme */

.dg[data-theme="dark"],
:root[data-theme="dark"] .dg {
    --dg-primary: #2dd4bf;
    --dg-primary-hover: #5eead4;
    --dg-primary-soft: rgba(45, 212, 191, 0.14);
    --dg-primary-soft-strong: rgba(45, 212, 191, 0.24);
    --dg-primary-contrast: #042f2e;

    --dg-background: #0f172a;
    --dg-surface: #1e293b;
    --dg-surface-alt: #16213a;
    --dg-header-bg: #1a2539;
    --dg-hover: #26334a;
    --dg-selected: rgba(45, 212, 191, 0.14);
    --dg-selected-hover: rgba(45, 212, 191, 0.22);

    --dg-border: #2b3a52;
    --dg-border-strong: #3d4f6d;

    --dg-text: #e2e8f0;
    --dg-muted-text: #94a3b8;
    --dg-disabled-text: #64748b;

    --dg-danger: #f87171;
    --dg-danger-soft: rgba(248, 113, 113, 0.14);
    --dg-warning: #fbbf24;
    --dg-success: #4ade80;

    --dg-focus: rgba(45, 212, 191, 0.35);

    --dg-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --dg-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);

    --dg-control-bg: #16213a;
    --dg-control-border: #3d4f6d;
    --dg-chip-bg: rgba(45, 212, 191, 0.12);
    --dg-skeleton: #26334a;
    --dg-overlay-bg: rgba(2, 6, 23, 0.6);

    --dg-group-background: #16213a;
    --dg-group-background-end: #1e2b44;
    --dg-group-hover: #26334a;
    --dg-group-border: #2b3a52;
    --dg-group-chip-border: #3d4f6d;
    --dg-group-level-indicator: #3d4f6d;
}

@media (prefers-color-scheme: dark) {
    .dg[data-theme="system"] {
        --dg-primary: #2dd4bf;
        --dg-primary-hover: #5eead4;
        --dg-primary-soft: rgba(45, 212, 191, 0.14);
        --dg-primary-soft-strong: rgba(45, 212, 191, 0.24);
        --dg-primary-contrast: #042f2e;

        --dg-background: #0f172a;
        --dg-surface: #1e293b;
        --dg-surface-alt: #16213a;
        --dg-header-bg: #1a2539;
        --dg-hover: #26334a;
        --dg-selected: rgba(45, 212, 191, 0.14);
        --dg-selected-hover: rgba(45, 212, 191, 0.22);

        --dg-border: #2b3a52;
        --dg-border-strong: #3d4f6d;

        --dg-text: #e2e8f0;
        --dg-muted-text: #94a3b8;
        --dg-disabled-text: #64748b;

        --dg-danger: #f87171;
        --dg-danger-soft: rgba(248, 113, 113, 0.14);
        --dg-warning: #fbbf24;
        --dg-success: #4ade80;

        --dg-focus: rgba(45, 212, 191, 0.35);

        --dg-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --dg-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);

        --dg-control-bg: #16213a;
        --dg-control-border: #3d4f6d;
        --dg-chip-bg: rgba(45, 212, 191, 0.12);
        --dg-skeleton: #26334a;
        --dg-overlay-bg: rgba(2, 6, 23, 0.6);

        --dg-group-background: #16213a;
        --dg-group-hover: #26334a;
        --dg-group-border: #2b3a52;
        --dg-group-level-indicator: #3d4f6d;
    }
}

/* ------------------------------------------------------------------ Shared controls */

.dg button {
    font: inherit;
}

.dg__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 4px 12px;
    font-size: var(--dg-font-size-sm);
    font-weight: 600;
    color: var(--dg-text);
    background: var(--dg-surface);
    border: 1px solid var(--dg-border-strong);
    border-radius: var(--dg-radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.dg__btn:hover {
    background: var(--dg-hover);
}

.dg__btn:focus-visible,
.dg__icon-btn:focus-visible,
.dg__filter-btn:focus-visible,
.dg__sort:focus-visible,
.dg__resizer:focus-visible,
.dg__chip-remove:focus-visible,
.dg__pager-btn:focus-visible,
.dg__pager-num:focus-visible,
.dg__menu-item:focus-visible,
.dg__input:focus-visible,
.dg__search-input:focus-visible {
    outline: 2px solid var(--dg-focus);
    outline-offset: 1px;
}

.dg__btn svg,
.dg__icon-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.dg__btn--primary {
    color: var(--dg-primary-contrast);
    background: var(--dg-primary);
    border-color: var(--dg-primary);
}

.dg__btn--primary:hover {
    background: var(--dg-primary-hover);
    border-color: var(--dg-primary-hover);
}

.dg__btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--dg-muted-text);
}

.dg__btn--ghost:hover {
    background: var(--dg-hover);
    color: var(--dg-text);
}

.dg__btn--danger-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--dg-danger);
}

.dg__btn--danger-ghost:hover {
    background: var(--dg-danger-soft);
}

.dg__btn--sm {
    min-height: 26px;
    padding: 2px 8px;
    font-size: 12px;
}

.dg__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--dg-muted-text);
    background: transparent;
    border: none;
    border-radius: var(--dg-radius-sm);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.dg__icon-btn:hover {
    background: var(--dg-hover);
    color: var(--dg-text);
}

.dg__icon-btn--sm {
    width: 24px;
    height: 24px;
}

.dg__icon-btn:disabled {
    color: var(--dg-disabled-text);
    cursor: not-allowed;
    background: transparent;
}

.dg__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ------------------------------------------------------------------ Toolbar */

.dg__toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px 0;
    flex-wrap: wrap;
}

.dg__toolbar-spacer {
    flex: 1 1 auto;
}

.dg__search {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 200px;
    flex: 0 1 320px;
}

.dg__search-icon {
    position: absolute;
    inset-inline-start: 10px;
    width: 15px;
    height: 15px;
    color: var(--dg-muted-text);
    pointer-events: none;
}

.dg__search-input {
    width: 100%;
    height: 34px;
    padding-inline: 32px 30px;
    font: inherit;
    font-size: var(--dg-font-size-sm);
    color: var(--dg-text);
    background: var(--dg-control-bg);
    border: 1px solid var(--dg-control-border);
    border-radius: var(--dg-radius-sm);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.dg__search-input::placeholder {
    color: var(--dg-disabled-text);
}

.dg__search-input:focus {
    outline: none;
    border-color: var(--dg-primary);
    box-shadow: 0 0 0 3px var(--dg-focus);
}

.dg__search-clear {
    position: absolute;
    inset-inline-end: 4px;
    width: 24px;
    height: 24px;
}

.dg__search--chooser {
    min-width: 0;
    width: 100%;
    flex: none;
    margin-block-end: 8px;
}

/* ------------------------------------------------------------------ Selection & filter bars */

.dg__selection-bar,
.dg__filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 6px 12px;
    font-size: var(--dg-font-size-sm);
}

.dg__selection-bar {
    background: var(--dg-selected);
    color: var(--dg-primary);
    border-block: 1px solid var(--dg-border);
}

.dg__selection-count {
    font-weight: 600;
}

.dg__filter-bar {
    border-block: 1px solid var(--dg-border);
}

.dg__filter-bar-title {
    font-weight: 600;
    color: var(--dg-muted-text);
}

.dg__chips {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1 1 auto;
}

.dg__chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 320px;
    padding: 3px 8px;
    font-size: 12px;
    color: var(--dg-primary);
    background: var(--dg-chip-bg);
    border-radius: 999px;
}

.dg__chip-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg__chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    color: inherit;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
}

.dg__chip-remove:hover {
    background: var(--dg-primary-soft-strong);
}

.dg__chip-remove svg {
    width: 10px;
    height: 10px;
}

/* ------------------------------------------------------------------ States (empty / error / loading) */

.dg__state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px 16px;
    color: var(--dg-muted-text);
    text-align: center;
}

.dg__state-icon {
    width: 34px;
    height: 34px;
    color: var(--dg-border-strong);
}

.dg__state-text {
    margin: 0;
    font-size: var(--dg-font-size);
}

.dg__skeleton {
    display: flex;
    flex-direction: column;
    padding: 0 12px 12px;
    gap: 6px;
}

.dg__skeleton-row {
    display: flex;
    gap: 12px;
    height: var(--dg-row-height);
    align-items: center;
}

.dg__skeleton-cell {
    flex: 1 1 0;
    height: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--dg-skeleton) 25%, var(--dg-hover) 50%, var(--dg-skeleton) 75%);
    background-size: 200% 100%;
    animation: dg-shimmer 1.4s ease-in-out infinite;
}

@keyframes dg-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ------------------------------------------------------------------ Table */

.dg__scroll {
    overflow: auto;
    /* The scroll body must never force the grid (or its ancestors) wider than the
       container: inline-size containment severs the table's intrinsic width from the
       parents' min-content sizing, so a wide table scrolls inside the grid box instead
       of stretching it on load. min-width: 0 is the classic flex/grid-item fallback. */
    contain: inline-size;
    min-width: 0;
    border-radius: var(--dg-radius-sm);
}

.dg__table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--dg-font-size);
}

.dg__th,
.dg__td {
    padding-inline: var(--dg-cell-padding-x);
    border-block-end: 1px solid var(--dg-border);
    text-align: start;
    vertical-align: middle;
    background: var(--dg-surface);
}

.dg__th {
    position: relative;
    height: var(--dg-header-height);
    font-size: var(--dg-font-size-sm);
    font-weight: 600;
    color: var(--dg-muted-text);
    background: var(--dg-header-bg);
    white-space: nowrap;
    user-select: none;
}

.dg--align-start { text-align: start; }
.dg--align-center { text-align: center; }
.dg--align-end { text-align: end; }

/* Sticky header + horizontal scroll */
.dg__thead .dg__th {
    position: sticky;
    top: 0;
    z-index: 3;
}

.dg__th--select,
.dg__td--select {
    position: sticky;
    inset-inline-start: 0;
    z-index: 4;
    width: 46px;
    min-width: 46px;
    max-width: 46px;
    padding-inline: 10px;
    text-align: center;
}

.dg__th--select {
    z-index: 5;
}

/* Frozen columns: sticky with a computed inline inset offset */
.dg__th--frozen-start,
.dg__td--frozen-start {
    position: sticky;
    z-index: 2;
    box-shadow: inset -1px 0 0 var(--dg-border);
}

.dg__th--frozen-start {
    z-index: 4;
}

.dg__th--frozen-end,
.dg__td--frozen-end {
    position: sticky;
    z-index: 2;
    box-shadow: inset 1px 0 0 var(--dg-border);
}

.dg__th--frozen-end {
    z-index: 4;
}

.dg__td {
    height: var(--dg-row-height);
    overflow: hidden;
    text-overflow: ellipsis;
}

.dg__tbody .dg__row {
    transition: background-color 100ms ease;
}

.dg__tbody .dg__row:hover .dg__td {
    background: var(--dg-hover);
}

.dg__row--selected .dg__td {
    background: var(--dg-selected);
}

.dg__row--selected:hover .dg__td {
    background: var(--dg-selected-hover);
}

.dg__row--disabled {
    color: var(--dg-disabled-text);
    cursor: not-allowed;
}

.dg__row--disabled .dg__td {
    background: var(--dg-surface);
}

.dg__row:focus-visible {
    outline: 2px solid var(--dg-focus);
    outline-offset: -2px;
}

.dg__td--footer {
    height: auto;
    min-height: 36px;
    font-weight: 600;
    background: var(--dg-surface-alt);
    border-block-end: none;
}

/* ------------------------------------------------------------------ Header content */

.dg__th-content {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
}

.dg__th-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.dg__sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding: 2px 4px;
    font: inherit;
    font-weight: 600;
    color: inherit;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.dg__sort:hover {
    color: var(--dg-text);
    background: var(--dg-hover);
}

.dg__sort-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg__sort-icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

.dg__th--sorted .dg__sort {
    color: var(--dg-primary);
}

.dg__sort-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 15px;
    height: 15px;
    padding-inline: 3px;
    font-size: 10px;
    font-weight: 700;
    color: var(--dg-primary-contrast);
    background: var(--dg-primary);
    border-radius: 999px;
}

.dg__filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    color: var(--dg-muted-text);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.dg__filter-btn:hover {
    background: var(--dg-hover);
    color: var(--dg-text);
}

.dg__filter-btn--active {
    color: var(--dg-primary);
    background: var(--dg-primary-soft);
}

.dg__filter-btn svg {
    width: 13px;
    height: 13px;
}

/* The header currently being dragged (reorder or drag-to-group) */
.dg__th--dragging {
    opacity: 0.55;
}

/* Drop indicators during drag & drop reordering */
.dg__th--drop-before::before,
.dg__th--drop-after::after {
    content: "";
    position: absolute;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 999px;
    background: var(--dg-primary);
    z-index: 6;
}

.dg__th--drop-before::before {
    inset-inline-start: 0;
}

.dg__th--drop-after::after {
    inset-inline-end: 0;
}

.dg__th[draggable="true"] {
    cursor: grab;
}

.dg__th[draggable="true"]:active {
    cursor: grabbing;
}

/* Resize handle */
.dg__resizer {
    position: absolute;
    inset-inline-end: -3px;
    top: 0;
    bottom: 0;
    width: 7px;
    cursor: col-resize;
    touch-action: none;
    z-index: 5;
}

.dg__resizer::after {
    content: "";
    position: absolute;
    inset-inline-start: 3px;
    top: 12px;
    bottom: 12px;
    width: 1px;
    background: transparent;
    transition: background-color 120ms ease;
}

.dg__resizer:hover::after,
.dg__resizer:active::after {
    background: var(--dg-primary);
}

/* ------------------------------------------------------------------ Checkboxes */

.dg__checkbox {
    position: relative;
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--dg-border-strong);
    border-radius: 4px;
    background: var(--dg-control-bg);
    vertical-align: middle;
    pointer-events: none;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.dg__checkbox--checked,
.dg__checkbox--indeterminate {
    background: var(--dg-primary);
    border-color: var(--dg-primary);
}

.dg__checkbox--checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 2px;
    width: 6px;
    height: 3px;
    border: solid var(--dg-primary-contrast);
    border-width: 0 0 2px 2px;
    transform: rotate(-45deg);
}

.dg__checkbox--indeterminate::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 50%;
    width: 8px;
    height: 2px;
    margin-top: -1px;
    border-radius: 1px;
    background: var(--dg-primary-contrast);
}

.dg__checkbox-input {
    /* Invisible but fully interactive: stretch over the positioned cell/container so the
       whole checkbox area is clickable (the decorative span stays pointer-events:none). */
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

/* Buttons inside a chooser item must stay above its full-cover checkbox input. */
.dg__chooser-item {
    position: relative;
}

.dg__chooser-item > .dg__icon-btn,
.dg__chooser-item > .dg__chooser-move {
    position: relative;
    z-index: 2;
}

/* The th/td provide a large hit area; clicking toggles via the label-less input handled
   by the component. Focus styling targets the cell when its input receives focus. */
.dg__th--select:has(.dg__checkbox-input:focus-visible),
.dg__td--select:has(.dg__checkbox-input:focus-visible) {
    outline: 2px solid var(--dg-focus);
    outline-offset: -2px;
}

/* ------------------------------------------------------------------ Cards (stacked mode)
   Modern card design: a header row (selection checkbox + primary field as the title) and
   labeled detail rows separated by hairlines. The checkbox is inline in the header, never
   absolutely positioned over cell content, so it can't overlap text. */

.dg__cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 12px 12px;
}

.dg__card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--dg-surface);
    border: 1px solid var(--dg-border);
    border-radius: 12px;
    box-shadow: var(--dg-shadow-sm);
    overflow: hidden;
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.dg__card:hover {
    border-color: var(--dg-border-strong);
    box-shadow: var(--dg-shadow-md);
    transform: translateY(-1px);
}

.dg__card--selected {
    border-color: var(--dg-primary);
    background: var(--dg-selected);
}

.dg__card--selected::before {
    /* Accent bar marking the selected card */
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 3px;
    background: var(--dg-primary);
}

.dg__card--disabled {
    color: var(--dg-disabled-text);
    cursor: not-allowed;
    opacity: 0.6;
}

.dg__card:focus-visible {
    outline: 2px solid var(--dg-focus);
    outline-offset: 2px;
}

.dg__card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
}

.dg__card-check {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    cursor: pointer;
}

.dg__card-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--dg-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg__card-body {
    border-block-start: 1px solid var(--dg-border);
}

.dg__card-cell {
    display: grid;
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
    gap: 12px;
    align-items: baseline;
    min-width: 0;
    padding: 9px 14px;
}

.dg__card-cell + .dg__card-cell {
    border-block-start: 1px solid var(--dg-border);
}

.dg__card-cell::before {
    content: attr(data-label);
    font-size: var(--dg-font-size-sm);
    font-weight: 600;
    color: var(--dg-muted-text);
}

/* ------------------------------------------------------------------ Row actions
   Per-row action buttons (DataGridView RowActions). The buttons float over the row: they
   live in no column and reserve no row space. The overlay cell is a zero-width sticky
   table cell pinned to the scroll body's inline-end edge (the right edge in LTR, the left
   edge under RTL), so the pill stays visible at the grid's edge while the table scrolls
   horizontally; the pill inside is absolutely positioned against the cell. The buttons
   fade in on row hover / keyboard focus with a small slide, sit in a pill so they stay
   readable over the cells they cover, and take their colors from per-action
   --dg-action-* custom properties (theme tokens by default). */

.dg__row {
    position: relative;
}

.dg__td-actions-overlay {
    display: table-cell;
    position: sticky;
    inset-inline-end: 0;
    width: 0;
    min-width: 0;
    max-width: 0;
    padding: 0;
    border: 0;
    z-index: 4;
    pointer-events: none;
    overflow: visible;
}

.dg__td-actions-overlay > .dg__row-actions {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 0;
}

.dg__row-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 2px;
    padding: 3px;
    border-radius: 9999px;
    background: var(--dg-surface);
    border: 1px solid var(--dg-border);
    box-shadow: var(--dg-shadow-sm);
    opacity: 0;
    transform: translateX(6px);
    pointer-events: none;
    transition: opacity 140ms ease, transform 140ms ease;
}

.dg[dir="rtl"] .dg__row-actions {
    transform: translateX(-6px);
}

/* Revealed on row hover and when any action inside carries keyboard focus. Buttons are
   interactive only while the pill is revealed (pointer-events is re-enabled per state). */
.dg__row:hover .dg__row-actions,
.dg__row:focus-within .dg__row-actions,
.dg__row-actions--always {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.dg__row:hover .dg__row-actions .dg__row-action,
.dg__row:focus-within .dg__row-actions .dg__row-action,
.dg__row-actions--always .dg__row-action {
    pointer-events: auto;
}

.dg__row-action {
    --dg-action-color: var(--dg-muted-text);
    --dg-action-bg: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    flex-shrink: 0;
    color: var(--dg-action-color);
    background: var(--dg-action-bg);
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.dg__row-action:hover:not(:disabled) {
    background: color-mix(in srgb, var(--dg-action-color) 14%, transparent);
}

/* Solid (background-colored) buttons keep their fill on hover and gain a soft ring. */
.dg__row-action--solid:hover:not(:disabled) {
    background: var(--dg-action-bg);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--dg-action-color) 20%, transparent);
}

.dg__row-action:active:not(:disabled) {
    transform: scale(0.92);
}

.dg__row-action:focus-visible {
    outline: 2px solid var(--dg-focus);
    outline-offset: 1px;
}

.dg__row-action:disabled {
    color: var(--dg-disabled-text);
    cursor: not-allowed;
    opacity: 0.55;
}

.dg__row-action-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Text-only fallback (no icon configured) renders as a compact label chip. */
.dg__row-action--text {
    width: auto;
    padding-inline: 10px;
    border-radius: var(--dg-radius-sm);
    font-size: var(--dg-font-size-sm);
    font-weight: 600;
}

.dg__row-action-label {
    white-space: nowrap;
}

.dg__row-actions--card {
    gap: 6px;
    margin-inline-start: auto;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

/* Density: action buttons scale with the row height. */
.dg[data-density="compact"] .dg__row-action {
    width: 26px;
    height: 26px;
}

.dg[data-density="spacious"] .dg__row-action {
    width: 34px;
    height: 34px;
}

/* Stacked cards always show the actions (touch has no hover). */
.dg--stacked .dg__row-actions {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

/* ------------------------------------------------------------------ Pagination */

.dg__pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 12px 12px;
}

.dg__pager-summary {
    font-size: var(--dg-font-size-sm);
    color: var(--dg-muted-text);
    white-space: nowrap;
}

.dg__pager-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.dg__pager-size select {
    height: 30px;
    padding-inline: 8px;
    font: inherit;
    font-size: var(--dg-font-size-sm);
    color: var(--dg-text);
    background: var(--dg-control-bg);
    border: 1px solid var(--dg-control-border);
    border-radius: var(--dg-radius-sm);
}

.dg__pager-btn,
.dg__pager-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding-inline: 4px;
    font-size: var(--dg-font-size-sm);
    color: var(--dg-muted-text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--dg-radius-sm);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.dg__pager-btn:hover:not(:disabled),
.dg__pager-num:hover {
    background: var(--dg-hover);
    color: var(--dg-text);
}

.dg__pager-btn:disabled {
    color: var(--dg-disabled-text);
    cursor: not-allowed;
}

.dg__pager-btn svg {
    width: 15px;
    height: 15px;
}

.dg__pager-num--active {
    color: var(--dg-primary-contrast);
    background: var(--dg-primary);
    border-color: var(--dg-primary);
}

.dg__pager-num--active:hover {
    color: var(--dg-primary-contrast);
    background: var(--dg-primary-hover);
}

.dg__pager-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    color: var(--dg-muted-text);
}

/* RTL: pagination chevrons point toward the reading direction */
.dg[dir="rtl"] .dg__pager-btn svg {
    transform: scaleX(-1);
}

/* ------------------------------------------------------------------ Popovers & overlays */

.dg__overlay {
    position: fixed;
    inset: 0;
    background: var(--dg-overlay-bg);
    z-index: var(--dg-z-overlay);
}

.dg__popover {
    position: fixed;
    z-index: var(--dg-z-popover);
    display: flex;
    flex-direction: column;
    max-width: min(92vw, 420px);
    background: var(--dg-surface);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    box-shadow: var(--dg-shadow-md);
    overflow: hidden;
}

.dg__popover-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-block-end: 1px solid var(--dg-border);
}

.dg__popover-title {
    font-weight: 600;
    font-size: var(--dg-font-size);
}

.dg__popover-body {
    padding: 10px 12px;
    overflow-y: auto;
    max-height: min(60vh, 380px);
}

.dg__popover-foot {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-block-start: 1px solid var(--dg-border);
}

.dg__popover-foot-spacer {
    flex: 1 1 auto;
}

/* ------------------------------------------------------------------ Help popover */

.dg__popover--help {
    max-width: min(94vw, 460px);
}

.dg__help-body {
    padding: 4px 12px 12px;
}

.dg__help-section {
    padding-block: 8px;
}

.dg__help-section + .dg__help-section {
    border-block-start: 1px solid var(--dg-border);
}

.dg__help-section-title {
    margin: 0;
    font-size: var(--dg-font-size);
    font-weight: 600;
    color: var(--dg-primary);
}

.dg__help-list {
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 4px;
    font-size: var(--dg-font-size);
}

.dg__help-list li {
    position: relative;
    padding-inline-start: 14px;
}

.dg__help-list li::before {
    content: "";
    position: absolute;
    inset-inline-start: 2px;
    inset-block-start: 0.55em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--dg-border-strong);
}

/* ------------------------------------------------------------------ Filter menu */

.dg__filter-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-block-end: 8px;
}

.dg__filter-row select.dg__input--sm {
    flex: 0 1 130px;
}

.dg__filter-row .dg__filter-join {
    flex: 0 0 58px;
}

.dg__filter-row input.dg__input--sm {
    flex: 1 1 120px;
    min-width: 70px;
}

.dg__input {
    height: 32px;
    padding-inline: 8px;
    font: inherit;
    font-size: var(--dg-font-size-sm);
    color: var(--dg-text);
    background: var(--dg-control-bg);
    border: 1px solid var(--dg-control-border);
    border-radius: var(--dg-radius-sm);
}

.dg__input--sm {
    height: 30px;
}

.dg__filter-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-block-start: 4px;
}

.dg__segmented {
    display: inline-flex;
    border: 1px solid var(--dg-border-strong);
    border-radius: var(--dg-radius-sm);
    overflow: hidden;
}

.dg__segmented button {
    padding: 4px 14px;
    font-size: var(--dg-font-size-sm);
    font-weight: 600;
    color: var(--dg-muted-text);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.dg__segmented button:hover {
    background: var(--dg-hover);
}

.dg__segmented button.is-active {
    color: var(--dg-primary);
    background: var(--dg-primary-soft);
}

/* ------------------------------------------------------------------ Column chooser */

.dg__chooser-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.dg__chooser-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-radius: var(--dg-radius-sm);
}

.dg__chooser-item:hover {
    background: var(--dg-hover);
}

.dg__chooser-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--dg-font-size-sm);
}

.dg__chooser-move {
    display: flex;
    gap: 2px;
}

/* ------------------------------------------------------------------ Density menu */

.dg__menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 8px;
    font-size: var(--dg-font-size-sm);
    color: var(--dg-text);
    background: transparent;
    border: none;
    border-radius: var(--dg-radius-sm);
    cursor: pointer;
    text-align: start;
}

.dg__menu-item:hover {
    background: var(--dg-hover);
}

.dg__menu-item.is-active {
    color: var(--dg-primary);
    font-weight: 600;
}

.dg__menu-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dg-border-strong);
    flex-shrink: 0;
}

.dg__menu-item.is-active .dg__menu-dot {
    background: var(--dg-primary);
}

/* ------------------------------------------------------------------ Responsive: adaptive → cards on small screens */

@media (max-width: 640px) {
    .dg--adaptive .dg__scroll {
        overflow: visible;
        border-radius: 0;
    }

    .dg--adaptive .dg__thead {
        display: none;
    }

    .dg--adaptive .dg__table,
    .dg--adaptive .dg__tbody,
    .dg--adaptive .dg__tr {
        display: block;
        width: 100%;
    }

    .dg--adaptive .dg__tbody .dg__row {
        position: relative;
        display: flex;
        flex-direction: column;
        margin: 0 12px 12px;
        padding: 13px 16px;
        background: var(--dg-surface);
        border: 1px solid var(--dg-border);
        border-radius: 12px;
        box-shadow: var(--dg-shadow-sm);
        overflow: hidden;
        transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
    }

    .dg--adaptive .dg__tbody .dg__row:hover {
        border-color: var(--dg-border-strong);
        box-shadow: var(--dg-shadow-md);
        transform: translateY(-1px);
    }

    .dg--adaptive .dg__tbody .dg__row:hover .dg__td,
    .dg--adaptive .dg__tbody .dg__row--selected .dg__td {
        background: transparent;
    }

    .dg--adaptive .dg__tbody .dg__row--selected {
        border-color: var(--dg-primary);
        background: var(--dg-selected);
    }

    .dg--adaptive .dg__tbody .dg__row--selected::before {
        content: "";
        position: absolute;
        inset-block: 0;
        inset-inline-start: 0;
        width: 3px;
        background: var(--dg-primary);
    }

    .dg--adaptive .dg__td {
        display: grid;
        grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
        gap: 12px;
        align-items: baseline;
        height: auto;
        min-height: 0;
        padding: 8px 0;
        border-block-end: none;
        background: transparent !important;
    }

    .dg--adaptive .dg__td + .dg__td {
        border-block-start: 1px solid var(--dg-border);
    }

    .dg--adaptive .dg__td::before {
        content: attr(data-label);
        font-size: var(--dg-font-size-sm);
        font-weight: 600;
        color: var(--dg-muted-text);
    }

    /* The first data cell doubles as the card title (label hidden, larger value). */
    .dg--adaptive .dg__row:has(.dg__td--select) .dg__td:nth-of-type(2),
    .dg--adaptive .dg__row:not(:has(.dg__td--select)) .dg__td:first-of-type {
        display: block;
        margin-block-end: 4px;
        font-size: 15px;
        font-weight: 700;
        color: var(--dg-text);
    }

    /* Only the title must clear the floating checkbox (it sits on the title's row, at
       the inline-start edge — the side the title text begins from in both directions). */
    .dg--adaptive .dg__row:has(.dg__td--select) .dg__td:nth-of-type(2) {
        padding-inline-start: 36px;
    }

    .dg--adaptive .dg__row:has(.dg__td--select) .dg__td:nth-of-type(2)::before,
    .dg--adaptive .dg__row:not(:has(.dg__td--select)) .dg__td:first-of-type::before {
        content: none;
    }

    .dg--adaptive .dg__td--select {
        position: absolute;
        inset-inline-start: 0;
        top: 14px;
        width: 22px;
        min-width: 22px;
        max-width: 22px;
        height: 22px;
        padding: 0;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .dg--adaptive .dg__td--select::before {
        content: none;
    }

    /* Popovers become bottom sheets on phones */
    .dg__popover {
        position: fixed;
        inset-inline: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        max-width: none;
        max-height: 82dvh;
        border-radius: 14px 14px 0 0;
    }

    /* Compact pagination: drop first/last, smaller targets */
    .dg__pager-btn:first-of-type,
    .dg__pager-btn:last-of-type {
        display: none;
    }

    .dg__pager {
        padding: 8px 8px 12px;
    }

    .dg__search {
        flex-basis: 100%;
    }

    /* Row actions in card mode: always visible, on their own row under the details. */
    .dg--adaptive .dg__row-actions {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }

    .dg--adaptive .dg__row-actions .dg__row-action {
        pointer-events: auto;
    }

    .dg--adaptive .dg__td-actions-overlay {
        position: static;
        inset: auto;
        width: auto;
        min-width: auto;
        max-width: none;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        height: auto;
        padding: 10px 0 2px;
        margin: 0;
        pointer-events: auto;
    }

    .dg--adaptive .dg__td-actions-overlay > .dg__row-actions {
        position: static;
        inset: auto;
    }
}

/* The same adaptive layout, driven by the grid's OWN width instead of the viewport: the JS
   module toggles .dg--narrow on the root when its container is ≤640px, so a grid placed in
   a narrow sidebar (or split view) still becomes cards. Viewport chrome (bottom-sheet
   popovers, compact pager) deliberately stays viewport-driven above. */
.dg--adaptive.dg--narrow .dg__scroll {
    overflow: visible;
    border-radius: 0;
}

.dg--adaptive.dg--narrow .dg__thead {
    display: none;
}

.dg--adaptive.dg--narrow .dg__table,
.dg--adaptive.dg--narrow .dg__tbody,
.dg--adaptive.dg--narrow .dg__tr {
    display: block;
    width: 100%;
}

.dg--adaptive.dg--narrow .dg__tbody .dg__row {
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 0 12px 12px;
    padding: 13px 16px;
    background: var(--dg-surface);
    border: 1px solid var(--dg-border);
    border-radius: 12px;
    box-shadow: var(--dg-shadow-sm);
    overflow: hidden;
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.dg--adaptive.dg--narrow .dg__tbody .dg__row:hover {
    border-color: var(--dg-border-strong);
    box-shadow: var(--dg-shadow-md);
    transform: translateY(-1px);
}

.dg--adaptive.dg--narrow .dg__tbody .dg__row:hover .dg__td,
.dg--adaptive.dg--narrow .dg__tbody .dg__row--selected .dg__td {
    background: transparent;
}

.dg--adaptive.dg--narrow .dg__tbody .dg__row--selected {
    border-color: var(--dg-primary);
    background: var(--dg-selected);
}

.dg--adaptive.dg--narrow .dg__tbody .dg__row--selected::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 3px;
    background: var(--dg-primary);
}

.dg--adaptive.dg--narrow .dg__td {
    display: grid;
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
    gap: 12px;
    align-items: baseline;
    height: auto;
    min-height: 0;
    padding: 8px 0;
    border-block-end: none;
    background: transparent !important;
}

.dg--adaptive.dg--narrow .dg__td + .dg__td {
    border-block-start: 1px solid var(--dg-border);
}

.dg--adaptive.dg--narrow .dg__td::before {
    content: attr(data-label);
    font-size: var(--dg-font-size-sm);
    font-weight: 600;
    color: var(--dg-muted-text);
}

/* The first data cell doubles as the card title (label hidden, larger value). */
.dg--adaptive.dg--narrow .dg__row:has(.dg__td--select) .dg__td:nth-of-type(2),
.dg--adaptive.dg--narrow .dg__row:not(:has(.dg__td--select)) .dg__td:first-of-type {
    display: block;
    margin-block-end: 4px;
    font-size: 15px;
    font-weight: 700;
    color: var(--dg-text);
}

/* Only the title must clear the floating checkbox (it sits on the title's row, at the
   inline-start edge — the side the title text begins from in both directions). */
.dg--adaptive.dg--narrow .dg__row:has(.dg__td--select) .dg__td:nth-of-type(2) {
    padding-inline-start: 36px;
}

.dg--adaptive.dg--narrow .dg__row:has(.dg__td--select) .dg__td:nth-of-type(2)::before,
.dg--adaptive.dg--narrow .dg__row:not(:has(.dg__td--select)) .dg__td:first-of-type::before {
    content: none;
}

.dg--adaptive.dg--narrow .dg__td--select {
    position: absolute;
    inset-inline-start: 0;
    top: 14px;
    width: 22px;
    min-width: 22px;
    max-width: 22px;
    height: 22px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dg--adaptive.dg--narrow .dg__td--select::before {
    content: none;
}

/* Row actions in container-driven card mode: always visible, own row under the details. */
.dg--adaptive.dg--narrow .dg__row-actions {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.dg--adaptive.dg--narrow .dg__row-actions .dg__row-action {
    pointer-events: auto;
}

.dg--adaptive.dg--narrow .dg__td-actions-overlay {
    position: static;
    inset: auto;
    width: auto;
    min-width: auto;
    max-width: none;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: auto;
    padding: 10px 0 2px;
    margin: 0;
    pointer-events: auto;
}

.dg--adaptive.dg--narrow .dg__td-actions-overlay > .dg__row-actions {
    position: static;
    inset: auto;
}

/* ------------------------------------------------------------------ Grouping
   Group rows, the grouping bar, chips, group cards, grand totals. Indentation is applied
   through padding-inline-start (logical), so nested groups indent correctly under RTL. */

/* The toolbar Group button is the mobile entry point; the inline bar is desktop-only.
   Visibility is driven both by the viewport media query and the container-driven
   .dg--narrow class (see the JS module). */
.dg__group-btn {
    display: none;
}

/* Grouping bar (below the toolbar) */
.dg__groupbar {
    display: flex;
    align-items: stretch;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 12px;
    font-size: var(--dg-font-size-sm);
    border-block: 1px solid var(--dg-border);
    background: var(--dg-surface-alt);
    transition: box-shadow 120ms ease, background-color 120ms ease;
}

.dg__groupbar-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    align-self: center;
    flex-shrink: 0;
    font-weight: 600;
    color: var(--dg-muted-text);
    white-space: nowrap;
}

.dg__groupbar-title-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--dg-primary);
}

.dg__groupbar--drag-over {
    background: var(--dg-primary-soft);
    box-shadow: inset 0 0 0 2px var(--dg-primary);
}

.dg__group-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
}

/* Empty drop zone: a dashed well inviting the user to drag a column here. */
.dg__group-dropzone {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 38px;
    padding: 6px 12px;
    color: var(--dg-muted-text);
    border: 1.5px dashed var(--dg-border-strong);
    border-radius: var(--dg-radius-sm);
    transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.dg__group-dropzone-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--dg-disabled-text);
    transition: color 120ms ease;
}

.dg__group-dropzone span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg__group-dropzone--drag-over {
    color: var(--dg-primary);
    border-color: var(--dg-primary);
    border-style: solid;
    background: var(--dg-primary-soft);
}

.dg__group-dropzone--drag-over .dg__group-dropzone-icon {
    color: var(--dg-primary);
}

/* Active group chips */
.dg__group-chips {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1 1 auto;
    min-width: 0;
    padding: 3px 4px;
    border-radius: var(--dg-radius-sm);
    transition: background-color 120ms ease, box-shadow 120ms ease;
}

.dg__group-chips--drag-over {
    background: var(--dg-primary-soft);
    box-shadow: inset 0 0 0 1.5px var(--dg-primary);
}

/* Group chips (one per grouping level) */
.dg__group-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    height: 32px;
    padding-inline: 4px;
    padding-inline-start: 5px;
    font-size: 12px;
    color: var(--dg-text);
    background: var(--dg-control-bg);
    border: 1px solid var(--dg-border-strong);
    border-radius: 8px;
    box-shadow: var(--dg-shadow-sm);
    cursor: grab;
    user-select: none;
    transition: border-color 120ms ease, box-shadow 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.dg__group-chip:active {
    cursor: grabbing;
}

.dg__group-chip:hover {
    border-color: var(--dg-primary);
    box-shadow: 0 0 0 3px var(--dg-focus);
}

.dg__group-chip--dragging {
    opacity: 0.45;
    transform: scale(0.97);
}

.dg__group-chip--drop-target {
    border-color: var(--dg-primary);
    box-shadow: 0 0 0 2px var(--dg-focus);
    transform: scale(1.03);
}

.dg__group-chip-level {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding-inline: 5px;
    font-size: 10px;
    font-weight: 700;
    color: var(--dg-primary-contrast);
    background: linear-gradient(135deg, var(--dg-primary), var(--dg-primary-hover));
    border-radius: 6px;
}

.dg__group-chip-title {
    padding-inline: 4px;
    font-weight: 600;
    white-space: nowrap;
}

.dg__group-chip .dg__group-chip-dir,
.dg__group-chip .dg__group-chip-remove {
    width: 24px;
    height: 24px;
    border-radius: 6px;
}

.dg__group-chip .dg__group-chip-remove:hover {
    color: var(--dg-danger);
    background: var(--dg-danger-soft);
}

/* Right-hand actions: add-group selector + expand/collapse/clear */
.dg__group-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 0;
    margin-inline-start: auto;
}

.dg__groupbar-add-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.dg__groupbar-add-icon {
    position: absolute;
    inset-inline-start: 8px;
    width: 13px;
    height: 13px;
    color: var(--dg-muted-text);
    pointer-events: none;
}

.dg__groupbar-add {
    min-width: 132px;
    padding-inline-start: 26px;
    flex: 0 1 170px;
}

.dg__group-action {
    width: 28px;
    height: 28px;
}

.dg__group-actions-divider {
    width: 1px;
    height: 18px;
    margin-inline: 4px;
    background: var(--dg-border);
}

.dg__group-clear {
    color: var(--dg-muted-text);
}

/* Group header rows */
.dg__group-row {
    /* The band owns the fill so it always spans the entire table width edge-to-edge,
       regardless of cell coverage. A soft two-stop gradient lifts the section off the
       rows below without the boxiness of a flat strip. */
    background: linear-gradient(180deg, var(--dg-group-background) 0%, var(--dg-group-background-end) 100%);
    outline: none;
}

.dg__group-cell {
    height: var(--dg-group-header-height);
    padding-block: 0;
    /* Transparent: the row paints the full-width band; the cell only carries the
       hover/level accents below. The hairline on top separates the band from the
       rows above; data rows already carry their own bottom border. */
    background: transparent;
    border-block-start: 1px solid var(--dg-group-border);
    transition: background-color 100ms ease;
}

/* .dg__td adds a bottom hairline; the band owns only the top edge. The reset is
   !important so it always wins over the shared td rule in every browser. */
.dg__group-row .dg__group-cell {
    border-block-end: none !important;
}

.dg__group-row:not(.dg__group-row--footer):hover .dg__group-cell {
    background: var(--dg-group-hover);
}

.dg__group-row:not(.dg__group-row--footer):focus-visible .dg__group-cell {
    outline: 2px solid var(--dg-focus);
    outline-offset: -2px;
}

/* Nested groups: a soft accent bar at the reading-start grows with the level. */
.dg__group-row--level-1 .dg__group-cell {
    box-shadow: inset 3px 0 0 var(--dg-primary-soft-strong);
}

.dg__group-row--level-2 .dg__group-cell {
    box-shadow: inset 6px 0 0 var(--dg-primary-soft-strong);
}

.dg__group-row--level-3 .dg__group-cell {
    box-shadow: inset 9px 0 0 var(--dg-primary-soft-strong);
}

.dg__group-row--level-4 .dg__group-cell {
    box-shadow: inset 12px 0 0 var(--dg-primary-soft-strong);
}

.dg__group-row-content {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.dg__group-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    flex-shrink: 0;
    color: var(--dg-muted-text);
    background: transparent;
    border: 1px solid var(--dg-group-border);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.dg__group-toggle:hover {
    background: var(--dg-surface);
    border-color: var(--dg-group-chip-border);
    color: var(--dg-primary);
}

.dg__group-toggle svg {
    width: 15px;
    height: 15px;
    transition: transform 140ms ease;
}

/* Chevron: down when expanded, toward the reading-start when collapsed (mirrors RTL). */
.dg__group-toggle svg {
    transform: rotate(0deg);
}

.dg[dir="ltr"] .dg__group-toggle.is-collapsed svg {
    transform: rotate(-90deg);
}

.dg[dir="rtl"] .dg__group-toggle.is-collapsed svg {
    transform: rotate(90deg);
}

/* The group value sits in a pill: an uppercase column label and a bold, accent-colored
   value. This is the signature "modern group row" look — the label explains the value,
   and the pill separates it from the surrounding rows. */
.dg__group-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    padding-block: 3px;
    padding-inline: 10px 14px;
    background: var(--dg-surface);
    border: 1px solid var(--dg-group-chip-border);
    border-radius: 999px;
    box-shadow: var(--dg-shadow-sm);
}

.dg__group-column {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--dg-muted-text);
    white-space: nowrap;
}

.dg__group-value {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--dg-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg__group-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 22px;
    padding-inline: 9px;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    color: var(--dg-primary);
    background: var(--dg-primary-soft);
    border-radius: 999px;
    flex-shrink: 0;
}

.dg__group-agg {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    margin-inline-start: 4px;
    font-size: var(--dg-font-size-sm);
    white-space: nowrap;
}

.dg__group-agg-label {
    color: var(--dg-muted-text);
}

.dg__group-agg-value {
    font-weight: 600;
    color: var(--dg-text);
}

/* Group selection checkbox */
.dg__group-check {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    cursor: pointer;
}

/* Group footer rows */
.dg__group-cell--footer {
    height: auto;
    min-height: 34px;
    font-size: var(--dg-font-size-sm);
    background: var(--dg-surface-alt);
}

.dg__group-footer-content {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.dg__group-footer-label {
    font-weight: 600;
    color: var(--dg-muted-text);
}

/* Grand total row in the grid footer */
.dg__grandtotal-row .dg__td--grandtotal {
    font-weight: 600;
    background: var(--dg-surface-alt);
}

.dg__grandtotal-label {
    font-weight: 700;
    color: var(--dg-primary);
    margin-inline-end: 8px;
}

/* Group headers in the stacked (cards) layout */
.dg__group-card-header,
.dg__group-card-footer {
    border: 1px solid var(--dg-group-border);
    border-radius: 10px;
    background: linear-gradient(180deg, var(--dg-group-background) 0%, var(--dg-group-background-end) 100%);
    outline: none;
}

.dg__group-card-header {
    min-height: 48px;
    padding: 8px 12px;
    cursor: pointer;
}

.dg__group-card-header:hover {
    background: var(--dg-group-hover);
}

.dg__group-card-header:focus-visible {
    outline: 2px solid var(--dg-focus);
    outline-offset: 2px;
}

.dg__group-card-footer {
    padding: 6px 12px;
    font-size: var(--dg-font-size-sm);
}

/* Header context menu (⋮) */
.dg__more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    color: var(--dg-muted-text);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.dg__more-btn:hover {
    background: var(--dg-hover);
    color: var(--dg-text);
}

.dg__more-btn--active {
    color: var(--dg-primary);
    background: var(--dg-primary-soft);
}

.dg__more-btn--grouped svg {
    color: var(--dg-primary);
}

.dg__more-btn svg {
    width: 13px;
    height: 13px;
}

.dg__menu-separator {
    height: 1px;
    margin: 4px 0;
    background: var(--dg-border);
}

/* Group badge in the column chooser */
.dg__group-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 18px;
    padding-inline: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--dg-primary-contrast);
    background: var(--dg-primary);
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Group rows under the adaptive card layout (small screens): full-width header blocks */
.dg--adaptive .dg__group-row .dg__group-cell,
.dg--adaptive.dg--narrow .dg__group-row .dg__group-cell {
    display: flex;
    align-items: center;
    height: auto;
    min-height: var(--dg-group-header-height);
    padding: 4px 12px;
    background: var(--dg-group-background) !important;
    border-block: 1px solid var(--dg-group-border);
}

.dg--adaptive .dg__group-row .dg__group-cell::before,
.dg--adaptive.dg--narrow .dg__group-row .dg__group-cell::before {
    content: none;
}

/* Mobile: the toolbar button opens the grouping sheet; the inline bar is hidden. */
@media (max-width: 640px) {
    .dg__group-btn {
        display: inline-flex;
    }

    .dg__groupbar {
        display: none;
    }

    /* Inside the mobile grouping sheet the actions stack; the add selector goes full width. */
    .dg__group-actions {
        margin-inline-start: 0;
    }

    .dg__groupbar-add-wrap {
        flex: 1 1 100%;
    }

    .dg__groupbar-add {
        width: 100%;
        min-width: 0;
    }
}

.dg--narrow .dg__group-btn {
    display: inline-flex;
}

.dg--narrow .dg__groupbar {
    display: none;
}

/* ------------------------------------------------------------------ Reduced motion */

@media (prefers-reduced-motion: reduce) {
    .dg__skeleton-cell {
        animation: none;
    }

    .dg__btn,
    .dg__icon-btn,
    .dg__row,
    .dg__sort,
    .dg__filter-btn,
    .dg__resizer::after,
    .dg__checkbox,
    .dg__pager-btn,
    .dg__pager-num,
    .dg__group-toggle svg,
    .dg__group-row,
    .dg__group-cell,
    .dg__group-chip,
    .dg__group-dropzone,
    .dg__group-chips,
    .dg__groupbar {
        transition: none;
    }
}
