@layer runeui.components {
  [data-slot="table-container"] { position: relative; width: 100%; min-width: 0; }
  [data-slot="table-scroll"] { width: 100%; overflow-x: auto; }
  [data-slot="table"] { width: 100%; border-collapse: collapse; caption-side: bottom; font-size: var(--ui-text-sm); }
  [data-slot="table"] thead tr { border-bottom: 1px solid var(--border); }
  [data-slot="table"] tbody tr { border-bottom: 1px solid var(--border); transition: background-color var(--ui-duration); }
  [data-slot="table"] tbody tr:last-child { border-bottom: 0; }
  [data-slot="table"] tbody tr:hover { background: color-mix(in oklab, var(--muted) 50%, transparent); }
  [data-slot="table"] tr:is([aria-selected="true"], [data-state="selected"]) { background: var(--muted); }
  [data-slot="table"] tfoot { border-top: 1px solid var(--border); background: color-mix(in oklab, var(--muted) 50%, transparent); font-weight: 500; }
  [data-slot="table"] th { height: 2.5rem; padding: 0 0.5rem; color: var(--foreground); font-weight: 500; text-align: start; white-space: nowrap; }
  [data-slot="table"] td { padding: 0.5rem; white-space: nowrap; }
  [data-slot="table"] :is(th, td)[data-align="end"] { text-align: end; font-variant-numeric: tabular-nums; }
  [data-slot="table"] :is(th, td):has([data-slot="checkbox"]) { width: 1px; padding-inline-end: 0; }
  /* Widths, as shadcn's table has them: every column is as wide as what it holds, on one line.
     data-grow marks the column that names each row: it takes what's left and cuts a long name
     short, never narrower than 12rem (a narrower table scrolls in its container instead).
     data-truncate caps a column of free text (16rem, or --ui-table-truncate). */
  [data-slot="table"] :is(th, td)[data-grow] { width: 100%; min-width: 12rem; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
  /* data-grow="wrap": a name that reads as a sentence (a task's title) wraps instead, to two
     lines at most where its content is one element (a link). */
  [data-slot="table"] td[data-grow="wrap"] { white-space: normal; overflow-wrap: anywhere; }
  [data-slot="table"] td[data-grow="wrap"] > a:only-child { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  [data-slot="table"] td[data-truncate] { max-width: var(--ui-table-truncate, 16rem); overflow: hidden; text-overflow: ellipsis; }
  [data-slot="table"] :is(th, td)[data-align="center"] { text-align: center; }
  [data-slot="table"] :is(th, td)[hidden] { display: none; }
  [data-slot="table-caption"] { margin-top: 1rem; color: var(--muted-foreground); }
}

/* Sortable headers, the checkbox column and the bulk bar (ui :sort_header, :select_cell, :bulk_bar). */
@layer runeui.components {
  [data-slot="table-sort"] {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-inline-start: -0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--ui-radius-sm);
    color: inherit;
    text-decoration: none;
  }
  [data-slot="table-sort"]:hover { background: var(--accent); color: var(--accent-foreground); }
  [data-slot="table-sort"] .ui-icon { width: 0.875rem; height: 0.875rem; color: var(--muted-foreground); }
  th[aria-sort] [data-slot="table-sort"] .ui-icon { color: var(--foreground); }
  th[data-align="end"] [data-slot="table-sort"] { margin-inline: 0 -0.5rem; }

  [data-slot="table-select"] { width: 2rem; padding-inline: 0.5rem 0; }
  [data-slot="table-select"] [data-slot="checkbox"] { vertical-align: middle; }
  /* The header's mixed state (some rows picked), drawn by data-mixed. */
  [data-select-all] .ui-mixed-icon { display: none; width: 0.875rem; height: 0.875rem; }
  [data-select-all][data-mixed] { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
  [data-select-all][data-mixed] .ui-mixed-icon { display: block; }
  [data-slot="table"] tr[aria-selected="true"] { background: var(--muted); }

  [data-slot="bulk-bar"] {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--ui-h);
    padding: 0.25rem 0.375rem 0.25rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--ui-radius-lg);
    background: var(--popover);
    box-shadow: var(--ui-shadow-md);
    font-size: var(--ui-text-sm);
  }
  [data-slot="bulk-count"] { font-weight: 500; font-variant-numeric: tabular-nums; }
  [data-slot="bulk-actions"] { display: flex; gap: 0.375rem; margin-inline-start: auto; }
}
