/**
 * Universal compact list-table layer.
 *
 * Scope only:
 * - .sortable tables
 * - table.table-* variants
 * - tables inside .result-table-wrapper / .table-scroll-x
 *
 * Explicitly excluded:
 * - .params-table
 * - .form-table
 * - form-legacy tables
 */

body.app-layout
  :where(.result-table-wrapper table, .table-scroll-x table, table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy']) {
  --table-universal-header-padding-y: calc(var(--table-header-padding-y, 0.5rem) * 0.82);
  --table-universal-header-padding-x: var(--table-header-padding-x, 0.6rem);
  --table-universal-cell-padding-y: calc(var(--table-cell-padding-y, 0.4rem) * 0.82);
  --table-universal-cell-padding-x: var(--table-cell-padding-x, 0.6rem);
  --table-universal-cell-line-height: 1.2;
}

body.app-layout
  :where(.result-table-wrapper table, .table-scroll-x table, table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  :is(th, td) {
  vertical-align: middle;
}

body.app-layout
  :where(.result-table-wrapper table, .table-scroll-x table, table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  thead
  th {
  padding: var(--table-universal-header-padding-y) var(--table-universal-header-padding-x);
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
  line-height: 1.25;
}

body.app-layout
  :where(.result-table-wrapper table, .table-scroll-x table, table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  tbody
  td {
  padding: var(--table-universal-cell-padding-y) var(--table-universal-cell-padding-x);
  line-height: var(--table-universal-cell-line-height);
}

/* Result/list tables default to compact single-line cells. */
body.app-layout
  .result-table-wrapper
  table:not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  tbody
  td,
body.app-layout
  .table-scroll-x
  table:not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  tbody
  td {
  white-space: nowrap;
}

/* Opt-in wrapping and truncation helpers for list tables. */
body.app-layout
  :where(.result-table-wrapper table, .table-scroll-x table, table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  :is(td, th).cell-wrap {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body.app-layout
  :where(.result-table-wrapper table, .table-scroll-x table, table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  :is(td, th).cell-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sticky action column only when explicitly marked via .col-actions. */
body.app-layout
  :is(.result-table-wrapper, .table-scroll-x)
  :where(table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  :is(th.col-actions, td.col-actions) {
  position: sticky;
  right: 0;
  z-index: 1;
  background: var(--table-wrapper-bg, #ffffff);
  background-clip: padding-box;
}

body.app-layout
  :is(.result-table-wrapper, .table-scroll-x)
  :where(table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  thead
  th.col-actions {
  z-index: 11;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.25;
  padding: var(--table-universal-header-padding-y) 0.4rem;
}

body.app-layout
  :is(.result-table-wrapper, .table-scroll-x)
  :where(table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  tbody
  td.col-actions {
  overflow: hidden;
}

/* Ensure images in action columns don't overflow */
body.app-layout
  :is(.result-table-wrapper, .table-scroll-x)
  :where(table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  th.col-actions
  img {
  max-height: 1.125rem;
  max-width: 1.125rem;
  display: inline-block;
  vertical-align: middle;
}

body.app-layout
  :is(.result-table-wrapper, .table-scroll-x)
  :where(table.sortable, table[class*='table-'])
  :not(.params-table):not(.form-table):not([data-layout='form-legacy'])
  td.col-actions
  img {
  max-height: 1.125rem;
  max-width: 1.125rem;
  display: inline-block;
  vertical-align: middle;
}
