@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; }
  @media (hover: hover) and (pointer: fine) { [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;
  }
  @media (hover: hover) and (pointer: fine) { [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); }
  /* Dragging down the checkbox column (runeui--selection): touch drags there, and scrolls
     anywhere else; the band shows the range the drag sets, picking (the ring's colour, a faint
     fill) or clearing (a quiet outline). It follows in 90ms on the ease-out and fades in and out. */
  [data-controller~="runeui--selection"] tbody [data-slot="table-select"] { touch-action: none; }
  [data-selecting] { user-select: none; }
  [data-slot="table-scroll"]:has(> [data-slot="table-select-band"]) { position: relative; isolation: isolate; }
  [data-slot="table-select-band"] {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 28px;
    height: 0;
    color: var(--muted-foreground);
    pointer-events: none;
    opacity: 0;
    transition: opacity 150ms ease-out, transform 90ms var(--ui-ease-out);
  }
  [data-slot="table-select-band"][data-open] { opacity: 1; }
  [data-slot="table-select-band"][data-picking="true"] { color: var(--ring); }
  [data-slot="table-select-band"] > * { position: absolute; top: 0; left: 0; width: 28px; border: 1.5px solid currentColor; transform-origin: 0 0; transition: transform 90ms var(--ui-ease-out); }
  [data-slot="table-select-band"][data-picking="true"] > * { background: color-mix(in oklab, currentColor 8%, transparent); }
  [data-slot="table-select-band-cap"] { height: 14px; }
  [data-slot="table-select-band-cap"]:first-child { border-bottom: 0; border-radius: 8px 8px 0 0; }
  [data-slot="table-select-band-cap"]:last-child { border-top: 0; border-radius: 0 0 8px 8px; }
  [data-slot="table-select-band-body"] { height: 1px; border-block: 0; }
  @media (forced-colors: active) {
    [data-slot="table-select-band"] { color: Highlight; }
  }

  [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; }
}

/* A data table (ui :data_table): shadcn's, the table in a bordered box with its pages under it,
   and a row's own buttons at its end (ui :row_actions), quiet until the row is hovered. */
@layer runeui.components {
  [data-slot="data-table"] { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
  [data-slot="data-table"] [data-slot="table-scroll"] { border: 1px solid var(--border); border-radius: var(--ui-radius-md); }
  /* In a card, the card is the box. */
  [data-slot="card"] [data-slot="data-table"] [data-slot="table-scroll"] { border: 0; border-radius: 0; }
  [data-slot="data-table"] [data-slot="table"] :is(th, td):first-child { padding-inline-start: 0.75rem; }
  [data-slot="data-table"] [data-slot="table"] :is(th, td):last-child { padding-inline-end: 0.75rem; }
  [data-slot="data-table-form"] { display: contents; }
  [data-slot="table-corner"] { width: 1%; }
  [data-slot="table-corner"] [data-slot="menu"] { display: inline-flex; margin-block: -0.25rem; font-weight: 400; }
  [data-slot="data-table-pages"] { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
  [data-slot="data-table-summary"] { color: var(--muted-foreground); font-size: var(--ui-text-sm); font-variant-numeric: tabular-nums; }
  [data-slot="row-actions"] { width: 1%; }
  [data-slot="row-actions-list"] { display: flex; align-items: center; justify-content: flex-end; gap: 0.125rem; }
  @media (hover: hover) and (pointer: fine) {
    [data-slot="row-actions-list"] > .ui-button { opacity: 0.6; transition: opacity var(--ui-duration); }
    tr:hover [data-slot="row-actions-list"] > .ui-button, [data-slot="row-actions-list"] > .ui-button:focus-visible { opacity: 1; }
  }
}
