/* OAIT Design System 2.1.0 · reference/css/table.css
   Data tables and the bulk bar (unit c-containers).

   Components
   - Table region (.oa-table-region): the named, focusable box a table scrolls sideways in.
   - Data table (.oa-table): 56px header row; 64px rows (avatar or two lines), 48px in --compact
     (one line); numbers at the inline end, IDs in mono; one link per row, in the row header;
     selection with a 48px target around a 20px checkbox; sortable headers; row actions.
   - Bulk bar (.oa-bulk-bar): the primary-container bar above a table while rows are selected, its
     count in a live region that exists from page load.
   Pagination below a table is .oa-pagination (site-nav.css, unit c-nav-site); the empty state
   inside a region is .oa-empty and loading rows are .oa-skeleton (feedback.css, unit c-feedback).

   Implements canonical §10.13, §4.11, §3.8, §6.2, §6.3, §2.7, §14.2, §14.3 and D-CSN-34, D-CSN-18,
   D-ARC-10, D-ARC-14, D-ARC-20, D-ARC-24, D-ARC-35, D-LAY-18, D-COL-05, D-SEM-10, D-SEM-11, D-TYP-12,
   D-TYP-13, D-BCP-30.

   Tokens read: --color-card-outlined-container, --color-outline-variant, --color-on-surface,
   --color-on-surface-variant, --color-primary-container, --color-on-primary-container,
   --radius-box, --radius-full; --size-table-header, --size-table-row,
   --size-menu-item, --size-touch-target, --size-icon-sm, --size-focus-inset; --space-1, --space-2,
   --space-3, --space-5; --font-mono; --opacity-state-hover, --opacity-state-pressed; --z-behind;
   --duration-short-3; --ease-standard; --text-label-md, --text-body-md, --text-code-sm with their
   --line-height, --letter-spacing, and --font-weight companions.
   Context property read: --oa-state (the state-layer opacity; documentation pages force it inline).
   Component-local property: --oa-table-min-width (the table's least width, the sum of its columns).

   Classes: .oa-table-region, .oa-table (+ --compact; __sort, __num, __id, __select, __actions,
   __entry, __link, __sub, __empty), .oa-bulk-bar (+ __icon, __count, __actions).

   Relies on base.css for .oa-icon, .oa-visually-hidden, and the focus ring; on link.css for
   .oa-title-link (the record link's color and hover underline); on selection.css for the drawn
   checkbox .oa-check__input; on button.css for the row-action .oa-icon-btn and the bulk bar's text
   buttons. */


/* ---------------------------------------------------------------------------------------------
   1. Region. The outlined container a table lives in: card-outlined-container, a 1px
   outline-variant edge, 16px corners. It scrolls sideways when the table is wider than the screen,
   takes focus (tabindex="0") so a keyboard can scroll it, and carries the table's name. It is
   positioned, so the visually hidden text in its cells never widens the page (D-CSN-34).
   --------------------------------------------------------------------------------------------- */

.oa-table-region {
  position: relative;
  overflow-x: auto;
  overscroll-behavior-x: contain; /* a swipe that reaches the table's edge is not a back gesture */
  box-sizing: border-box;
  max-inline-size: 100%;
  border: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-box);
  background-color: var(--color-card-outlined-container);
  color: var(--color-on-surface);
}


/* ---------------------------------------------------------------------------------------------
   2. Table. Collapsed borders, the full width of its region, and never narrower than the sum of
   its columns (--oa-table-min-width; Global ID's directory: 65rem). Header 56px, label-md in
   on-surface-variant, sentence case, no wrap, aligned like its column. Body cells 12px inline and
   8px block, body-md, a 1px outline-variant rule above each row. Rows 64px; 48px in --compact
   (canonical §4.11, §10.13; D-CSN-34, D-LAY-18, D-ARC-20). Rows are not clickable and have no
   hover fill.
   --------------------------------------------------------------------------------------------- */

.oa-table {
  --oa-table-min-width: auto;
  inline-size: 100%;
  min-inline-size: var(--oa-table-min-width);
  border-collapse: collapse;
  color: var(--color-on-surface);
  font-size: var(--text-body-md);
  line-height: var(--text-body-md--line-height);
  letter-spacing: var(--text-body-md--letter-spacing);
  font-weight: var(--text-body-md--font-weight);
}

.oa-table :is(th, td) {
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  text-align: start;
  vertical-align: middle;
}

.oa-table thead th {
  block-size: var(--size-table-header);
  padding-block: 0;
  color: var(--color-on-surface-variant);
  font-size: var(--text-label-md);
  line-height: var(--text-label-md--line-height);
  letter-spacing: var(--text-label-md--letter-spacing);
  font-weight: var(--text-label-md--font-weight);
  white-space: nowrap;
}

.oa-table tbody tr {
  block-size: var(--size-table-row);
}

.oa-table tbody :is(th, td) {
  border-block-start: 1px solid var(--color-outline-variant);
  font-weight: var(--text-body-md--font-weight);
}

.oa-table--compact tbody tr {
  block-size: var(--size-menu-item);
}

/* Cells that hold a 48px control (the box, the record link, the row actions) drop their block
   padding: the control sits centered, 8px from the edges of a 64px row as the cells' padding would
   put it, and the row keeps its 64px with its 1px rule, where 8px of padding would have made it
   65px. A compact row holding the 48px box or icon button measures 49px with its rule: the target
   wins (canonical §4.11). There the icon button fills the row, so it draws its ring inset (-4px)
   and the scrolling region never clips it (canonical §6.3: table cells); the 24px checkbox's ring
   fits outside it. */
.oa-table tbody :is(.oa-table__select, .oa-table__actions, th[scope="row"]) {
  padding-block: 0;
}

.oa-table--compact tbody .oa-table__actions :is(:focus-visible, [data-demo-focus]) {
  outline-offset: var(--size-focus-inset);
}


/* Columns (two-class selectors, so they win over the cell defaults above). Numbers at the inline end with tabular figures; IDs and codes in mono code-sm, never
   wrapped, their value in <bdi dir="ltr" translate="no">; an empty value is an aria-hidden "—"
   plus visually hidden words (D-CSN-34, D-TYP-12, D-TYP-13, D-BCP-30). */

.oa-table .oa-table__num {
  font-variant-numeric: tabular-nums;
  text-align: end;
  white-space: nowrap;
}

.oa-table tbody .oa-table__id {
  font-family: var(--font-mono);
  font-size: var(--text-code-sm);
  line-height: var(--text-code-sm--line-height);
  letter-spacing: var(--text-code-sm--letter-spacing);
  font-weight: var(--text-code-sm--font-weight);
  white-space: nowrap;
}

.oa-table__empty {
  color: var(--color-on-surface-variant);
}


/* ---------------------------------------------------------------------------------------------
   3. The record link. One link per row, in the row header (<th scope="row">): an optional 40px
   avatar, then the link, at least 48px tall (in a one-line compact row, the words with a 48px
   ::after target), holding the name in label-md and an optional second
   line (__sub) in body-md on-surface-variant, neither ever wrapping (the region scrolls). The color and the hover underline are the title
   link's (.oa-title-link). The row itself is never a link (D-CSN-34).
   --------------------------------------------------------------------------------------------- */

.oa-table__entry {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-inline-size: 0;
  white-space: nowrap; /* the region scrolls; a name or an address never breaks inside the row header */
}

/* The record link is a 48px target in both directions: a short name ("Gym") keeps the width. */
.oa-table .oa-table__link {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  min-inline-size: var(--size-touch-target);
  min-block-size: var(--size-touch-target);
  font-size: var(--text-label-md);
  line-height: var(--text-label-md--line-height);
  letter-spacing: var(--text-label-md--letter-spacing);
  font-weight: var(--text-label-md--font-weight);
}

/* A compact row is one line: the record link's box is its line, at least 24px (half the touch
   target, WCAG 2.5.8's minimum), and an ::after extends its target to 48px (canonical §4.6), so its
   8px-cornered ring sits around the words, inside the row. */
.oa-table--compact .oa-table__link {
  position: relative;
  min-block-size: calc(var(--size-touch-target) / 2);
}

.oa-table--compact .oa-table__link::after {
  content: "";
  position: absolute;
  inset-block: calc((100% - var(--size-touch-target)) / 2); /* lint-ok: layout maths, a 48px target centered on the line */
  inset-inline: 0;
}

.oa-table .oa-table__sub {
  color: var(--color-on-surface-variant);
  font-size: var(--text-body-md);
  line-height: var(--text-body-md--line-height);
  letter-spacing: var(--text-body-md--letter-spacing);
  font-weight: var(--text-body-md--font-weight);
}


/* ---------------------------------------------------------------------------------------------
   4. Selection. The first column holds a 48px round target (a <label>, with the 8% / 12% state
   layer) around the family's 20px checkbox in primary-ink; the header's box also shows the
   indeterminate state (set by script: input.indeterminate). A row whose box is ticked takes
   primary-container at 30%; the row's text keeps 8.64:1 or more (canonical §2.5, §2.13; D-ARC-10,
   D-ARC-35).
   --------------------------------------------------------------------------------------------- */

.oa-table .oa-table__select {
  inline-size: calc(var(--size-touch-target) + 2 * var(--space-2));
  padding-inline: var(--space-2);
}

.oa-table__select > label {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--size-touch-target);
  block-size: var(--size-touch-target);
  border-radius: var(--radius-full);
  color: var(--color-on-surface-variant);
  vertical-align: middle;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.oa-table__select > label::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-behind);
  border-radius: inherit;
  background-color: currentColor;
  opacity: var(--oa-state, 0);
  pointer-events: none;
  transition: opacity var(--duration-short-3) var(--ease-standard);
}

@media (hover: hover) {
  .oa-table__select > label:hover {
    --oa-state: var(--opacity-state-hover);
  }
}

.oa-table__select > label:active {
  --oa-state: var(--opacity-state-pressed);
}

.oa-table__select > label:active::before {
  transition-duration: 0ms; /* lint-ok: a press shows at once; only hover and release fade (canonical §2.7, §7.2) */
}

/* The box is the family's drawn checkbox (.oa-check__input, selection.css): a 24px input drawing
   the 20px box, so the input itself meets the 24px minimum and the label is the 48px target.
   Here it sits centered in the label, not on a text line. */
.oa-table__select .oa-check__input {
  margin: 0;
}

.oa-table tbody tr:has(> .oa-table__select input:checked) {
  background-color: color-mix(in srgb, var(--color-primary-container) 30%, transparent);
}


/* ---------------------------------------------------------------------------------------------
   5. Sorting (M3 default). A sortable header holds a button that fills the cell; aria-sort sits on
   the <th> of the sorted column only. An 18px arrow_upward or arrow_downward follows the label
   while the column is sorted, and appears on hover and focus elsewhere; pressing toggles
   ascending and descending. The button takes the state layer (over its border box) and the
   inset ring (canonical §10.13; D-CSN-34).
   --------------------------------------------------------------------------------------------- */

.oa-table thead th:has(> .oa-table__sort) {
  padding: 0;
}

.oa-table__sort {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  box-sizing: border-box;
  inline-size: 100%;
  min-block-size: var(--size-table-header);
  margin: 0;
  padding-block: 0;
  padding-inline: var(--space-3);
  border: 1px solid transparent;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: start;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.oa-table__sort::before {
  content: "";
  position: absolute;
  inset: -1px; /* over the 1px transparent edge as well */
  z-index: var(--z-behind);
  background-color: currentColor;
  opacity: var(--oa-state, 0);
  pointer-events: none;
  transition: opacity var(--duration-short-3) var(--ease-standard);
}

@media (hover: hover) {
  .oa-table__sort:hover {
    --oa-state: var(--opacity-state-hover);
  }
}

.oa-table__sort:active {
  --oa-state: var(--opacity-state-pressed);
}

.oa-table__sort:active::before {
  transition-duration: 0ms; /* lint-ok: a press shows at once; only hover and release fade (canonical §2.7, §7.2) */
}

.oa-table__sort:is(:focus-visible, [data-demo-focus]) {
  outline-offset: var(--size-focus-inset);
}

.oa-table__sort > .oa-icon {
  font-size: var(--size-icon-sm);
  opacity: 0;
  transition: opacity var(--duration-short-3) var(--ease-standard);
}

.oa-table thead th:is([aria-sort="ascending"], [aria-sort="descending"]) .oa-table__sort > .oa-icon,
.oa-table__sort:is(:hover, :focus-visible, [data-demo-focus]) > .oa-icon {
  opacity: 1;
}

.oa-table thead th.oa-table__num .oa-table__sort {
  justify-content: flex-end;
}


/* ---------------------------------------------------------------------------------------------
   6. Row actions: the last cell, as narrow as its 48px "More actions for {name}" icon button,
   at the inline end (canonical §10.13).
   --------------------------------------------------------------------------------------------- */

.oa-table .oa-table__actions {
  inline-size: 1%;
  text-align: end;
  white-space: nowrap;
}


/* ---------------------------------------------------------------------------------------------
   7. Bulk bar. Above the table while at least one row is ticked: primary-container with
   on-primary-container, 16px corners, padding 8px 8px 8px 20px, 12px between its parts; a filled
   24px check_box, the count in label-md, then small text buttons. Its count is an aria-live
   region that exists, empty, from page load: while the count is empty the bar is visually hidden
   and its actions leave the page. Script writes the count and sets the bar's aria-label ("People
   selected") while rows are ticked, and empties both when none is, so an empty bar is never listed
   as a region (D-CSN-34, D-ARC-14, D-ARC-20).
   --------------------------------------------------------------------------------------------- */

.oa-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--space-3);
  row-gap: var(--space-1);
  box-sizing: border-box;
  margin: 0;
  padding-block: var(--space-2);
  padding-inline: var(--space-5) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-box);
  background-color: var(--color-primary-container);
  color: var(--color-on-primary-container);
}

.oa-bulk-bar__icon {
  flex-shrink: 0;
}

.oa-bulk-bar__count {
  margin: 0;
  margin-inline-end: auto;
  font-size: var(--text-label-md);
  line-height: var(--text-label-md--line-height);
  letter-spacing: var(--text-label-md--letter-spacing);
  font-weight: var(--text-label-md--font-weight);
}

.oa-bulk-bar__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.oa-bulk-bar:has(> .oa-bulk-bar__count:empty) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.oa-bulk-bar:has(> .oa-bulk-bar__count:empty) > :not(.oa-bulk-bar__count) {
  display: none;
}
