[data-table-scroll] {
  --table-scroll-limit: min(66vh, 42rem);
  min-width: 0;
  max-width: 100%;
  max-height: var(--table-scroll-limit);
  overflow: auto;
  overscroll-behavior-x: contain;
}

@supports (height: 1dvh) {
  [data-table-scroll] { --table-scroll-limit: min(66dvh, 42rem); }
}

.fbo-map-items[data-table-scroll] { max-height: min(210px, var(--table-scroll-limit)); }
.geo-stock .table-wrap[data-table-scroll] { max-height: min(460px, var(--table-scroll-limit)); }
.aida-result[data-table-scroll] { max-height: min(500px, var(--table-scroll-limit)); }

[data-table-scroll]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* A row group keeps all header rows together and leaves left-pinned cells intact. */
[data-table-scroll] > table > thead,
[data-table-scroll] > :is(.sales-posting-header, .fbo-history-columns) {
  position: sticky;
  top: 0;
  z-index: 5;
}

[data-table-scroll] > table > thead { background: var(--surface, #fff); }

[data-table-scroll] > table > :is(thead, tbody, tfoot) > tr > th {
  top: auto;
}

.fbo-history-scroll > .fbo-history-columns { background: var(--surface, #fff); }
.abc58-table-scroll + .abc58-pagination { border-top: 1px solid var(--line); }

/* Keep words whole before the measured widths have been applied. */
[data-table-scroll] > table[data-table-adaptive] {
  width: 100%;
  min-width: 0;
  max-width: none;
  table-layout: auto;
}
[data-table-scroll] > table[data-table-columns] {
  width: var(--table-content-width);
  table-layout: fixed;
  border-spacing: 0;
}
[data-table-scroll] > table[data-table-adaptive] > :is(thead, tbody, tfoot) > tr > :is(th, td) {
  width: auto;
  min-width: 0;
  max-width: none;
  padding-inline: 10px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: none;
}
[data-table-scroll] > table[data-table-adaptive] > thead > tr > :is(th, td) {
  padding-inline-end: 18px;
  font-size: max(11px, .705rem);
}
[data-table-scroll] > table[data-table-adaptive] > thead > tr > :is(th, td),
[data-table-scroll] > table[data-table-adaptive] > thead .table-sort-button,
[data-table-scroll] > table[data-table-adaptive] > thead .table-sort-button > span {
  white-space: normal;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
}
[data-table-scroll] > table[data-table-adaptive] > thead .table-sort-button {
  max-width: 100%;
  padding-inline: 0;
}
[data-table-scroll] > table[data-table-adaptive] > thead .table-sort-icon { flex: 0 0 auto; }
[data-table-scroll] > table[data-table-adaptive] > thead td { position: relative; }

[data-table-scroll] > table[data-table-adaptive] > :is(tbody, tfoot) > tr > [data-table-value] {
  white-space: nowrap;
  overflow-wrap: normal;
  font-variant-numeric: tabular-nums;
}
[data-table-scroll] > table[data-table-adaptive] :is(.sku-cell, .p129-product, .fbo-product, .abc58-product) {
  min-width: 0;
  max-width: none;
  overflow-wrap: anywhere;
  hyphens: none;
}
[data-table-scroll] > table[data-table-adaptive] :is(.sku-cell, .p129-product, .fbo-product, .abc58-product) > :last-child {
  min-width: 0;
}
[data-table-scroll] > table[data-table-adaptive] :is(.product-dot, .p129-thumb, .fbo-thumb, .abc58-thumb) {
  flex-shrink: 0;
}
[data-table-scroll] > table[data-table-adaptive] :is(input, select, button, .badge) {
  max-inline-size: 100%;
}
[data-table-scroll] > table[data-table-adaptive] :is(input, select) { min-width: 0; }
[data-table-scroll] > table[data-table-adaptive] :is(.abc58-product-name, .p129-product-name, .fbo-product-name) {
  overflow-wrap: anywhere;
  hyphens: none;
}

[data-table-scroll] > table[data-table-columns].abc-table .sticky-1 { left: var(--table-pin-1, 0px); }
[data-table-scroll] > table[data-table-columns].abc-table .sticky-2 { left: var(--table-pin-2, 0px); }
[data-table-scroll] > table[data-table-columns].abc-table .sticky-3 { left: var(--table-pin-3, 0px); }
[data-table-scroll] > table[data-table-columns].abc-table .sticky-4 { left: var(--table-pin-4, 0px); }
[data-table-scroll] > table[data-table-unpin] > :is(thead, tbody) > tr > :is(th, td) { left: auto; }
[data-table-scroll] > table[data-table-unpin].abc-table .sticky-col { left: auto; }

[data-column-grip] {
  position: absolute;
  z-index: 3;
  inset-block: 0;
  inset-inline-end: 0;
  inline-size: 16px;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  outline: none;
}
[data-column-grip]::after {
  content: "";
  position: absolute;
  inset-inline-end: 2px;
  inset-block: max(5px, 14%);
  width: 2px;
  border-radius: 1px;
  background: var(--primary, #007a83);
  opacity: .18;
}
[data-column-grip]:is(:hover, :focus-visible, [data-column-dragging])::after {
  width: 3px;
  opacity: 1;
}
html:has([data-column-dragging]) { cursor: col-resize; user-select: none; }

.table-grid-toggle { margin: 8px 12px; }
.table-grid-toggle[hidden] { display: none; }
.sales-posting-scroll[data-grid-columns] :is(.sales-posting-header, .sales-posting-row),
.fbo-history-scroll[data-grid-columns] :is(.fbo-history-columns, .fbo-history-row) {
  grid-template-columns: var(--table-tracks);
  width: var(--table-content-width);
  max-width: none;
}
[data-grid-columns] > :is(.sales-posting-header, .fbo-history-columns) > span {
  position: relative;
  align-self: stretch;
  align-content: center;
  min-width: 0;
  padding-inline-end: 18px;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}
.fbo-history-scroll[data-grid-columns] > .fbo-history-columns > span { padding-inline-start: 4px; }
.fbo-history-scroll[data-grid-columns] .fbo-history-row > span { padding-inline: 4px; }
.sales-posting-scroll[data-grid-columns] .sales-posting-row > span { hyphens: none; }
.sales-posting-scroll[data-grid-columns] :is(.sales-product, .sales-product-name) { max-inline-size: none; }
.sales-posting-scroll[data-grid-columns] .sales-product-name { hyphens: none; }

@media (max-width: 700px) {
  .abc58-table-scroll { container-type: inline-size; }
  .abc58-detail > td > * {
    position: sticky;
    left: 14px;
    max-width: calc(100cqw - 28px);
  }
}

@media print {
  [data-table-scroll] {
    max-height: none !important;
    overflow: visible;
  }
  [data-table-scroll] > table[data-table-columns] {
    width: 100%;
    table-layout: auto;
  }
  [data-table-scroll] > table[data-table-columns] > colgroup > col { width: auto !important; }
  [data-table-scroll] > table > thead { position: static; }
  [data-column-grip], .table-grid-toggle { display: none; }
}
