/* Post Box Express — component layer.
   The single definition of every shared UI primitive. Pages lay out; they do
   not restyle. Values come from tokens.css only.

   Load order (base.html / base_app.html):
     tokens.css → app.css (shell) → components.css → page stylesheet
   A page stylesheet may position a component, never redefine it. */

/* ── Primitives ──────────────────────────────────────────────────────── */

/* The HTML `hidden` attribute is the one show/hide switch every script in
   this project toggles, so it must always win over a component's `display`.
   Author styles outrank the UA `[hidden]` rule, so a plain `.btn` (or any
   other `display` declaration) used to paint a hidden control. `!important`
   makes the attribute authoritative without every component repeating a
   scoped `[hidden]` rule; removing the attribute restores the normal display. */
[hidden] {
  display: none !important;
}

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

.num {
  text-align: right;
  /* Tabular figures + slashed zero keep AWB numbers, weights and rates
     aligned in columns and distinguishable at a glance. The --font-numeric
     token from tokens.css is the canonical definition. */
  font-variant-numeric: var(--font-numeric, tabular-nums slashed-zero);
}

.mono {
  font-family: var(--font-mono);
}

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

.nowrap {
  white-space: nowrap;
}

/* ── Copy affordance ──────────────────────────────────────────────────
   One control for every copyable identifier (AWB, reference, address).
   static/js/app-shell.js writes the value on click and toggles `.is-copied`
   for the confirmation state, so no page re-implements the feedback. */

.copy-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--duration-fast) var(--easing-standard),
    border-color var(--duration-fast) var(--easing-standard),
    background-color var(--duration-fast) var(--easing-standard);
}

.copy-btn svg {
  display: block;
}

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

.copy-btn:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 1px;
}

.copy-btn.is-copied {
  border-color: var(--color-success-border);
  background: var(--color-success-soft);
  color: var(--color-success);
}

/* Labelled variant: the icon plus a short verb, for a toolbar row. */
.copy-btn--labelled {
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: var(--space-4);
  width: auto;
  padding: 0 var(--space-8);
  border-color: var(--color-border);
  font-family: var(--font-sans);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
}

/* ── Breadcrumbs ─────────────────────────────────────────────────────── */

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-8);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
}

.breadcrumbs li {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.breadcrumbs li + li::before {
  content: "/";
  color: var(--color-text-muted);
  opacity: 0.6;
}

.breadcrumbs a {
  color: var(--color-text-secondary);
  text-decoration: none;
  border-radius: var(--radius-xs);
}

.breadcrumbs a:hover {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.breadcrumbs a:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.breadcrumbs [aria-current="page"] {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

/* ── Page header ─────────────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-16);
  margin-bottom: var(--space-20);
}

.page-head__titles {
  min-width: 0;
}

.page-head__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-8);
  flex: none;
}

.page-head__meta {
  margin: var(--space-4) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

/* Entry screens keep only the action band and state meta, so the first field
   starts near the fold. */
.page-head--compact {
  align-items: center;
  margin-bottom: var(--space-12);
}

.page-head--compact .page-head__meta {
  margin-top: var(--space-4);
}

/* Ledger variant: a register keeps a visible title, its row-count pill and a
   one-line meta. Shared by every register; module styles must not restyle it. */
.page-head--ledger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  margin-bottom: var(--space-10);
  min-height: 32px;
}

.page-head--ledger .page-head__titles {
  display: flex;
  align-items: baseline;
  gap: var(--space-8);
  flex-wrap: wrap;
  min-width: 0;
}

.page-head--ledger .page-head__title-row {
  display: inline-flex;
  align-items: center;
  gap: var(--space-6);
}

.page-head--ledger .page-head__title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.page-head--ledger .page-head__count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  min-width: 20px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-pill);
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.page-head--ledger .page-head__meta {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: 1.2;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  height: var(--control-height-xs);
  padding: 0 var(--space-10);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--easing-standard),
    border-color var(--duration-fast) var(--easing-standard),
    color var(--duration-fast) var(--easing-standard);
}

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

.btn--primary {
  background: var(--color-button-background);
  border-color: var(--color-button-background);
  color: var(--color-button-text);
}

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

.btn--secondary {
  border-color: var(--color-input-border);
  background: var(--color-surface);
  color: var(--color-primary);
}

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

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--color-text-secondary);
}

.btn--ghost:hover {
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
}

.btn--danger {
  border-color: var(--color-error);
  background: var(--color-error);
  color: var(--color-text-inverse);
}

.btn--danger:hover {
  background: color-mix(in srgb, var(--color-error) 86%, var(--color-text-primary));
  border-color: color-mix(in srgb, var(--color-error) 86%, var(--color-text-primary));
}

.btn--link {
  height: auto;
  padding: 0;
  border: 0;
  color: var(--color-link);
  font-weight: var(--font-weight-medium);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn--sm {
  height: var(--control-height-2xs);
  padding: 0 var(--space-8);
  font-size: var(--font-size-2xs);
}

.btn--xs {
  height: var(--control-height-3xs);
  padding: 0 var(--space-6);
  font-size: var(--font-size-2xs);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  border-color: var(--color-border);
  background: var(--color-background-secondary);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.btn[aria-busy="true"] {
  cursor: progress;
  opacity: 0.85;
}

/* The busy state keeps the label and adds a spinner, so the operator can still
   read what the button is doing. Scripts set aria-busy when a submit starts. */
.btn[aria-busy="true"]::before {
  content: "";
  flex: none;
  width: 12px;
  height: 12px;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: var(--radius-circle);
  animation: spin 700ms linear infinite;
}

.btn kbd {
  margin-left: var(--space-2);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--control-height);
  height: var(--control-height);
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 1px;
}

/* Dense icon control: one icon per table row. Same vocabulary as .icon-btn,
   stepped down to the row rhythm so a ledger keeps its height. */
.icon-action {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.icon-action:hover {
  border-color: var(--color-border);
  background: var(--color-background-secondary);
  color: var(--color-primary);
}

.icon-action:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 1px;
}

/* ── Theme switch ─────────────────────────────────────────────────────── */

.theme-toggle {
  flex: none;
  color: var(--color-text-secondary);
}

/* `theme.js` sets data-theme as the first thing in <head>. If it never runs,
   the switch would be a dead control, so keep it out of the page. */
html:not([data-theme]) .theme-toggle {
  display: none;
}

.theme-toggle:hover {
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 1px;
}

.theme-toggle__icon {
  display: block;
}

.theme-toggle__icon--sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle__icon--moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle__icon--sun {
  display: block;
}

/* Page shells without a topbar (sign-in, 403/404/500) dock the switch to the
   viewport corner so the control is present on every rendered page. */
.theme-toggle--floating {
  position: fixed;
  inset-block-start: var(--space-16);
  inset-inline-end: var(--space-16);
  z-index: var(--z-sticky);
  border-color: var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

/* Brand artwork carries dark ink and a translucent brand fill; a second asset
   keeps the wordmark legible without filtering the brand colours. */
.brand-art--dark {
  display: none;
}

html[data-theme="dark"] .brand-art--dark {
  display: block;
}

html:not([data-theme="dark"]) .brand-art--dark {
  display: none;
}

html[data-theme="dark"] .brand-art--light {
  display: none;
}

/* ── Fields ──────────────────────────────────────────────────────────── */

.field {
  min-width: 0;
}

.field__label,
.field > label {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
}

.field__name {
  min-width: 0;
}

.field__unit {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.req {
  color: var(--color-error);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
}

.field__help {
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  line-height: var(--line-height-snug);
}

.field__error {
  margin: var(--space-2) 0 0;
  color: var(--color-error);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-snug);
}

/* A non-blocking warning (a partial provider result). Same rhythm as an
   error so both read as one message column, without the error tone. */
.field__warning {
  margin: var(--space-2) 0 0;
  color: var(--color-warning);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-snug);
}

.form-control {
  width: 100%;
  height: var(--control-height-2xs);
  min-height: var(--control-height-2xs);
  padding: 0 var(--space-6);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-xs);
  background: var(--color-input-background);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-size-2xs);
  line-height: var(--line-height-snug);
  transition: border-color var(--duration-fast) var(--easing-standard),
    box-shadow var(--duration-fast) var(--easing-standard);
}

.form-control:hover {
  border-color: var(--color-input-border-strong);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-focus-ring);
  box-shadow: var(--shadow-focus);
}

.form-control:disabled,
.form-control[readonly] {
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  cursor: not-allowed;
}

.form-control::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

.form-control--sm {
  height: var(--control-height-3xs);
  min-height: var(--control-height-3xs);
  padding: 0 var(--space-6);
  font-size: var(--font-size-2xs);
}

.form-control--mono {
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  letter-spacing: 0;
}

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

textarea.form-control {
  height: auto;
  min-height: calc(var(--control-height) * 2);
  padding: var(--space-6);
  resize: vertical;
}

select.form-control {
  appearance: none;
  padding-right: var(--space-32);
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%),
    linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%);
  background-position: right 15px center, right 10px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

select.form-control[multiple] {
  appearance: auto;
  padding-right: var(--control-padding-x);
  background-image: none;
  cursor: default;
}

/* Native date/time controls keep the platform picker; only the affordance is
   tinted so it matches the surrounding field. */
input[type="date"].form-control,
input[type="datetime-local"].form-control,
input[type="time"].form-control {
  font-variant-numeric: tabular-nums;
}

input[type="date"].form-control::-webkit-calendar-picker-indicator,
input[type="datetime-local"].form-control::-webkit-calendar-picker-indicator,
input[type="time"].form-control::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.6;
}

input[type="date"].form-control::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"].form-control::-webkit-calendar-picker-indicator:hover,
input[type="time"].form-control::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

input[type="search"].form-control::-webkit-search-cancel-button {
  cursor: pointer;
}

/* Invalid state is authored by the server or the form script
   (`.field--invalid`); the browser's `:invalid` pseudo-class fires before the
   operator has typed anything, so it is never styled. */
.field--invalid .form-control {
  border-color: var(--color-error);
}

.field--invalid .form-control:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-error) 20%, transparent);
}

.field--invalid .field__label {
  color: var(--color-error);
}

/* Checkbox / radio rows */
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-8);
  font-size: var(--font-size-2xs);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--color-primary);
}

.check input:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* Segmented choice group: a small, fixed set of options shown at once instead
   of behind a select. Options reuse the `.check` row; the strip is the canvas
   that marks the control's boundary and the checked option's surface. */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-height: var(--control-height-2xs);
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-accent-light);
}

.segmented__option {
  flex: 1 1 0;
  align-items: center;
  min-width: 0;
  min-height: calc(var(--control-height-2xs) - 6px);
  padding: 0 var(--space-4);
  border-radius: var(--radius-xs);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
}

.segmented__option:hover {
  background: color-mix(in srgb, var(--color-secondary) 8%, transparent);
}

.segmented__option:focus-within {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: -2px;
}

.segmented__option:has(input:checked) {
  background: var(--color-surface);
}

.segmented__option input {
  margin: 0;
  accent-color: var(--color-secondary);
}

.segmented__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field--invalid .segmented {
  border-color: var(--color-error);
}

/* ── Form sections ─────────────────────────────────────────────────────
   The dense entry-workspace composition used by every operator form: a
   bordered section with a compact numbered header over the 12-column field
   grid. The reference is a high-volume logistics desk; sections therefore
   keep 12 px padding, a 30 px header and a 10 px gap instead of the roomier
   panel rhythm used by registers and detail pages. */
.form-section {
  padding: var(--space-12);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.form-section + .form-section {
  margin-top: var(--space-10);
}

.form-section__head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-8);
  min-height: 30px;
  margin: calc(var(--space-12) * -1) calc(var(--space-12) * -1) var(--space-8);
  padding: var(--space-6) var(--space-12);
  border-bottom: 1px solid var(--color-accent-wash-border);
  border-radius: calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px) 0 0;
  background: var(--color-accent-wash);
}

.form-section__num {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xs);
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
}

.form-section__title {
  min-width: 0;
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-tight);
  line-height: var(--line-height-tight);
}

.form-section__meta {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  margin-left: auto;
  flex: none;
}

.form-section__body {
  min-width: 0;
}

.form-section__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-10);
  margin-top: var(--space-10);
  padding-top: var(--space-10);
  border-top: 1px solid var(--color-divider);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

/* The body of a section that contains a matcher, table or notice rather
   than only a field grid. */
.form-section__body > :first-child {
  margin-top: 0;
}

.form-section .form-actions {
  padding-top: var(--space-10);
}

/* The bar at the foot of a form: same surface as the sections, compact
   padding, actions right-aligned. */
.form-actions--bar {
  justify-content: flex-end;
  padding: var(--space-10) var(--space-12);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

/* Forms that are not a flex/grid stack get the section rhythm here. */
.form-section + .form-actions--bar {
  margin-top: var(--space-10);
}

/* Entry actions sit on the shared 28 px button rhythm; the primary action
   keeps its fill and stays the loudest control. */
.form-actions--bar .btn,
.form-section .form-actions .btn {
  height: var(--control-height-xs);
  font-size: var(--font-size-2xs);
}

/* Layout inside a form section */
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--space-10) var(--space-12);
}

.form-grid--dense {
  gap: var(--space-8) var(--space-10);
}

.form-grid .col-3 { grid-column: span 3; }
.form-grid .col-4 { grid-column: span 4; }
.form-grid .col-5 { grid-column: span 5; }
.form-grid .col-6 { grid-column: span 6; }
.form-grid .col-8 { grid-column: span 8; }
.form-grid .col-12 { grid-column: span 12; }

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-8);
}

/* Error summary — the block that lists every invalid field */
.form-errors {
  margin: 0 0 var(--space-16);
  padding: var(--space-12) var(--space-16);
  border: 1px solid var(--color-error-border);
  border-radius: var(--radius-sm);
  background: var(--color-error-soft);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
}

.form-errors:focus-visible {
  outline: 2px solid var(--color-error);
  outline-offset: 1px;
}

.form-errors__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  color: var(--color-error);
  font-weight: var(--font-weight-semibold);
}

.form-errors ul {
  margin: var(--space-8) 0 0;
  padding-left: var(--space-20);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-normal);
}

.form-errors a {
  color: var(--color-text-secondary);
  text-decoration: underline;
  text-decoration-color: var(--color-error-border);
  text-underline-offset: 2px;
}

.form-errors a:hover {
  color: var(--color-error);
}

/* ── Notices ─────────────────────────────────────────────────────────── */

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  border: 1px solid var(--color-information-border);
  border-radius: var(--radius-sm);
  background: var(--color-information-soft);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.notice__text {
  min-width: 0;
  flex: 1;
}

.notice__title {
  display: block;
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

.notice__actions {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex: none;
}

/* A notice that carries a button keeps its sentence readable: below the
   tablet width the action moves under the text instead of squeezing it into
   a 200 px column (the shipment ledger's unconfirmed-bookings notice). */
@media (max-width: 768px) {
  .notice:has(> .notice__actions) {
    flex-wrap: wrap;
  }

  .notice__actions {
    width: 100%;
  }
}

.notice--warn {
  border-color: var(--color-warning-border);
  background: var(--color-warning-soft);
}

.notice--error {
  border-color: var(--color-error-border);
  background: var(--color-error-soft);
}

.notice--success {
  border-color: var(--color-success-border);
  background: var(--color-success-soft);
}

/* ── Toolbar, tabs, filters ──────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.toolbar__filters {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-10);
  min-width: 0;
  max-width: 100%;
}

.toolbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  flex: none;
}

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

.filter-field > label,
.filter-field > .filter-label {
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  line-height: 1.2;
}

.filter-field--grow {
  min-width: 220px;
  flex: 1;
}

.filter-field .form-control {
  min-height: var(--control-height);
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search svg {
  position: absolute;
  left: var(--space-10);
  color: var(--color-text-muted);
  pointer-events: none;
}

.search .form-control {
  padding-left: var(--space-32);
}

.date-range {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.date-range .form-control {
  flex: 1 1 6rem;
  min-width: 0;
  width: auto;
}

.date-range__sep {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

.tabs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs__tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-6);
  height: var(--control-height-sm);
  padding: 0 var(--space-10);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  text-decoration: none;
}

.tabs__tab:hover {
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
}

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

.tabs__tab:active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.tabs__tab[aria-current="page"] {
  border-color: var(--color-border);
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
}

.tabs__count {
  padding: 0 var(--space-6);
  border-radius: var(--radius-pill);
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  font-size: var(--font-size-2xs);
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-weight-semibold);
}

.tabs__tab[aria-current="page"] .tabs__count {
  background: var(--color-surface);
  color: var(--color-primary);
}

/* ── Panels ──────────────────────────────────────────────────────────── */

.panel {
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.panel + .panel {
  margin-top: var(--space-16);
}

.panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-8) var(--space-16);
  padding: var(--space-14, 14px) var(--space-16);
  border-bottom: 1px solid var(--color-accent-wash-border);
  background: var(--color-accent-wash);
}

.panel__title {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
}

.panel__sub {
  max-width: 80ch;
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-normal);
}

.panel__count {
  padding: 0 var(--space-8);
  border-radius: var(--radius-pill);
  background: var(--color-section);
  color: var(--color-text-secondary);
  font-size: var(--font-size-2xs);
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-weight-semibold);
}

/* A panel head carrying the brand colour instead of the pale wash. The fill
   is the logo's deep blue, so every ink on the band flips to the inverse
   pair and the header controls take the same ink: the count becomes a solid
   white pill, and the ghost action only lifts its fill on hover. */
.panel--brand .panel__head {
  background: var(--color-brand-band);
  border-bottom-color: var(--color-brand-band-hover);
}

.panel--brand .panel__title {
  color: var(--color-brand-band-ink);
}

.panel--brand .panel__sub {
  color: var(--color-brand-band-ink-muted);
}

.panel--brand .panel__count {
  background: var(--color-brand-band-ink);
  color: var(--color-brand-band);
}

.panel--brand .btn--ghost {
  color: var(--color-brand-band-ink);
}

.panel--brand .btn--ghost:hover {
  background: var(--color-brand-band-hover);
  color: var(--color-brand-band-ink);
}

.panel--brand .btn--ghost:focus-visible {
  outline-color: var(--color-brand-band-ink);
}

.panel__tools {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  flex: none;
}

.panel__body {
  padding: var(--space-16);
}

.panel__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  border-top: 1px solid var(--color-divider);
  background: var(--color-background-secondary);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.panel > .table-wrap {
  border-radius: 0;
}

.section {
  margin-bottom: var(--space-24);
}

.section__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-16);
  margin-bottom: var(--space-12);
}

.section__title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-tight);
}

/* ── Stats ───────────────────────────────────────────────────────────── */

.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.stat {
  padding: var(--space-14, 14px) var(--space-16);
}

.stat + .stat {
  border-left: 1px solid var(--color-divider);
}

.stat__label {
  display: block;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
}

.stat__value {
  display: block;
  margin: var(--space-4) 0 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--letter-spacing-tight);
  line-height: var(--line-height-tight);
}

.stat__note {
  display: block;
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

.stat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.stat__icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: var(--radius-xs);
  background: var(--color-section);
  color: var(--color-text-muted);
}

.stat__icon[data-tone="primary"] {
  color: var(--color-primary);
}

.stat__icon[data-tone="info"] {
  color: var(--color-secondary);
}

/* Card variant: each figure is its own tile. Use it where the figures are a
   summary rather than the fields of one record. */
.stat-strip--cards {
  gap: var(--space-12);
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: none;
}

.stat-strip--cards .stat {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.stat-strip--cards .stat + .stat {
  border-left: 1px solid var(--color-border);
}

/* Dense variant: record sheets show five or six figures at once, so the
   figures step down one size and the cells inherit the sheet's rhythm. */
.stat-strip--dense .stat {
  padding: var(--space-10) var(--space-12);
}

.stat-strip--dense .stat__value {
  margin-top: var(--space-2);
  font-size: var(--font-size-xl);
}

.stat-strip--dense .stat__note {
  font-size: var(--font-size-2xs);
  line-height: var(--line-height-snug);
}

/* ── Tables ──────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table caption {
  padding: 0 0 var(--space-8);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-align: left;
}

.data-table th {
  padding: var(--space-8) var(--space-16);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-section);
  color: var(--color-text-secondary);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-caps);
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: bottom;
}

.data-table td {
  padding: var(--space-10) var(--space-16);
  border-top: 1px solid var(--color-divider);
  color: var(--color-text-secondary);
  vertical-align: middle;
  line-height: var(--line-height-snug);
}

.data-table tbody tr:first-child td {
  border-top: 0;
}

.data-table tbody tr:hover td {
  background: color-mix(in srgb, var(--color-background-secondary) 60%, transparent);
}

.data-table th.num,
.data-table td.num {
  text-align: right;
}

.data-table--dense th {
  padding: var(--space-6) var(--space-12);
}

.data-table--dense td {
  padding: var(--space-6) var(--space-12);
}

/* Register width: two-line records in a 54–60 px row. A cell is laid out by
   its own module, this variant only sets the shared density and header. */
.data-table--ledger {
  table-layout: fixed;
}

.data-table--ledger th {
  padding: var(--space-10) var(--space-12);
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
  font-size: var(--font-size-xs);
  letter-spacing: 0.04em;
}

.data-table--ledger td {
  height: 56px;
  padding: var(--space-6) var(--space-12);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-snug);
}

.data-table--ledger th:first-child,
.data-table--ledger td:first-child {
  padding-left: var(--space-16);
}

.data-table--ledger th:last-child,
.data-table--ledger td:last-child {
  padding-right: var(--space-16);
}

.data-table__primary {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-medium);
}

.data-table__meta {
  display: block;
  margin-top: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-snug);
}

.data-table__empty {
  padding: var(--space-32) var(--space-16);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  text-align: center;
}

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-xs);
}

.th-sort:hover {
  color: var(--color-primary);
}

.th-sort:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.sort-glyph {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--color-primary);
}

.sort-glyph--idle {
  color: var(--color-border);
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.row-actions a,
.row-actions button {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height-xs);
  padding: 0 var(--space-8);
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-link);
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  cursor: pointer;
}

.row-actions a:hover,
.row-actions button:hover {
  border-color: var(--color-border);
  background: var(--color-surface);
  text-decoration: underline;
}

.row-actions a:focus-visible,
.row-actions button:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.row-actions a:active,
.row-actions button:active {
  background: var(--color-primary-light);
}

.row-actions .is-danger {
  color: var(--color-error);
}

/* Icon-only actions in a dense register row. */
.row-actions--compact {
  gap: 0;
}

.row-actions--compact a,
.row-actions--compact button {
  padding: 0 var(--space-4);
}

/* ── Pagination ──────────────────────────────────────────────────────── */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.pager__range {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

.pager__range strong {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

.pager__controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.pager__pages {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.pager__btn {
  display: inline-grid;
  place-items: center;
  min-width: var(--control-height-sm);
  height: var(--control-height-sm);
  padding: 0 var(--space-8);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
}

.pager__btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

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

.pager__btn:active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.pager__btn[aria-current="page"] {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
}

.pager__btn[aria-current="page"]:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-text-inverse);
}

.pager__gap {
  display: inline-grid;
  place-items: center;
  min-width: var(--control-height-sm);
  height: var(--control-height-sm);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

.pager__current {
  padding: 0 var(--space-8);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
}

/* ── Badges ──────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: 1px var(--space-8);
  border: 1px solid var(--color-neutral-border);
  border-radius: var(--radius-pill);
  background: var(--color-neutral-soft);
  color: var(--color-text-secondary);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1.5;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: var(--radius-circle);
  background: currentColor;
}

.badge--ok {
  border-color: var(--color-success-border);
  background: var(--color-success-soft);
  color: var(--color-success);
}

.badge--warn {
  border-color: var(--color-warning-border);
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.badge--error {
  border-color: var(--color-error-border);
  background: var(--color-error-soft);
  color: var(--color-error);
}

.badge--info {
  border-color: var(--color-information-border);
  background: var(--color-information-soft);
  color: var(--color-information);
}

.badge--muted {
  border-color: var(--color-neutral-border);
  background: var(--color-neutral-soft);
  color: var(--color-text-muted);
}

.badge--plain::before {
  display: none;
}

/* ── Menu (details-based dropdown) ───────────────────────────────────── */

.menu {
  position: relative;
}

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

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

.menu > summary::after {
  content: "";
  width: 5px;
  height: 5px;
  margin-left: var(--space-2);
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
}

.menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-6));
  z-index: var(--z-dropdown);
  display: grid;
  min-width: 210px;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-elevated);
  box-shadow: var(--shadow-md);
}

/* Shell-positioned row menu (app-shell.js): fixed against the trigger so a
   scroll container or panel edge never clips it. */
.menu__panel[data-floating] {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  width: 100%;
  min-height: var(--control-height-sm);
  padding: 0 var(--space-8);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  text-align: left;
  cursor: pointer;
}

.menu__item:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.menu__item:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: -2px;
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.menu__item:active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.menu__item--danger {
  color: var(--color-error);
}

.menu__separator {
  height: 1px;
  margin: var(--space-4) 0;
  background: var(--color-divider);
}

/* Status tones written by script (`data-tone`), matching the --modifiers. */
.badge[data-tone="ok"],
.badge[data-tone="ready"],
.badge[data-tone="saved"],
.badge[data-tone="booked"],
.badge[data-tone="delivered"] {
  border-color: var(--color-success-border);
  background: var(--color-success-soft);
  color: var(--color-success);
}

.badge[data-tone="warn"],
.badge[data-tone="pending"] {
  border-color: var(--color-warning-border);
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.badge[data-tone="error"],
.badge[data-tone="failed"] {
  border-color: var(--color-error-border);
  background: var(--color-error-soft);
  color: var(--color-error);
}

.badge[data-tone="info"] {
  border-color: var(--color-information-border);
  background: var(--color-information-soft);
  color: var(--color-information);
}

.badge[data-tone="muted"],
.badge[data-tone="draft"] {
  border-color: var(--color-neutral-border);
  background: var(--color-neutral-soft);
  color: var(--color-text-muted);
}

/* ── Empty state ─────────────────────────────────────────────────────── */

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-8);
  padding: var(--space-48) var(--space-24);
  text-align: center;
}

.empty-state__title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}

.empty-state__text {
  max-width: 52ch;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.empty-state__actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-4);
}

/* ── Summary panel ───────────────────────────────────────────────────── */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-16) var(--space-24);
  margin: 0;
}

.summary__item {
  min-width: 0;
}

.summary__label {
  display: block;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
}

.summary__value {
  display: block;
  margin: var(--space-4) 0 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  overflow-wrap: anywhere;
}

/* ── Error page ──────────────────────────────────────────────────────── */

.error-page {
  max-width: 34rem;
  margin: var(--space-64) auto;
  padding: 0 var(--space-20);
}

.error-page__code {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-caps);
}

.error-page__title {
  margin: var(--space-8) 0 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-tight);
  line-height: var(--line-height-tight);
}

.error-page__text {
  margin: var(--space-8) 0 0;
  color: var(--color-text-secondary);
  line-height: var(--line-height-normal);
}

.error-page__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
  margin-top: var(--space-20);
}

/* ── Dialog ──────────────────────────────────────────────────────────── */

/* Entry and exit transitions using @starting-style + transition-behavior.
   Per the animate-to-from-top-layer guide:
   - MANDATORY: include `overlay` in transition-property for top-layer elements
   - MANDATORY: `transition-behavior: allow-discrete` as a SEPARATE declaration
     (not inside the transition shorthand) so older browsers don't drop the rule
   - Transforms are opt-in under prefers-reduced-motion: no-preference only
   - The [data-closing] attribute is set by closeTopLayer() in app-shell.js as
     a fallback for Firefox/Safari where overlay isn't supported, so the entry
     animation still works in pure CSS while exit is JS-managed */

/* Base (closed/exit) state */
.dialog,
.confirm-dialog {
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: var(--duration-base);
  transition-timing-function: var(--easing-standard);
  /* MANDATORY: separate declaration — not inside the shorthand */
  transition-behavior: allow-discrete;

  @media (prefers-reduced-motion: no-preference) {
    transform: scale(0.94) translateY(4px);
  }
}

/* Open state */
:is(.dialog, .confirm-dialog)[open]:where(:not([data-closing])) {
  opacity: 1;

  @media (prefers-reduced-motion: no-preference) {
    transform: scale(1) translateY(0);
  }

  /* Entry starting-state — must come AFTER the open state in the cascade */
  @starting-style {
    opacity: 0;

    @media (prefers-reduced-motion: no-preference) {
      transform: scale(0.94) translateY(4px);
    }
  }
}

/* [data-closing] exit — set by app-shell.js closeTopLayer() */
:is(.dialog, .confirm-dialog)[data-closing] {
  opacity: 0;

  @media (prefers-reduced-motion: no-preference) {
    transform: scale(0.94) translateY(4px);
  }
}

/* Shared sizing and surface — after transition rules */
.dialog,
.confirm-dialog {
  width: min(92vw, 440px);
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-elevated);
  box-shadow: var(--shadow-lg);
  color: var(--color-text-primary);
}

.dialog::backdrop,
.confirm-dialog::backdrop {
  background: color-mix(in srgb, var(--color-text-primary) 42%, transparent);
  /* Animate backdrop alongside dialog — MANDATORY: include overlay and
     transition-behavior as separate declaration */
  transition-property: background-color, display, overlay;
  transition-duration: var(--duration-base);
  transition-timing-function: var(--easing-standard);
  transition-behavior: allow-discrete;

  @starting-style {
    background: color-mix(in srgb, var(--color-text-primary) 0%, transparent);
  }
}

.dialog__body,
.confirm-dialog-body {
  padding: var(--space-20);
}

.dialog__title,
.confirm-dialog-title {
  margin: 0;
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
}

.dialog__text,
.confirm-dialog-message {
  margin: var(--space-8) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

/* Confirmation dialog only: an icon tile, an optional subtitle and the body
   on a wash, so the decision reads before the action buttons. */
.confirm-dialog-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  margin-bottom: var(--space-12);
}

.confirm-dialog-icon {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.confirm-dialog[data-tone="danger"] .confirm-dialog-icon {
  background: var(--color-error-soft);
  color: var(--color-error);
}

.confirm-dialog-copy {
  min-width: 0;
}

.confirm-dialog-subtitle {
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

.confirm-dialog-message {
  margin: 0;
  padding: var(--space-12);
  border-radius: var(--radius-sm);
  background: var(--color-background-secondary);
}

.confirm-dialog-message[hidden] {
  display: none;
}

.dialog__actions,
.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-8);
  margin-top: var(--space-20);
}

/* ── Flash + toast ───────────────────────────────────────────────────── */

.flash-list {
  display: grid;
  gap: var(--space-8);
  margin: 0 0 var(--space-16);
  padding: 0;
  list-style: none;
}

.flash {
  display: flex;
  align-items: flex-start;
  gap: var(--space-8);
  padding: var(--space-10) var(--space-16);
  border: 1px solid var(--color-information-border);
  border-radius: var(--radius-sm);
  background: var(--color-information-soft);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.flash--success {
  border-color: var(--color-success-border);
  background: var(--color-success-soft);
}

.flash--warning {
  border-color: var(--color-warning-border);
  background: var(--color-warning-soft);
}

.flash--error {
  border-color: var(--color-error-border);
  background: var(--color-error-soft);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-8);
  padding: var(--space-10) var(--space-12);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-elevated);
  box-shadow: var(--shadow-md);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-snug);
  pointer-events: auto;
}

.toast[data-tone="warn"] {
  border-color: var(--color-warning-border);
  background: var(--color-warning-soft);
}

.toast[data-tone="error"] {
  border-color: var(--color-error-border);
  background: var(--color-error-soft);
}

.toast[data-tone="info"] {
  border-color: var(--color-information-border);
  background: var(--color-information-soft);
}

/* Script-driven toast: top-right, clear of the sticky header and the desk's
   action bar, so it never overlaps a control the operator is using. */
.toast--floating {
  position: fixed;
  top: calc(var(--app-topbar, 60px) + var(--space-12));
  right: var(--space-20);
  z-index: var(--z-toast);
  max-width: min(92vw, 420px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity var(--duration-base) var(--easing-standard),
    transform var(--duration-base) var(--easing-standard);
}

.toast--floating.is-visible {
  opacity: 1;
  transform: none;
}

/* ── Loading ─────────────────────────────────────────────────────────── */

.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: var(--radius-circle);
  animation: spin 700ms linear infinite;
}

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

/* ── Combobox (searchable select) ────────────────────────────────────── */
/* Markup is built by static/js/awb-kit.js; the native <select> stays the
   form value and the accessibility fallback. */

.cmb-panel {
  position: fixed;
  z-index: var(--z-sticky);
  display: flex;
  flex-direction: column;
  max-height: 300px;
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-elevated);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.cmb-panel[hidden] {
  display: none !important;
}

.cmb-list {
  overflow-y: auto;
  padding: var(--space-4);
  scrollbar-width: thin;
}

.cmb-group {
  padding: var(--space-6) var(--space-8) var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
}

.cmb-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-10);
  width: 100%;
  min-height: var(--control-height-xs);
  padding: var(--space-6) var(--space-8);
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  text-align: left;
  cursor: pointer;
}

.cmb-option small {
  flex: none;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.cmb-option:hover,
.cmb-option.is-active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.cmb-option[aria-selected="true"]::after {
  content: "✓";
  color: var(--color-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
}

.cmb-empty {
  padding: var(--space-12);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-align: center;
}

.cmb-foot {
  display: flex;
  gap: var(--space-8);
  padding: var(--space-4) var(--space-8);
  border-top: 1px solid var(--color-divider);
  background: var(--color-background-secondary);
  color: var(--color-text-muted);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-medium);
}

.cmb-foot kbd {
  height: 16px;
  min-width: 16px;
  font-size: var(--font-size-2xs);
}

.cmb-caret {
  position: absolute;
  right: 2px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 20px;
  height: 22px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.cmb-caret:hover {
  color: var(--color-primary);
}

.cmb-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  overflow: hidden !important;
}

.cmb-input {
  padding-right: var(--space-24);
}

/* ── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .page-head {
    flex-direction: column;
    gap: var(--space-12);
  }

  .page-head__actions {
    width: 100%;
  }

  /* A register head keeps title and actions on one row until the phone width;
     the shell's stack would otherwise centre the title. */
  .page-head--ledger {
    flex-direction: row;
    align-items: center;
  }

  .page-head--ledger .page-head__actions {
    width: auto;
  }
}

@media (max-width: 768px) {
  /* Phone: a register head stacks, with its actions full width. */
  .page-head--ledger {
    flex-direction: column;
    align-items: stretch;
  }

  .page-head--ledger .page-head__actions {
    width: 100%;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  /* A flex child with horizontal overflow does not stretch to the stacked
     column here in Chromium; without this the last status tab is clipped. */
  .toolbar > .tabs {
    width: 100%;
  }

  .toolbar__filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-field {
    width: 100%;
  }

  .filter-field--grow {
    min-width: 0;
  }

  .date-range {
    width: 100%;
  }

  .date-range .form-control {
    flex: 1;
    width: auto;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid .col-3,
  .form-grid .col-4,
  .form-grid .col-5,
  .form-grid .col-6,
  .form-grid .col-8,
  .form-grid .col-12 {
    grid-column: span 2;
  }

  .pager {
    align-items: flex-start;
    flex-direction: column;
  }

  .stat + .stat {
    border-left: 0;
    border-top: 1px solid var(--color-divider);
  }

  /* Registers stack into records; a cell carries its own label. */
  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody {
    display: block;
  }

  .data-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
    padding: var(--space-12) var(--space-16);
    border-top: 1px solid var(--color-divider);
  }

  .data-table tbody tr:first-child {
    border-top: 0;
  }

  .data-table td {
    display: block;
    padding: 0;
    border: 0;
  }

  .data-table td[data-label] {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-12);
    font-size: var(--font-size-xs);
    text-align: right;
  }

  .data-table td[data-label]::before {
    content: attr(data-label);
    min-width: 88px;
    color: var(--color-text-muted);
    font-size: var(--font-size-2xs);
    font-weight: var(--font-weight-semibold);
    letter-spacing: var(--letter-spacing-caps);
    text-transform: uppercase;
  }

  .data-table td.num {
    text-align: left;
  }

  .table-wrap {
    overflow-x: visible;
  }
}

@media (max-width: 640px) {
  .empty-state {
    padding: var(--space-32) var(--space-16);
  }

  .page-head--compact .page-head__actions,
  .page-head--compact .page-head__actions .btn {
    width: 100%;
  }

  .form-section {
    padding: var(--space-10);
  }

  .form-section__meta {
    flex-wrap: wrap;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-grid .col-3,
  .form-grid .col-4,
  .form-grid .col-5,
  .form-grid .col-6,
  .form-grid .col-8,
  .form-grid .col-12 {
    grid-column: span 1;
  }
}

/* ── Press feedback ──────────────────────────────────────────────────────
   Every control confirms the press. Colour and a 1 px sink are enough; the
   sink is suppressed when the operator opts out of motion. */
@media (prefers-reduced-motion: no-preference) {
  .btn:active:not(:disabled):not([aria-disabled="true"]),
  .icon-btn:active,
  .icon-action:active,
  .copy-btn:active,
  .pager__btn:active,
  .row-actions a:active,
  .row-actions button:active,
  .tabs__tab:active,
  .menu__item:active,
  .theme-toggle:active {
    transform: translateY(1px);
  }
}

/* ── Coarse pointer ──────────────────────────────────────────────────────
   The visual box stays dense; the hit area grows. Icon-only controls get a
   centred 40–44 px pseudo-element, and row actions get enough gap that no
   two hit areas overlap. `touch-action: manipulation` removes the 300 ms
   double-tap delay from every interactive control. */
@media (pointer: coarse) {
  .btn,
  .icon-btn,
  .icon-action,
  .copy-btn,
  .pager__btn,
  .theme-toggle,
  .tabs__tab,
  .menu__item,
  .row-actions a,
  .row-actions button,
  .check,
  .form-control {
    touch-action: manipulation;
  }

  .copy-btn,
  .icon-btn,
  .icon-action,
  .theme-toggle {
    position: relative;
  }

  .copy-btn::before,
  .icon-btn::before,
  .theme-toggle::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
  }

  .icon-action::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    transform: translate(-50%, -50%);
  }

  .row-actions,
  .row-actions--compact {
    gap: var(--space-12);
  }
}

/* Phones additionally need 16 px field text (below that iOS Safari zooms the
   viewport on focus) and a 44 px control height. */
@media (pointer: coarse) and (max-width: 640px) {
  .form-control {
    min-height: 44px;
    font-size: var(--font-size-lg);
  }

  .btn,
  .btn--sm,
  .btn--xs,
  .pager__btn,
  .tabs__tab,
  .menu__item,
  .row-actions a,
  .row-actions button {
    min-height: 44px;
  }

  .row-actions a,
  .row-actions button {
    min-width: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .form-control,
  .toast,
  .spinner,
  .btn[aria-busy="true"]::before {
    transition: none;
    animation: none;
  }

  /* Suppress the dialog entry/exit scale under reduced motion — the opacity
     transition still runs at its reduced pace via the transition-duration
     already set on the element. */
  .dialog,
  .confirm-dialog {
    transition-duration: 0.1s;
  }
}

/* ── Checked-row highlight (:has() — Baseline Widely Available 2023-12) ──
   When a row checkbox is checked the whole <tr> lifts to a tinted surface,
   giving the operator an instant count of what they've selected without
   having to track individual ticks across a long register.
   Performance tip from the child-state-based-styling guide: anchor :has()
   at the most specific container (.data-table tbody tr) not at body, to
   avoid broad recalc. */
.data-table tbody tr:has(input[type="checkbox"]:checked) td {
  background: color-mix(in srgb, var(--color-primary-light) 70%, transparent);
}

/* ── Container queries on stat cards ─────────────────────────────────────
   Stat cards are placed in different grid widths (full-width dashboard,
   split-screen detail pane). container-type: inline-size lets the card
   adapt its value font-size to the available space rather than to the
   viewport. Per size-aware-styling guide: MANDATORY to set container-type
   on the parent before using @container inside the child. */
.stat-strip--cards {
  container-type: inline-size;
}

@container (max-width: 160px) {
  .stat__value {
    font-size: var(--font-size-xl);
  }

  .stat__label {
    font-size: 10px;
  }
}

/* Compact segmented choice group for a dense field grid: 26 px strip, 11 px
   labels and a 14 px radio, so a two- or three-way choice fits a narrow
   column. Declared last so it refines the primitive without moving it. */
.segmented--compact {
  min-height: var(--control-height-2xs);
  padding: 2px;
}

.segmented--compact .segmented__option {
  min-height: calc(var(--control-height-2xs) - 6px);
  padding: 0 var(--space-2);
  gap: var(--space-4);
  font-size: var(--font-size-2xs);
}

.segmented--compact .segmented__option input {
  width: 14px;
  height: 14px;
}

/* ── Phone form controls ───────────────────────────────────────────────
   iOS Safari zooms any focused control below 16 px. The floor applies
   under the 640 px breakpoint; desktop density is unchanged. */
@media (max-width: 640px) {
  .form-control,
  input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
  select,
  textarea {
    font-size: var(--font-size-lg) !important;
  }
}
