/* DataTable — only the rules styles.css does not already paint.
 *
 * The table itself is `table.data` (styles.css): sticky header, row hover,
 * sort buttons, `.l` / `.c` alignment. This file adds the message slot (the
 * stale notice; the empty state reuses `.empty-note` from styles.css), the
 * optional stretched row link, and the phone list mode (MOBILE_PLAN.md §2.5:
 * `.dt-list-sortbar`, `ul.dt-list`, `li.dt-item` and friends). Every colour
 * and length comes from tokens.css. The list classes only ever exist while
 * the JS list rendering is on (below `mobile.below`, default 768), so this
 * file needs no media queries.
 */

.data-table {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.data-table-msg {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Stale: data stays on screen, the notice explains its age. */
.data-table-stale {
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-label);
}

/* Optional row link: a real anchor stretched over the first cell. */
table.data td.data-table-link-cell { position: relative; }

a.data-table-link {
  position: absolute;
  inset: 0;
}

a.data-table-link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

/* Visually hidden text that names the stretched link. */
.data-table-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- list mode (MOBILE_PLAN.md §2.5) ---------------------------------- */

.dt-list-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

/* [Sort: RVOL ▾] [↓] — one select plus a direction toggle. */
.dt-list-sortbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.dt-list-sort-label {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  color: var(--muted);
  font-size: var(--fs-label);
}

select.dt-list-sort {
  min-height: var(--hit-min);
  min-width: 0;
  max-width: 100%;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-table);
}

button.dt-list-sort-dir {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--hit-min);
  min-height: var(--hit-min);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}

/* The rounded corner clips the hit box just enough to fail the 44 px probe
 * at (±21, ±21). A centred, square, transparent overlay sized from the
 * BORDER box (pattern 1, §2.9 — max(100%, …) resolves 100% against the
 * padding box, so the overlay is 44 px even with the 1 px border) restores
 * the full corner hit area without touching the rounded look. */
button.dt-list-sort-dir::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100%, var(--hit-min));
  height: max(100%, var(--hit-min));
  transform: translate(-50%, -50%);
}

button.dt-list-sort-dir[disabled] {
  color: var(--muted);
  cursor: default;
}

button.dt-list-sort-dir:focus-visible,
select.dt-list-sort:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

ul.dt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

li.dt-item {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-subtle);
}

/* flex-basis 0 keeps the body from ever forcing the ▾ toggle onto its own
 * line (flex-wrap is on so the detail can wrap); it grows to fill whatever
 * the toggle leaves. min-width: 0 lets long values shrink instead of pushing. */
.dt-item-main {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--hit-min);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-1);
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

a.dt-item-main:focus-visible,
button.dt-item-main:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.dt-item-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

/* The meta line callers may use for the muted second row (§2.10 allowlist). */
.dt-item-meta {
  color: var(--muted);
  font-size: var(--fs-meta);
}

/* The ▾ expander, outside the stretched link so both stay clickable. */
button.dt-item-toggle {
  flex: 0 0 var(--hit-min);
  min-width: var(--hit-min);
  min-height: var(--hit-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
}

button.dt-item-toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Expand + detailRow host: full width under the body. */
.dt-item-detail {
  flex: 1 0 100%;
  min-width: 0;
  padding: var(--space-1);
}

.dt-item-expand {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: var(--space-1) var(--space-3);
  align-items: baseline;
}

.dt-item-expand-label {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--muted);
  font-size: var(--fs-label);
  white-space: nowrap;
}

.dt-item-expand-value {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-size: var(--fs-table);
  overflow-wrap: anywhere;
}

/* Fixed-height loading skeletons — the layout does not jump (brief §28). */
li.dt-item-skeleton {
  border-bottom: 1px solid var(--border-subtle);
}

li.dt-item-skeleton .dt-item-main {
  height: calc(var(--hit-min) + var(--space-4));
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* ⓘ info button — the attach point for the touch tooltip (§2.7 Popover). */
button.dt-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--hit-min);
  min-height: var(--hit-min);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}

button.dt-info .dt-info-glyph {
  font-size: var(--fs-label);
  line-height: 1;
}

button.dt-info:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Sortable headers keep the sort button full-bleed; an info button sits
 * beside it instead of inside it (buttons never nest). The flex lives on an
 * inner span — a `display:flex` th stops being a table cell and can break
 * column widths and the sticky thead. */
table.data th.dt-th-has-info {
  white-space: nowrap;
}

table.data th.dt-th-has-info .dt-th-inner {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
}

table.data th.dt-th-has-info .dt-th-inner .sort-btn {
  width: auto;
  flex: 1 1 auto;
}

table.data th.dt-th-has-info .dt-th-inner button.dt-info {
  min-width: var(--space-5);
  min-height: var(--space-5);
}
