/* Virtual-scrolling grids (docs/superpowers/specs/2026-10-12-grid-virtual-scrolling-design.md).
   A DxGrid with VirtualScrollingEnabled must have a BOUNDED height, otherwise it renders every row.
   Every element between the tab clip box and a .kx-grid-fill grid becomes a flex column that takes
   the remaining height, so the grid always reaches the bottom of the page - whatever the page markup.
   Siblings in that chain (headers, toolbars) keep their natural height: flex items default to
   min-height:auto and never shrink below their content.

   :where() gives these rules ZERO specificity, so anything a page's own CSS sets (a flex ratio, a fixed
   height, overflow, a grid template) still wins. A page container that lays its children out side by
   side (flex row, CSS grid) gets class kx-keep-layout: it keeps its own display/direction and only
   takes its share of the height. A Bootstrap .row is always side by side, so it is treated the same. */
:where(.tab-content :has(.kx-grid-fill):not(.kx-keep-layout, .row)) {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

:where(.tab-content :is(.kx-keep-layout, .row):has(.kx-grid-fill)) {
    flex: 1 1 auto;
    min-height: 0;
}

/* DevExpress sets display:block on its own <dxbl-tabs> element, which a zero-specificity rule cannot
   beat; the tab page below it then sizes to its content and the grid stops at min-height. Only for tabs
   that hold a fill grid, so other DxTabs are untouched. */
.tab-content dxbl-tabs:has(.kx-grid-fill) {
    display: flex;
    flex-direction: column;
}

:where(.dxbl-grid.kx-grid-fill) {
    flex: 1 1 auto;
    min-height: 240px;
}

/* Page-scroll sticky header (opt-in .kx-page-sticky-head, kx-grid.js sets the variables). The header is
   moved, not re-created, so column resize, sort and the column chooser keep working on it. */
.kx-page-sticky-head .dxbl-grid-table > thead {
    position: relative;
    z-index: 3;
    transform: translateY(var(--kx-head-shift, 0px));
}

/* Keyboard navigation focuses a cell and the browser scrolls that cell into view, so the margin sits on
   the cell (a margin on the row is ignored). */
.kx-page-sticky-head .dxbl-grid-table > tbody > tr > td {
    scroll-margin-top: var(--kx-sticky-offset, 0px);
}

/* Inline "Click here to add a new row" (EditNewRowPosition LastRow/FixedOnTop). DevExpress sizes it to one
   line of small text (~24px), noticeably shorter than the data rows above it and an easy target to miss,
   especially at the bottom where the horizontal scrollbar crowds it. A td height acts as a min-height in a
   table, so the row grows to a full data-row height and still grows further if its editors need more. */
.dxbl-grid tr.dxbl-grid-edit-new-item-row > td {
    height: 2.5rem;
    vertical-align: middle;
}

/* Breathing room under that row, so it does not sit flush on the grid's bottom edge / horizontal scrollbar.
   Padding on the grid's own scroller (.dxbl-scroll-viewer-content) adds to its scroll height, so the space is
   there after scrolling to the end too. Matches the "-inplace" class DevExpress swaps in while the new row is
   being edited, so the gap does not jump away on the first click. */
.dxbl-grid .dxbl-scroll-viewer-content:has(> .dxbl-grid-table > tbody > tr:is(.dxbl-grid-edit-new-item-row, .dxbl-grid-edit-new-item-row-inplace)) {
    padding-bottom: 1.25rem;
}

/* Popups render outside .tab-content and have no fixed height: size to the rows, then scroll. */
:where(.dxbl-popup .dxbl-grid.kx-grid-fill, .dxbl-modal .dxbl-grid.kx-grid-fill) {
    flex: 0 1 auto;
    min-height: 160px;
}

/* The 60vh cap goes through DevExpress's own variable: the theme sets
   .dxbl-grid { max-height: var(--dxbl-grid-max-height) } with the variable = 10000px ON the grid, so a
   0-specificity :where() max-height lost and popup lists grew to every row (buttons pushed off-screen,
   2026-11-06). A popup that sizes its grid itself (max-height / height on the grid) still wins. */
.dxbl-popup .dxbl-grid.kx-grid-fill,
.dxbl-modal .dxbl-grid.kx-grid-fill {
    --dxbl-grid-max-height: 60vh;
}

/* A popup with little around its list, where 60vh still pushes the buttons out (a MaxHeight popup, or one with a
   few rows above the list): put kx-popup-fit on the DxPopup CssClass and kx-popup-fit-area on every wrapper
   between the popup body and the grid. The list then takes only the room that is left and scrolls inside
   itself; the buttons under it stay in view. Same chain as the Split / VoucherPicker dialogs. */
.kx-popup-fit .dxbl-modal-content {
    max-height: 100%;
    min-height: 0;
}

.kx-popup-fit .dxbl-modal-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.kx-popup-fit .kx-popup-fit-area {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.kx-popup-fit .dxbl-grid.kx-grid-fill {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

/* A popup with a long form AND a list (Setup create/edit dialogs) can be taller than the window whatever the
   list does: its OK / Cancel row sticks to the bottom of the scrolling popup body and the form scrolls under
   it. Put kx-popup-actions on the element holding the buttons whose parent runs the full height of the body
   (for buttons inside a DxFormLayout: the DxFormLayoutGroup / Item that holds them). No effect when the
   content fits. */
.dxbl-modal-body .kx-popup-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background-color: var(--dxbl-popup-bg);
}

/* Grid row action buttons are text OUTLINE buttons (ui-standards.md "Action Column Pattern", 2026-10-16).
   Their transparent fill vanishes on the focused (theme-coloured) row; a solid page-coloured fill keeps
   them readable on any row tint. Hover/active keep the DevExpress fill. Scoped to grid data cells only. */
.dxbl-grid td .dxbl-btn[class*="dxbl-btn-outline-"]:not(:hover):not(:active) {
    background-color: var(--dxbl-body-bg);
}

/* Column chooser "Deselect all" / "Select all" row added by kx-grid.js (Alfa Test #91). */
.kx-chooser-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: .5rem .75rem;
    border-top: 1px solid var(--dxbl-border-color);
}

.kx-chooser-actions .dxbl-btn {
    gap: .375rem;
}

/* Worksheet (journal) pick lists: a journal locked by ANOTHER user (frmPickJournal.frm:1428-1433 vbGrayText,
   plus italic — Alfa Test #31). Set by each list's CustomizeElement via JournalListAutoRefresh.LockedRowCssClass;
   the class exists only on those rows. Row buttons keep their own colour and upright text. */
.dxbl-grid tr.kx-journal-locked-row > td {
    color: var(--dxbl-text-secondary-color);
    font-style: italic;
}

.dxbl-grid tr.kx-journal-locked-row .dxbl-btn {
    font-style: normal;
}

/* Alfa Test #127 round 2 — kladde account lists (Finans / Lager / Projekt, "code - name" lists): Overskrift and
   Sumkonto rows are listed bold with their type, as in Kompas4's Kontoplan, but cannot be picked (HeaderSumAccountGuard).
   The type is generated content so the row's innerText stays the list text (custom.js kompasxAccountLock). Only rows
   rendered by HeaderSumAccountItem carry this class. */
.kx-account-headsum {
    font-weight: 600;
}

.kx-account-headsum::after {
    content: "  (" attr(data-kx-acctype) ")";
    font-weight: normal;
    opacity: 0.7;
}

/* Alfa #236 — "colour every other row" (My profile → Settings → Lists), Kompas4 "Linjefarve for linje 1 / linje 2"
   (UserColor LineColorEven/Odd, CGridUtil.cls:203-206). GridRowStripes.ApplyAsync puts .kx-row-stripes on <html>.
   - The tint is the theme's own grid TEXT colour mixed lightly into its own grid BACKGROUND, so it suits every theme
     (light: soft grey, dark: a slightly lighter dark) and the text keeps its contrast — no colour of our own (Rule 4).
     Declared on .dxbl-grid, where every theme sets --dxbl-grid-bg / --dxbl-grid-color.
   - Rows are picked by their absolute data-visible-index (odd = second, fourth … row), not :nth-child, so the
     stripes stay put while a virtual-scrolling grid swaps rows in and out. Row 1 keeps the normal background.
   - The striped row sets --dxbl-grid-bg itself, so pinned (fixed) cells, which paint var(--dxbl-grid-bg), follow.
   - :where() = zero specificity: focused / selected / hovered rows and every row tint of a page still win.
     Focused and selected rows are excluded outright (lesson 2026-11-24: a tint must never cover the focused row).
   - 5% on purpose: lighter than the 8-10% greys that MEAN something on order lines (unselected / locked line,
     OrderLedgerLineGrid / PurchaseLineGrid, !important so they still win), so a stripe is never read as one. */
html.kx-row-stripes .dxbl-grid {
    --kx-row-stripe-bg: color-mix(in srgb, var(--dxbl-grid-color) 5%, var(--dxbl-grid-bg));
}

:where(html.kx-row-stripes .dxbl-grid .dxbl-grid-table > tbody > tr:is([data-visible-index$="1"], [data-visible-index$="3"], [data-visible-index$="5"], [data-visible-index$="7"], [data-visible-index$="9"]):not(.dxbl-grid-focused-row, .dxbl-grid-selected-row, .dxbl-grid-group-row, .dxbl-grid-group-footer-row, .dxbl-grid-edit-row, .dxbl-grid-empty-row, .dxbl-grid-edit-new-item-row, :has(> td.dxbl-grid-detail-cell))) {
    --dxbl-grid-bg: var(--kx-row-stripe-bg);
    background-color: var(--kx-row-stripe-bg);
}
