/*
 * Composed scrolling (decision 5): a non-scrolling frame hosts the overlay thumbs and becomes a subgrid when its
 * viewport inherits; the viewport's gutter tracks are its padding, so the thumb sits in the end gutter.
 */

@layer dx-components {
  .dx-scroll-root {
    position: relative;
    min-height: 0;
    min-width: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr);
    container-type: inline-size;
  }

  /* `thin` fits inside the rail Block's margin at every size; `regular` may overlap its icon. */
  .dx-scroll-root[data-width='thin'] {
    --dx-scroll-width: 4px;
  }
  .dx-scroll-root[data-width='regular'] {
    --dx-scroll-width: 8px;
  }

  .dx-scroll-root:has(> .dx-container[data-gutter='inherit']) {
    grid-column: full;
    grid-template-columns: subgrid;
    /* Containment makes a grid independent, which silently turns subgrid back into a standalone grid. */
    container-type: normal;
  }

  /*
   * Contained only on the axis that scrolls: a swipe along the other axis passes to the nearest ancestor that scrolls
   * it (a horizontal chart inside a vertical panel), where `contain` on both would swallow it.
   */
  .dx-scroll-viewport {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
  /*
   * A row track with a fixed minimum (`minmax(block, auto)`) grows only into the viewport's free space, so content
   * taller than the viewport overflowed it centred, half above the top; content-sized rows let the viewport scroll.
   */
  .dx-scroll-viewport.dx-container[data-layout='row'] {
    grid-auto-rows: auto;
  }
  /*
   * A nested scrolling list that joins its host's gutters (a subgrid viewport) is height-bound by its host, where
   * `auto` rows shrink toward their items' minimum to fit; its rows keep their content height and the list scrolls.
   * Host bodies (template roots) keep `auto` rows so a flexible child, like this list, can take the remaining height.
   */
  .dx-scroll-viewport.dx-container[data-gutter='inherit']:not([data-layout='row']) {
    grid-auto-rows: max-content;
  }
  .dx-scroll-viewport:not([data-native]) {
    scrollbar-width: none;
  }
  .dx-scroll-viewport:not([data-native])::-webkit-scrollbar {
    display: none;
  }
  .dx-scroll-root[data-mode='reserve'] > .dx-scroll-viewport,
  .dx-scroll-viewport[data-native] {
    --dx-scroll-reserve: var(--dx-scroll-width);
  }
  .dx-scroll-viewport[data-native] {
    scrollbar-gutter: stable;
  }
  .dx-scroll-viewport[data-native]::-webkit-scrollbar {
    width: var(--dx-scroll-width);
    height: var(--dx-scroll-width);
  }
  .dx-scroll-viewport[data-native]::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb, gray);
  }

  /* Axis: a horizontal pane scrolls sideways only, so a native bar takes nothing out of the end track. */
  .dx-scroll-root[data-orientation='horizontal'] > .dx-scroll-viewport {
    --dx-scroll-reserve: 0px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    /* `stable` would still reserve an inline-end gutter for the hidden vertical axis. */
    scrollbar-gutter: auto;
  }
  .dx-scroll-root[data-orientation='all'] > .dx-scroll-viewport {
    overflow: auto;
    overscroll-behavior: contain;
  }

  /* Mandatory snapping on the scrolling axis; the children carry their own `scroll-snap-align`. */
  .dx-scroll-root[data-snap][data-orientation='vertical'] > .dx-scroll-viewport {
    scroll-snap-type: y mandatory;
  }
  .dx-scroll-root[data-snap][data-orientation='horizontal'] > .dx-scroll-viewport {
    scroll-snap-type: x mandatory;
  }
  .dx-scroll-root[data-snap][data-orientation='all'] > .dx-scroll-viewport {
    scroll-snap-type: both mandatory;
  }

  /* No bar at all: the native one is hidden too, and reserves no width. */
  .dx-scroll-root[data-scrollbars='false'] > .dx-scroll-viewport {
    --dx-scroll-reserve: 0px;
    scrollbar-width: none;
  }
  .dx-scroll-root[data-scrollbars='false'] > .dx-scroll-viewport::-webkit-scrollbar {
    display: none;
  }
}
