/* The table, its filter bar and the empty state: DataTableComponent, FilterBarComponent and
   EmptyStateComponent in app/components (design-direction.md section 5, items 10 and 11).

   Linked after 36-form-fields.css and before 40-native.css, so the touch target floor in
   40-native.css still wins over this file's (the controls here that it does not name have their
   own coarse-pointer rule). Tokens only and logical properties only, both enforced
   (test/styles/tokens_test.rb, test/styles/components_test.rb), so all of it reads on the light
   shell and on the console, in light and in dark, and mirrors in a right-to-left language. It
   decides no mode and no surface.

   `table.data` in 10-globals.css is the table's base look (the collapsed hairlines, the small
   tracked header, the row hover) and is reused: the component adds the class `data-table` and
   the rules below. Two things in the ported rules are physical and are corrected here for the
   table's own cells: `text-align: left` and `right` (`start` and `end` mirror), and the sticky
   uppercase `th` that a row header would inherit (a row header is a name, not a column title,
   and a sticky one in the body overlaps the rows it names). */

/* ── Data table ───────────────────────────────────────────────────────────
   The region is what scrolls. It is focusable and named (the component gives it a role and a
   label), so a table wider than the screen is reached by keyboard and nothing past the edge is
   lost (WCAG 1.4.10, 2.1.1); the page itself never scrolls sideways. The global focus ring is
   drawn outside the box, where the region's own scrolling and the page's `overflow-x: clip` would
   cut it, so on the region it is drawn inside.

   The region is also the containing block of what is positioned inside it. `.sr-only` is
   `position: absolute`, and one in a cell (the words "no value" for a dash) is placed where its cell
   is, far to the end of a wide table. An absolutely positioned box is clipped by the scroller only
   when the scroller is its containing block; without that it escapes the region and the page grows a
   sideways scrollbar for a one-pixel word (found by the 320px reflow test on the wide preview). */

.data-table-region {
  position: relative;
  container-type: inline-size;
  /* The cue that there is more to the side (WCAG 1.3.1, 1.4.10: a region that scrolls says so, and does not hide what is past its edge): a soft shadow
     at the edge of the region that has more beyond it, and none where the table starts or ends. The "local" layers are the region's own background
     and move with what is scrolled; they cover the "scroll" layers, the shadows, which stay at the edges, wherever the table has been scrolled to
     its end. So the shadow shows only on the side with more, and a table that fits shows none. Tokens only: the cover is the page's color and the
     shadow is the text color made faint, so it is a shade in light and a glow in dark. In a right-to-left language the sides swap (`:dir(rtl)`). */
  --region-cover: var(--bg);
  --region-edge: color-mix(in srgb, var(--fg1) 26%, transparent);
  --region-to-end: to right;
  --region-to-start: to left;
  --region-start: 0;
  --region-end: 100%;
  background:
    linear-gradient(var(--region-to-end), var(--region-cover) 30%, transparent) var(--region-start) 0 / 2.5rem 100% no-repeat local,
    linear-gradient(var(--region-to-start), var(--region-cover) 30%, transparent) var(--region-end) 0 / 2.5rem 100% no-repeat local,
    radial-gradient(farthest-side at var(--region-start) 50%, var(--region-edge), transparent) var(--region-start) 0 / 0.75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at var(--region-end) 50%, var(--region-edge), transparent) var(--region-end) 0 / 0.75rem 100% no-repeat scroll;
}
.data-table-region:dir(rtl) {
  --region-to-end: to left;
  --region-to-start: to right;
  --region-start: 100%;
  --region-end: 0;
}
.data-table-region:focus-visible {
  outline-offset: -2px;
}
/* The header row is part of the region's background, so the shadow runs down the whole edge and not from under the header. */
.data-table-region table.data.data-table thead th {
  background: transparent;
}

table.data.data-table th,
table.data.data-table td {
  text-align: start;
}
table.data.data-table :is(th, td)[data-numeric] {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

/* A cell's words wrap at spaces, and a word with none breaks only when it has no room left
   (`break-word`). It is not `anywhere` as the rest of the components are: `anywhere` lowers a
   column's minimum width to one letter, and the browser's table layout then gives a column that
   little ("Informat / ion / technol / ogy") while the table is as wide as it was. With `break-word` a
   column is never narrower than its longest word, and a table too wide for the screen is what the
   scroll region is for. A badge in a cell does not wrap for the same reason: its word is its whole
   cell. */
table.data.data-table td,
table.data.data-table tbody th {
  overflow-wrap: break-word;
}
table.data.data-table td .pill {
  white-space: nowrap;
  overflow-wrap: normal;
}
/* A column that says `nowrap` keeps each cell on one line (a class, an id): the width of the phrase is the width of the column, and the long cells beside it
   are what wrap. It does so only when the region has the room for it (66rem of the region, which is what the region is a container for): a table with less
   keeps the cells wrapping, as it did, rather than make every column's minimum wider and scroll in its region for it. */
@container (min-width: 66rem) {
  table.data.data-table :is(th, td)[data-nowrap] {
    white-space: nowrap;
    overflow-wrap: normal;
  }
}

/* The row header: the cell that says which row it is. */
table.data.data-table tbody th[scope="row"] {
  position: static;
  z-index: auto;
  padding: 0.68rem 0.75rem;
  border-block-end: 1px solid var(--rule);
  background: transparent;
  color: var(--fg1);
  font-size: inherit;
  font-weight: 650;
  letter-spacing: normal;
  text-transform: none;
  white-space: normal;
  vertical-align: top;
}

/* A column that can be sorted: its header is a link, drawn as the header's own text. The mark
   is a triangle that follows the text color and is drawn by the component as an SVG, so it
   survives forced colors; the column in order shows one triangle and its direction, and the
   others show both, faint, to say they can be sorted. 24px at the least (WCAG 2.5.8), 44px on touch. */
.data-table-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-block-size: 1.5rem;
  color: inherit;
  text-decoration: none;
}
.data-table-sort:hover {
  color: var(--fg1);
}
.data-table-sort:hover .data-table-sort-label {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
th[data-numeric] .data-table-sort {
  justify-content: flex-end;
}
/* A sortable header's label wraps at its spaces (`table.data th` is `nowrap`, 10-globals.css): nine one-line headers made the incident list 1022px wide, wider than the region of a 1280px
   screen, and its last column scrolled out of sight. A table that can be cards also keeps its cells a little closer, so nine columns fit the region from a 900px screen up (the region is
   what a table is measured against, so the cards take over under 48rem of it as before). */
table.data.data-table thead th:has(.data-table-sort) {
  white-space: normal;
}
table.data.data-table[data-cards] :is(th, td) {
  padding-inline: 0.6rem;
}
th[aria-sort] .data-table-sort {
  color: var(--fg1);
}
.data-table-sort-icon {
  flex: none;
  inline-size: 0.5rem;
  block-size: 0.75rem;
  fill: currentColor;
  color: var(--fg-faint);
}
th[aria-sort] .data-table-sort-icon {
  color: inherit;
}
th[aria-sort="ascending"] .sort-down,
th[aria-sort="descending"] .sort-up {
  display: none;
}
@media (pointer: coarse) {
  .data-table-sort {
    min-block-size: var(--target-min);
  }
}

/* ── A table drawn as cards where it has little room ──────────────────────────────
   `cards: true` on DataTableComponent puts `data-cards` on the table. Where its region is under 48rem wide (a phone, a narrow panel; the region is the container, so the width is the table's own and not
   the screen's) a row is a card, as the Hotwire Native shells always draw one (95-native-shell.css): the row header is the card's title, every other cell is a fact that names itself with its column's
   label (`data-label`, put on every cell by the component), and the headers that sort are kept as a strip of links after the words "Sort by" (`data-sort-label` on the header row), so nothing scrolls
   sideways at 320 CSS px and every column is still a way to order the list. The rest of the headers are not drawn: a column's name is on each fact. The same strip and label are drawn in a native
   shell for such a table. A table that does not say `cards` is not touched. */
@container (max-width: 48rem) {
  table.data.data-table[data-cards],
  table.data.data-table[data-cards] :is(thead, tbody) {
    display: block;
    inline-size: 100%;
    min-inline-size: 0;
    border: 0;
  }
  table.data.data-table[data-cards] thead tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-4);
    padding-block: 0 var(--space-3);
  }
  table.data.data-table[data-cards] thead th {
    display: none;
    padding: 0;
    border: 0;
    background: none;
  }
  table.data.data-table[data-cards] thead th:has(.data-table-sort) {
    display: block;
  }
  table.data.data-table[data-cards] tbody tr {
    box-sizing: border-box;
    inline-size: 100%;
    min-inline-size: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-4);
    margin-block-end: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
  }
  table.data.data-table[data-cards] tbody tr:hover {
    background: var(--surface-raised);
  }
  table.data.data-table[data-cards] tbody th[scope="row"] {
    flex: 1 1 100%;
    padding: 0;
    border: 0;
  }
  table.data.data-table[data-cards] tbody td {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0 var(--space-2);
    padding: 0;
    border: 0;
    color: var(--fg1);
    font-size: var(--text-sm);
  }
  table.data.data-table[data-cards] tbody td::before {
    content: attr(data-label);
    color: var(--fg3);
    font-size: var(--text-xs);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  table.data.data-table[data-cards] thead tr[data-sort-label]::before {
    content: attr(data-sort-label);
    color: var(--fg3);
    font-size: var(--text-xs);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
}

/* The flag on a row: a 3px bar at the start of its first cell, and the label in words above what the
   cell says. The first cell of every row keeps the same room for the bar, so a flagged row does not
   shift its cells against the others. The bar is the tone's text color (3:1 against the row, which
   the contrast check measures as text at 4.5:1). */
table.data.data-table :is(th, td):first-child {
  border-inline-start: 3px solid transparent;
}
/* More specific than the transparent bar above, which is the shorthand and would otherwise win by one
   pseudo-class and leave the bar invisible. test/system/data_table_flag_test.rb reads the computed color. */
table.data.data-table :is(th, td):first-child[data-flag] {
  border-inline-start-color: var(--flag-color);
}
/* Forced colors (a high-contrast setting) turns every border color into a system color, a transparent one
   included, so the room kept for the bar would draw a bar on every row, and the rows with nothing to say would
   look flagged. A system color an author names is kept, so the room is the page's own color (`Canvas`, which
   cannot be seen) and the flagged row's bar is the text color (`CanvasText`). The label in words is the same
   either way. test/system/data_table_flag_test.rb looks at it with forced colors on. */
@media (forced-colors: active) {
  table.data.data-table :is(th, td):first-child {
    border-inline-start-color: Canvas;
  }
  table.data.data-table :is(th, td):first-child[data-flag] {
    border-inline-start-color: CanvasText;
  }
}
table.data.data-table [data-flag="good"] {
  --flag-color: var(--tone-good-fg);
}
table.data.data-table [data-flag="warn"] {
  --flag-color: var(--tone-warn-fg);
}
table.data.data-table [data-flag="bad"] {
  --flag-color: var(--tone-bad-fg);
}
table.data.data-table [data-flag="info"] {
  --flag-color: var(--tone-info-fg);
}
table.data.data-table [data-flag="accent"] {
  --flag-color: var(--tone-accent-fg);
}
table.data.data-table [data-flag="mute"] {
  --flag-color: var(--tone-mute-fg);
}
.data-table-flag-label {
  display: block;
  margin-block-end: 0.15rem;
  color: var(--flag-color);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.3;
}

/* ── Filter bar ───────────────────────────────────────────────────────────
   A search box and a row of choices, laid out to wrap: nothing has a fixed width, so a longer word
   in another language, or a phone, only makes it go to a second line. With room the search and the
   choices share a line, and what is said about the result (how many, and how to clear it) is a line
   of its own under them. */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--density-gap) 1.5rem;
  min-inline-size: 0;
  margin-block-end: var(--density-gap);
}
.filter-bar-search {
  display: flex;
  flex: 1 1 15rem;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--density-gap);
  min-inline-size: 0;
}
.filter-bar-search .filter-bar-field {
  flex: 1 1 10rem;
  min-inline-size: 0;
}
.filter-bar-group {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem var(--density-gap);
  min-inline-size: 0;
}
.filter-bar-group-label {
  overflow-wrap: anywhere;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A choice is a link drawn as a pill. Its edge is the control line (3:1, WCAG 1.4.11). The one that
   is on is also heavier: a thicker edge in the accent and bold type, on the soft accent fill, so it
   is never a color alone (1.4.1) and its box does not grow (the padding gives back the edge). */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  max-inline-size: 100%;
  min-block-size: var(--density-chip);
  padding: 0.2rem 0.75rem;
  border: 1px solid var(--control-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg1);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  overflow-wrap: anywhere;
}
/* The count is "(7)", one word that a narrow chip may put on the line below the label but never cut in two: with
   `overflow-wrap: anywhere` on the chip, "(7" and ")" would otherwise land on two lines in a longer language. */
.filter-chip-count {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* The dot of a choice that has a tone (an office on the spine): the same bar color its rows carry, 3:1 against
   everything a chip is set on (config/contrast_pairs.yml). A memory aid; the label is the choice. */
.filter-chip-dot {
  flex: none;
  inline-size: 0.65rem;
  block-size: 0.65rem;
  border-radius: 50%;
  background: var(--spine-neutral-line);
}
.filter-chip-dot[data-tone="plum"] {
  background: var(--spine-plum-line);
}
.filter-chip-dot[data-tone="green"] {
  background: var(--spine-green-line);
}
.filter-chip-dot[data-tone="teal"] {
  background: var(--spine-teal-line);
}
.filter-chip-dot[data-tone="blue"] {
  background: var(--spine-blue-line);
}
.filter-chip-dot[data-tone="amber"] {
  background: var(--spine-amber-line);
}
.filter-chip-dot[data-tone="rose"] {
  background: var(--spine-rose-line);
}
.filter-chip-dot[data-tone="slate"] {
  background: var(--spine-slate-line);
}
/* Forced colors drops a background, so the dot keeps its shape as an outline in the text color. */
@media (forced-colors: active) {
  .filter-chip-dot {
    border: 1px solid CanvasText;
  }
}
.filter-chip:hover {
  background: var(--surface-tint);
  color: var(--fg1);
}
.filter-chip[aria-current="true"] {
  padding: calc(0.2rem - 1px) calc(0.75rem - 1px);
  border-width: 2px;
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}
@media (pointer: coarse) {
  .filter-chip {
    min-block-size: var(--target-min);
  }
}

.filter-bar-status {
  display: flex;
  flex: 1 0 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
}
.filter-bar-count {
  color: var(--fg2);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* ── Empty state ──────────────────────────────────────────────────────────
   Two kinds, never drawn alike. Nothing here: a dashed edge round plain words, the quietest thing
   on the page, because there is nothing to find. An honest absence: a sunken well with a solid bar
   at its start and the words in full strength, because there is something and the person is not
   shown it. Neither has a picture; the words are all of it. Both edges are the control line (3:1
   against the surfaces, WCAG 1.4.11, measured by the contrast check): the drawing is what tells the two
   apart, so it is not the faint rule, which is 1.6 to 1.9:1. */

.empty-state {
  display: grid;
  gap: 0.4rem;
  min-inline-size: 0;
  padding: 1.25rem 1.15rem;
  border-radius: var(--radius-md);
  overflow-wrap: anywhere;
}
.empty-state[data-kind="nothing"] {
  border: 1px dashed var(--control-line);
  color: var(--fg2);
}
.empty-state[data-kind="absence"] {
  border-inline-start: 3px solid var(--control-line);
  background: var(--surface-sunken);
  color: var(--fg1);
}
.empty-state-message {
  font-size: var(--text-base);
  line-height: 1.45;
}
.empty-state[data-kind="absence"] .empty-state-message {
  font-weight: 650;
}
.empty-state-detail {
  color: var(--fg2);
  font-size: var(--text-sm);
  line-height: 1.45;
}
.empty-state-action {
  margin-block-start: 0.4rem;
}
