/* The shared table: a bordered box the page does not scroll around, a fixed header row, sortable and resizable
   columns. Built on the tokens in app.css. No inline styles (strict CSP); widths set by tables.js are set through the
   DOM, which the policy allows. */

:root { --field-gap: 4px; }

/* A filter block and its table sit one field-gap apart: the same distance a label sits from its input. */
.tblock { display: flex; flex-direction: column; gap: var(--field-gap); min-height: 0; }
.tblock > .filters, .tblock > .books-head { margin: 0; }

.tablebox { border: var(--border); border-radius: var(--radius); background: var(--row); overflow: auto;
            min-height: 0; }
.tablebox table { border-collapse: separate; border-spacing: 0; }
.tablebox thead th { position: sticky; top: 0; z-index: 2; }
.tablebox tfoot td { position: sticky; bottom: 0; z-index: 1; }
.tablebox td { border-bottom: 1px solid var(--line); }
.tablebox tbody tr:last-child td { border-bottom: 0; }

/* A table wider than its box scrolls sideways. Where a browser can tie a style to that scrolling, the box fades at
   the edge that has more behind it: the right edge at first, both in the middle, the left at the end. A table that
   fits has nothing to scroll, so nothing fades. Elsewhere the box is as it was (dsa157/benco 51). The fade itself
   is app.css's `more-behind`. Never on a box that lets its rows' menus out (`.inflow`): a mask would cut them off. */
@media screen {
  @supports (animation-timeline: scroll()) {
    .tablebox:not(.inflow) { animation: more-behind linear both, more-behind-across linear both;
                             animation-timeline: scroll(self inline); }
  }
}

/* On a laptop the page does not scroll: the box takes what is left and its rows scroll inside it. On a small screen
   the page scrolls and the box is as tall as its rows. */
@media (min-width: 761px) {
  main.fill .tblock { flex: 1 1 auto; }
  main.fill .tblock > .tablebox { flex: 1 1 auto; }
}

th.sortable { padding: 0; }
th.sortable .sortlink { display: block; padding: var(--cell-y) var(--cell-x); color: inherit; text-decoration: none; white-space: nowrap;
                        transition: background-color var(--dur-1) var(--ease); }
th.sortable .sortlink:hover { background: color-mix(in srgb, var(--head-ink) 9%, transparent); }
th.sortable .sortlink:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
th.sortable .ind { margin-left: 5px; font-size: .8em; opacity: .4; }
th.sortable[aria-sort="ascending"] .ind, th.sortable[aria-sort="descending"] .ind { opacity: 1; }
th.fig .sortlink { text-align: right; }

/* Resizable columns (tables.js). Without the script the table lays itself out as usual. */
table.sized[data-resize] { table-layout: fixed; min-width: 100%; width: auto; }
table.sized th { position: sticky; }
table.sized td { overflow: hidden; text-overflow: ellipsis; }
table.sized th .grip { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; z-index: 3; }
table.sized th .grip::after { content: ""; position: absolute; top: 20%; bottom: 20%; right: 3px;
                              border-right: 1px solid var(--head-ink); opacity: .35; }
table.sized th .grip:hover::after, table.sized th .grip:focus-visible::after, table.resizing th .grip::after { opacity: 1; }
table.resizing { user-select: none; cursor: col-resize; }
.tablebox.inflow { overflow: visible; }

/* The width controls above a resizable table: choose a column, make it narrower or wider, or reset every column. */
/* The handle is 8px wide, so its ring is heavier than the page's (QA-030: a keyboard user must see which column's
   handle has focus): 3px of the focus color, which is held to 3 to 1 against the header band in both modes. */
table.sized th .grip:focus-visible { outline: 3px solid var(--focus); outline-offset: -2px;
                                     background: color-mix(in srgb, var(--focus) 30%, transparent); }
