/* Table and record cards.
   One table at standard density (48px rows, 16px cells) and administration
   density (.pr-table--dense: 36px rows, 12px cells). Real table markup with
   scope; sortable headers are buttons inside th[aria-sort].
   Rows in their normal state recede; a row that differs gets primary text and
   a 3px inset bar (brand colour when unsaved). A missing value is a dash.
   Phone: pattern A swaps the table for a card per row (.pr-rtable); pattern B
   keeps the table with its sticky first column and scrolls sideways. */

.pr-table-wrap {
  position: relative;
  overflow: auto;
  border: var(--pr-border-hairline) solid var(--pr-border-subtle);
  border-radius: var(--pr-radius-md);
  background: var(--pr-surface-card);
}
.pr-table {
  --row: var(--pr-density-standard-row);
  --pad: var(--pr-density-standard-pad);
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  font-size: 0.85rem; line-height: 1.3;
}
.pr-table--dense { --row: var(--pr-density-dense-row); --pad: var(--pr-density-dense-pad); }
.pr-table caption { text-align: left; padding: var(--pr-space-md) var(--pad); font-size: 0.75rem; color: var(--pr-text-caption); caption-side: top; }
.pr-table th, .pr-table td {
  height: var(--row);
  padding: 0 var(--pad);
  border-bottom: var(--pr-border-hairline) solid var(--pr-border-subtle);
  white-space: nowrap;
  text-align: left;
  vertical-align: middle;
}
.pr-table thead th {
  position: sticky; top: 0; z-index: var(--pr-z-sticky);
  background: var(--pr-surface-nested);
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
  color: var(--pr-text-caption);
}
.pr-table td { color: var(--pr-text-secondary); }
.pr-table td:first-child, .pr-table th[scope="row"], .pr-table .pr-strong { color: var(--pr-text-primary); font-weight: 500; }
.pr-table tbody th[scope="row"] { font-size: 0.85rem; }
.pr-table .pr-num { text-align: right; font-variant-numeric: tabular-nums; }
.pr-table .pr-null { color: var(--pr-text-caption); }
.pr-table .pr-wrapcell { white-space: normal; }

/* Sticky first column with a hairline shadow when the table scrolls sideways */
.pr-table .pr-sticky { position: sticky; left: 0; z-index: 1; background: var(--pr-surface-card); box-shadow: 1px 0 0 var(--pr-border-default); }
.pr-table thead .pr-sticky { background: var(--pr-surface-nested); z-index: calc(var(--pr-z-sticky) + 1); }
.pr-table .pr-table__check { width: 36px; min-width: 36px; max-width: 36px; padding-right: 0; }
.pr-table .pr-table__check .pr-opt { min-height: 0; }
.pr-table .pr-sticky--after-check { left: 36px; }

.pr-table tbody tr:hover > * { background: var(--pr-surface-hover); }
.pr-table tbody tr[aria-selected="true"] > *, .pr-table tbody tr.is-selected > * { background: var(--pr-brand-tint); }
.pr-table tbody tr.is-diff > * { color: var(--pr-text-primary); }
.pr-table tbody tr.is-diff > :first-child { box-shadow: inset 3px 0 0 var(--pr-text-primary); font-weight: 600; }
.pr-table tbody tr.is-dirty > :first-child { box-shadow: inset 3px 0 0 var(--pr-brand-text); }
.pr-table tfoot td, .pr-table tfoot th { font-weight: 600; color: var(--pr-text-primary); background: var(--pr-surface-nested); border-bottom: 0; }

/* Sortable header: the whole label is a button; the glyph shows direction */
.pr-th-sort {
  display: inline-flex; align-items: center; gap: var(--pr-space-xs);
  height: 100%; padding: 0; border: 0; background: none;
  font: inherit; letter-spacing: inherit; color: inherit;
  cursor: pointer;
}
.pr-th-sort:hover { color: var(--pr-text-primary); }
.pr-th-sort:focus-visible { outline: var(--pr-border-focus) solid var(--pr-focus-ring); outline-offset: var(--pr-border-focus); border-radius: var(--pr-radius-xs); }
th[aria-sort="ascending"] .pr-th-sort, th[aria-sort="descending"] .pr-th-sort { color: var(--pr-text-primary); }
.pr-table th.pr-num .pr-th-sort { flex-direction: row-reverse; }

/* Loading rows and the empty row */
.pr-table tr.pr-table__loading td { color: transparent; }
.pr-table tr.pr-table__loading .pr-skel { height: 12px; }
.pr-table td.pr-table__empty { height: auto; padding: 0; white-space: normal; text-align: center; }
.pr-table td.pr-table__empty:first-child { font-weight: 400; }

/* Expanded row content opens in place */
.pr-table td.pr-table__detail { height: auto; padding: var(--pr-space-md) var(--pad); white-space: normal; background: var(--pr-surface-nested); color: var(--pr-text-secondary); }

/* Bulk action bar: inverse ground, a count and actions */
.pr-bulkbar {
  display: flex; align-items: center; gap: var(--pr-space-md);
  padding: var(--pr-space-sm) var(--pr-space-md);
  border-radius: var(--pr-radius-md);
  background: var(--pr-surface-inverse);
  color: var(--pr-text-on-inverse);
  font-size: 0.85rem; font-weight: 500;
}
.pr-bulkbar .pr-btn { color: var(--pr-text-on-inverse); border-color: currentColor; background: none; }
.pr-bulkbar .pr-btn:focus-visible { outline-color: currentColor; }

.pr-table-foot { display: flex; align-items: center; gap: var(--pr-space-sm); margin-top: var(--pr-space-sm); font-size: 0.75rem; color: var(--pr-text-caption); }
.pr-table-foot > :first-child { flex: 1; }

/* Record card (phone pattern A, and record lists) */
.pr-rowcard {
  display: grid; gap: 6px;
  padding: var(--pr-space-md) var(--pr-space-lg);
  border-radius: var(--pr-radius-md);
  border: var(--pr-border-hairline) solid var(--pr-border-subtle);
  background: var(--pr-surface-card);
}
.pr-rowcard.is-diff { box-shadow: inset 3px 0 0 var(--pr-text-primary); }
.pr-rowcard.is-dirty { box-shadow: inset 3px 0 0 var(--pr-brand-text); }
.pr-rowcard[aria-selected="true"], .pr-rowcard.is-selected { background: var(--pr-brand-tint); }
.pr-rowcard__head { display: flex; align-items: center; gap: var(--pr-space-sm); min-height: var(--pr-touch-target); margin: -6px 0; }
.pr-rowcard__title { flex: 1; min-width: 0; font-weight: 600; color: var(--pr-text-primary); }
.pr-rowcard__title a { color: inherit; text-decoration: none; }
/* A card with a link is one target: the title link stretches over it, the row menu sits above. */
.pr-rowcard.is-link { position: relative; }
.pr-rowcard.is-link .pr-rowcard__title a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.pr-rowcard.is-link .pr-rowcard__title a:focus-visible { outline: none; }
.pr-rowcard.is-link:has(.pr-rowcard__title a:focus-visible) { outline: var(--pr-border-focus) solid var(--pr-focus-ring); outline-offset: var(--pr-border-focus); }
.pr-rowcard__menu { position: relative; z-index: 1; display: inline-flex; }
.pr-rowcard__go { flex: none; display: inline-flex; color: var(--pr-text-caption); }
.pr-rowcard__title a:hover { text-decoration: underline; }
.pr-rowcards { display: grid; gap: var(--pr-space-sm); margin: 0; padding: 0; list-style: none; }

/* Key-value list with provenance captions */
.pr-kv { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 6px var(--pr-space-lg); font-size: 0.85rem; margin: 0; }
.pr-kv dt { color: var(--pr-text-caption); }
.pr-kv dd { margin: 0; min-width: 0; color: var(--pr-text-primary); }
.pr-prov { display: block; font-size: 0.75rem; color: var(--pr-text-caption); }

/* Pattern A: the card list exists beside the table and replaces it on a phone */
.pr-rtable__cards { display: none; }

/* Tablet: the lowest-priority column leaves the table (A21). */
@media (max-width: 1024px) {
  .pr-table .pr-col--drop { display: none; }
}

@media (max-width: 768px) {
  .pr-rtable__table { display: none; }
  .pr-rtable__cards { display: grid; }
  .pr-table--dense { --row: var(--pr-touch-target); }
  .pr-th-sort { min-height: var(--pr-touch-target); }
  .pr-bulkbar { flex-wrap: wrap; }
}
