/* -- Page-background tables
   Opt in native tables and editorial row grids. Closing CTA tables, framed
   app previews and dashboard illustrations keep their own component surfaces. */
:is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table) {
  --tacet-table-head: color-mix(in oklch, var(--beige-700), transparent 84%);
  --tacet-table-rule: var(--border-strong);
  --tacet-table-row-rule: var(--border);
  --tacet-table-ink: var(--foreground);
  border-block: 1px solid var(--tacet-table-rule);
  border-inline: 0;
  border-radius: 0;
  background: transparent;
}

html.dark
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table) {
  --tacet-table-head: color-mix(in oklch, var(--beige-800), transparent 20%);
}

/* Native table borders collapse to one rule; row grids retain their layout. */
table:is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table) {
  border-collapse: collapse;
}

main .tacet-page-table-scroll,
main .sl-table-scroll {
  border: 0;
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__row,
main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__row
  > *,
main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  :is(th, td) {
  border-inline: 0;
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__row {
  border-block: 0;
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__row
  + .tacet-page-table__row {
  border-top: 1px solid var(--tacet-table-row-rule);
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  > thead,
main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__head {
  border-top: 0;
  border-bottom: 1px solid var(--tacet-table-rule);
  background: var(--tacet-table-head);
  color: var(--tacet-table-ink);
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  > thead
  > tr
  > :is(th, td) {
  border-block: 1px solid var(--tacet-table-rule);
  background: transparent;
  color: var(--tacet-table-ink);
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__head
  > * {
  color: var(--tacet-table-ink);
}

/* Avoid a second body rule touching the header or the table's bottom edge. */
main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__head
  + .tacet-page-table__row {
  border-top: 0;
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  .tacet-page-table__row:last-child {
  border-bottom: 0;
}

main
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  > :is(tbody, tfoot):last-child
  > tr:last-child
  > :is(th, td) {
  border-bottom: 1px solid var(--tacet-table-rule);
}

/* Reference and permission tables inherit their system's palette, not its
   preview-window styling. Preserve Swage type, numeric alignment and data. */
:is(.swage-system, .swage-system-child.nx)
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table) {
  --tacet-table-head: color-mix(in oklch, var(--swage-ink), transparent 94%);
  --tacet-table-rule: var(--swage-line-strong);
  --tacet-table-row-rule: var(--swage-line);
  --tacet-table-ink: var(--swage-ink);
}

:is(.swage-system, .swage-system-child.nx)
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
  > thead
  > tr
  > :is(th, td) {
  background: transparent;
  color: var(--tacet-table-ink);
  border-block-color: var(--tacet-table-rule);
}

/* Default row dividers for new consumers; established horizontal rules win. */
:where(
  :is(.tacet-page-table, :where(.doc-body, .ctx-doc-body, .sys-depth, .sl-table-scroll) table)
    > tbody
    > tr
    > :is(th, td)
) {
  border-bottom: 1px solid var(--tacet-table-row-rule);
}
