/* Jewelry Stock & Billing — screen styles. Design system "Assay Office" (docs/DESIGN.md,
   SPEC A50). It is software, not a website: a persistent frame (velvet top bar, white menu
   bar under it, breadcrumbs; SPEC A75), page headers with their actions on the right, flat panels on 1 px
   rules, dense ruled grids and status stamps. One action colour (brand navy). The trade
   shows in two places only: the hallmark (the shop's initials in a gold cartouche) and the
   velvet tag tray with its millimetre ruler.
   Icons: Lucide (lucide-static 1.53.0, ISC, parts MIT from Feather; /vendor/lucide.LICENSE.txt).
   The status-line, alert and field-error marks below are CSS masks copied from the same
   Lucide icons (circle-check, circle-alert, triangle-alert, info). */

/* ---------- Fonts (self-hosted, OFL; see /fonts/*.LICENSE.txt) ---------- */
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/public-sans-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/public-sans-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/public-sans-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Bodoni Moda';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/bodoni-moda-latin-600-normal.woff2') format('woff2');
}

/* ---------- Tokens (DESIGN §2; contrast pairs in §3) ---------- */
:root {
  color-scheme: light;

  --velvet: #1C2A4A;
  --velvet-2: #2B3C61;
  --on-velvet: #FFFFFF;
  --on-velvet-muted: #B9C3D3;
  --brand: #24467F;
  --brand-hover: #1B3765;
  --brand-press: #16305A;
  --brand-tint: #E8EEF7;
  --focus: #24467F;
  --gold: #C6A24E;            /* hallmark and tray diamonds only */
  --gold-edge: #9E7F35;       /* receipt-new's split bar only */
  --find-field: #24375C;
  --find-edge: #8494B0;
  --find-placeholder: #AEB9CB;
  --on-velvet-error: #FFD7DD;
  --canvas: #F2F4F7;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --row-hover: #F5F7FA;
  --landed: #DCE6F7;
  --preview-ground: #E3E6EB;
  --ink: #1A2230;
  --ink-2: #3D4757;
  --muted: #5B6577;
  --field-border: #7A8495;
  --line: #DDE1E7;
  --line-strong: #C5CBD4;
  --disabled-fill: #E6E9EE;
  --emerald: #17633F;
  --emerald-tint: #E2F2E9;
  --emerald-edge: #A9D6BF;
  --topaz: #8A4A00;
  --topaz-tint: #FCEFD9;
  --topaz-edge: #EBC48A;
  --garnet: #9E1F33;
  --garnet-tint: #FBE6E9;
  --garnet-edge: #EBA9B4;
  --sapphire: #1F4E9E;
  --sapphire-tint: #E4ECFA;
  --sapphire-edge: #A9C1EA;
  --slate: #465163;
  --slate-tint: #ECEFF3;
  --slate-edge: #C5CBD4;

  --font-ui: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Bodoni Moda', 'Didot', 'Bodoni 72', Georgia, serif;

  --text-xs: 0.75rem;         /* 12 */
  --text-sm: 0.8125rem;       /* 13 */
  --text-md: 0.875rem;        /* 14 */
  --text-lg: 0.9375rem;       /* 15 */
  --text-xl: 1.125rem;        /* 18 */
  --text-2xl: 1.375rem;       /* 22 */
  --text-3xl: 1.375rem;       /* alias; no shared rule uses it */

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --radius-badge: 3px;
  --radius-control: 4px;
  --radius-panel: 6px;
  --radius-menu: 6px;
  --radius-dialog: 8px;
  --radius-tray: 10px;

  --shadow-menu: 0 4px 12px rgba(20, 33, 58, 0.14);
  --shadow-dialog: 0 12px 32px rgba(20, 33, 58, 0.24);
  --shadow-toast: 0 6px 18px rgba(20, 33, 58, 0.18);

  --control-h: 36px;
  --control-h-sm: 28px;
  --row-h: 40px;
  --nav-h: 34px;
  --tap: 36px;

  --topbar-h: 48px;
  /* The main menu bar under the top bar from 64rem (DESIGN §6.6, SPEC A75); both stay sticky. */
  --navbar-h: 44px;
  /* What the sticky header covers at the top of the viewport: both bars from 64rem, the top bar
     alone below (redefined in the 63.99rem block). Scroll padding and sticky columns read it. */
  --header-h: calc(var(--topbar-h) + var(--navbar-h));
  /* The content column (DESIGN §2.7): the page, the breadcrumbs and both header bars share one
     centred edge, at most --content-max wide with at least 24 px either side. */
  --content-max: 80rem;
  --shell-inset: max(24px, calc((100% - var(--content-max)) / 2));
  --side-width: 21rem;
  --gutter: 16px;
  /* Room a docked save bar takes at the viewport foot (DESIGN §7.7): page padding, scroll
     padding and the toast stack all read it, so they move together. */
  --save-bar-reserve: 116px;

  --mark-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");
  --mark-ok: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m16 9-5.5 5.5L8 12'/%3E%3C/svg%3E");
  --mark-warn: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
  --mark-bad: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' x2='12' y1='8' y2='12'/%3E%3Cline x1='12' x2='12.01' y1='16' y2='16'/%3E%3C/svg%3E");
}

@media (pointer: coarse) { :root { --control-h: 44px; --control-h-sm: 36px; --row-h: 48px; --nav-h: 44px; --tap: 44px; } }

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Keyboard focus never lands under the sticky header (one bar or two). */
  scroll-padding-top: calc(var(--header-h) + 8px);
  /* A classic scrollbar's width is reserved on every page, tall or short, so the main
     container (and every @container main layout) is the same width whatever the page height. */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  color: var(--ink);
  line-height: 1.3;
}

h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 20px;
}

h3 {
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 20px;
}

p {
  margin: 0;
}

a {
  color: var(--brand);
  text-decoration-color: rgba(36, 70, 127, 0.4);
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-color: currentColor;
}

img {
  max-width: 100%;
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* iOS zooms on focus below 16 px; keep every text control at 16 px or more (SPEC §8.3). */
input,
select,
textarea {
  font-size: max(16px, 1rem);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

kbd {
  font-family: var(--font-ui);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* On velvet the ring is white (DESIGN §11). */
.app-topbar :focus-visible,
.auth-brand :focus-visible,
.tag-preview :focus-visible {
  outline-color: var(--on-velvet);
}

/* Menus that open from the top bar sit on white again: the navy ring comes back. */
.app-topbar .menu-panel :focus-visible {
  outline-color: var(--focus);
}

/* A heading focused after a screen renders is a reading position, not a control. */
h1[tabindex='-1']:focus {
  outline: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -100px;
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--brand);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--space-2);
}

.muted {
  color: var(--muted);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.center {
  text-align: center;
}

.nowrap {
  white-space: nowrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.stack-lg {
  gap: var(--space-5);
}

.stack > *,
.row > * {
  min-width: 0;
}

.stack > [data-error-slot]:empty,
.page > [data-error-slot]:empty {
  display: none;
}

/* A76: any other empty mount point (a div a page fills later, not a live region) takes no room
   either, so it adds no gap: every screen has the same space under its header. */
:is(.stack, .page, .work-main, .work-side) > div:empty:not([role]):not([aria-live]) {
  display: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
}

.spacer {
  flex: 1 1 auto;
}

/* A disabled control's reason, derived from the state that disables it (DESIGN §7.1). */
.why {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.cell-sub {
  display: block;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.unit {
  color: var(--muted);
}

/* ---------- Icons (DESIGN §5, §7.20) ---------- */
.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.25em;
}

.icon-16,
.btn-sm .icon,
.chip .icon {
  width: 16px;
  height: 16px;
}

.icon-20 {
  width: 20px;
  height: 20px;
}

/* ---------- Application shell (DESIGN §6) ---------- */
/* One column: the top bar, the main menu bar (from 64rem; a fixed drawer below, out of the
   grid) and main. Each spans the full width and insets its content to the content column. */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 100vh;
}

.app-topbar {
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) var(--shell-inset) 0;
  background: var(--velvet);
  color: var(--on-velvet);
}

/* The hallmark lines up with the content edge; the link keeps 8 px of its own on each side.
   From 64rem the brand keeps its width (at most 22rem, ellipsised) and the find box gives way. */
.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  max-width: 22rem;
  height: 40px;
  margin-inline-start: -8px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-control);
  color: inherit;
  text-decoration: none;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hallmark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 24px;
  border: 1.5px solid var(--gold);
  border-radius: 12px / 50%;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  line-height: 12px;
  letter-spacing: 0.02em;
}

.wordmark-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  line-height: 20px;
}

/* Global find: scan a tag, or find a document number or a name (DESIGN §6.4). */
.app-find {
  position: relative;
  flex: 0 1 35rem;
  min-width: 0;
  margin: 0 0 0 var(--space-4);
}

.app-find > .icon {
  position: absolute;
  left: 10px;
  top: 9px;
  color: var(--on-velvet-muted);
  pointer-events: none;
}

.app-find-input {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 40px 0 36px;
  border: 1px solid var(--find-edge);
  border-radius: var(--radius-control);
  background: var(--find-field);
  color: var(--on-velvet);
  font-size: max(16px, 1rem);
  -webkit-appearance: none;
  appearance: none;
}

.app-find-input::placeholder {
  color: var(--find-placeholder);
  opacity: 1;
}

.app-find-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.app-find-input:focus-visible {
  outline-offset: 0;
}

.app-find-key {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 0 6px;
  border: 1px solid var(--find-edge);
  border-radius: var(--radius-badge);
  color: var(--on-velvet-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 18px;
  pointer-events: none;
}

.app-find:focus-within .app-find-key,
.app-find.is-busy .app-find-key {
  display: none;
}

@media (pointer: coarse) {
  .app-find-key {
    display: none;
  }
}

.app-find.is-busy::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 10px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--on-velvet-muted);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.app-find-status {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 41;
  padding: 6px 10px;
  border-radius: var(--radius-control);
  background: var(--velvet);
  box-shadow: var(--shadow-menu);
  color: var(--on-velvet);
  font-size: var(--text-sm);
  line-height: 18px;
}

.app-find-status:empty {
  display: none;
}

.app-find-status.is-error {
  color: var(--on-velvet-error);
  font-weight: 600;
}

.app-find-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  max-height: min(24rem, 60vh);
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-menu);
  background: var(--surface);
  box-shadow: var(--shadow-menu);
  color: var(--ink);
  animation: menu-in 80ms ease-out;
}

.app-find-list [role='option'] {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: var(--radius-control);
  cursor: pointer;
}

.app-find-list [role='option'] .icon {
  color: var(--muted);
}

.app-find-list [role='option']:hover,
.app-find-list [role='option'][aria-selected='true'] {
  background: var(--surface-2);
  box-shadow: inset 2px 0 0 var(--brand);
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--on-velvet);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  list-style: none;
  touch-action: manipulation;
}

.topbar-btn::-webkit-details-marker {
  display: none;
}

.topbar-btn:hover,
.app-new[open] > .topbar-btn,
.app-user[open] > .topbar-btn {
  background: var(--velvet-2);
}

/* The New menu never shrinks: a long shop name gives way instead (the brand ellipsises). */
.app-new {
  flex: none;
}

.app-new > .topbar-btn {
  border-color: var(--find-edge);
}

/* The user menu (from 64rem; the drawer's foot holds the same below): the name, at most 14rem
   (ellipsised), then the chevron, which lines up with the content's right edge. */
.app-user {
  flex: none;
  margin-inline-end: -12px;
}

.app-user > .topbar-btn .topbar-label {
  min-width: 0;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-head {
  display: flex;
  flex-direction: column;
  padding: 8px 12px 6px;
}

.menu-head-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.app-topbar .app-menu-button,
.app-topbar .app-find-toggle {
  display: none;
}

.app-topbar .spacer {
  flex: 1 1 0;
}

@media (pointer: coarse) {
  .topbar-btn {
    height: 44px;
  }
}

/* Disclosure menus: the New menu, the page More menu and ui.menuButton (DESIGN §7.2). */
.menu {
  position: relative;
  display: inline-block;
  min-width: 0;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu[open] > summary .icon-chevron {
  transform: rotate(180deg);
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 15rem;
  max-width: min(20rem, 100vw - 32px);
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-menu);
  background: var(--surface);
  box-shadow: var(--shadow-menu);
  color: var(--ink);
  font-weight: 400;
  white-space: normal;
  animation: menu-in 80ms ease-out;
}

@keyframes menu-in {
  from {
    opacity: 0;
  }
}

.menu-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: var(--ink);
  font-weight: 400;
  line-height: 20px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item .icon {
  margin-top: 1px;
  color: var(--muted);
}

.menu-item > span {
  min-width: 0;
}

.menu-item:hover:not(:disabled) {
  background: var(--surface-2);
  box-shadow: inset 2px 0 0 var(--brand);
}

.menu-item:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.menu-item.is-danger,
.menu-item.is-danger .icon {
  color: var(--garnet);
}

.menu-item:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

/* The screen shown now (the main menu's link, Your account): the drawer's current look. */
.menu-item[aria-current] {
  background: var(--brand-tint);
  box-shadow: inset 2px 0 0 var(--brand);
  color: var(--brand);
  font-weight: 600;
}

.menu-item[aria-current] .icon {
  color: var(--brand);
}

.menu-item-hint,
.menu-item-reason {
  display: block;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.menu-sep {
  height: 1px;
  margin: 4px 0;
  border: 0;
  background: var(--line);
}

@media (pointer: coarse) {
  .menu-item,
  .app-find-list [role='option'] {
    min-height: 44px;
  }
}

/* Main menu (DESIGN §6.6, SPEC A75). From 64rem: a white bar under the top bar, sticky with it,
   holding Dashboard and one disclosure menu per group (.nav-bar). Below 64rem: a drawer of
   grouped links (.nav-groups) with the user block at its foot (.nav-user). Both lists are in
   the markup; each width shows one. */
.app-nav {
  grid-column: 1;
  grid-row: 2;
  background: var(--surface);
}

@media (min-width: 64rem) {
  .app-nav {
    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    z-index: 29;
    padding-inline: var(--shell-inset);
    border-bottom: 1px solid var(--line);
  }

  .app-nav .nav-groups,
  .app-nav .nav-user {
    display: none;
  }
}

/* The items' text lines up with the content edge; their 12 px padding hangs outside it. */
.nav-bar {
  display: flex;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
  margin: 0 -12px;
  padding: 0;
  list-style: none;
}

.nav-bar-item,
.nav-menu {
  display: flex;
}

.nav-top {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: var(--navbar-h);
  padding: 0 12px;
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  list-style: none;
  touch-action: manipulation;
}

.nav-top::-webkit-details-marker {
  display: none;
}

.nav-top .icon-chevron {
  color: var(--muted);
}

/* Open (or hovered) is a grey fill; current is a navy word with a navy rule at the bar's foot,
   the tab look (DESIGN §7.12). An open menu of the current group shows both. */
.nav-top:hover,
.nav-menu[open] > .nav-top {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-top[aria-current] {
  color: var(--brand);
  box-shadow: inset 0 -2px 0 var(--brand);
}

.nav-top[aria-current] .icon-chevron {
  color: var(--brand);
}

.nav-top:focus-visible {
  outline-offset: -2px;
}

/* A group's panel opens under its own button, left-aligned (ui.js keeps it inside the viewport). */
.nav-menu > .menu-panel {
  left: 0;
  right: auto;
  top: calc(100% + 1px);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.nav-groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 12px;
}

.nav-group-label {
  padding: 8px 12px 4px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 16px;
}

.nav-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--nav-h);
  padding: 0 12px;
  border-radius: var(--radius-control);
  color: var(--ink-2);
  text-decoration: none;
}

.nav-link .icon {
  color: var(--muted);
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-link[aria-current] {
  background: var(--brand-tint);
  color: var(--brand);
  font-weight: 600;
}

.nav-link[aria-current] .icon {
  color: var(--brand);
}

.nav-link[aria-current]::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--brand);
}

.nav-user {
  margin-top: auto;
  padding: 12px 12px 0;
  border-top: 1px solid var(--line);
}

.nav-user-name {
  font-weight: 600;
}

.nav-user-role {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.nav-user-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-top: var(--space-2);
}

.nav-link-quiet {
  color: var(--brand);
}

.nav-link-quiet[aria-current] {
  font-weight: 600;
}

.app-scrim {
  position: fixed;
  inset: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) 0 0;
  z-index: 35;
  background: rgba(20, 33, 58, 0.45);
}

/* The content column (DESIGN §2.7, §6.8): main's content box is at most --content-max wide and
   centred, so every @container main rule measures the column the page really gets. */
.app-main {
  grid-column: 1;
  grid-row: 3;
  min-width: 0;
  padding: 16px var(--shell-inset) 48px;
  container: main / inline-size;
}

.app-main:focus {
  outline: none;
}

/* Breadcrumbs (DESIGN §6.7) */
.app-crumbs {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.app-crumbs ol {
  display: flex;
  flex-wrap: wrap;
  /* A76: a link crumb's 24 px touch box sits on the same line as its neighbours. */
  align-items: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-crumbs li + li::before {
  content: '/';
  margin: 0 4px;
  color: var(--line-strong);
}

.app-crumbs a {
  color: var(--muted);
  text-decoration-color: currentColor;
}

.app-crumbs [aria-current] {
  color: var(--ink-2);
}

/* A crumb is the way back to its list on a phone: at least a 24 px target (WCAG 2.5.8). */
@media (pointer: coarse) {
  .app-crumbs a {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
  }
}

.page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 90rem;
  min-width: 0;
}

.bare-main,
.print-main {
  min-height: 100vh;
}

.bare-main:focus,
.print-main:focus {
  outline: none;
}

@media (max-width: 63.99rem) {
  :root {
    --header-h: var(--topbar-h);
  }

  .app-topbar {
    gap: 4px;
    padding-inline: 4px;
  }

  .app-brand {
    flex: 1 1 auto;
    min-width: 0;
    margin-inline-start: 0;
    padding: 0 8px;
  }

  /* Below 64rem the user block is the drawer's foot (DESIGN §6.1 phone frame). */
  .app-topbar .app-user {
    display: none;
  }

  .app-topbar .app-menu-button,
  .app-topbar .app-find-toggle {
    display: inline-flex;
  }

  /* The brand keeps its 22rem cap (its link and focus ring stay its own size); Find and New
     sit at the right edge of the bar at every width below 64rem (DESIGN §6.1 phone frame). */
  .app-topbar .app-find-toggle {
    margin-inline-start: auto;
  }

  .topbar-btn {
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .app-new > .topbar-btn {
    border-color: transparent;
  }

  /* Hidden for the eye only: the label still names the icon button. */
  .topbar-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .topbar-btn .icon-chevron,
  .app-topbar .spacer {
    display: none;
  }

  .app-find {
    display: none;
    margin: 0;
  }

  .app-find.is-open {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    padding: 8px var(--gutter);
    background: var(--velvet);
  }

  .app-find.is-open > .icon {
    left: calc(var(--gutter) + 10px);
    top: 17px;
  }

  .app-find.is-open .app-find-key {
    display: none;
  }

  .app-find.is-open.is-busy::after {
    right: calc(var(--gutter) + 12px);
    top: 18px;
  }

  .app-find.is-open .app-find-status,
  .app-find.is-open .app-find-list {
    left: var(--gutter);
    right: var(--gutter);
  }

  .app-nav {
    position: fixed;
    z-index: 40;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: min(288px, 85vw);
    overflow-y: auto;
    padding: 12px 8px;
    box-shadow: var(--shadow-dialog);
    scrollbar-width: thin;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 160ms ease-out, visibility 0s linear 160ms;
  }

  .app-nav.is-open {
    transform: none;
    visibility: visible;
    transition: transform 160ms ease-out;
  }

  .app-nav .nav-bar {
    display: none;
  }

  .app-main {
    padding: 12px var(--gutter) max(48px, env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Page header (DESIGN §7.3) ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 24px;
  min-width: 0;
}

.page-header-text {
  flex: 1 1 20rem;
  min-width: 0;
}

.page-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-width: 0;
}

/* Several status chips wrap as one group (ui.pageHeader): all beside the title or all on the
   next line; inside the group they wrap only when the group is wider than the row. */
.page-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-width: 0;
}

.page-title {
  min-width: 0;
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 28px;
}


.page-subtitle {
  margin-top: 2px;
  color: var(--muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

@container main (max-width: 40rem) {
  .page-title {
    font-size: 1.25rem;
    line-height: 26px;
  }

  /* More is an icon button here; its label stays for assistive technology. */
  .page-actions .menu-more .menu-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .page-actions .menu-more .icon-chevron {
    display: none;
  }

  /* A76: the actions take the row under the title and their buttons fill each row they wrap into,
     so a phone never shows a ragged row ("Print, Modify" over a lone "Record receipt"); More
     keeps its icon size. */
  .page-actions {
    flex: 1 1 100%;
  }

  .page-actions > .btn {
    flex: 1 1 auto;
  }
}

/* ---------- Panels (DESIGN §7.4) ---------- */
.panel { --panel-pad: 16px; min-width: 0; padding: var(--panel-pad); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
@container main (max-width: 30rem) { .panel { --panel-pad: 12px; } }
.panel-flush { --panel-pad: 0px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-height: 48px; margin: calc(var(--panel-pad) * -1) calc(var(--panel-pad) * -1) 16px; padding: 6px 16px; border-bottom: 1px solid var(--line); }
.panel-flush > .panel-head { margin: 0; }
.panel > .table-wrap, .panel > .stack > .table-wrap { width: calc(100% + 2 * var(--panel-pad)); max-width: none; margin-inline: calc(var(--panel-pad) * -1); }
.panel > .panel-head + .table-wrap { margin-top: -16px; }
/* A flush panel's head has no bottom margin to take back: the grid starts under its rule. */
.panel-flush > .panel-head + .table-wrap { margin-top: 0; }
.panel > .table-wrap:first-child { margin-top: calc(var(--panel-pad) * -1); border-radius: 5px 5px 0 0; }
.panel > .table-wrap:last-child, .panel > .stack:last-child > .table-wrap:last-child { margin-bottom: calc(var(--panel-pad) * -1); border-radius: 0 0 5px 5px; }

.panel-head > * {
  min-width: 0;
}

/* A padded panel's title lines up with its content at either panel padding (16 or 12 px). */
.panel:not(.panel-flush) > .panel-head {
  padding-inline: var(--panel-pad);
}

/* ---------- Summary band (DESIGN §7.5) ---------- */
.summary-band { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); margin: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
/* Rules on each cell's right and bottom (the band's edge clips the outer ones), so a short last
   row leaves a closed empty area, never a rule that stops part-way. Each cell is a size
   container (a definite grid track, so containment cannot collapse it) for the lead step below. */
.summary-band > div { min-width: 0; padding: 10px 16px; box-shadow: 1px 1px 0 var(--line); container: band-cell / inline-size; }

.summary-band dt {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.summary-band dd {
  margin: 2px 0 0;
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 20px;
  overflow-wrap: break-word;
}

.summary-band dd.is-lead {
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 24px;
}

/* A figure is one word: never split inside it ($1,234,567.89 never becomes "…567.8" / "9"). */
.summary-band .figure {
  overflow-wrap: normal;
}

/* A seven-figure amount with its Dr/Cr suffix ("$1,234,567.89 Cr") is 9.26em wide in Public Sans
   tabular figures: 166.6 px at 18, 138.9 at 15, 129.6 at 14. A cell whose content box is 10.75rem
   (172 px) or less steps its lead figure down to the 15/700 stacked-lead size (5 per row at 1240,
   6 per row at 1240 and 1366), so the figure and its suffix stay on one line. */
@container band-cell (max-width: 10.75rem) {
  .summary-band dd.is-lead {
    font-size: var(--text-lg);
    line-height: 20px;
  }
}

/* On a phone (main 30rem or narrower) the track minimum is 10rem (2 per row from 320 to 480 px
   wide, never 3 cramped cells) and a cell keeps its 16 px left inset (aligned with the title and
   the panels) but only 8 px on the right. In a cell whose content box is then under 8.75rem
   (139 px at 360) every value steps to 14/20 (the lead keeps 700, so it still leads), and
   "$1,234,567.89 Cr" (129.6 px) stays on one line. */
@container main (max-width: 30rem) {
  .summary-band { grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); }
  .summary-band > div { padding-inline: 16px 8px; }

  @container band-cell (max-width: 8.74rem) {
    .summary-band dd:not(.note) {
      font-size: var(--text-md);
      line-height: 20px;
    }
  }
}

/* Between a phone and the two-column layout: six cells 3 + 3, never 4 + 2 or 5 + 1; exactly
   five cells 3 + 2 on six tracks (cells 1 to 3 span 2, cells 4 and 5 span 3), never 4 + 1. */
@container main (min-width: 30rem) and (max-width: 57.99rem) {
  .summary-band:has(> div:nth-child(6)) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-band:has(> div:nth-child(5):last-child) {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .summary-band:has(> div:nth-child(5):last-child) > div {
    grid-column: span 2;
  }

  .summary-band:has(> div:nth-child(5):last-child) > div:nth-child(n + 4) {
    grid-column: span 3;
  }
}

.summary-band dd > a {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.summary-band dd.note {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: 18px;
}

/* A value with a chip wraps as a row: when the chip drops under the figure it lines up with it. */
.summary-band dd:has(> .chip) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

/* ---------- Facts (DESIGN §7.6) ---------- */
.facts {
  display: grid;
  gap: 6px;
  margin: 0;
  container: facts / inline-size;
}

/* A76: the label column is 38 % of a narrow panel but never more than 13rem, so on a wide panel
   the value stays beside its label. */
.facts > div {
  display: grid;
  grid-template-columns: minmax(7rem, min(38%, 13rem)) minmax(0, 1fr);
  gap: 12px;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
}

@container facts (max-width: 18rem) {
  .facts > div {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
}

/* ---------- Toolbars, filters, list meta bar, segmented groups (DESIGN §7.8) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  min-width: 0;
}

.toolbar > * {
  min-width: 0;
}

.panel-flush > .toolbar, .panel-flush > .filters { padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.panel-flush > .toolbar .field { flex: 1 1 9.5rem; max-width: 14rem; }
.panel-flush > .toolbar .field.grow { flex: 1 1 16rem; max-width: none; }
.filters > summary { display: flex; align-items: center; gap: 6px; min-height: var(--control-h); font-weight: 600; cursor: pointer; }
.filters[open] > summary { margin-bottom: 12px; }
.list-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-height: 44px; padding: 4px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.list-meta.has-selection { background: var(--brand-tint); color: var(--brand); }
.list-meta.has-selection .list-count { font-weight: 600; }
/* A toolbar that ends its panel leaves the bottom rule to the panel's own border. */
.panel-flush > .toolbar:last-child, .panel-flush > .filters:last-child { border-bottom: 0; }

.filters > summary::-webkit-details-marker {
  display: none;
}

.filters > summary {
  list-style: none;
}

.filters > summary::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  margin: 0 4px 0 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.filters[open] > summary::before {
  transform: rotate(45deg);
}

.segmented {
  position: relative;
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.segmented > .btn {
  flex: none;
  margin-left: -1px;
  border-radius: 0;
  white-space: nowrap;
}

.segmented > .btn:first-child {
  margin-left: 0;
  border-radius: var(--radius-control) 0 0 var(--radius-control);
}

.segmented > .btn:last-child {
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
}

.segmented > .btn:only-child {
  border-radius: var(--radius-control);
}

.segmented > .btn[aria-pressed='true'] {
  position: relative;
  z-index: 1;
  background: var(--brand);
  border-color: var(--brand);
  color: #FFFFFF;
}

.segmented > .btn:focus-visible {
  position: relative;
  z-index: 2;
  outline-offset: -2px;
}

/* ---------- Pager (DESIGN §7.9) ---------- */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pager-label {
  color: var(--muted);
  font-size: var(--text-sm);
}

/* ---------- Buttons (DESIGN §7.1) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  max-width: 100%;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  overflow-wrap: break-word;
  cursor: pointer;
  touch-action: manipulation;
}

.table .btn {
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn-primary:active {
  background: var(--brand-press);
  border-color: var(--brand-press);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--field-border);
  color: var(--ink);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--ink-2);
}

.btn-danger {
  background: var(--garnet);
  border-color: var(--garnet);
  color: #FFFFFF;
}

.btn-danger:hover {
  background: #861A2B;
  border-color: #861A2B;
}

/* A destructive action is never the loudest thing in a header. */
.page-actions .btn-danger:not(:disabled):not([aria-disabled='true']),
.panel-head .btn-danger:not(:disabled):not([aria-disabled='true']) {
  background: var(--surface);
  border-color: var(--garnet);
  color: var(--garnet);
}

.page-actions .btn-danger:not(:disabled):not([aria-disabled='true']):hover,
.panel-head .btn-danger:not(:disabled):not([aria-disabled='true']):hover {
  background: var(--garnet-tint);
}

.btn-link {
  min-height: var(--control-h);
  padding-inline: 4px;
  color: var(--brand);
  text-decoration: underline;
  text-decoration-color: rgba(36, 70, 127, 0.4);
  text-underline-offset: 3px;
}

.btn-link:hover {
  text-decoration-color: currentColor;
}

.btn-sm {
  min-height: var(--control-h-sm);
  padding: 0 10px;
  font-size: var(--text-sm);
}

.btn-link.btn-sm {
  padding-inline: 4px;
}

.btn-icon {
  width: var(--control-h);
  padding: 0;
}

.btn-block {
  width: 100%;
}

/* Disabled keeps a legible label (4.83:1) and says so by its dashed edge, never by opacity. */
.btn:disabled,
.btn[aria-disabled='true'] {
  background: var(--disabled-fill);
  border: 1px dashed var(--field-border);
  color: var(--muted);
  cursor: not-allowed;
}

.btn-link:disabled,
.btn-link[aria-disabled='true'] {
  background: none;
  border-color: transparent;
  text-decoration: none;
}

.btn[aria-busy='true'] {
  cursor: progress;
}

/* ---------- Form controls (DESIGN §7.13) ---------- */
.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px 16px;
  min-width: 0;
}

@container main (min-width: 40rem) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container main (min-width: 64rem) {
  .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.form-grid > * {
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.form-narrow {
  max-width: 28rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* A76: a form's own action row stays in view while the form is taller than the screen: it sticks
   to the viewport foot on a white strip (in a panel, the panel's white; the panel's bottom padding
   still ends the panel when it is not stuck). */
form > .form-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-bottom: -12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  background: var(--surface);
}

/* A76: a single-column form page (its form is a column of panels: item, party) stops at 60rem, so
   no field runs wider than a reading line; it stays on the content column's left edge. Its action
   row is the form's footer: a white bar with the panel edge, the same whether stuck or not. */
.page:has(> form.stack > .panel) {
  max-width: 60rem;
}

.page > form.stack > .form-actions {
  margin: 0;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom, 0px));
  border: 1px solid var(--line);
  border-radius: 6px;
}

@container main (max-width: 40rem) {
  /* On a phone the form's buttons share the row in full (the reason line below them). */
  .form-actions > .btn {
    flex: 1 1 auto;
  }
}

/* Focus never lands under a stuck action row (observation 0319), and toasts never cover it on a
   phone. Weighs (0,1,1) and comes before the save bar's reserve, which wins where both apply. */
:where(html):has(form > .form-actions) {
  scroll-padding-bottom: 88px;
}

@media (max-width: 40rem) {
  html:has(.page > form.stack > .form-actions) .toast-region {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

/* A76: a visible file chooser is a secondary button, the same on every screen (items import,
   packing list, Diamond rates); 44 px tall on touch. */
input[type='file'] {
  max-width: 100%;
  min-height: var(--control-h);
  color: var(--muted);
}

input[type='file']::file-selector-button {
  min-height: var(--control-h);
  margin-right: 12px;
  padding: 0 14px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
}

input[type='file']:not(:disabled)::file-selector-button:hover {
  background: var(--surface-2);
  border-color: var(--ink-2);
}

input[type='file']:disabled::file-selector-button {
  background: var(--disabled-fill);
  border-style: dashed;
  color: var(--muted);
  cursor: not-allowed;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-label {
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 18px;
}

.field-req {
  color: var(--muted);
  font-weight: 400;
}

.field-hint {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--garnet);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 18px;
}

.field-error::before {
  content: '';
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  background: currentColor;
  -webkit-mask: var(--mark-bad) center / contain no-repeat;
  mask: var(--mark-bad) center / contain no-repeat;
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--control-h);
  padding: 6px 10px;
  border: 1px solid var(--field-border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: max(16px, 1rem);
  line-height: 1.25;
}

.textarea {
  min-height: 5rem;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 30px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%233D4757' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--ink-2);
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--brand);
  outline-offset: 0;
}

.input[aria-invalid='true'],
.select[aria-invalid='true'],
.textarea[aria-invalid='true'] {
  border: 2px solid var(--garnet);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background-color: var(--disabled-fill);
  border-style: dashed;
  color: var(--muted);
  cursor: not-allowed;
}

.input[readonly],
.textarea[readonly] {
  background: var(--surface-2);
}

.input.num {
  text-align: right;
}

.input-affix {
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.input-affix .input {
  flex: 1 1 auto;
  border-radius: 0;
}

.input-affix .input:first-child {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.input-affix .input:last-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.affix {
  display: flex;
  align-items: center;
  /* A unit never shrinks or wraps ('mm' on one line): the input beside it gives way instead. */
  flex: none;
  padding: 0 12px;
  border: 1px solid var(--field-border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.affix:first-child {
  border-right: 0;
  border-radius: 4px 0 0 4px;
}

.affix:last-child {
  border-left: 0;
  border-radius: 0 4px 4px 0;
}

.check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 0 10px;
  min-width: 0;
}

.check input[type='checkbox'],
.check input[type='radio'] {
  width: 18px;
  height: 18px;
  margin: calc((var(--control-h) - 18px) / 2) 0;
  accent-color: var(--brand);
}

.check label {
  display: flex;
  align-items: center;
  min-height: var(--control-h);
  padding: 4px 0;
}

.check .field-hint,
.check .field-error {
  grid-column: 2;
}

@media (pointer: coarse) {
  .check input[type='checkbox'],
  .check input[type='radio'] {
    width: 22px;
    height: 22px;
    margin: calc((var(--control-h) - 22px) / 2) 0;
  }
}

/* ---------- Alerts (DESIGN §7.15) ---------- */
.alert {
  position: relative;
  padding: 10px 16px 10px 44px;
  border: 1px solid var(--sapphire-edge);
  border-left: 4px solid var(--sapphire);
  border-radius: 4px;
  background: var(--sapphire-tint);
  color: var(--ink);
}

.alert::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 11px;
  width: 18px;
  height: 18px;
  background: var(--sapphire);
  -webkit-mask: var(--mark-info) center / contain no-repeat;
  mask: var(--mark-info) center / contain no-repeat;
}

.alert-warn {
  border-color: var(--topaz-edge);
  border-left-color: var(--topaz);
  background: var(--topaz-tint);
}

.alert-warn::before {
  background: var(--topaz);
  -webkit-mask-image: var(--mark-warn);
  mask-image: var(--mark-warn);
}

.alert-bad {
  border-color: var(--garnet-edge);
  border-left-color: var(--garnet);
  background: var(--garnet-tint);
}

.alert-bad::before {
  background: var(--garnet);
  -webkit-mask-image: var(--mark-bad);
  mask-image: var(--mark-bad);
}

.alert-ok {
  border-color: var(--emerald-edge);
  border-left-color: var(--emerald);
  background: var(--emerald-tint);
}

.alert-ok::before {
  background: var(--emerald);
  -webkit-mask-image: var(--mark-ok);
  mask-image: var(--mark-ok);
}

.alert:focus {
  outline: none;
}

.alert:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.alert-text {
  color: var(--ink);
  font-weight: 600;
}

.alert-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.alert-list {
  margin: 6px 0 0;
  padding-left: 24px;
}

/* ---------- Data grid (DESIGN §7.10) ---------- */
.table-wrap { position: relative; max-width: 100%; overflow-x: auto; container: grid / inline-size;
  background: linear-gradient(90deg, var(--surface) 30%, rgba(255,255,255,0)) left / 24px 100% no-repeat local,
    linear-gradient(270deg, var(--surface) 30%, rgba(255,255,255,0)) right / 24px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(20,33,58,.18), transparent) left / 10px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(20,33,58,.18), transparent) right / 10px 100% no-repeat scroll, var(--surface); }
.table-wrap:focus-visible { outline-offset: -2px; }
.table { width: 100%; border-collapse: collapse; overflow-wrap: break-word; font-variant-numeric: tabular-nums; }
.table th, .table td { height: var(--row-h); padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 16px; }
.table th:last-child, .table td:last-child { padding-right: 16px; }
.table thead th { height: 36px; padding-block: 9px; background: var(--surface-2); border-bottom-color: var(--line-strong); color: var(--muted); font-size: 12px; font-weight: 600; line-height: 16px; white-space: nowrap; vertical-align: bottom; }
.table th.num, .table td.num { text-align: right; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--row-hover); }
.table tbody tr[aria-selected='true'], .table tbody tr:has(> td[data-pick] input:checked) { background: var(--brand-tint); box-shadow: inset 3px 0 0 var(--brand); }
.table tfoot td { border-top: 1px solid var(--ink-2); border-bottom: 0; font-weight: 700; }
.table a { font-weight: 600; }
.table td[data-pick], .table th[data-pick] { width: 40px; }
.table td[data-pick] input, .table th[data-pick] input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--brand); }
.table-wrap[data-scroll] .table td, .table-wrap[data-scroll] .table th { white-space: nowrap; }
/* A long-text column of a report grid (a name, a reference; dataTable wrap: true or class wrap-text)
   wraps at 10-16rem, so a 60-character name cannot push the figures out of view; figures and codes
   stay on one line. */
.table-wrap[data-scroll] .table :is(td, th).wrap-text { min-width: 10rem; max-width: 16rem; white-space: normal; }
.table-wrap[data-scroll] .table > * > tr > :first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: inset -1px 0 0 var(--line); }
.table-wrap[data-scroll] .table > thead > tr > :first-child { background: var(--surface-2); }
@keyframes landed { from { background: var(--landed); } to { background: transparent; } }
.is-landed { animation: landed 1.4s ease-out; }
/* Narrow table (36-52rem): secondary columns hide, and the first and last SHOWN cells of a row take
   the 16 px grid inset that :first-child / :last-child gave a hidden cell (a grid whose first
   column is narrow-hidden still lines up with its panel title and with every other grid). The
   path is in :where() so the rules weigh (0,2,0): above `.table td` (0,1,1), below any page rule
   that stacks a grid at this width and zeroes its cell padding. A wide grid (data-stack='wide')
   has no narrow band: it is stacked here, every column shown. The :where(:not(…)) that leaves it
   out adds no weight, so a stack: true grid matches these rules exactly as before. */
@container grid (36rem < width <= 52rem) {
  .table-wrap[data-stack]:where(:not([data-stack='wide'])) [data-narrow='hide'] { display: none; }
  :where(.table-wrap[data-stack]:not([data-stack='wide']) > .table > * > tr) > :not([data-narrow='hide']):not(:not([data-narrow='hide']) ~ *) { padding-left: 16px; }
  :where(.table-wrap[data-stack]:not([data-stack='wide']) > .table > * > tr) > :not([data-narrow='hide']):not(:has(~ :not([data-narrow='hide']))) { padding-right: 16px; }
}

/* Stacked records: ONE indivisible block (observations 0441/0443/0444). Never split it. */
@container grid (max-width: 36rem) {
  .table-wrap[data-stack] > .table,
  .table-wrap[data-stack] > .table > thead,
  .table-wrap[data-stack] > .table > tbody,
  .table-wrap[data-stack] > .table > tfoot,
  .table-wrap[data-stack] > .table > * > tr > th,
  .table-wrap[data-stack] > .table > * > tr > td { display: block; }
  .table-wrap[data-stack] > .table > * > tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr)); gap: 6px 16px; position: relative; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .table-wrap[data-stack] > .table > tbody > tr:last-child { border-bottom: 0; }
  .table-wrap[data-stack] > .table > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-wrap[data-stack] > .table > * > tr > td { height: auto; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
  .table-wrap[data-stack] > .table > * > tr > td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 16px; }
  .table-wrap[data-stack] > .table > * > tr > td[data-stack-hide] { display: none; }
  .table-wrap[data-stack] > .table > * > tr > td[data-lead] { order: -1; grid-column: 1 / -1; padding-right: 2.5rem; font-size: 15px; font-weight: 600; }
  .table-wrap[data-stack] > .table > * > tr > td[data-lead] .cell-sub { font-weight: 400; }
  .table-wrap[data-stack] > .table > * > tr > td[data-span='full'] { grid-column: 1 / -1; }
  .table-wrap[data-stack] > .table > * > tr > td:is([data-lead], [data-pick], [data-label=''])::before { content: none; }
  .table-wrap[data-stack] > .table > * > tr > td[data-pick] { position: absolute; top: 10px; right: 16px; width: auto; }
  .table-wrap[data-stack] > .table > * > tr > td:empty { display: none; }
  .table-wrap[data-stack] > .table > * > tr > td .chip { max-width: 100%; height: auto; min-height: 22px; padding-block: 2px; line-height: 16px; white-space: normal; }
}

/* Wide stacking (dataTable stack: 'wide', DESIGN §7.10): the block above, declaration for
   declaration, for a wide grid up to 52rem, so it is stacked in the 36-52rem band where a
   stack: true grid is a narrow table. CSS cannot give one block two breakpoints by selector, so
   the two blocks stand side by side; only the breakpoint and [data-stack='wide'] differ, and
   tests/frontend.test.js fails on any other difference. Edit both together, never one. */
@container grid (max-width: 52rem) {
  .table-wrap[data-stack='wide'] > .table,
  .table-wrap[data-stack='wide'] > .table > thead,
  .table-wrap[data-stack='wide'] > .table > tbody,
  .table-wrap[data-stack='wide'] > .table > tfoot,
  .table-wrap[data-stack='wide'] > .table > * > tr > th,
  .table-wrap[data-stack='wide'] > .table > * > tr > td { display: block; }
  .table-wrap[data-stack='wide'] > .table > * > tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr)); gap: 6px 16px; position: relative; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .table-wrap[data-stack='wide'] > .table > tbody > tr:last-child { border-bottom: 0; }
  .table-wrap[data-stack='wide'] > .table > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td { height: auto; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 16px; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td[data-stack-hide] { display: none; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td[data-lead] { order: -1; grid-column: 1 / -1; padding-right: 2.5rem; font-size: 15px; font-weight: 600; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td[data-lead] .cell-sub { font-weight: 400; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td[data-span='full'] { grid-column: 1 / -1; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td:is([data-lead], [data-pick], [data-label=''])::before { content: none; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td[data-pick] { position: absolute; top: 10px; right: 16px; width: auto; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td:empty { display: none; }
  .table-wrap[data-stack='wide'] > .table > * > tr > td .chip { max-width: 100%; height: auto; min-height: 22px; padding-block: 2px; line-height: 16px; white-space: normal; }
}

.table-wrap[aria-busy='true'] {
  cursor: progress;
}

/* ---------- Status badges (DESIGN §7.11; the mark's shape carries the kind) ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 7px; border: 1px solid; border-radius: 3px; font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap; vertical-align: middle; }
.chip::before { content: ''; flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-ok { color: var(--emerald); background: var(--emerald-tint); border-color: var(--emerald-edge); }
.chip-warn { color: var(--topaz); background: var(--topaz-tint); border-color: var(--topaz-edge); }
.chip-warn::before { border-radius: 1px; transform: rotate(45deg); }
.chip-bad { color: var(--garnet); background: var(--garnet-tint); border-color: var(--garnet-edge); }
.chip-bad::before { width: 8px; height: 2px; border-radius: 0; }
.chip-info { color: var(--sapphire); background: var(--sapphire-tint); border-color: var(--sapphire-edge); }
.chip-neutral { color: var(--slate); background: var(--slate-tint); border-color: var(--slate-edge); }
.chip-neutral::before { background: transparent; border: 1.5px solid currentColor; }
.page-title-row .chip { height: 24px; font-size: 13px; }

/* ---------- Tabs and sub-navigation (DESIGN §7.12) ---------- */
.tabs {
  position: relative;
  display: flex;
  overflow-x: auto;
  /* The tabs' -1px bottom margin is a 1 px vertical overflow: never a vertical scrollbar. */
  overflow-y: hidden;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.tab {
  display: inline-flex;
  align-items: center;
  flex: none;
  min-height: 40px;
  margin-bottom: -1px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover {
  color: var(--ink);
}

.tab[aria-selected='true'],
.tab[aria-current] {
  border-bottom-color: var(--brand);
  color: var(--brand);
}

.tab:focus-visible {
  outline-offset: -2px;
}

@media (pointer: coarse) {
  .tab {
    min-height: 44px;
  }
}

.subnav-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
}

.subnav-group {
  display: none;
  padding: 8px 10px 2px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 16px;
}

/* 58rem (928 px) of main: at a 1240 viewport main is 945 px once the scrollbar gutter is reserved
   (1240 - 232 rail - 48 padding - 15), so the two-column layouts of DESIGN §2.7 still hold there. */
@container main (min-width: 58rem) {
  .subnav-layout {
    grid-template-columns: 13.5rem minmax(0, 1fr);
    align-items: start;
  }

  .subnav-layout > .tabs {
    position: sticky;
    top: calc(var(--header-h) + 16px);
    flex-direction: column;
    overflow: visible;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
  }

  .subnav-layout > .tabs .tab {
    min-height: 34px;
    margin: 0;
    padding: 0 10px;
    border: 0;
    border-radius: 4px;
    color: var(--ink-2);
    font-weight: 400;
    white-space: normal;
  }

  .subnav-layout > .tabs .tab:hover {
    background: var(--surface-2);
    color: var(--ink);
  }

  .subnav-layout > .tabs .tab[aria-selected='true'],
  .subnav-layout > .tabs .tab[aria-current] {
    background: var(--brand-tint);
    color: var(--brand);
    font-weight: 600;
  }

  .subnav-layout > .tabs .subnav-group {
    display: block;
  }
}

/* A76: the shell's loading line while a screen's code arrives (app.js, after 250 ms). */
.page-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 0;
  color: var(--muted);
}

.page-loading::before {
  content: '';
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

/* ---------- Empty state (DESIGN §7.16) ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 24px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.panel .empty,
.table-wrap .empty,
.dialog .empty {
  border: 0;
  border-radius: 0;
  background: none;
}

/* A76: inside a padded panel the panel's padding is the inset, so an empty state adds none of its
   own and starts on the panel title's edge (in a grid it keeps its 16 px: grids bleed to the
   panel edge). Weighs (0,1,0): a page's own empty-state rule still wins. */
:where(.panel:not(.panel-flush)) .empty:where(:not(.table-wrap .empty)) {
  padding: 8px 0;
}

.empty-icon {
  width: 24px;
  height: 24px;
  color: var(--muted);
}

.empty-title {
  color: var(--ink);
  font-size: var(--text-md);
  font-weight: 600;
}

.empty-body {
  max-width: 40rem;
  color: var(--muted);
}

.empty-action {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 4px;
}

/* ---------- Work layout, totals and the save bar (DESIGN §7.7, §8.2) ---------- */
.work {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.work > * {
  align-content: start;
}

.work-main,
.work-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

@container main (min-width: 58rem) {
  .work {
    grid-template-columns: minmax(0, 1fr) var(--side-width);
  }

  .work-side.is-sticky {
    position: sticky;
    top: calc(var(--header-h) + 16px);
  }
}

.totals-list {
  display: grid;
  gap: 4px;
  margin: 0;
}

.totals-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.totals-list dt {
  color: var(--muted);
}

.totals-list dd {
  margin: 0;
  white-space: nowrap;
}

.totals-list .is-total {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--ink-2);
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 24px;
}

.totals-list .is-total dt {
  color: var(--ink);
}

.save-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-top: 16px; }
.save-bar .btn-primary { width: 100%; min-height: 44px; }
.save-bar-summary { display: none; }
.save-bar .why { max-height: 36px; overflow-y: auto; line-height: 18px; overflow-wrap: anywhere; }
/* The viewport widths at which the save bar can dock (main under 58rem). From 64rem main is at
   least 1024 - 48 padding - a 17 px scrollbar = 959 px, so it docks only below 64rem, where
   main is the viewport less 32 px of padding and the scrollbar: under 960 + 19 px, 61.24rem.
   A media query, because the toast region lives outside main. */
@media (max-width: 61.24rem) {
  html:has(.save-bar) { scroll-padding-bottom: var(--save-bar-reserve); }
  /* Toasts stack above a docked bar and never cover Save (DESIGN §7.7: never a toast host). */
  html:has(.save-bar) .toast-region { bottom: calc(var(--save-bar-reserve) + env(safe-area-inset-bottom, 0px)); }
}
@container main (max-width: 57.99rem) {
  .save-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; margin: 0; padding: 8px 16px max(8px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line-strong); box-shadow: 0 -2px 8px rgba(20, 33, 58, 0.08); }
  .save-bar-summary { display: block; font-size: 15px; font-weight: 700; line-height: 20px; }
  .save-bar .btn-primary { width: auto; }
  .save-bar .why { grid-column: 1 / -1; }
  .page:has(.save-bar) { padding-bottom: var(--save-bar-reserve); }
}

/* ---------- Dialog (DESIGN §7.17) ---------- */
.dialog {
  width: min(32rem, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-dialog);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-dialog);
}

.dialog::backdrop {
  background: rgba(20, 33, 58, 0.45);
}

.dialog[open] {
  animation: dialog-in 120ms ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

.dialog-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 24px;
}

.dialog-form.is-danger .dialog-title::before {
  content: '';
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  background: var(--garnet);
  -webkit-mask: var(--mark-bad) center / contain no-repeat;
  mask: var(--mark-bad) center / contain no-repeat;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dialog-body ul {
  margin: 0;
  padding-left: 24px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 30rem) {
  .dialog-form {
    padding: 20px 16px;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .btn {
    width: 100%;
  }
}

/* ---------- Toasts (DESIGN §7.18) ---------- */
.toast-region {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: min(24rem, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--sapphire);
  border-radius: var(--radius-dialog);
  background: var(--surface);
  box-shadow: var(--shadow-toast);
  color: var(--ink);
  pointer-events: auto;
  animation: toast-in 160ms ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.toast-ok {
  border-left-color: var(--emerald);
}

.toast-warn {
  border-left-color: var(--topaz);
}

.toast-bad {
  border-left-color: var(--garnet);
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 4px;
}

.toast-close {
  flex: none;
}

/* ---------- Party picker (DESIGN §7.19) ---------- */
.party-picker {
  min-width: 0;
}

.party-picker-search {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* An empty status line takes no room but stays in the page, so its live region still speaks. */
.party-picker-status:empty {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* A button row whose buttons are all hidden (no walk-in, nothing to keep) leaves no gap. */
.party-picker-search > .row:not(:has(> :not([hidden]))) {
  display: none;
}

.party-picker-box {
  position: relative;
  min-width: 0;
}

.party-picker-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  max-height: min(20rem, 50vh);
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-menu);
  background: var(--surface);
  box-shadow: var(--shadow-menu);
  animation: menu-in 80ms ease-out;
}

.party-picker-list [role='option'] {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--radius-control);
  cursor: pointer;
}

.party-picker-list [role='option']:hover,
.party-picker-list [aria-selected='true'] {
  background: var(--surface-2);
  box-shadow: inset 2px 0 0 var(--brand);
}

@media (pointer: coarse) {
  .party-picker-list [role='option'] {
    min-height: 44px;
  }
}

.party-option-name {
  font-weight: 600;
}

.party-option-detail {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 18px;
}

.party-picker-chosen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
}

.party-picker-label {
  grid-column: 1 / -1;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 18px;
}

.party-picker-name {
  color: var(--ink);
  font-size: var(--text-lg);
  font-weight: 600;
}

.party-picker-detail {
  grid-column: 1;
  font-size: var(--text-sm);
  line-height: 18px;
}

.party-picker-chosen [data-change] {
  grid-column: 2;
  grid-row: 2 / span 2;
}

/* ---------- Scan box (DESIGN §7.14; scan.js keeps the class names) ---------- */
.scanbox { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.scanbox-row { display: flex; gap: 8px; min-width: 0; }
.scanbox-field { position: relative; flex: 1 1 auto; min-width: 0; }
.scanbox-field > .icon { position: absolute; left: 12px; top: 15px; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.scanbox-input { width: 100%; min-width: 0; height: 50px; padding: 0 12px 0 42px; border: 2px solid var(--field-border); border-radius: 4px; background: var(--surface); font-size: 1.25rem; font-weight: 600; letter-spacing: 0.03em; }
.scanbox:focus-within .scanbox-input { border-color: var(--brand); }
.scanbox:focus-within .scanbox-field > .icon { color: var(--brand); }
.scanbox-row > .btn { height: 50px; }
.scanbox-status { display: flex; align-items: flex-start; gap: 6px; min-height: 22px; color: var(--muted); font-size: 13px; }
.scanbox-status.is-ok { color: var(--emerald); font-weight: 600; }
.scanbox-status.is-error { color: var(--garnet); font-weight: 600; }
/* An empty status line takes no room (SPEC A58): no height, and -6px cancels the .scanbox column
   gap above it, so no blank band shows under the box. It stays in the page as the aria-live
   region (never display: none, which would drop it from the accessibility tree), and a message
   brings the line back without moving focus. */
.scanbox-status:empty { min-height: 0; margin-top: -6px; }

/* Without the .scanbox-field wrapper the input keeps a plain left padding. */
.scanbox-row > .scanbox-input {
  flex: 1 1 auto;
  padding-left: 12px;
}

.scanbox-row > .btn {
  flex: none;
}

.scanbox-input:focus-visible {
  outline-offset: 0;
}

.scanbox-input:disabled {
  background: var(--disabled-fill);
  border-style: dashed;
  border-color: var(--field-border);
  color: var(--muted);
  cursor: not-allowed;
}

.scanbox-status {
  line-height: 18px;
  overflow-wrap: anywhere;
}

.scanbox-status.is-ok::before,
.scanbox-status.is-error::before {
  content: '';
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  background: currentColor;
  -webkit-mask: var(--mark-ok) center / contain no-repeat;
  mask: var(--mark-ok) center / contain no-repeat;
}

.scanbox-status.is-error::before {
  -webkit-mask-image: var(--mark-bad);
  mask-image: var(--mark-bad);
}

/* In a list toolbar the scan input is an ordinary control height. */
.toolbar .scanbox-input {
  height: var(--control-h);
  padding-left: 36px;
  border-width: 1px;
  font-size: max(16px, 1rem);
  letter-spacing: normal;
}

.toolbar .scanbox-row > .scanbox-input {
  padding-left: 10px;
}

.toolbar .scanbox-field > .icon {
  left: 10px;
  top: calc((var(--control-h) - 18px) / 2);
  width: 18px;
  height: 18px;
}

.toolbar .scanbox-row > .btn {
  height: auto;
}

.scanbox-camera {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* The camera shows as a short strip (SPEC 13 A91): the middle band of the picture, where the read
   square sits, so the lines and messages under it stay in view on a phone. The reader's own box
   keeps the video's full size (its read square maps to it); the strip only crops what shows. */
.scanbox-window {
  position: relative;
  width: 100%;
  max-width: 28rem;
  height: 11rem;
  overflow: hidden;
  border-radius: 8px;
  background: var(--velvet);
}

.scanbox-video {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  transform: translateY(-50%);
}

.scanbox-video video {
  display: block;
  width: 100%;
  height: auto;
}

.scanbox-camera-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.scanbox-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Tag tray (signature; DESIGN §7.21; lib/tag.js markup unchanged) ---------- */
.tag-preview { --tag-scale: 3; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; min-width: 0; padding: clamp(16px, 3vw, 32px); border-radius: 10px; background: var(--velvet); box-shadow: inset 0 2px 0 rgba(255,255,255,.05), inset 0 10px 28px rgba(0,0,0,.38); color: var(--on-velvet); }
.tag-preview:has([data-tag-actual][aria-pressed='true']) { --tag-scale: 1; }
.tag-preview-stage { position: relative; flex: 1 1 auto; min-width: 0; max-width: 100%; overflow-x: auto; padding: 12px 4px 26px;
  background:
    repeating-linear-gradient(90deg, var(--on-velvet-muted) 0 1px, transparent 1px calc(var(--tag-scale) * 10mm)) 4px calc(100% - 4px) / calc(var(--tag-scale) * 100mm + 1px) 12px no-repeat local,
    repeating-linear-gradient(90deg, var(--on-velvet-muted) 0 1px, transparent 1px calc(var(--tag-scale) * 5mm)) 4px calc(100% - 4px) / calc(var(--tag-scale) * 100mm + 1px) 8px no-repeat local,
    repeating-linear-gradient(90deg, rgba(185,195,211,.7) 0 1px, transparent 1px calc(var(--tag-scale) * 1mm)) 4px calc(100% - 4px) / calc(var(--tag-scale) * 100mm + 1px) 4px no-repeat local; }
.tag-preview-notes .btn { align-self: flex-start; }

/* The stage's flex basis is its content (the label + 8 px), not 24rem (DESIGN §7.21 amended):
   the notes wrap under a label that needs the row, so the whole printed body shows from 768 px
   and only the blank tail end scrolls; a short label or Actual size keeps the notes beside it.
   Its own scrollbar matches the velvet (the cue for that tail). */
.tag-preview-stage {
  scrollbar-color: var(--on-velvet-muted) var(--velvet-2);
  scrollbar-width: thin;
}

/* Inside a panel the tray sits on a padded surface already: a little less velvet margin. */
.panel .tag-preview {
  padding: clamp(12px, 2vw, 24px);
}

.tag-preview-stage > * {
  background: #FFFFFF;
  color: #000000;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

.tag-preview-notes {
  flex: 1 1 14rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--on-velvet);
  font-size: var(--text-sm);
  line-height: 18px;
}

.tag-preview-notes h3 {
  color: var(--on-velvet);
}

.tag-preview-notes ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tag-preview-notes li {
  position: relative;
  padding-left: 16px;
  color: var(--on-velvet-muted);
}

.tag-preview-notes li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  background: var(--gold);
  transform: rotate(45deg);
}

.tag-preview .btn-primary:not(:disabled):not([aria-disabled='true']) {
  background: #FFFFFF;
  border-color: #FFFFFF;
  color: var(--velvet);
}

/* Enabled buttons only: a disabled one keeps the shared .btn:disabled look. */
.tag-preview .btn-secondary:not(:disabled):not([aria-disabled='true']) {
  background: transparent;
  border-color: var(--find-edge);
  color: var(--on-velvet);
}

.tag-preview .btn-secondary:not(:disabled):not([aria-disabled='true']):hover {
  background: var(--velvet-2);
}

/* ---------- Sign-in, setup and boot failure (DESIGN §7.23) ---------- */
.auth-screen { min-height: 100vh; display: grid; justify-items: center; align-content: start; gap: 24px; padding: clamp(32px, 9vh, 88px) 16px 32px; background: linear-gradient(to bottom, var(--velvet) 0 clamp(200px, 34vh, 300px), var(--canvas) 0); }
.auth-brand { display: flex; align-items: center; gap: 14px; max-width: 100%; color: #FFFFFF; }
.auth-brand .hallmark { width: 48px; height: 40px; border-width: 2px; border-radius: 20px / 50%; font-size: 18px; }
.auth-brand .wordmark-name { font-size: 28px; line-height: 32px; white-space: normal; }
.auth-panel { width: min(100%, 24rem); display: flex; flex-direction: column; gap: 16px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 1px 3px rgba(20,33,58,.16); }
.auth-panel-wide { width: min(100%, 32rem); }
.auth-title { font-family: var(--font-ui); font-size: 20px; font-weight: 600; }
.auth-panel .input, .auth-panel .btn { min-height: 44px; }
.auth-panel .btn-primary { width: 100%; }
.auth-note { color: var(--muted); font-size: 13px; text-align: center; }

.auth-brand .wordmark {
  gap: 14px;
}

.auth-brand .wordmark-name {
  overflow: visible;
}

.auth-title {
  line-height: 26px;
}

.auth-lede {
  color: var(--muted);
}

.auth-note {
  line-height: 18px;
}

.auth-panel .btn-link {
  min-height: var(--control-h);
}

/* ---------- Motion (DESIGN §10) ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* The drawer's links inherit its visibility; under the 0.01 ms transition above they stay
     hidden for a few frames after opening and setMenuOpen's focus() would miss (DESIGN §6.6). */
  .app-nav,
  .app-nav * {
    transition: none !important;
  }

  .is-landed {
    animation: none;
    box-shadow: inset 2px 0 0 var(--brand);
  }

  .app-find.is-busy::after {
    animation: none;
  }
}

/* ---------- The phone list pattern (SPEC 13 A77; DESIGN §7.10 "Cards", §8.1 "Phone and tablet", §9) ----------
   Below 64rem, the drawer breakpoint, a list screen shows one compact search row, the filter bar
   (a Filters button with the number applied, the applied filters as removable chips and Clear
   all), the count, the rows as cards, the pager at the foot of the list and, while rows are
   selected, a selection bar fixed to the foot of the screen. From 64rem every list is exactly
   as before: the filter bar, the foot and the selection bar are not shown, and data-cards,
   .list-search and [data-filter-panel] change nothing. The card block is ONE indivisible set
   (observations 0441/0443/0444): it sets every part of the table, after the stacked blocks
   above and at a weight that wins over them. */
.filter-bar,
.bulk-bar,
.list-foot {
  display: none;
}

@media (max-width: 63.99rem) {
  /* One compact search row. The label and the hint stay the field's name and description for
     screen readers; the field shows a magnifier and a placeholder (ui.phonePlaceholders). A hint
     that carries a live message (the "type more of the name" advice) stays in view. */
  .list-search .field:has(input[type='search']) > .field-label,
  .list-search .field:has(input[type='search']) > .field-hint:not([data-more-parties]) { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .list-search .field { gap: 4px; }
  .panel-flush > .list-search .field,
  .panel-flush > .list-search .field.grow,
  .panel-flush > .list-search > .grow { flex: 1 1 100%; max-width: none; }
  .list-search input[type='search'] { padding-left: 40px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235B6577' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21 21-4.34-4.34'/%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3C/svg%3E") no-repeat 12px 50% / 18px 18px; }
  /* The input keeps 16 px (no zoom on focus); a long placeholder fits the field at 15 px. */
  .list-search input::placeholder { font-size: 15px; }

  /* The filter bar: the Filters button opens the page's own filters, whose summary it replaces. */
  .filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1 1 100%; min-width: 0; }
  .panel-flush > .filter-bar { padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
  .filter-bar-toggle[aria-expanded='true'] { background: var(--brand-tint); border-color: var(--brand); color: var(--brand); }
  .filter-bar-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: var(--radius-badge); background: var(--brand); color: #FFFFFF; font-size: 12px; font-weight: 700; line-height: 1; }
  .filter-bar-count[hidden] { display: none; }
  .filter-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1 1 12rem; min-width: 0; margin: 0; padding: 0; list-style: none; }
  .filter-chips[hidden] { display: none; }
  .filter-chips > li { min-width: 0; max-width: 100%; }
  .filter-chip { position: relative; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: var(--control-h-sm); padding: 4px 8px 4px 10px; border: 1px solid var(--field-border); border-radius: var(--radius-control); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; line-height: 18px; text-align: left; cursor: pointer; }
  /* A 44 px target on a 36 px chip: the chips' 8 px gaps take the rest. */
  .filter-chip::after { content: ''; position: absolute; inset: -4px 0; }
  .filter-chip:hover { background: var(--surface-2); border-color: var(--ink-2); }
  .filter-chip > .icon { color: var(--muted); }
  .filter-chip-text { min-width: 0; overflow-wrap: anywhere; }
  .filter-chips-clear { min-height: var(--control-h-sm); }
  [data-filter-panel] > summary { display: none; }
  details[data-filter-panel]:not([open]),
  [data-filter-panel]:not(details):not(.is-open) { display: none; }
  .toolbar > [data-filter-panel] { flex: 1 1 100%; }

  /* The count line: "Select all on this page" only once a row is selected. */
  .list-meta:not(.has-selection) .bulk-select-all,
  .list-meta .bulk-desktop { display: none; }
  /* It appears beside "2 selected" in the line's own height: nothing under the finger moves. */
  .list-meta .bulk-select-all { margin-block: -4px; }

  /* The pager at the foot of the list, its buttons 44 px. */
  .list-foot { display: block; padding: 12px 16px; border-top: 1px solid var(--line); }
  .list-foot:not(:has(.pager)) { display: none; }
  .list-foot .pager { flex-wrap: nowrap; justify-content: space-between; }
  .list-foot .pager .btn { min-height: 44px; padding-inline: 16px; }

  /* The selection bar: fixed to the foot of the screen while a row is selected. */
  .bulk-bar.has-selection { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 12px; padding: 8px 16px max(8px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line-strong); box-shadow: 0 -2px 8px rgba(20, 33, 58, 0.08); }
  .bulk-count { margin: 0; color: var(--ink); font-weight: 600; }
  .bulk-bar > :not(.bulk-count):not(.bulk-clear) { grid-column: 1 / -1; }
  .bulk-bar .btn:not(.btn-link) { min-height: 44px; flex: 1 1 auto; }
  .bulk-bar > :not(.bulk-count):not(.bulk-clear):has(> .btn) { display: flex; flex-wrap: wrap; gap: 8px; }
  .bulk-bar .why:not(:empty) { flex: 1 1 100%; }
  .bulk-bar .why { overflow-wrap: anywhere; }
  /* A button's count ("Print tags (2)") is read but not shown in the bar, which says "2 selected":
     every label stays on one line at 360. */
  .bulk-bar .bulk-hide { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .bulk-bar .btn { white-space: nowrap; }
  .page:has(.bulk-bar.has-selection) { padding-bottom: var(--save-bar-reserve); }
  html:has(.bulk-bar.has-selection) { scroll-padding-bottom: var(--save-bar-reserve); }
  html:has(.bulk-bar.has-selection) .toast-region { bottom: calc(var(--save-bar-reserve) + env(safe-area-inset-bottom, 0px)); }

  /* Cards (dataTable card: true). Key facts first: the select box, the number (its link covers the
     card), the amount on the right, the name or description, the status chips, then small
     "Label value" facts. Every cell keeps its text, label and table role. */
  .table-wrap[data-cards] > .table,
  .table-wrap[data-cards] > .table > tbody,
  .table-wrap[data-cards] > .table > tfoot { display: block; }
  .table-wrap[data-cards] > .table > thead { display: block; position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-wrap[data-cards] > .table > * > tr { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 16px; position: relative; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table-wrap[data-cards] > .table > tbody > tr:last-child { border-bottom: 0; }
  /* The number and the amount always share the first line alone: a full-width break follows them. */
  .table-wrap[data-cards] > .table > tbody > tr::after { content: ''; order: 2; flex: 0 0 100%; height: 0; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card] { display: block; order: 5; min-width: 0; height: auto; margin: 0; padding: 0; border: 0; color: var(--ink); font-size: 14px; font-weight: 400; line-height: 20px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card]::before { content: none; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='pick'] { order: 0; flex: none; position: relative; inset: auto; z-index: 2; width: 44px; height: 44px; margin: -12px -8px -12px -11px; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='pick'] .pick-hit { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; cursor: pointer; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='pick'] input { width: 22px; height: 22px; margin: 0; }
  /* A row's picture (card: 'media', SPEC 13 A83): after the select box, before the number. */
  .table-wrap[data-cards] > .table > * > tr > td[data-card='media'] { order: 1; flex: none; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='title'] { order: 1; flex: 1 1 auto; font-size: 15px; font-weight: 600; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='title'] > a { white-space: nowrap; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='title'] .cell-sub { font-weight: 400; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='amount'] { order: 2; flex: none; margin-left: auto; font-size: 15px; font-weight: 600; text-align: right; white-space: nowrap; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='amount'] .cell-sub { font-size: 13px; font-weight: 400; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='name'] { order: 3; flex: 1 1 100%; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='status'] { order: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='meta'] { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 4px; max-width: 100%; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='meta']:not([data-label=''])::before { content: attr(data-label); display: inline; color: var(--muted); font-size: 13px; font-weight: 400; line-height: 20px; }
  /* A fact's own card label ('' for none: a link that says what it is), and a second fact inside a
     cell (.cell-fact, "Net 3.800 g"), styled as a fact of its own. */
  .table-wrap[data-cards] > .table > * > tr > td[data-card='meta'][data-card-label]::before { content: attr(data-card-label); display: inline; color: var(--muted); font-size: 13px; font-weight: 400; line-height: 20px; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='meta'][data-card-label='']::before { content: none; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card] .cell-fact { display: inline; margin-left: 12px; color: var(--ink); font-size: 14px; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card] .cell-fact-label { color: var(--muted); font-size: 13px; }
  /* Any other sub-line of a fact or of the status takes its own line under it, as in the table. */
  .table-wrap[data-cards] > .table > * > tr > td:is([data-card='meta'], [data-card='status']) > .cell-sub:not(.cell-fact) { flex-basis: 100%; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card='meta'][data-span='full'] { flex-basis: 100%; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card]:is(:empty, [data-stack-hide]) { display: none; }
  .table-wrap[data-cards] > .table > * > tr > td[data-card] .chip { max-width: 100%; height: auto; min-height: 22px; padding-block: 2px; line-height: 16px; white-space: normal; }
  /* The whole card opens the row's page: its first link is stretched over the card; the other
     controls in it (the select box, a Preview button, a link in a fact) sit above that layer. */
  .table-wrap[data-cards] > .table > tbody > tr > td[data-card='title'] > a:first-of-type::after { content: ''; position: absolute; inset: 0; z-index: 1; }
  .table-wrap[data-cards] > .table > tbody > tr > td:not([data-card='title']) :is(a, button, input, select, textarea, summary, label) { position: relative; z-index: 2; }
  .table-wrap[data-cards] > .table > tbody > tr > td[data-card='title'] > a:first-of-type:focus-visible { outline: none; }
  .table-wrap[data-cards] > .table > tbody > tr:has(> td[data-card='title'] > a:first-of-type:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }
  .table-wrap[data-cards] > .table > tbody > tr:has(> td[data-card='title'] > a:first-of-type:active) { background: var(--brand-tint); }
}
