/* ==========================================================================
   Table — flat data tables for admin apps. Lines between rows only.

   <div class="table-wrap">
     <table class="table table-hover">
       <thead><tr><th><button class="table-sort">Name</button></th><th class="text-end">Amount</th></tr></thead>
       <tbody><tr><td>…</td><td class="text-end">$129.00</td></tr></tbody>
     </table>
   </div>

   .table-sm · .table-lg · .table-hover · .table-striped · .table-sticky (in a .table-wrap)
   Rows highlight automatically when a checkbox in them is checked.
   moey.js sorts a column when its .table-sort header button is clicked.
   ========================================================================== */

.table {
  --mo-table-cell-y: .75rem;
  --mo-table-cell-x: 1rem;
  --mo-table-edge: var(--mo-table-cell-x);       /* padding of the first & last column */
  --mo-table-font-size: .875rem;
  --mo-table-head-bg: transparent;
  --mo-table-row-hover: color-mix(in oklab, var(--mo-fg-body) 4%, transparent);
  --mo-table-row-stripe: color-mix(in oklab, var(--mo-fg-body) 2.5%, transparent);
  --mo-table-row-selected: color-mix(in oklab, var(--mo-theme-base) 9%, transparent);
  width: 100%;
  font-size: var(--mo-table-font-size);
  font-variant-numeric: tabular-nums;
  color: var(--mo-fg-body);
  vertical-align: middle;
  border-collapse: separate;
  border-spacing: 0;
}

.table :is(th, td) {
  padding: var(--mo-table-cell-y) var(--mo-table-cell-x);
  text-align: start;
  vertical-align: inherit;
}
.table :is(th, td):first-child { padding-inline-start: var(--mo-table-edge); }
.table :is(th, td):last-child { padding-inline-end: var(--mo-table-edge); }

/* Header: small, quiet, uppercase labels */
.table > thead :is(th, td) {
  padding-block: .625rem;
  font-size: .75rem;
  font-weight: var(--mo-font-weight-semibold);
  color: var(--mo-fg-3);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  vertical-align: bottom;
  background: var(--mo-table-head-bg);
  border-bottom: var(--mo-border-width) solid var(--mo-border-color);
}

/* Lines between body rows only */
.table > tbody > tr + tr > :is(th, td) { border-top: var(--mo-border-width) solid var(--mo-border-color); }
.table > tbody > tr > th { font-weight: var(--mo-font-weight-medium); }
.table > tfoot :is(th, td) {
  font-weight: var(--mo-font-weight-semibold);
  border-top: var(--mo-border-width) solid var(--mo-border-color);
}
.table > caption { padding: .625rem var(--mo-table-edge); font-size: .8125rem; color: var(--mo-fg-3); text-align: start; caption-side: bottom; }

/* Inside a card, the outer columns line up with the card's padding */
.card .table { --mo-table-edge: var(--mo-card-padding); }

/* Hover & stripes (see-through tints: they work on any background) */
.table-hover > tbody > tr:hover > * { background-color: var(--mo-table-row-hover); }
.table-striped > tbody > tr:nth-child(odd) > * { background-color: var(--mo-table-row-stripe); }

/* Selected rows: automatic when a checkbox in the row is checked, or add .is-selected */
.table > tbody > tr:is(.is-selected, [aria-selected="true"], :has(> td > input[type="checkbox"]:checked, > td > .form-check > input:checked)) > * {
  background-color: var(--mo-table-row-selected);
}
/* A checkbox column */
.table .table-check { width: 1%; padding-inline-end: 0; }
.table .table-check > input,
.table .table-check > .form-check { margin: 0; vertical-align: middle; }

/* Density */
.table-sm { --mo-table-cell-y: .4375rem; --mo-table-cell-x: .75rem; --mo-table-font-size: .8125rem; }
.table-lg { --mo-table-cell-y: 1rem; --mo-table-cell-x: 1.25rem; }

/* Row actions — appear on row hover / keyboard focus (always visible on touch) */
.table .table-actions { width: 1%; white-space: nowrap; text-align: end; }
.table .table-actions > * { vertical-align: middle; }
@media (hover: hover) {
  .table > tbody > tr .table-actions > * { opacity: 0; transition: opacity var(--mo-duration); }
  .table > tbody > tr:is(:hover, :focus-within) .table-actions > * { opacity: 1; }
  .table .table-actions > [aria-expanded="true"] { opacity: 1; }   /* its menu is open */
}

/* Sortable header: <th aria-sort="ascending"><button class="table-sort">Name</button></th> */
.table-sort {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: var(--mo-radius-1);
}
.table-sort:hover { color: var(--mo-fg-body); }
.table-sort::after {
  width: .75rem;
  height: .75rem;
  content: "";
  background-color: currentcolor;
  mask: var(--mo-icon-chevron) center / contain no-repeat;
  opacity: 0;
  transition: opacity var(--mo-duration), rotate var(--mo-duration);
}
.table-sort:hover::after { opacity: .4; }
th[aria-sort] .table-sort { color: var(--mo-fg-body); }
th[aria-sort] .table-sort::after { opacity: 1; }
th[aria-sort="ascending"] .table-sort::after { rotate: 180deg; }
.text-end > .table-sort { flex-direction: row-reverse; }

/* Scroll container — horizontal on small screens; add .table-sticky for a fixed header */
.table-wrap {
  position: relative;            /* keeps anything positioned inside it (inside the scrolling) */
  max-width: 100%;
  overflow: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table-sticky > thead :is(th, td) {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--mo-table-head-bg, var(--mo-bg-surface));
}
.table-sticky { --mo-table-head-bg: var(--mo-bg-surface); }

/* Long text: truncate a cell with .text-truncate (utility), keep numbers on one line */
.table td.text-end, .table th.text-end { white-space: nowrap; }
