.dg {
  height: 100%; /* instead of 500px */
  width: 100%; /* fill container */
  /* border: 1px solid #ccc; */
  display: flex;
  flex-direction: column;
  /* border-radius: 5px; */

  /* ---- themeable tokens -------------------------------------------------
     Grid appearance defaults, each consumed below as var(--token, <same default>) — that fallback is
     only a safety net for a page loading this file's rules without these. These lines used to read
     `--token: var(--token, <default>)`, which is not an override hook but a cycle: a
     self-referencing var() is invalid at computed-value time, the token becomes the
     guaranteed-invalid value (treated as never set, and not inherited), so the declaration did
     nothing and even swallowed an override set on an ancestor. Plain values now.

     Override a token on `.dg` itself — a later `.dg` rule, a more specific selector, or the grid
     element's inline style. Tokens that must be themeable from anywhere are deliberately left
     undeclared here: --dg-pencil / --dg-pencil-font (set on documentElement by grid.js) and
     --dg-row-height (set inline by the grid from its rowHeight option, the single source of truth
     for the virtualization math; the .dg-row fallback covers the pre-JS / no-JS case). */
  --dg-row-hover: lightgray;
  --dg-row-selected: #dbeafe;
  --dg-row-selected-hover: #c6dfff;
  --dg-row-border: #eee;
  --dg-header-border: black;
  --dg-sticky-bg: #fff;
  --dg-bad-dot: #dc3545;
  --dg-tip-bg: #fff;
  --dg-tip-border: #dc3545;
  --dg-tip-text: #842029;
  /* distinct from the context menu's 2000 so the two overlays never fight over paint order */
  --dg-tip-z: 2100;
  /* focus ring + spinner chrome — tokens so a dark theme can actually see them (the spinner used to
     be hardcoded #ccc/#333, near-invisible on dark backgrounds, the file's only non-token colors) */
  --dg-focus: #2563eb;
  --dg-spinner-track: #ccc;
  --dg-spinner-head: #333;
}

/* The grid fills whatever container it is mounted in. `.content` is THIS app's wrapper class;
   `.dg-content` is the namespaced alias, so a different host can opt into a collision-free wrapper
   class without editing the grid. Either way the grid's own root (.dg) already does width and
   height 100% — this rule only gives the WRAPPER a definite size for that 100% to resolve against.
   The grid's own classes (the "dg-" and "dc-" prefixes) are already a namespace; appearance is
   overridable via the --dg-* tokens above, and text and icons via the strings and icons options. */
.content,
.dg-content {
  width: 100%;
  height: 100%;
  /* overflow:scroll; */
}

.dg-header,
.dg-row {
  display: grid;
}

.dg-header {
  /* background: #eee; */
  /* No position:sticky on purpose: the header is NOT inside the scroller (.dg-body is), so it is
     never left by scrolling — stickiness comes from the structure plus the JS scrollLeft sync.
     A sticky declaration here was a no-op that bought only a stacking context and misled the
     reader; z-index alone (no position) is inert too. Paint order above scrolled rows is owned
     by .dg-row (z-index:1) and the frozen cells (z-index:2 inline) staying below this block's
     normal-flow paint... which holds because rows sit BELOW the header box, not above it. */
  padding: 4px 0;
  border-bottom: 1px solid var(--dg-header-border, black);
}

.dg-header div {
  /* cursor:pointer belongs to the SORTABLE headers only — the JS sets data-dg-sortable on exactly
     those; the __select__ header has no listener and must not fake one (false affordance) */
  cursor: default;
  padding: 4px;
  /* overflow was hidden here, which clipped the UA focus ring off every keyboard-sortable header
     (D4). The ring lives on the div itself (an outline is not clipped by the element's own
     overflow), while the LABEL text is what needed clipping — moved to the label span below. */
  overflow: visible;
}

.dg-header div[data-dg-sortable] {
  cursor: pointer;
}

/* the header title is the text that must not spill into the neighbour column */
.dg-header .dg-col-header > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dg-header div:focus-visible,
.dg-row:focus-visible {
  /* visible keyboard focus for headers (sortable) and rows (arrow-key surface); negative offset
     keeps the ring inside the scroller's clip instead of half-outside the box */
  outline: 2px solid var(--dg-focus, #2563eb);
  outline-offset: -2px;
}

.dg-body {
  overflow: auto;
  flex: 1;
  position: relative;
  /* virtualized-scroller wins (B14): overscroll-behavior stops a flick at the end of the sheet
     from chaining into a page bounce/scroll; scrollbar-gutter keeps the content box a constant
     width whether or not the scrollbar is up, so _applyTemplate's sheet width and the sticky
     offsets cannot jump when the vertical scrollbar appears or disappears. */
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.dg-row {
  height: var(--dg-row-height, 32px);
  position: absolute;
  width: 100%;
  border-bottom: 1px solid var(--dg-row-border, #eee);
  /* rows sit above the spacer and ordinary flow of the scroller, below the sticky header content
     (z 3 inline) — the explicit base keeps frozen cells' 2 above ordinary cells everywhere */
  z-index: 1;
  /* containment tells the browser this row's contents cannot affect layout/paint outside it —
     free work saved on every frame that shows/hides/repaints a row in the virtual window (B14).
     paint additionally clips descendants to the row box (the pencil and cells live inside). */
  contain: layout paint;
}

.dc-cell {
  /* ONE declaration: mixing `padding: 4px` with `padding-left: .35rem` across two rules made the
     horizontal padding depend on declaration order and turned autoFit's `padding` constant into
     guesswork (E5). 0.35rem stays the left inset the design uses — now explicit as px at the
     default root size while remaining rem-scaled. */
  padding: 4px 4px 4px 0.35rem;
  position: relative;
  overflow: hidden;
  /* Never wrap. A wrapped value in the fixed-height .dg-row (32px) has its second line cut off by
     overflow:hidden, so a number such as "14 028.66" renders as just "1" — the bug reported on the
     JPK K_13/K_14 columns. autoFit sizes the track from the text width, but ceil() plus the editable
     cell's 15px inner padding (the edit pencil) can leave the glyph area ~0.4px short, which is
     enough for the browser to wrap at the grouping space. Keeping every value on one line makes the
     whole amount visible regardless of that sub-pixel slack. */
  white-space: nowrap;
}

/* B13 moved the pencil's base box onto `.editable` only: `opacity:0` still LAYS OUT and PAINTS a
   box, so as a bare `.dc-cell::before` every cell of every column (sortable headers' cells,
   read-only columns — usually the majority) generated an extra box per frame. Non-editable cells
   never show a pencil, so they never build one. */
.dc-cell.editable::before {
  /* The edit pencil (::before is the pencil; ::after is the bad-value dot). Default is a
     dependency-free emoji so the component ships with no icon-font requirement; a host using an
     icon font overrides the two custom properties (grid.js sets them to the Bootstrap Icons pencil). */
  content: var(--dg-pencil, "✏️");
  font-family: var(--dg-pencil-font, sans-serif);
  position: absolute;
  left: 0;
  top: 2px;
  opacity: 0;
  /* E7: below the frozen cells' inline z-index 2, so a pencil scrolling UNDER a frozen column
     hides behind it instead of floating on top of the frozen background (it used to be 10 —
     above everything, header included once stacking allowed). Inside a frozen cell itself the
     cell's own z-index 2 context paints it normally. */
  z-index: 1;
}

/* E5: the pencil indent belongs to the cell's OWN display box (direct child) — `div` matched
   customRenderFunction wrappers too, double-indenting their content 15px per nesting level, which
   is part of why hosts need hand-tuned `fitExtra` to stop clipping. */
.dc-cell.editable > div {
  padding-left: 15px;
}

/* Opt-in per column (`truncate: true`, see the DataCell constructor). The cell clips at its own
   box, but the text lives in the inner display div, so `text-overflow` has to be set THERE — an
   ellipsis is painted by the block whose own inline content overflows, and that block must clip
   itself. The display div's right edge is exactly the cell's clip line (cell width minus its
   padding), so the cut does not move; it just becomes visible. */
.dc-cell.dc-truncate > div {
  overflow: hidden;
  text-overflow: ellipsis;
}

.dc-cell.editable:hover::before,
/* D5: hover was the pencil's ONLY reveal — invisible to a keyboard user tabbing/sorting through
   the grid. Reveal it when the cell's editor takes focus, and when the ROW has keyboard focus
   (rows are the keyboard surface — focus sits on the row, so cell-side :focus-within cannot
   match it from below). */
.dg-row:focus-visible .dc-cell.editable::before,
.dc-cell.editable:focus-within::before {
  opacity: 0.5;
}

/* A `number` cell whose value is not a number: the text stays visible (hiding a value the server
   sent would hide data) and a dot in the corner marks it. Clicking the cell shows .dc-bad-value-tip
   (see showBadValueTip in datagrid.js). ::before is the edit pencil, so the dot is ::after. */
.dc-cell.dc-bad-value {
  /* keep the dot off the digits (numbers are right-aligned). E5: this shrinks the text area while
     autoFit's budget is plain text + `padding`, so a flagged cell used to clip earlier than a
     clean one — autoFit now adds the difference for bad-value cells (see the cell loop there),
     which is what makes the two clip at the same width. */
  padding-right: 12px;
}

.dc-cell.dc-bad-value::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dg-bad-dot, #dc3545);
}

/* one shared element, positioned inline (fixed) by showBadValueTip so it escapes the
   overflow:auto of .dg-body; hidden by scrolling, Escape or a click outside */
.dc-bad-value-tip {
  position: fixed;
  z-index: var(--dg-tip-z, 2100);
  max-width: 22rem;
  padding: 6px 8px;
  background: var(--dg-tip-bg, #fff);
  border: 1px solid var(--dg-tip-border, #dc3545);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  font-size: 12px;
  line-height: 1.35;
  color: var(--dg-tip-text, #842029);
  cursor: default;
  /* E6: one long unbroken server value (an IBAN, a base64 blob) used to overflow the 22rem box —
     break anywhere rather than paint past the border */
  overflow-wrap: break-word;
}

/* Inputs of in-cell editors fill the cell box. The built-in date editor lives on document.body
   (fixed-positioned, inline-sized by JS) and is reached through .dc-editor-input, not through
   the descendant selector — both are listed so the sizing intent is stated once (E4). */
.dc-editor input,
.dc-editor-input {
  width: 100%;
  box-sizing: border-box;
}
/* E3: was `.col-header` — an unnamespaced name leaking into every host page, and mostly
   redundant: JS sets display/justify-content inline per column type. The class is now
   `.dg-col-header` (the grid's own dg- prefix) and this rule keeps only what JS does NOT
   set: bold + vertical centering. */
.dg-col-header {
  font-weight: bold;
  align-items: center;
}


.dg-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--dg-spinner-track, #ccc);
  border-top: 2px solid var(--dg-spinner-head, #333);
  border-radius: 50%;
  animation: dg-spin 1s linear infinite;
  margin-left: 1rem;
}

@keyframes dg-spin {
  to {
    transform: rotate(360deg);
  }
}

/* D7: honor reduced-motion — a spinning head next to the sorted column would otherwise run
   regardless of the user's system setting; freeze it and just mark it active. */
@media (prefers-reduced-motion: reduce) {
  .dg-spinner {
    animation-duration: 2.5s;
  }
}

.dg-row:hover {
  background-color: var(--dg-row-hover, lightgray);
}

.dg-row.selected {
  background: var(--dg-row-selected, #dbeafe);
}

.dg-row.selected:hover {
  background: var(--dg-row-selected-hover, #c6dfff);
}

.dg-sticky-cell {
  /* solid background so columns scrolling underneath stay covered (was: inherit) */
  background: var(--dg-sticky-bg, #fff);
}

.dg-row:hover .dg-sticky-cell {
  background-color: var(--dg-row-hover, lightgray);
}

.dg-row.selected .dg-sticky-cell {
  background: var(--dg-row-selected, #dbeafe);
}
.dg-row.selected:hover .dg-sticky-cell {
  background: var(--dg-row-selected-hover, #c6dfff);
}