/* ==========================================================================
   Prosper Starter 2.0
   One stylesheet. Tokens, shell, components, screens.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  /* Brand */
  --brand: oklch(0.55 0.185 25);
  --brand-deep: oklch(0.46 0.17 25);
  --brand-bright: oklch(0.62 0.19 25);
  --teal: oklch(0.5 0.085 195);
  --teal-deep: oklch(0.42 0.08 195);
  --navy: oklch(0.28 0.052 250);
  --amber: oklch(0.62 0.13 70);

  /* Surfaces */
  --bg: oklch(0.977 0.005 80);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.985 0.004 80);
  --surface-3: oklch(0.965 0.006 80);
  --surface-inset: oklch(0.955 0.008 80);
  --rail: oklch(0.988 0.004 80);

  /* Text */
  --text: oklch(0.27 0.02 60);
  --text-strong: oklch(0.28 0.052 250);
  --text-muted: oklch(0.52 0.015 60);
  --text-subtle: oklch(0.62 0.012 60);
  --text-on-brand: oklch(0.99 0.004 80);

  /* Lines */
  --border: oklch(0.918 0.006 80);
  --border-strong: oklch(0.86 0.008 80);
  --border-focus: var(--brand);

  /* Tones */
  --good: oklch(0.48 0.09 165);
  --good-wash: oklch(0.95 0.03 165);
  --bad: oklch(0.5 0.17 25);
  --bad-wash: oklch(0.955 0.03 25);
  --warn: oklch(0.55 0.12 70);
  --warn-wash: oklch(0.96 0.045 80);
  --info: oklch(0.45 0.09 250);
  --info-wash: oklch(0.955 0.022 250);
  --brand-wash: oklch(0.958 0.028 25);
  --teal-wash: oklch(0.955 0.025 195);

  /* Radius */
  --r-xs: 6px;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* Elevation */
  --shadow-xs: 0 1px 2px oklch(0.28 0.052 250 / 0.06);
  --shadow-sm: 0 1px 2px oklch(0.28 0.052 250 / 0.05), 0 2px 6px oklch(0.28 0.052 250 / 0.05);
  --shadow-md: 0 2px 4px oklch(0.28 0.052 250 / 0.05), 0 8px 20px oklch(0.28 0.052 250 / 0.09);
  --shadow-lg: 0 4px 8px oklch(0.28 0.052 250 / 0.06), 0 20px 48px oklch(0.28 0.052 250 / 0.16);
  --ring: 0 0 0 3px oklch(0.55 0.185 25 / 0.22);

  /* Space */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.25rem;
  --s6: 1.5rem;
  --s7: 2rem;
  --s8: 2.5rem;
  --s9: 3.25rem;
  --s10: 4rem;

  /* Type */
  --font-display: "Poppins", system-ui, sans-serif;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;

  /* Layout */
  --sidebar: 16.5rem;
  --sidebar-rail: 4.5rem;
  --content-max: 100rem;
  --page-gutter: var(--s4);
  --topbar-h: 3.5rem;
  --touch: 2.75rem;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
}

[data-theme="dark"] {
  --brand: oklch(0.66 0.17 25);
  --brand-deep: oklch(0.58 0.17 25);
  --brand-bright: oklch(0.72 0.16 25);
  --teal: oklch(0.68 0.09 195);
  --teal-deep: oklch(0.6 0.09 195);
  --navy: oklch(0.9 0.02 250);
  --amber: oklch(0.76 0.12 75);

  --bg: oklch(0.19 0.012 260);
  --surface: oklch(0.225 0.014 260);
  --surface-2: oklch(0.245 0.014 260);
  --surface-3: oklch(0.27 0.015 260);
  --surface-inset: oklch(0.2 0.012 260);
  --rail: oklch(0.21 0.013 260);

  --text: oklch(0.9 0.008 260);
  --text-strong: oklch(0.97 0.006 260);
  --text-muted: oklch(0.7 0.012 260);
  --text-subtle: oklch(0.6 0.012 260);
  --text-on-brand: oklch(0.16 0.01 260);

  --border: oklch(0.32 0.014 260);
  --border-strong: oklch(0.4 0.016 260);

  --good: oklch(0.75 0.11 165);
  --good-wash: oklch(0.3 0.045 165);
  --bad: oklch(0.72 0.15 25);
  --bad-wash: oklch(0.31 0.055 25);
  --warn: oklch(0.79 0.11 75);
  --warn-wash: oklch(0.31 0.045 75);
  --info: oklch(0.75 0.09 250);
  --info-wash: oklch(0.29 0.04 250);
  --brand-wash: oklch(0.3 0.05 25);
  --teal-wash: oklch(0.29 0.04 195);

  --shadow-xs: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3), 0 2px 6px oklch(0 0 0 / 0.24);
  --shadow-md: 0 2px 4px oklch(0 0 0 / 0.3), 0 8px 20px oklch(0 0 0 / 0.36);
  --shadow-lg: 0 4px 8px oklch(0 0 0 / 0.32), 0 20px 48px oklch(0 0 0 / 0.5);
  --ring: 0 0 0 3px oklch(0.66 0.17 25 / 0.3);

  color-scheme: dark;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
}

/* Components below set their own display, which would otherwise beat the
   browser's rule for [hidden] and leave a hidden element on screen. A wired
   screen toggles hidden constantly, so the attribute has to win. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  line-height: 1.5;
  font-feature-settings: "cv05" 1, "ss03" 1;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text-strong);
  font-weight: 600;
  letter-spacing: -0.022em;
  line-height: 1.18;
}

p {
  margin: 0;
}

a {
  color: inherit;
}

img,
svg {
  max-width: 100%;
}

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

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection {
  background: var(--brand-wash);
  color: var(--text-strong);
}

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

.skip {
  position: fixed;
  top: -4rem;
  left: var(--s4);
  z-index: 200;
  padding: var(--s3) var(--s4);
  border-radius: var(--r-sm);
  background: var(--brand);
  color: var(--text-on-brand);
  font-weight: 600;
  text-decoration: none;
  transition: top 140ms ease-out;
}

.skip:focus {
  top: var(--s4);
}

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */

.app {
  min-height: 100dvh;
}

/* --- Sidebar (desktop) --- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  width: min(19rem, 86vw);
  padding: calc(var(--s4) + var(--safe-top)) var(--s3) calc(var(--s4) + var(--safe-bottom));
  background: var(--rail);
  border-right: 1px solid var(--border);
  transform: translateX(-102%);
  overflow-y: auto;
  overscroll-behavior: contain;
}

@media (prefers-reduced-motion: no-preference) {
  .sidebar {
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
  }
}

html.nav-open .sidebar {
  transform: none;
  box-shadow: var(--shadow-lg);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s2) var(--s5);
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: auto;
  height: var(--s9);
  flex: none;
  object-fit: contain;
  object-position: left center;
}

.brand-name {
  display: block;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  line-height: 1.2;
}

/* Shared brand lockup: logo first, workspace label below. */
.sidebar-brand-stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s2) var(--s3) var(--s5);
}
.sidebar-brand-stacked .brand-mark {
  width: 104px;
  height: auto;
}
.sidebar-brand-stacked .brand-name {
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1.5;
}

.brand-sub {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.nav-group + .nav-group {
  margin-top: var(--s5);
}

.nav-group-label {
  padding: 0 var(--s3) var(--s2);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--touch);
  padding: 0 var(--s3);
  margin-bottom: 1px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 0.90625rem;
  font-weight: 500;
  text-decoration: none;
}

body[data-portal="true"] .nav-item.pro-only { display: none; }
body[data-pro-license="true"] .nav-item.pro-only { display: flex; }

.nav-item:hover {
  background: var(--surface-3);
  color: var(--text-strong);
}

.nav-item .icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  opacity: 0.85;
}

.nav-item.is-current {
  background: var(--surface);
  color: var(--text-strong);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

.nav-item.is-current::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 1.125rem;
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  background: var(--brand);
  transform: translateY(-50%);
}

.nav-item.is-current .icon {
  color: var(--brand);
  opacity: 1;
}

.nav-count {
  margin-left: auto;
  padding: 0 0.4rem;
  min-width: 1.375rem;
  height: 1.375rem;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: var(--brand-wash);
  color: var(--brand-deep);
  font-size: 0.6875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.nav-foot {
  margin-top: auto;
  padding-top: var(--s5);
}

.nav-foot .nav-group + .nav-group {
  margin-top: var(--s3);
}

.sidebar-foot {
  margin-top: auto;
}

.sidebar-version {
  margin: var(--s2) var(--s3) 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s4);
  padding: var(--s3);
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-user .avatar {
  flex: none;
}

.sidebar-user-copy {
  min-width: 0;
}

.sidebar-user-name {
  display: block;
  font-size: 0.84375rem;
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-org {
  display: block;
  font-size: 0.75rem;
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 89;
  background: oklch(0.2 0.02 260 / 0.5);
  backdrop-filter: blur(2px);
  border: 0;
  padding: 0;
}

.nav-backdrop[hidden] {
  display: none;
}

/* --- Top bar (mobile) --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--s2);
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--s4) + var(--safe-right)) 0 calc(var(--s4) + var(--safe-left));
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Work bar (desktop): permanent home for Ask, theme and account --- */

.workbar {
  display: none;
}

@media (min-width: 1024px) {
  .workbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: var(--s3);
    height: var(--topbar-h);
    padding: 0 var(--page-gutter);
    background: color-mix(in oklab, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
  }

  .workbar-crumb {
    display: flex;
    align-items: center;
    gap: var(--s2);
    color: var(--text-muted);
    font-size: 0.84375rem;
    font-weight: 500;
  }

  .workbar-crumb .icon {
    width: 1rem;
    height: 1rem;
    color: var(--text-subtle);
  }

  .workbar-crumb strong {
    color: var(--text-strong);
    font-weight: 600;
  }
}

@media (min-width: 1440px) {
  :root {
    --page-gutter: var(--s5);
  }
}

/* --- Content --- */

.content {
  min-width: 0;
  padding-bottom: calc(var(--safe-bottom) + var(--s6));
}

.page {
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  padding: var(--s5) calc(var(--page-gutter) + var(--safe-right)) var(--s9) calc(var(--page-gutter) + var(--safe-left));
}

@media (min-width: 1024px) {
  .app {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    width: auto;
    transform: none;
    box-shadow: none;
    padding-left: var(--s4);
    padding-right: var(--s4);
  }

  .topbar,
  .nav-backdrop {
    display: none !important;
  }

  .content {
    padding-bottom: 0;
  }

  .page {
    padding: var(--s6) var(--page-gutter) var(--s10);
  }
}

/* --------------------------------------------------------------------------
   4. Page header
   -------------------------------------------------------------------------- */

.page-back {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  min-height: 2rem;
  margin-bottom: var(--s2);
  color: var(--text-muted);
  font-size: 0.84375rem;
  font-weight: 600;
  text-decoration: none;
}

.page-back:hover {
  color: var(--brand);
}

.page-back .icon {
  width: 1rem;
  height: 1rem;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  margin-bottom: var(--s5);
}

.page-heading {
  flex: 1 1 22rem;
  min-width: 0;
  max-width: 44rem;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s2);
  color: var(--brand);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.eyebrow .icon {
  width: 0.9375rem;
  height: 0.9375rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.032em;
}

.page-lede {
  margin-top: var(--s2);
  color: var(--text-muted);
  font-size: 0.9375rem;
  max-width: 46rem;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
}

@media (min-width: 1024px) {
  .page-title {
    font-size: 2.125rem;
  }

  .page-lede {
    font-size: 1rem;
  }
}

/* Subnav */

.subnav {
  display: flex;
  gap: var(--s1);
  margin-bottom: var(--s5);
  padding: var(--s1);
  border-radius: var(--r);
  background: var(--surface-inset);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.subnav a {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 2.25rem;
  padding: 0 var(--s4);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.subnav a:hover {
  color: var(--text-strong);
}

.subnav a[aria-current="page"] {
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: var(--shadow-xs);
}

.subnav .icon {
  width: 1rem;
  height: 1rem;
}

/* --------------------------------------------------------------------------
   5. Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--touch);
  padding: 0 var(--s4);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

@media (prefers-reduced-motion: no-preference) {
  .btn {
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  }
}

.btn .icon {
  width: 1.0625rem;
  height: 1.0625rem;
  flex: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn-primary {
  background: var(--brand);
  color: var(--text-on-brand);
  box-shadow: var(--shadow-xs);
}

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

.btn-secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: var(--shadow-xs);
}

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

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

.btn-ghost:hover {
  background: var(--surface-3);
  color: var(--text-strong);
}

/* Legacy add actions are secondary. Choose btn-primary explicitly for the
   single main task; constructive actions do not have a separate colour. */
.btn-add { border-color: var(--border-strong); background: var(--surface); color: var(--text-strong); box-shadow: var(--shadow-xs); }
.btn-add:hover { background: var(--surface-2); border-color: var(--text-subtle); }
.btn-primary:disabled { background: var(--surface-2); color: var(--text-muted); box-shadow: none; }
.btn-save-state { min-inline-size: 10rem; justify-content: center; }
.draft-status { color: var(--text-muted); font-size: .8125rem; margin-inline-end: 0; }
.draft-status[data-state=dirty] { color: var(--warn); }
.draft-status[data-state=saved] { color: var(--good); }

.btn-danger {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--bad);
}

.btn-danger:hover {
  background: var(--bad-wash);
  border-color: var(--bad);
}

.btn-sm {
  min-height: 2.125rem;
  padding: 0 var(--s3);
  font-size: 0.8125rem;
  border-radius: var(--r-xs);
}

.btn-sm .icon {
  width: 0.9375rem;
  height: 0.9375rem;
}

.btn-lg {
  min-height: 3rem;
  padding: 0 var(--s5);
  font-size: 0.9375rem;
}

.btn-icon {
  width: var(--touch);
  min-width: var(--touch);
  padding: 0;
}

.btn-icon.btn-sm {
  width: 2.125rem;
  min-width: 2.125rem;
}

.btn-block {
  width: 100%;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-group {
  display: inline-flex;
  gap: var(--s2);
  flex-wrap: wrap;
}

.btn-group > .count {
  align-self: center;
  min-width: 3.25rem;
  margin: 0;
  text-align: center;
}

/* Text button, inline in copy */

.link-btn {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-strong);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--brand);
  text-decoration-color: currentColor;
}

/* Purchase order line: the price source note is the invoice PDF link, keeping the row at meta-line height. */
.link-btn.order-source-link { display: block; text-align: left; font-weight: 400; }

/* --------------------------------------------------------------------------
   6. Cards, sections, layout helpers
   -------------------------------------------------------------------------- */

.card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.card-pad {
  padding: var(--s5);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border);
}

.card-head-plain {
  border-bottom: 0;
  padding-bottom: 0;
}

.card-title {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.card-title .icon {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--text-subtle);
}

.card-lede {
  margin-top: var(--s1);
  color: var(--text-muted);
  font-size: 0.84375rem;
}

.card-body {
  padding: var(--s5);
}

.card-foot {
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* Item identity review uses the shared card, status and action components. */
.identity-review .card-head { align-items: center; }
.identity-review-label { font-size: .875rem; font-weight: 600; color: var(--text-strong); }
.identity-review-copy { max-width: 75ch; font-size: .875rem; line-height: 1.6; }
.identity-review-links { list-style: none; padding: 0; margin: 0; }
.identity-review-links li + li { border-top: 1px solid var(--border); }
.identity-review-link {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) 0; min-height: 44px; color: var(--text-strong); text-decoration: none;
}
.identity-review-link > .stack-sm { min-width: 0; gap: var(--s1); overflow-wrap: anywhere; }
.identity-review-link strong { font-size: .875rem; }
.identity-review-open { flex-shrink: 0; font-size: .8125rem; text-decoration: underline; text-underline-offset: .2em; }
.identity-review-link:hover .identity-review-open { color: var(--brand); }
.identity-review .page-actions { justify-content: flex-start; }
.identity-review .btn { min-height: 44px; }
@media (max-width: 480px) {
  .identity-review .card-head, .identity-review .card-body, .identity-review .card-foot { padding: var(--s4); }
  .identity-review-link { align-items: flex-start; flex-direction: column; gap: var(--s2); }
  .identity-review .page-actions .btn { width: 100%; justify-content: center; }
}

.section {
  margin-top: var(--s8);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.section-title {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.024em;
}

.section-title .icon {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--text-subtle);
}

.section-lede {
  margin-top: var(--s1);
  color: var(--text-muted);
  font-size: 0.875rem;
  max-width: 44rem;
}

.grid {
  display: grid;
  gap: var(--s4);
}

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

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

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

  .grid-2-1 {
    align-items: stretch;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  }

  .grid-2-1 > .card:has(#spend-chart) {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .grid-2-1 > .card:has(#spend-chart) > .card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .grid-2-1 > .card:has(#spend-chart) #spend-chart {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
  }

  .grid-2-1 > .card:has(#spend-chart) #spend-chart .chart {
    flex: 1;
    width: 100%;
    height: auto;
  }

  .grid-2-1 > .stack {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .grid-2-1 > .stack > .card:last-child {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .grid-2-1 > .stack > .card:last-child > .card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .grid-2-1 > .stack .rank-list {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    justify-content: space-between;
    min-height: 0;
  }

  .grid-2-1 > .stack .rank-list > li {
    flex: 1 1 auto;
    align-content: center;
  }

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

@media (min-width: 640px) and (max-width: 899px) {
  .grid-4,
  .grid-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.stack {
  display: grid;
  gap: var(--s4);
}

.stack-sm {
  display: grid;
  gap: var(--s2);
}

.stack-lg {
  display: grid;
  gap: var(--s6);
}

.map {
  height: 28rem;
  min-height: 22rem;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface-inset);
  border: 1px solid var(--border);
}

.map.leaflet-container {
  width: 100%;
  font: inherit;
  background: var(--surface-inset);
}

.map .leaflet-pane,
.map .leaflet-tile,
.map .leaflet-tile-container,
.map .leaflet-zoom-box,
.map .leaflet-image-layer,
.map .leaflet-layer,
.map .leaflet-pane > svg,
.map .leaflet-pane > canvas {
  position: absolute;
  left: 0;
  top: 0;
}

.map .leaflet-container {
  overflow: hidden;
}

.map img.leaflet-tile,
.map .leaflet-tile-pane img,
.map .leaflet-layer img {
  max-width: none !important;
  max-height: none !important;
  width: auto;
  padding: 0;
}

.map .leaflet-tile {
  filter: inherit;
  user-select: none;
}

.map .leaflet-map-pane svg,
.map .leaflet-overlay-pane svg {
  max-width: none !important;
  max-height: none !important;
}

.map .leaflet-pane { z-index: 400; }
.map .leaflet-tile-pane { z-index: 200; }
.map .leaflet-overlay-pane { z-index: 400; }
.map .leaflet-shadow-pane { z-index: 500; }
.map .leaflet-marker-pane { z-index: 600; }
.map .leaflet-tooltip-pane { z-index: 650; }
.map .leaflet-popup-pane { z-index: 700; }
.map .leaflet-map-pane canvas { z-index: 100; }
.map .leaflet-map-pane svg { z-index: 200; }

.map .leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
  clear: both;
  float: left;
}

.map .leaflet-top,
.map .leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.map .leaflet-top { top: 0; }
.map .leaflet-right { right: 0; }
.map .leaflet-bottom { bottom: 0; }
.map .leaflet-left { left: 0; }
.map .leaflet-right .leaflet-control { float: right; }
.map .leaflet-top .leaflet-control { margin-top: var(--s3); }
.map .leaflet-bottom .leaflet-control { margin-bottom: var(--s3); }
.map .leaflet-left .leaflet-control { margin-left: var(--s3); }
.map .leaflet-right .leaflet-control { margin-right: var(--s3); }

.map .leaflet-bar {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-xs);
}

.map .leaflet-bar a {
  display: block;
  width: var(--touch);
  height: var(--touch);
  line-height: var(--touch);
  text-align: center;
  text-decoration: none;
  color: var(--text-strong);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.map .leaflet-bar a:last-child {
  border-bottom: 0;
}

.map .leaflet-bar a:hover,
.map .leaflet-bar a:focus {
  background: var(--surface-2);
}

.map .leaflet-popup {
  position: absolute;
  text-align: center;
  margin-bottom: var(--s5);
}

.map .leaflet-popup-content-wrapper {
  padding: 1px;
  text-align: left;
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
}

.map .leaflet-popup-content {
  margin: var(--s3) var(--s4);
  font-size: 0.875rem;
  line-height: 1.4;
}

.map .leaflet-popup-tip-container {
  width: 40px;
  height: 20px;
  position: absolute;
  left: 50%;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.map .leaflet-popup-tip {
  width: 17px;
  height: 17px;
  padding: 1px;
  margin: -10px auto 0;
  transform: rotate(45deg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.map a.leaflet-popup-close-button {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--touch);
  height: var(--touch);
  line-height: var(--touch);
  text-align: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 1.25rem;
}

.map .leaflet-fade-anim .leaflet-popup {
  opacity: 0;
  transition: opacity 0.2s linear;
}

.map .leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
  opacity: 1;
}

.map .leaflet-zoom-animated {
  transform-origin: 0 0;
}

.map .leaflet-control-attribution {
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  color: var(--text-subtle);
  margin: 0;
  padding: 0 var(--s2);
  font-size: 0.6875rem;
}

.map .leaflet-control-attribution a {
  color: var(--text-muted);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}

.row-tight {
  gap: var(--s2);
}

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

.spacer {
  flex: 1;
}

.divider {
  height: 1px;
  margin: var(--s5) 0;
  background: var(--border);
  border: 0;
}

/* --------------------------------------------------------------------------
   7. Metrics
   -------------------------------------------------------------------------- */

.metric {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s4) var(--s5) var(--s5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.metric-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.metric-head .icon {
  width: 1rem;
  height: 1rem;
  color: var(--text-subtle);
}

.metric-value {
  font-family: var(--font-display);
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.metric-value-sm {
  font-size: 1.375rem;
}

.metric-note {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.metric-foot {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-top: auto;
  padding-top: var(--s1);
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 0.1875rem;
  padding: 0.0625rem 0.4375rem 0.0625rem 0.3125rem;
  border-radius: var(--r-pill);
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.delta .icon {
  width: 0.8125rem;
  height: 0.8125rem;
}

.delta-up {
  background: var(--bad-wash);
  color: var(--bad);
}

.delta-down {
  background: var(--good-wash);
  color: var(--good);
}

.delta-flat {
  background: var(--surface-3);
  color: var(--text-muted);
}

/* Price block: invoice / list / venue stay separate */

.price-grid {
  display: grid;
  gap: var(--s3);
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

.price-cell {
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}

.price-cell-label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.price-cell-value {
  margin-top: var(--s2);
  font-family: var(--font-display);
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.price-cell-unit {
  margin-top: 0.125rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.price-cell-note {
  margin-top: var(--s2);
  color: var(--text-subtle);
  font-size: 0.78125rem;
  line-height: 1.4;
}

.price-cell-empty .price-cell-value {
  color: var(--text-subtle);
}

/* --------------------------------------------------------------------------
   8. Tables
   Desktop: CSS grid rows. Mobile: stacked record cards.
   Set columns per table with style="--cols: ..."
   -------------------------------------------------------------------------- */

.table {
  --cols: minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.table-flush {
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  overflow: visible;
}

.thead {
  display: none;
}

.tbody > li + li,
.tbody > .tr + .tr {
  border-top: 1px solid var(--border);
}

.tr {
  display: block;
  padding: var(--s4);
}

.tr:hover {
  background: var(--surface-2);
}

.td {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  column-gap: var(--s3);
  row-gap: 0.125rem;
  min-width: 0;
  padding: 0.1875rem 0;
}

.td::before {
  content: attr(data-label);
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.td > * {
  grid-column: 2;
  min-width: 0;
}

.td:not([data-label])::before {
  display: none;
}

.td-primary {
  display: block;
  padding-bottom: var(--s2);
}

.td-primary::before {
  display: none;
}

.td-value {
  min-width: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.td-full {
  display: block;
}

.td-full::before {
  display: block;
  margin-bottom: 0.1875rem;
}

@media (min-width: 1024px) {
  .thead {
    display: grid;
    grid-template-columns: var(--cols);
    gap: var(--s4);
    align-items: center;
    padding: 0 var(--s5);
    height: 2.75rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
  }

  .tr {
    display: grid;
    grid-template-columns: var(--cols);
    gap: var(--s4);
    align-items: center;
    padding: var(--s3) var(--s5);
    min-height: 3.75rem;
  }

  .tr-top {
    align-items: start;
  }

  .td {
    display: block;
    min-width: 0;
    overflow: hidden;
    padding: 0;
    text-align: left;
  }

  .td::before {
    display: none;
  }

  .td-value {
    text-align: left;
  }

  .td-primary {
    padding-bottom: 0;
  }

  .td:has(.input) {
    overflow: visible;
  }
}

.table.table-scroll {
  max-height: 28rem;
  overflow: auto;
}

/* Detail lines on a catalogue import row are read, not skimmed, so they wrap. */
.cell-meta.catalogue-import-detail {
  white-space: normal;
  overflow-wrap: anywhere;
}

.catalogue-undo-corrections {
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.catalogue-undo-corrections > summary {
  min-height: var(--touch);
  padding: var(--s3) var(--s4);
  color: var(--text-strong);
  font-weight: 600;
  cursor: pointer;
}

.catalogue-undo-corrections > summary:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.catalogue-undo-corrections-scroll {
  max-height: 20rem;
  overflow: auto;
  border-top: 1px solid var(--border);
}

.catalogue-undo-corrections table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.catalogue-undo-corrections th,
.catalogue-undo-corrections td {
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--border);
}

.catalogue-undo-corrections th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
}

.catalogue-undo-corrections td:first-child {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Page-scrolling registers: keep column headings beneath the work bar. */
@media screen and (min-width: 1024px) {
  .table.table-sticky-head,
  [data-portal] .table.table-sticky-head {
    overflow: clip;
  }

  .table-sticky-head > .thead,
  .table-sticky-head > [role="row"]:has(> [role="columnheader"]),
  table.table-sticky-head > thead {
    position: sticky;
    top: var(--topbar-h);
    z-index: 20;
    background: var(--surface-2);
    box-shadow: 0 1px 0 var(--border);
  }

  [data-portal] .table-sticky-head > .thead,
  [data-portal] .table-sticky-head > [role="row"]:has(> [role="columnheader"]),
  [data-portal] table.table-sticky-head > thead {
    top: calc(var(--topbar-h) + var(--portal-context-h, 0px));
  }

  .buy-review-supplier:has(.table-sticky-head) {
    overflow: clip;
  }

}

@media (min-width: 1024px) {
  .table.table-scroll .thead {
    position: sticky;
    top: 0;
    z-index: 1;
  }
}

/* Header cells and sorting */

.th {
  display: flex;
  align-items: center;
  gap: var(--s1);
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-subtle);
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

button.th {
  cursor: pointer;
}

button.th:hover {
  color: var(--text-strong);
}

.th .icon {
  width: 0.875rem;
  height: 0.875rem;
  opacity: 0;
}

button.th:hover .icon {
  opacity: 0.5;
}

.th[data-sort-direction] {
  color: var(--brand);
}

.th[data-sort-direction] .icon {
  opacity: 1;
}

.th[data-sort-direction="ascending"] .icon {
  transform: rotate(180deg);
}

/* Cell content */

.invoice-evidence-table .cell-name,
.invoice-evidence-table .cell-meta,
.invoice-evidence-table .td-value { white-space: normal; overflow-wrap: anywhere; }

.invoice-line-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s4);
}
.invoice-line-copy { flex: 1 1 16rem; min-width: 0; }
.invoice-line-item > .btn { flex: 0 0 auto; margin-left: auto; }
@media (min-width: 1024px) {
  .invoice-line-copy { flex-basis: 0; }
}

/* The name is the thing being scanned, so marks and badges wrap under it
   rather than squeezing it into an ellipsis. */
.cell-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s2);
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.012em;
}

.cell-name a {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.cell-name a:hover {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

@media (max-width: 1023px) {
  .cell-name a {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    overflow-wrap: anywhere;
  }

  .td[data-label] .td-value,
  .td[data-label] .td-value a,
  .td[data-label] .cell-sub,
  .td[data-label] .cell-meta,
  .td[data-label] .nil {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    overflow-wrap: anywhere;
    text-align: right;
  }

  .td[data-label] .cell-meta {
    margin-top: 0;
  }

  .mover-name,
  .rank-name {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    overflow-wrap: anywhere;
  }
}

/* Block, not inline: text-overflow has no effect on an inline box, so a long
   second line would clip mid-word instead of ending in an ellipsis. */
.cell-meta {
  display: block;
  margin-top: 0.125rem;
  color: var(--text-subtle);
  font-size: 0.8125rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-meta a {
  color: var(--text-muted);
  text-decoration: none;
}

.cell-meta a:hover {
  color: var(--brand);
  text-decoration: underline;
}

/* .cell-meta clips overflow, so draw the focus ring inside the link. */
.cell-meta a:focus-visible {
  outline-offset: -2px;
}

.cell-sub {
  display: block;
  color: var(--text-muted);
  font-size: 0.875rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}

.money-lg {
  font-size: 1rem;
}

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

.nil {
  color: var(--text-subtle);
}

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* Row emphasis */

.tr.is-flagged {
  background: color-mix(in oklab, var(--warn-wash) 55%, var(--surface));
}

.tr.is-selected {
  background: var(--good-wash);
}

.row-selection {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  color: var(--good);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.row-selection[hidden] { display: none; }
.row-selection .icon { width: 14px; height: 14px; }

/* Grouped rows, used for possible duplicates */

.tr-group {
  padding: var(--s3);
  border-left: 3px solid var(--info);
  background: var(--info-wash);
}

.tr-group .tr {
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
}

.tr-group .tr + .tr {
  margin-top: var(--s2);
  border-top: 1px solid var(--border);
}

.tr-group-note {
  display: flex;
  gap: var(--s2);
  padding: var(--s2) var(--s2) var(--s3);
  color: var(--text-muted);
  font-size: 0.84375rem;
}

.tr-group-note .icon {
  flex: none;
  width: 1rem;
  height: 1rem;
  margin-top: 0.125rem;
  color: var(--info);
}

.tr-group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  padding: var(--s2);
}

/* --------------------------------------------------------------------------
   9. Toolbar, search, filters
   -------------------------------------------------------------------------- */

.toolbar {
  display: grid;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

/* A toolbar under the page header already has the header's margin to breathe on.
   One sitting under metric cards or a facts row has nothing, so it needs its own. */
.grid + .toolbar,
.facts + .toolbar {
  margin-top: var(--s6);
}

.toolbar-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
  min-width: 0;
}

.toolbar-line > .count {
  margin-left: auto;
}

/* Labelled dropdown filters share one baseline and stack on narrow screens. */
.filter-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s3);
  max-width: 52rem;
}
.filter-fields > .field { min-width: 0; }
.filter-fields .filter-select { width: 100%; min-height: 2.75rem; font-weight: 400; text-align: left; }
.filter-fields .filter-select > .icon { flex-shrink: 0; }
@media (max-width: 600px) {
  .filter-fields { grid-template-columns: minmax(0, 1fr); }
}

.search {
  position: relative;
  flex: 1 1 16rem;
  min-width: 0;
}

.search > .icon {
  position: absolute;
  left: var(--s3);
  top: 50%;
  width: 1.0625rem;
  height: 1.0625rem;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.search > input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--s3) 0 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.search > input::placeholder {
  color: var(--text-subtle);
}

.search > input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.search > input[type="search"]::-webkit-search-decoration,
.search > input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.count {
  color: var(--text-muted);
  font-size: 0.84375rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.count strong {
  color: var(--text-strong);
  font-weight: 600;
}

.filter-set {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

.filter-label {
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 2.125rem;
  padding: 0 var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.toggle-chip .icon {
  width: 0.9375rem;
  height: 0.9375rem;
}

.toggle-chip:hover {
  border-color: var(--text-subtle);
  color: var(--text-strong);
}

.toggle-chip[aria-pressed="true"] {
  border-color: var(--text-strong);
  background: var(--text-strong);
  color: var(--surface);
}

[data-theme="dark"] .toggle-chip[aria-pressed="true"] {
  color: var(--bg);
}

.toggle-chip[aria-pressed="true"] .icon {
  opacity: 1;
}

.toggle-chip-count {
  padding: 0 0.3125rem;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

.toggle-chip[aria-pressed="true"] .toggle-chip-count {
  background: color-mix(in oklab, var(--surface) 25%, transparent);
  color: inherit;
}

/* Search chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: center;
  width: 100%;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  max-width: 100%;
  min-width: 0;
  min-height: 1.875rem;
  height: auto;
  padding: 0.3125rem 0.3125rem 0.3125rem var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text-strong);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.chip > span:not(.chip-dot) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chip-dot {
  flex: none;
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: var(--r-pill);
  background: var(--chip-color, var(--text-subtle));
}

.chip-x {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.375rem;
  height: 1.375rem;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  color: var(--text-subtle);
  cursor: pointer;
}

.chip-x .icon {
  width: 0.8125rem;
  height: 0.8125rem;
}

.chip-x:hover {
  background: var(--surface-3);
  color: var(--text-strong);
}

/* Segmented control */

.segmented {
  display: inline-flex;
  padding: 0.1875rem;
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  border: 1px solid var(--border);
}

.segmented button {
  min-height: 2rem;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-xs);
  background: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.segmented button[aria-pressed="true"],
.segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: var(--shadow-xs);
}

/* Suggest dropdown */

/* The last-row price-list lookup must extend beyond its table cell. */
[data-page="price-list-detail"] .table:has(#price-list-draft-suggest),
[data-page="price-list-detail"] .td:has(#price-list-draft-suggest) {
  overflow: visible;
}

[data-page="price-list-detail"] .table:has(#price-list-draft-suggest) > .thead {
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}

[data-page="price-list-detail"] .table:has(#price-list-draft-suggest) > .table-foot {
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

[data-page="price-list-detail"] #price-list-draft-suggest .suggest-option-count {
  flex: none;
  text-align: right;
  white-space: nowrap;
}

[data-page="price-list-detail"] #price-list-draft-suggest .suggest-option-count strong {
  display: block;
  margin-top: var(--s1);
  color: var(--text-strong);
  font-weight: 600;
}

[data-page="price-list-detail"] [data-current-list-price] .cell-meta,
[data-page="price-list-detail"] .cell-meta[data-uom-basis],
[data-page="price-list-detail"] .cell-meta[data-price-basis] {
  white-space: normal;
  overflow-wrap: anywhere;
}

.suggest {
  position: absolute;
  z-index: 40;
  top: calc(100% + var(--s1));
  left: 0;
  right: 0;
  max-height: 22rem;
  overflow-y: auto;
  padding: var(--s2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

/* Picker results inside a sheet sit in the body's flow, so the sheet grows to show them instead of clipping. */
.suggest.suggest-inline {
  position: static;
  margin-top: var(--s2);
  max-height: min(20rem, 40dvh);
  box-shadow: none;
}

[data-page="price-list-detail"] #price-list-draft-suggest {
  top: auto;
  bottom: calc(100% + var(--s1));
  max-height: min(22rem, 45vh);
}

.suggest-group {
  padding: var(--s2) var(--s3) var(--s1);
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.suggest-option {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 2.5rem;
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.suggest-option input {
  flex: none;
}

.suggest-option:hover,
.suggest-option[data-active],
.suggest-option[aria-selected="true"] {
  background: var(--surface-3);
}

.suggest-option[aria-checked="true"] {
  background: var(--good-wash);
}

.suggest-option-name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  color: var(--text-strong);
  overflow-wrap: anywhere;
}

.suggest-option-path {
  display: block;
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 400;
}

.suggest-option-count {
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.suggest-foot {
  position: sticky;
  bottom: calc(var(--s2) * -1);
  display: flex;
  justify-content: flex-end;
  margin: var(--s2) calc(var(--s2) * -1) calc(var(--s2) * -1);
  padding: var(--s2);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* --------------------------------------------------------------------------
   10. Badges, tags, marks
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  height: 1.5rem;
  padding: 0 0.5rem;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
}

.badge .icon {
  width: 0.8125rem;
  height: 0.8125rem;
}

.badge::before {
  content: "";
  width: 0.375rem;
  height: 0.375rem;
  border-radius: var(--r-pill);
  background: currentColor;
  opacity: 0.7;
}

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

.badge-good {
  background: var(--good-wash);
  color: var(--good);
}

.badge-bad {
  background: var(--bad-wash);
  color: var(--bad);
}

.badge-warn {
  background: var(--warn-wash);
  color: var(--warn);
}

.badge-info {
  background: var(--info-wash);
  color: var(--info);
}

.badge-brand {
  background: var(--brand-wash);
  color: var(--brand-deep);
}

.badge-teal {
  background: var(--teal-wash);
  color: var(--teal-deep);
}

.badge-lg {
  height: 1.75rem;
  padding: 0 var(--s3);
  font-size: 0.8125rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  box-sizing: border-box;
  min-height: 1.625rem;
  max-width: 100%;
  height: auto;
  padding: 0.1875rem 0.625rem;
  border-radius: var(--r-pill);
  border: 1px solid color-mix(in oklab, var(--tag-color, var(--text-subtle)) 32%, transparent);
  background: color-mix(in oklab, var(--tag-color, var(--text-subtle)) 12%, var(--surface));
  color: var(--text-strong);
  font-size: 0.78125rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.tag-dot {
  flex: none;
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: var(--r-pill);
  background: var(--tag-color, var(--text-subtle));
}

.tag-x {
  display: grid;
  place-items: center;
  width: 1.125rem;
  height: 1.125rem;
  margin-right: -0.25rem;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  color: var(--text-subtle);
  cursor: pointer;
}

.tag-x .icon {
  width: 0.75rem;
  height: 0.75rem;
}

.tag-x:hover {
  background: var(--surface-3);
  color: var(--text-strong);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: flex-start;
  min-width: 0;
  max-width: 100%;
}

/* Source marks: where a value came from */

.marks {
  display: inline-flex;
  align-items: center;
  gap: 0.1875rem;
  flex: none;
}

.mark {
  display: grid;
  place-items: center;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: var(--r-xs);
  color: var(--text-subtle);
}

.mark .icon {
  width: 0.875rem;
  height: 0.875rem;
}

.mark-invoice {
  background: var(--info-wash);
  color: var(--info);
}

.mark-list {
  background: var(--surface-3);
  color: var(--text-muted);
}

.mark-deal {
  background: var(--teal-wash);
  color: var(--teal-deep);
}

.mark-preferred {
  background: var(--good-wash);
  color: var(--good);
}

/* Avatar */

.avatar {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.avatar-lg {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.875rem;
}

.avatar-brand {
  background: var(--brand-wash);
  color: var(--brand-deep);
}

/* Keyboard hint */

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 0.3125rem;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   11. Forms
   -------------------------------------------------------------------------- */

.form {
  display: grid;
  gap: var(--s4);
}

.form-grid {
  display: grid;
  gap: var(--s4);
}

@media (min-width: 640px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.field {
  position: relative;
  display: grid;
  gap: var(--s2);
  align-content: start;
  min-width: 0;
}

.field > label,
.field-label {
  color: var(--text-strong);
  font-size: 0.84375rem;
  font-weight: 600;
}

/* A hint reads the same whether it sits under a field or under a toolbar,
   so it is styled on its own rather than only as a descendant of .field. */
.hint {
  color: var(--text-subtle);
  font-size: 0.78125rem;
  line-height: 1.4;
}

.input,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.field select,
.field textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* .field input beats .search > input, so the icon inset has to be restated. */
.field .search > input:not([type="checkbox"]):not([type="radio"]):not([type="color"]) {
  padding-left: 2.5rem;
}

.field textarea {
  min-height: 5.5rem;
  padding: var(--s3);
  resize: vertical;
  line-height: 1.5;
}

.field select,
select.input,
select:not([multiple]):is(:not([size]),[size="0"],[size="1"]) {
  appearance: none;
  padding-right: var(--s7);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.125rem) 55%, calc(100% - 0.75rem) 55%;
  background-size: 0.375rem 0.375rem, 0.375rem 0.375rem;
  background-repeat: no-repeat;
  cursor: pointer;
}

.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.input::placeholder,
.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-subtle);
}

.input-money {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding-left: var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  font-variant-numeric: tabular-nums;
}

.input-money:focus-within {
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.input-money > span {
  color: var(--text-muted);
  font-weight: 600;
}

.input-money input {
  flex: 1;
  min-width: 0;
  border: 0 !important;
  background: none !important;
  box-shadow: none !important;
  padding-left: 0.0625rem !important;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.input-money input:focus {
  outline: none;
  box-shadow: none !important;
}

.input-inline {
  min-height: 2.25rem;
  padding: 0 var(--s2);
  font-size: 0.875rem;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  min-height: var(--touch);
  padding: var(--s1) 0;
  cursor: pointer;
}

.check input[type="checkbox"],
.check input[type="radio"] {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.1875rem;
  accent-color: var(--brand);
  cursor: pointer;
}

.check-copy {
  min-width: 0;
}

.check-label {
  display: block;
  color: var(--text-strong);
  font-size: 0.875rem;
  font-weight: 600;
}

.check-hint {
  display: block;
  color: var(--text-subtle);
  font-size: 0.78125rem;
}

.check-card {
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
}

.check-card:hover {
  border-color: var(--border-strong);
}

.field > .check {
  align-items: center;
  padding: 0;
}

.field > .check input[type="checkbox"],
.field > .check input[type="radio"] {
  margin-top: 0;
}

/* Switch */

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  width: 2.5rem;
  height: 1.5rem;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

@media (prefers-reduced-motion: no-preference) {
  .switch-track,
  .switch-track::after {
    transition: all 160ms ease-out;
  }
}

.switch input:checked + .switch-track {
  background: var(--brand);
  border-color: var(--brand);
}

.switch input:checked + .switch-track::after {
  transform: translateX(1rem);
}

.switch input:focus-visible + .switch-track {
  box-shadow: var(--ring);
}

/* Status line under a form */

.status {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
  font-size: 0.84375rem;
}

.status .icon {
  width: 1rem;
  height: 1rem;
}

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

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

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

.status:empty {
  display: none;
}

/* --------------------------------------------------------------------------
   12. Notices, empty states, loading
   -------------------------------------------------------------------------- */

.notice {
  display: flex;
  gap: var(--s3);
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
}

.notice > .icon {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.0625rem;
  color: var(--text-muted);
}

.notice-title {
  display: block;
  font-weight: 600;
  color: var(--text-strong);
}

.notice-body {
  min-width: 0;
}

.notice-info {
  border-color: color-mix(in oklab, var(--info) 26%, transparent);
  background: var(--info-wash);
}

.notice-info > .icon {
  color: var(--info);
}

.notice-warn {
  border-color: color-mix(in oklab, var(--warn) 30%, transparent);
  background: var(--warn-wash);
}

.notice-warn > .icon {
  color: var(--warn);
}

.notice-bad {
  border-color: color-mix(in oklab, var(--bad) 26%, transparent);
  background: var(--bad-wash);
}

.notice-bad > .icon {
  color: var(--bad);
}

.notice-good {
  border-color: color-mix(in oklab, var(--good) 26%, transparent);
  background: var(--good-wash);
}

.notice-good > .icon {
  color: var(--good);
}

.empty {
  display: grid;
  justify-items: center;
  gap: var(--s2);
  padding: var(--s9) var(--s5);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: var(--s1);
  border-radius: var(--r);
  background: var(--surface-3);
  color: var(--text-subtle);
}

.empty-icon .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.empty-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-strong);
}

.empty-copy {
  max-width: 26rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface-3) 0%,
    var(--surface-2) 50%,
    var(--surface-3) 100%
  );
  background-size: 200% 100%;
}

@media (prefers-reduced-motion: no-preference) {
  .skeleton {
    animation: shimmer 1.3s ease-in-out infinite;
  }
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.skeleton-row {
  height: 3.5rem;
  margin: var(--s2) 0;
}

.sheet-loading {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 4.5rem;
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
}

.sheet-loading p {
  margin: 0;
  min-width: 0;
  font-size: 0.875rem;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  box-sizing: border-box;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
}

@media (prefers-reduced-motion: no-preference) {
  .spinner {
    animation: spinner-spin 0.7s linear infinite;
  }
}

@keyframes spinner-spin {
  to {
    transform: rotate(1turn);
  }
}

/* --------------------------------------------------------------------------
   13. Dialogs and sheets
   Desktop: centred modal. Mobile: bottom sheet.
   -------------------------------------------------------------------------- */

dialog.sheet {
  width: min(40rem, calc(100% - 2 * var(--s4)));
  max-height: min(88dvh, 52rem);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

dialog.sheet[open] {
  display: flex;
  flex-direction: column;
}

dialog.sheet::backdrop {
  background: oklch(0.2 0.02 260 / 0.5);
  backdrop-filter: blur(3px);
}

@media (max-width: 639px) {
  dialog.sheet {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
  }
}

@media (min-width: 640px) {
  dialog.sheet {
    margin: auto;
    border-radius: var(--r-xl);
  }
}

@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] {
    animation: sheet-in 240ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  dialog.sheet[open]::backdrop {
    animation: fade-in 200ms ease-out;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(1.5rem);
    opacity: 0;
  }
}

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

dialog.sheet.sheet-wide {
  width: min(56rem, calc(100% - 2 * var(--s4)));
}

dialog.sheet.sheet-full {
  width: min(52rem, calc(100% - var(--s6)));
  height: calc(100dvh - var(--s6) - var(--safe-top) - var(--safe-bottom));
  max-height: calc(100dvh - var(--s6) - var(--safe-top) - var(--safe-bottom));
  margin: auto;
}

@media (min-width: 960px) {
  dialog.sheet.sheet-full {
    width: min(72rem, calc(100% - var(--s8)));
  }
}

.sheet-grabber {
  display: block;
  width: 2.25rem;
  height: 0.25rem;
  margin: var(--s2) auto 0;
  border-radius: var(--r-pill);
  background: var(--border-strong);
}

@media (min-width: 640px) {
  .sheet-grabber {
    display: none;
  }
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 1px solid var(--border);
}

.sheet-head-copy {
  flex: 1;
  min-width: 0;
}

.sheet-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.028em;
}

.sheet-meta {
  margin-top: var(--s1);
  color: var(--text-muted);
  font-size: 0.84375rem;
}

.sheet-close {
  flex: none;
  margin: -0.375rem -0.375rem 0 0;
}

.sheet-body {
  /* Use the content height when sizing an auto-height dialog. A zero basis
     can collapse the scrollable body in Safari's top-layer flex layout. */
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s5);
}

.sheet-body-flush {
  padding: 0;
}

.sheet-head,
.sheet-tabs,
.sheet-foot,
.sheet-grabber {
  flex-shrink: 0;
}

.sheet-body-flush:has(.pdf-viewer) {
  display: flex;
  overflow: hidden;
}

.pdf-viewer {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: var(--s3);
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: var(--s3);
}

.pdf-viewer:has(.pdf-thumbs[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

.pdf-thumbs {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  min-height: 0;
  overflow: auto;
}

.pdf-thumbs[hidden] {
  display: none;
}

.pdf-thumb {
  flex: none;
  display: grid;
  justify-items: center;
  gap: var(--s1);
  width: 100%;
  margin: 0;
  padding: var(--s1);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-ui);
  cursor: pointer;
}

.pdf-thumb canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--surface-2);
}

.pdf-thumb span {
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
}

.pdf-thumb:hover {
  border-color: var(--border-strong);
  color: var(--text-strong);
}

.pdf-thumb[aria-current="true"] {
  border-color: var(--text-strong);
  color: var(--text-strong);
}

.pdf-pages {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  min-width: 0;
  min-height: 0;
  padding: var(--s4);
  overflow: auto;
  background: var(--surface-3);
}

.pdf-page {
  flex: none;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
}

@media (max-width: 639px) {
  .pdf-viewer {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .pdf-viewer:has(.pdf-thumbs[hidden]) {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .pdf-thumbs {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .pdf-thumb {
    flex: 0 0 3.6rem;
    width: 3.6rem;
  }
}

.sheet-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s2);
  padding: var(--s3) var(--s5) calc(var(--s3) + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.sheet-foot-split {
  justify-content: space-between;
}

/* The primary group stays right even when the secondary action is hidden. */
.sheet-foot-split > .btn-group:last-child {
  margin-left: auto;
}

/* The draft status leads the footer actions (as in the Users editor); on phones it takes its own row
   so Cancel and Save stay together. */
.sheet-foot > .draft-status {
  margin-right: auto;
}

@media (max-width: 639px) {
  .sheet-foot > .draft-status,
  .sheet-foot .btn-group > .draft-status {
    flex-basis: 100%;
  }

  .sheet-foot .btn-group:has(> .draft-status) {
    justify-content: flex-end;
  }
}

.sheet-tabs {
  display: flex;
  gap: var(--s5);
  padding: 0 var(--s5);
  border-bottom: 1px solid var(--border);
}

.sheet-tabs button {
  position: relative;
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.sheet-tabs button[aria-selected="true"] {
  color: var(--text-strong);
}

.sheet-tabs button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 -1px 0;
  height: 2px;
  border-radius: var(--r-pill) var(--r-pill) 0 0;
  background: var(--brand);
}

/* Popover, used by the calendar and small menus */

.popover {
  position: fixed;
  inset: auto;
  z-index: 120;
  width: min(20rem, calc(100vw - 2rem));
  max-height: calc(100vh - 1rem);
  margin: 0;
  overflow-y: auto;
  padding: var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.popover[hidden] {
  display: none;
}

.filter-select { justify-content:space-between; max-width:100%; }
.checkbox-filter { width:min(21rem, calc(100vw - 1rem)); padding:var(--s2); }
.checkbox-filter-option { align-items:center; padding:var(--s2); border-radius:var(--r-sm); }
.checkbox-filter-option:hover, .checkbox-filter-option:focus-within { background:var(--surface-2); }
.checkbox-filter-option input[type="checkbox"] { margin-top:0; }
.checkbox-filter .hint { margin:var(--s2); }

/* Date range popover */

.range-pop {
  width: min(23rem, calc(100vw - 2rem));
  padding: var(--s2);
}

.range-menu {
  display: grid;
}

.range-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-xs);
  background: none;
  text-align: left;
  cursor: pointer;
}

.range-option:hover,
.range-option[aria-pressed="true"] {
  background: var(--surface-inset);
}

.range-option:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.range-option-label {
  color: var(--text-strong);
  font-size: 0.875rem;
  font-weight: 600;
}

.range-option-window {
  grid-column: 1;
  color: var(--text-subtle);
  font-size: 0.78125rem;
  font-variant-numeric: tabular-nums;
}

/* The tick carries the choice, so it holds its column whether or not it shows.
   Navy rather than red: a settled selection is not an alert. */
.range-tick {
  grid-column: 2;
  grid-row: 1 / span 2;
  color: var(--text-strong);
  visibility: hidden;
}

.range-option[aria-pressed="true"] .range-tick {
  visibility: visible;
}

.range-custom {
  display: grid;
  gap: var(--s3);
  margin-top: var(--s2);
  padding: var(--s3);
  border-top: 1px solid var(--border);
}

.range-dates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s3);
}

/* Too tall to hang off a button on a phone, so it becomes a sheet. The
   anchored position is set inline, hence the important. */
@media (max-width: 639px) {
  .range-pop {
    inset: auto 0 var(--safe-bottom) 0 !important;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
}

/* Toast */

.toast-stack {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(var(--safe-bottom) + var(--s3));
  display: grid;
  gap: var(--s2);
  width: min(24rem, calc(100vw - 2rem));
  transform: translateX(-50%);
  pointer-events: none;
}

@media (min-width: 1024px) {
  .toast-stack {
    left: auto;
    right: var(--s6);
    bottom: var(--s6);
    transform: none;
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r);
  background: var(--text-strong);
  color: var(--surface);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

[data-theme="dark"] .toast {
  background: var(--surface-3);
  color: var(--text-strong);
}

.toast .icon {
  width: 1.0625rem;
  height: 1.0625rem;
  flex: none;
  color: var(--teal);
}

@media (prefers-reduced-motion: no-preference) {
  .toast {
    animation: toast-in 220ms cubic-bezier(0.32, 0.72, 0, 1);
  }
}

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

/* --------------------------------------------------------------------------
   14. Ask
   -------------------------------------------------------------------------- */

.ask-launch {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
}

.ask-launch .kbd {
  margin-left: var(--s1);
}

.ask-context {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  max-width: 100%;
  min-height: 1.75rem;
  height: auto;
  padding: 0.25rem var(--s3);
  border-radius: var(--r-pill);
  background: var(--surface-inset);
  color: var(--text-muted);
  font-size: 0.78125rem;
  font-weight: 500;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.ask-thread {
  display: grid;
  gap: var(--s6);
  min-width: 0;
}

.ask-thread > * {
  min-width: 0;
}

.ask-q {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  overflow-wrap: anywhere;
}

.ask-a {
  margin-top: var(--s3);
  min-width: 0;
  max-width: 100%;
}

.ask-finding {
  max-width: 100%;
  padding: var(--s4);
  border-radius: var(--r);
  border: 1px solid color-mix(in oklab, var(--teal) 24%, transparent);
  background: var(--teal-wash);
  color: var(--text-strong);
  font-size: 0.9375rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.ask-md {
  margin-top: var(--s4);
  display: grid;
  gap: var(--s3);
  min-width: 0;
  max-width: 100%;
  font-size: 0.9375rem;
}

.ask-md > * {
  min-width: 0;
  max-width: 100%;
}

.ask-md h4 {
  font-size: 0.9375rem;
  font-weight: 600;
}

.ask-md ul,
.ask-md ol {
  display: grid;
  gap: var(--s2);
  padding-left: var(--s5);
}

.ask-md ul {
  list-style: disc;
}

.ask-md ol {
  list-style: decimal;
}

.ask-md a {
  color: var(--brand);
  font-weight: 600;
  text-underline-offset: 0.18em;
}

.ask-md .data-table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
}

.ask-md .data-table th,
.ask-md .data-table td {
  white-space: normal;
  overflow-wrap: anywhere;
}

.ask-checked {
  margin-top: var(--s3);
  color: var(--text-subtle);
  font-size: 0.8125rem;
}

.ask-thinking {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-top: var(--s3);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.ask-dots {
  display: inline-flex;
  gap: 0.1875rem;
}

.ask-dots span {
  width: 0.3125rem;
  height: 0.3125rem;
  border-radius: var(--r-pill);
  background: var(--brand);
  opacity: 0.3;
}

@media (prefers-reduced-motion: no-preference) {
  .ask-dots span {
    animation: ask-pulse 1.2s ease-in-out infinite;
  }

  .ask-dots span:nth-child(2) {
    animation-delay: 0.16s;
  }

  .ask-dots span:nth-child(3) {
    animation-delay: 0.32s;
  }
}

@keyframes ask-pulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

.ask-composer {
  display: grid;
  flex: 1;
  min-width: 0;
  width: 100%;
  gap: var(--s2);
}

.ask-composer textarea {
  width: 100%;
  min-height: 3.25rem;
  padding: var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  resize: none;
  line-height: 1.5;
}

.ask-composer textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.ask-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

.ask-prompt {
  min-height: 2.125rem;
  padding: 0 var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.ask-prompt:hover {
  border-color: var(--border-strong);
  color: var(--text-strong);
}

/* --------------------------------------------------------------------------
   15. Data tables inside sheets (history and so on)
   -------------------------------------------------------------------------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: var(--s3) var(--s3) var(--s3) 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table a {
  color: var(--text-strong);
  font-weight: 600;
  text-decoration: none;
}

.data-table a:hover {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.data-table .up {
  color: var(--bad);
  font-weight: 600;
}

.data-table .down {
  color: var(--good);
  font-weight: 600;
}

.data-table .flat {
  color: var(--text-subtle);
}

.data-table-group th {
  padding-top: var(--s5);
  color: var(--text-strong);
  font-size: 0.75rem;
}

/* --------------------------------------------------------------------------
   16. Charts
   -------------------------------------------------------------------------- */

.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-axis {
  fill: var(--text-subtle);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 500;
}

.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: currentColor;
  opacity: 0.1;
}

.chart-bar {
  fill: currentColor;
  rx: 3;
}

.chart-dash {
  stroke-dasharray: 4 4;
}

.chart-dot {
  fill: var(--surface);
  stroke: currentColor;
  stroke-width: 2;
}

.chart-brand {
  color: var(--brand);
}

.chart-navy {
  color: var(--text-strong);
}

.chart-teal {
  color: var(--teal);
}

.chart-info {
  color: var(--info);
}

.spark {
  display: block;
  width: 5.5rem;
  height: 1.75rem;
  overflow: visible;
}

.spark-up {
  color: var(--bad);
}

.spark-down {
  color: var(--good);
}

.spark-flat {
  color: var(--text-subtle);
}

.spark-sales {
  color: var(--navy);
}

button.spark-btn {
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding: var(--s1);
  margin: calc(var(--s1) * -1);
  border: 0;
  border-radius: var(--r-xs);
  background: none;
  cursor: pointer;
}

button.spark-btn:hover {
  background: var(--surface-3);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  margin-top: var(--s3);
  color: var(--text-muted);
  font-size: 0.78125rem;
}

.legend-key {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
}

.legend-swatch {
  width: 0.75rem;
  height: 0.25rem;
  border-radius: var(--r-pill);
  background: currentColor;
}

/* Ranked bar list, used for "what you buy" */

.rank-list > li {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s2) var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--border);
}

.rank-list > li:last-child {
  border-bottom: 0;
}

.rank-list > li:has(.spark) {
  grid-template-columns: 1.5rem minmax(0, 1fr) 5.5rem auto;
}

.rank-num {
  color: var(--text-subtle);
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rank-copy {
  min-width: 0;
}

.rank-name {
  display: block;
  color: var(--text-strong);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-name:hover {
  color: var(--brand);
}

.rank-meta {
  display: block;
  color: var(--text-subtle);
  font-size: 0.78125rem;
}

.rank-bar {
  grid-column: 2 / -1;
  height: 0.25rem;
  border-radius: var(--r-pill);
  background: var(--surface-inset);
  overflow: hidden;
}

.rank-bar > span {
  display: block;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--brand);
  opacity: 0.75;
}

.rank-list > li.is-active .rank-bar > span {
  opacity: 1;
}

.rank-value {
  color: var(--text-strong);
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Invoice spend by venue, on manufacturer Overview */

.grid:has(.venue-sales-map) {
  align-items: start;
}

.venue-sales-map {
  margin: 0;
}

.venue-sales-map svg {
  display: block;
  width: 100%;
  height: auto;
}

.venue-sales-map .hint {
  margin-top: var(--s3);
}

.venue-sales-land {
  fill: color-mix(in oklab, var(--navy) 7%, var(--surface-2));
  stroke: var(--border);
  stroke-width: 1.25;
}

.venue-sales-dot {
  color: var(--navy);
  text-decoration: none;
}

.venue-sales-hit {
  fill: transparent;
}

.venue-sales-mark {
  fill: currentColor;
  stroke: var(--surface);
  stroke-width: 1.5;
}

.venue-sales-label {
  fill: var(--text-strong);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  pointer-events: none;
}

.venue-sales-dot:hover .venue-sales-mark,
.venue-sales-dot:focus-visible .venue-sales-mark,
.venue-sales-dot.is-active .venue-sales-mark {
  opacity: 1;
}

.venue-sales-dot:focus-visible {
  outline: none;
}

.venue-sales-dot:focus-visible .venue-sales-mark {
  stroke: var(--border-focus);
  stroke-width: 2;
}

@media (prefers-reduced-motion: no-preference) {
  .venue-sales-mark {
    transition: opacity 160ms ease-out;
  }
}

/* Action list: the attention queue */

.action-list > li {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  align-items: start;
  gap: var(--s2) var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border);
}

.action-list > li:last-child {
  border-bottom: 0;
}

.action-list > li:hover {
  background: var(--surface-2);
}

.action-tile {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text-muted);
}

.action-tile .icon {
  width: 1.1875rem;
  height: 1.1875rem;
}

.action-tile-bad {
  background: var(--bad-wash);
  color: var(--bad);
}

.action-tile-warn {
  background: var(--warn-wash);
  color: var(--warn);
}

.action-tile-info {
  background: var(--info-wash);
  color: var(--info);
}

.action-tile-good {
  background: var(--good-wash);
  color: var(--good);
}

.action-tile-teal {
  background: var(--teal-wash);
  color: var(--teal-deep);
}

.action-copy {
  min-width: 0;
}

.action-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.012em;
}

.action-title a {
  text-decoration: none;
}

.action-title a:hover {
  color: var(--brand);
}

.action-note {
  margin-top: 0.125rem;
  color: var(--text-muted);
  font-size: 0.84375rem;
}

.action-actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s1);
}

.action-actions-stacked {
  flex-direction: column;
  align-items: stretch;
}

#item-offer-terms .action-actions {
  width: 14rem;
  max-width: 100%;
}

@media (min-width: 700px) {
  .action-list > li {
    grid-template-columns: 2.5rem minmax(0, 1fr) auto;
    align-items: center;
  }

  .action-actions {
    grid-column: auto;
    margin-top: 0;
  }
}

/* Selectable search results use the full row, without an attention-tile column. */
.action-list-choices > li {
  grid-template-columns: minmax(0, 1fr) auto;
  padding: var(--s3);
  align-items: center;
}
.action-list-choices .action-title,
.action-list-choices .action-note { overflow-wrap: anywhere; }
.action-list-choices > li.is-selected { background: var(--good-wash); }
.action-list-choices [aria-pressed="true"] { color: var(--good); border-color: var(--good); }
.invoice-assignment-sheet .action-list-choices {
  max-height: 20rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.invoice-assignment-sheet .sheet-body { grid-auto-rows: max-content; align-content: start; }
.invoice-assignment-sheet .sheet-body > * { min-width: 0; overflow-wrap: anywhere; }
.invoice-assignment-sheet .assignment-current { align-self: flex-start; justify-self: start; width: fit-content; }
@media (max-width: 639px) {
  .action-list-choices > li.is-flagged { grid-template-columns: minmax(0, 1fr); }
  .action-list-choices > li.is-flagged > .btn { justify-self: start; }
}
@media (max-width: 399px) {
  .invoice-assignment-sheet .sheet-foot > .btn-primary { flex-basis: 100%; }
}

/* Mover lists: prices up and down */

.mover-list > li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  min-width: 0;
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--border);
}

.mover-list > li:last-child {
  border-bottom: 0;
}

.mover-copy {
  flex: 1;
  min-width: 0;
}

.mover-name {
  display: block;
  color: var(--text-strong);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mover-name:hover {
  color: var(--brand);
}

.mover-meta {
  display: block;
  color: var(--text-subtle);
  font-size: 0.78125rem;
  font-variant-numeric: tabular-nums;
}

/* Donut */

.donut-wrap {
  display: grid;
  gap: var(--s4);
  align-items: center;
  grid-template-columns: 8.75rem minmax(0, 1fr);
}

.donut {
  width: 8.75rem;
  height: 8.75rem;
}

.donut-legend {
  display: grid;
  gap: var(--s2);
  font-size: 0.84375rem;
}

.donut-legend li {
  display: grid;
  grid-template-columns: 0.625rem minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
}

.donut-key {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: var(--r-xs);
}

.donut-value {
  color: var(--text-strong);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   16b. Calendar popover
   -------------------------------------------------------------------------- */

.calendar {
  padding: var(--s4);
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.cal-month {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-strong);
}

.cal-week,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.125rem;
}

.cal-week {
  margin: var(--s3) 0 var(--s1);
}

.cal-week span {
  text-align: center;
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cal-day {
  min-height: 2.25rem;
  border: 0;
  border-radius: var(--r-xs);
  background: none;
  color: var(--text);
  font-size: 0.84375rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.cal-day:hover {
  background: var(--surface-3);
}

.cal-day.is-outside {
  pointer-events: none;
}

.cal-day[aria-current="date"] {
  box-shadow: inset 0 0 0 1px var(--border-strong);
  font-weight: 700;
}

.cal-day[aria-selected="true"] {
  background: var(--brand);
  color: var(--text-on-brand);
  font-weight: 600;
}

.cal-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  margin-top: var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   16c. Document viewer
   -------------------------------------------------------------------------- */

.doc-viewer {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: var(--s3);
  padding: var(--s3);
  background: var(--surface-inset);
}

@media (max-width: 639px) {
  .doc-viewer {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .doc-thumbs {
    flex-direction: row !important;
    overflow-x: auto;
  }

  .doc-thumb {
    flex: 0 0 3.25rem;
  }
}

.doc-thumbs {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  overflow-y: auto;
}

.doc-thumb {
  display: grid;
  gap: 0.1875rem;
  justify-items: center;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 700;
  cursor: pointer;
}

.doc-thumb[aria-current="true"] {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
  color: var(--text-strong);
}

.doc-thumb-page {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.414;
  border-radius: 2px;
  background: linear-gradient(var(--surface-3) 0 100%);
}

.doc-pages {
  overflow: auto;
  padding: var(--s2);
}

.doc-page {
  width: 100%;
  max-width: 46rem;
  margin: 0 auto var(--s4);
  padding: var(--s7);
  background: #fff;
  color: #1a1a1a;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  font-size: 0.75rem;
  line-height: 1.5;
}

.doc-page-blank {
  min-height: 18rem;
  display: grid;
  place-items: center;
  color: #8a8a8a;
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: var(--s5);
  padding-bottom: var(--s4);
  border-bottom: 2px solid #1a1a1a;
}

.doc-brand {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.doc-fine {
  color: #6a6a6a;
  font-size: 0.6875rem;
}

.doc-head-right {
  text-align: right;
}

.doc-kind {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6a6a6a;
}

.doc-number {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.doc-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s3);
  margin: var(--s4) 0;
}

.doc-meta span {
  display: block;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8a8a8a;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.doc-table th,
.doc-table td {
  padding: 0.375rem 0.5rem 0.375rem 0;
  text-align: left;
  border-bottom: 1px solid #e4e4e4;
}

.doc-table th {
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8a8a8a;
  border-bottom-color: #bbb;
}

.doc-table .r {
  text-align: right;
  padding-right: 0;
}

.doc-totals {
  display: grid;
  gap: 0.25rem;
  justify-content: end;
  margin-top: var(--s4);
  font-variant-numeric: tabular-nums;
}

.doc-totals > div {
  display: grid;
  grid-template-columns: 5rem 5rem;
  gap: var(--s3);
  text-align: right;
}

.doc-totals span {
  color: #6a6a6a;
}

.doc-total {
  padding-top: 0.375rem;
  border-top: 1px solid #1a1a1a;
  font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   17. Timeline and steps
   -------------------------------------------------------------------------- */

.steps {
  display: grid;
  gap: 0;
}

.step {
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr);
  gap: var(--s3);
  padding-bottom: var(--s5);
}

.step:last-child {
  padding-bottom: 0;
}

.step-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 700;
}

.step:not(:last-child) .step-marker::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 1px;
  height: calc(100% + var(--s5) - 1.75rem + 0.5rem);
  margin-top: 0.25rem;
  background: var(--border);
}

.step.is-done .step-marker {
  border-color: var(--good);
  background: var(--good);
  color: var(--surface);
}

.step.is-current .step-marker {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--text-on-brand);
}

.step-copy {
  min-width: 0;
  padding-top: 0.1875rem;
}

.step-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-strong);
}

.step-body {
  margin-top: var(--s1);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.step-actions {
  margin-top: var(--s3);
}

/* --------------------------------------------------------------------------
   17b. Detail page furniture
   -------------------------------------------------------------------------- */

/* Sticky identity bar on item detail: name, save and history stay reachable. */

.item-bar {
  position: sticky;
  top: calc(var(--topbar-h) + var(--safe-top));
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  margin: 0 calc(var(--page-gutter) * -1) var(--s5);
  padding: var(--s3) var(--page-gutter);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

@media (min-width: 1024px) {
  .item-bar {
    top: var(--topbar-h);
    margin-bottom: var(--s6);
  }
}

.item-bar-copy {
  min-width: 0;
  flex: 1 1 16rem;
}

.item-bar-supplier {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text-muted);
  font-size: 0.78125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.item-bar h1 {
  margin-top: 0.125rem;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.028em;
}

@media (min-width: 1024px) {
  .item-bar h1 {
    font-size: 1.5rem;
  }
}

.item-bar-actions {
  display: flex;
  align-items: center;
  align-self: center;
  flex-wrap: wrap;
  gap: var(--s2);
}

.item-bar ~ *,
#item-rest .section,
#pack-title {
  scroll-margin-top: 6.25rem;
}

/* The pack sentence. A spoken line, not a field grid. */

.pack-say {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
  font-size: 1rem;
  line-height: 2.4;
}

.pack-word {
  color: var(--text-strong);
  font-weight: 600;
}

.pack-slot {
  width: auto;
  min-width: 5rem;
  min-height: 2.5rem !important;
  padding: 0 var(--s3) !important;
  font-weight: 600;
  text-align: center;
}

.pack-slot-wide {
  min-width: 8rem;
}

.pack-slot-num {
  min-width: 4.25rem;
  font-variant-numeric: tabular-nums;
}

select.pack-slot {
  appearance: none;
  padding-right: 1.75rem !important;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 0.85rem) 55%, calc(100% - 0.5rem) 55%;
  background-size: 0.3125rem 0.3125rem, 0.3125rem 0.3125rem;
  background-repeat: no-repeat;
  cursor: pointer;
}

.pack-say .field {
  display: block;
  flex: none;
  width: auto;
}

.pack-say .field:has(> .pack-slot[hidden]) {
  display: none;
}

.pack-say .field > .pack-slot {
  width: auto;
}

.pack-say .suggest {
  left: 0;
  right: auto;
  min-width: max(14rem, 100%);
  width: max-content;
  max-width: min(22rem, 70vw);
}

.field-suggest {
  color: var(--teal-deep) !important;
  border-color: color-mix(in oklab, var(--teal) 45%, transparent) !important;
  background: var(--teal-wash) !important;
}

.field-suggest:focus {
  border-color: var(--teal) !important;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--teal) 28%, transparent);
}

/* Source fields table, collapsed by default */

.disclose-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  min-height: var(--touch);
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.disclose-head:hover .section-title {
  color: var(--brand);
}

/* Key and value list used on detail summaries */

.facts {
  display: grid;
  gap: var(--s4);
  /* 16rem so email and phone cannot squeeze into four skinny columns and
     run into each other. Two across on desktop, one on a phone. */
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

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

.fact-label {
  display: flex;
  align-items: center;
  gap: var(--s1);
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fact-value {
  margin-top: 0.1875rem;
  color: var(--text-strong);
  font-size: 0.9375rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.fact-value a {
  text-decoration: none;
}

.fact-value a:hover {
  color: var(--brand);
}

.fact-note {
  display: block;
  color: var(--text-subtle);
  font-size: 0.78125rem;
  font-weight: 400;
}

/* Venue profile: contact facts first, administrative settings below. */
.venue-profile {
  margin-bottom: var(--s6);
  border-block: 1px solid var(--border);
}

.venue-profile-facts {
  grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr));
  gap: var(--s5);
  padding-block: var(--s5);
}

.venue-profile .fact-value { margin-top: var(--s2); }
.venue-profile .fact-note { margin-top: var(--s1); }

.venue-profile-settings {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: var(--s5);
  padding-block: var(--s5);
  border-top: 1px solid var(--border);
}

.venue-profile-inbox, .venue-profile-plan, .venue-profile-status { min-width: 0; }
.venue-profile-inbox { grid-column: span 2; }
.venue-profile-plan > .fact-label, .venue-profile-status > .fact-label { color: var(--text-subtle); font-size: 0.6875rem; }
.venue-profile-inbox .btn-group { margin-top: var(--s3); }
.venue-profile-inbox [role="status"]:empty { display: none; }

@media (max-width: 1100px) {
  .venue-profile-facts, .venue-profile-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .venue-profile-inbox { grid-column: auto; }
}

@media (max-width: 639px) {
  .venue-profile-settings { grid-template-columns: minmax(0, 1fr); gap: var(--s5); }
  .venue-profile-inbox .btn { min-height: var(--touch); }
}

@media (max-width: 399px) {
  .venue-profile-facts { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------------------------
   18. Utilities
   -------------------------------------------------------------------------- */

.icon {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

.icon-fill {
  fill: currentColor;
  stroke: none;
}

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

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

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

.small {
  font-size: 0.8125rem;
}

.tiny {
  font-size: 0.75rem;
}

.up {
  color: var(--bad);
}

.down {
  color: var(--good);
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.mt-0 {
  margin-top: 0;
}
.mt-1 {
  margin-top: var(--s1);
}
.mt-2 {
  margin-top: var(--s2);
}
.mt-3 {
  margin-top: var(--s3);
}
.mt-4 {
  margin-top: var(--s4);
}
.mt-5 {
  margin-top: var(--s5);
}
.mt-6 {
  margin-top: var(--s6);
}
.mt-7 {
  margin-top: var(--s7);
}

.mb-0 {
  margin-bottom: 0;
}
.mb-2 {
  margin-bottom: var(--s2);
}
.mb-3 {
  margin-bottom: var(--s3);
}
.mb-4 {
  margin-bottom: var(--s4);
}
.mb-5 {
  margin-bottom: var(--s5);
}

.hide-mobile {
  display: none;
}

@media (min-width: 1024px) {
  .hide-mobile {
    display: revert;
  }

  .hide-desktop {
    display: none !important;
  }
}

@media (max-width: 639px) {
  .hide-phone {
    display: none !important;
  }
}

/* Venue workspace. Shared foundations, operational additions. */
.portal-context {
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) max-content minmax(0, 1fr);
  align-items: end;
  gap: var(--s6);
  margin-bottom: var(--s7);
  padding-bottom: var(--s5);
  border-bottom: 1px solid var(--border);
}
.portal-context .field { min-width: 0; }
.portal-context .field label, .portal-context .field-label { font-size: 11px; line-height: 16px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .09em; }
.portal-context select { height: 48px; font-weight: 600; color: var(--text-strong); }
.portal-mode { display: inline-grid; grid-template-columns: repeat(2, minmax(0, 1fr)); height: 48px; padding: 1px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); gap: var(--s1); }
.portal-mode a { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--touch); padding: 0 var(--s4); border-radius: var(--r-xs); font-size: 13px; font-weight: 600; text-decoration: none; color: var(--text-muted); }
.portal-mode a:hover { color: var(--text-strong); background: var(--surface); }
.portal-mode a[aria-current] { background: var(--surface); color: var(--text-strong); box-shadow: var(--shadow-sm); }
.portal-local { min-height: 48px; justify-self: end; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: var(--s2); font-size: 12px; color: var(--text-muted); }
.portal-split { display: grid; grid-template-columns: minmax(0,1.7fr) minmax(280px,1fr); gap: var(--s6); align-items: start; }
.portal-queue { list-style: none; padding: 0; margin: 0; }
.portal-queue li + li { border-top: 1px solid var(--border); }
.portal-queue a { display: flex; align-items: center; gap: var(--s4); padding: 22px 24px; text-decoration: none; color: var(--text-strong); transition: background 150ms; }
.portal-queue a:hover { background: var(--surface-2); }
.portal-task-icon { display: flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: var(--r); background: var(--warn-wash); color: var(--warn); flex: 0 0 auto; }
.portal-task-icon.good { background: var(--good-wash); color: var(--good); }
.portal-task-icon.info { background: var(--info-wash); color: var(--info); }
.portal-task-copy { flex: 1; min-width: 0; }
.portal-task-copy strong { display: block; font-size: 15px; margin-bottom: 5px; }
.portal-task-copy small { display: block; color: var(--text-muted); line-height: 1.5; font-size: 13px; }
.portal-strip { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: var(--s6) 0; }
.portal-stat { padding: 23px 24px 23px 0; }
.portal-stat + .portal-stat { padding-left: 24px; border-left: 1px solid var(--border); }
.portal-stat dt { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.portal-stat dd { margin: 0; font-size: 26px; letter-spacing: -.04em; font-weight: 650; color: var(--text-strong); }
.portal-stat small { display: block; font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.portal-delivery { display: flex; align-items: start; gap: 14px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.portal-delivery:last-child { border: 0; }
.portal-date { text-align: center; border: 1px solid var(--border); border-radius: var(--r-sm); min-width: 48px; padding: 8px; color: var(--text-strong); }
.portal-date small { display: block; font-size: 10px; text-transform: uppercase; color: var(--text-muted); }
.portal-date strong { font-size: 19px; }
.portal-delivery-copy { flex: 1; min-width: 0; }
.portal-delivery-copy strong { display: block; }
.portal-delivery-copy p { color: var(--text-muted); font-size: 12px; margin: 5px 0 10px; }
.portal-tabs { margin: 0 0 var(--s5); overflow-x: auto; }
.portal-tabs button { white-space: nowrap; }
.portal-buy-grid { display: grid; grid-template-columns: minmax(0,1fr) 315px; gap: var(--s5); align-items: start; }
/* Venue order guide: a stable quantity-entry surface and per-supplier delivery book. */
.buy-controls { display: grid; grid-template-columns: minmax(220px,2fr) repeat(3,minmax(120px,1fr)); gap: var(--s3); align-items: end; margin-bottom: var(--s5); }
.buy-controls .field { gap: var(--s2); font-size: 12px; }
.buy-search { position: relative; display: block; }
.buy-search .input { padding-left: var(--s3); padding-right: var(--touch); }
.search-clear-field { position: relative; min-width: 0; width: 100%; }
.search-clear-field > input { width: 100%; }
.search > input.has-search-clear, .search-clear-field > input.has-search-clear { padding-right: var(--touch); }
input.has-search-clear::-webkit-search-cancel-button,
input.has-search-clear::-webkit-search-decoration { -webkit-appearance: none; }
.search > .search-clear, .search-clear-field > .search-clear { position: absolute; right: 0; top: 0; width: var(--touch); height: 100%; min-height: var(--touch); padding: 0; }
.buy-suggestions { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20; display: grid; max-height: 360px; overflow-y: auto; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-lg); }
.buy-suggestions:empty { display: none; }
.buy-suggestions button { padding: var(--s3); text-align: left; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text-strong); cursor: pointer; }
.buy-suggestions button:hover, .buy-suggestions [aria-selected="true"] { background: var(--surface-2); }
.buy-suggestions small { display: block; margin-top: var(--s1); color: var(--text-muted); }
.buy-layout { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: var(--s5); align-items: start; }
.buy-list-summary { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: var(--s4); }
.buy-group { margin-bottom: var(--s5); }
.buy-group .section-head { align-items: center; margin-bottom: var(--s3); }
.buy-group .section-head h2 { margin: 0; }
/* Distributor status beside the group name: order value against its minimum or free-delivery threshold. */
.buy-group-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s2); min-width: 0; }
.buy-group-status { font-size: 12px; color: var(--text-muted); }
.buy-group-status::before { content: "·"; margin-right: var(--s2); color: var(--text-subtle); }
.buy-group-status.is-warn { color: var(--warn); font-weight: 600; }
.buy-group-status.is-good { color: var(--good); }
.buy-order-minimum { color: var(--warn); font-weight: 600; }
.link-btn.buy-order-minimum { font-size: inherit; text-align: left; text-decoration: underline; text-underline-offset: 0.18em; }
@media (max-width: 1023px) { .link-btn.buy-order-minimum { display: inline-flex; align-items: center; min-height: 44px; } }
@media (max-width: 639px) { .buy-group-status { flex-basis: 100%; } .buy-group-status::before { content: none; } }
.buy-group h2 { font-family: Inter,sans-serif; font-size: 15px; font-weight: 600; margin: 0 0 var(--s3); }
.buy-table .td { padding: var(--s3); font-size: 13px; }
.buy-table .tr { padding: 0; }
@media (min-width: 1024px) { .buy-table .tr { align-items: start; } }
/* Cell padding spaces the item grid, so header and rows drop the extra column gap; offer badges may wrap. */
.buy-table > .thead, .buy-table .tr { column-gap: 0; }
.buy-table [data-buy-offer] .badge { white-space: normal; }
.buy-table .th { padding: var(--s3); font-size: 10px; }
.buy-table .td-primary strong { white-space: normal; overflow-wrap: anywhere; }
.buy-table .cell-meta { font-size: 11px; line-height: 1.5; white-space: normal; overflow: visible; text-overflow: clip; }
.buy-price-source { display: block; font-size: 10px; color: var(--text-muted); margin-top: var(--s1); line-height: 1.5; }
/* The source repaints with each quote; two lines at most, the full text stays in the title. */
@container buy-table (min-width: 800px) { .buy-table .buy-price-source[data-buy-source] { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; } }
.buy-quantity { width: 100%; display: grid; grid-template-columns: minmax(0,1fr); gap: 0; }
.buy-item-heading { display: grid; grid-template-rows: auto 18px; row-gap: var(--s1); }
.buy-table [data-buy-offer] { height: 37px; }
.buy-table [data-buy-offer] > .cell-meta,
.buy-offer-details summary .cell-meta { display: block; margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buy-offer-details { position: relative; max-width: 100%; }
.buy-offer-details summary { display: flex; align-items: center; gap: var(--s1); cursor: pointer; list-style: none; }
.buy-offer-details summary::-webkit-details-marker { display: none; }
.buy-offer-details summary::after { content: "▾"; flex: none; }
.buy-offer-details[open] summary::after { transform: rotate(180deg); }
.buy-offer-popover { position: absolute; z-index: 8; top: calc(100% + var(--s1)); left: 0; width: min(320px, calc(100vw - 32px)); max-height: min(50vh, 320px); overflow: auto; padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow-lg); }
.buy-offer-popover .cell-meta { display: block; white-space: normal; margin-top: var(--s1); }
.buy-offer-details.is-above .buy-offer-popover { top: auto; bottom: calc(100% + var(--s1)); }
.buy-table:has(.buy-offer-details[open]) { overflow: visible; }
.buy-price-main + .buy-best-price { margin-top: var(--s1); }
/* Deal price: the list price it undercuts, struck through beside pay-now. A compact Deal badge, saving
   and end date, then an optional larger-order nudge, share the fixed-height offer slot. */
.buy-was-price { margin-left: var(--s2); color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.buy-was-price[hidden] { display: none; }
.buy-table [data-buy-offer] .badge { height: 1.25rem; padding: 0 0.375rem; font-size: 0.6875rem; }
.buy-deal-line { display: flex; align-items: center; gap: var(--s1); min-width: 0; }
.buy-deal-line > .cell-meta, .buy-offer-details summary .buy-deal-badge + .cell-meta { margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buy-deal-badge { flex: none; }
.buy-deal-nudge { color: var(--teal-deep); font-weight: 600; }
.buy-table [data-buy-offer] > .buy-deal-meta { display: block; margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buy-deal-saving { color: var(--good); }
.buy-review-terms { display: grid; gap: 2px; margin-top: var(--s2); }
.buy-review-terms .cell-meta { margin-top: 0; white-space: normal; }
.buy-review-terms strong { color: var(--teal-deep); font-weight: 600; }
.buy-best-note { margin: 0 auto 0 0; color: var(--text-strong); font-weight: 600; }
.buy-table .tr:has(.buy-offer-details[open]) { position: relative; z-index: 6; }
.buy-table .td[data-label="Price, ex GST"]:has(.buy-offer-details[open]) { overflow: visible; }
.buy-quantity .input[aria-invalid="true"] { border-color: var(--bad); }
.buy-quantity .buy-warning { color: var(--bad); }
.buy-quantity .input { width: 100%; padding: var(--s2); font-size: 14px; }
.buy-quantity small { display: none; }
.buy-quantity .buy-warning:not([hidden]) { display: block; margin-top: var(--s1); }
.buy-quantity .btn, .buy-row-actions .btn { font-size: 11px; padding: var(--s1); min-height: 32px; white-space: normal; }
.buy-quantity .btn { min-height: 24px; }
.buy-row-actions { display: grid; }
.buy-pending { font-size: 11px; color: var(--warn); margin-top: var(--s2); }
.buy-pending p { margin: var(--s1) 0; }
.buy-basket { position: sticky; top: 88px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); padding: var(--s4); max-height: calc(100vh - 108px); overflow-y: auto; }
.buy-basket-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
.buy-basket-heading h2, .buy-review h2, .buy-compare h2 { font-size: 18px; margin: 0; }
.buy-basket-heading span { font-size: 12px; color: var(--text-muted); }
.buy-supplier { padding: var(--s4) 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.buy-supplier h3 { font: 600 14px Inter,sans-serif; margin: 0; }
.buy-supplier .field { margin: var(--s3) 0; }
.buy-supplier select { width: 100%; }
.buy-supplier summary { cursor: pointer; font-size: 12px; min-height: 32px; padding-top: var(--s2); }
.buy-cutoff { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.buy-warning { color: var(--warn); font-size: 12px; line-height: 1.6; }
.buy-totals { display: grid; gap: var(--s2); margin: var(--s3) 0; font-size: 12px; }
.buy-totals div { display: flex; justify-content: space-between; gap: var(--s3); }
.buy-totals dd { margin: 0; font-weight: 600; text-align: right; }
.buy-basket-footer { padding-top: var(--s4); }
.buy-basket-footer > .btn { width: 100%; }
.buy-supplier .check-row { display: flex; gap: var(--s2); align-items: start; font-size: 12px; line-height: 1.6; }
.buy-supplier .check-row input { margin-top: 4px; }
.buy-comparison-row { list-style: none; border-bottom: 1px solid var(--border); }
.buy-compare { scroll-margin-top: 72px; padding: var(--s5); background: var(--surface-2); }
.buy-compare > .between { align-items: flex-start; gap: var(--s4); }
.buy-compare h2 { line-height: 1.5; }
.buy-opportunities { display: grid; justify-items: start; gap: var(--s1); margin-top: var(--s2); }
.buy-opportunities:empty { display: none; }
.buy-opportunities .btn { font-size: 11px; text-align: left; white-space: normal; min-height: 32px; padding: var(--s1) 0; justify-content: flex-start; }
/* Cheaper verdict: plain text, info colour so it scans next to Best price. */
.buy-opportunities [data-buy="cheaper"] { color: var(--info); font-weight: 600; }
[data-portal] .table.buy-alternatives-scroll { overflow-x: auto; width: 100%; max-width: 100%; min-width: 0; }
.buy-comparison-row > div, .buy-compare { min-width: 0; }
.buy-alternatives-grid { width: 100%; min-width: 700px; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.buy-alternatives-grid th { background: var(--surface-2); color: var(--text-muted); font-size: 11px; font-weight: 600; text-align: left; }
.buy-alternatives-grid th, .buy-alternatives-grid td { padding: var(--s3); border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
/* Headers wrap between words only, so labels like Expected delivery never split mid-word. */
.buy-alternatives-grid th { overflow-wrap: normal; word-break: normal; hyphens: manual; }
.buy-alternatives-grid th:first-child { width: 28%; }
.buy-alternatives-grid th:nth-child(2) { width: 12%; }
.buy-alternatives-grid th:nth-child(3) { width: 12%; }
.buy-alternatives-grid th:nth-child(4) { width: 15%; }
.buy-alternatives-grid th:nth-child(5) { width: 13%; }
/* Fits Request account on one line. */
.buy-alternatives-grid th:nth-child(6) { width: 136px; }
.buy-alternatives-grid tr:last-child td { border-bottom: 0; }
.buy-account-requested { display: block; }
/* A catalogue row from a preferred distributor without an account: the request sits where the quantity would. */
.buy-account-action { display: grid; gap: var(--s1); justify-items: start; }
.buy-account-requested strong { display: block; }
.buy-alternatives-grid .cell-meta { font-size: 11px; }
.buy-comparison-benefit { margin-top: var(--s2); font-size: 11px; }
.buy-alternatives-grid .btn { padding: var(--s2); min-height: 32px; font-size: 12px; }
.buy-alternatives-grid td:nth-child(3) { font-variant-numeric: tabular-nums; }
.buy-swap-feedback { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s3) var(--s4); margin-bottom: var(--s4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); font-size: 13px; }
.buy-review { width: 100%; }
.buy-review-lines { list-style: none; margin: 0 0 var(--s5); padding: 0; }
.buy-review-lines li { display: flex; justify-content: space-between; gap: var(--s4); padding: var(--s3) 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.buy-review-lines small { display: block; color: var(--text-muted); margin-top: var(--s1); }
@media (max-width: 1350px) {
  .buy-layout { grid-template-columns: minmax(0,1fr); }
  .buy-basket { position: static; max-height: none; }
}
@media (max-width: 767px) {
  .page:has(#buy-workspace) .portal-context { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,1fr); gap: var(--s3); margin-bottom: var(--s4); padding-bottom: var(--s3); }
  .page:has(#buy-workspace) .portal-context > .field { min-width: 0; width: auto; }
  .page:has(#buy-workspace) #portal-venue { font-size: 12px; }
  .page:has(#buy-workspace) .portal-mode a { padding: var(--s2); font-size: 12px; gap: var(--s1); }
  .page:has(#buy-workspace) .portal-mode .icon { display: none; }
  .page:has(#buy-workspace) .portal-local { grid-column: 1 / -1; margin: 0; }
  .page:has(#buy-workspace) .page-header { margin-bottom: var(--s4); gap: var(--s3); }
  .page:has(#buy-workspace) .page-header .eyebrow { display: none; }
  .page:has(#buy-workspace) .page-title { font-size: 24px; }
  .page:has(#buy-workspace) .page-lede { font-size: 13px; line-height: 1.5; }
  .buy-controls { grid-template-columns: 1fr 1fr; }
  .buy-search { grid-column: 1 / -1; }
  .buy-controls .field { min-width: 0; }
  .buy-list-summary { font-size: 11px; }
  .buy-compare { padding: var(--s4); }
  .buy-opportunities .btn { min-height: 44px; }
  .buy-swap-feedback { align-items: flex-start; }
}
.portal-basket { position: sticky; top: 85px; }
.portal-basket-line { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.portal-basket-line small { display: block; color: var(--text-muted); margin-top: 5px; }
.portal-qty { display: flex; align-items: center; gap: 3px; }
.portal-qty input { width: 62px; text-align: center; padding: 8px 3px; min-height: 44px; }
.portal-qty .btn { width: 44px; padding: 0; }
.portal-form { padding: var(--s6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); margin: 0 0 var(--s5); }
.portal-form h2 { font-size: 20px; margin: 0 0 8px; }
.portal-form .form-grid { margin: var(--s6) 0; row-gap: var(--s5); align-items: end; }
.portal-form-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 12px; margin-top: var(--s5); }
.portal-error { margin-bottom: var(--s4); }
.portal-progress { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.portal-progress span { padding: 7px 10px; border-radius: var(--r-xs); background: var(--surface-2); font-size: 12px; color: var(--text-muted); }
.portal-progress .active { background: var(--good-wash); color: var(--good); font-weight: 600; }
.portal-counter input { width: 100%; max-width: 125px; min-height: 48px; font-size: 18px; text-align: center; }
.portal-bars { display: flex; align-items: flex-end; gap: 10px; height: 156px; margin: 28px 0 32px; }
.portal-bars > div { flex: 1; min-height: 3px; height: var(--height); background: var(--teal); border-radius: 4px 4px 0 0; position: relative; }
.portal-bars span { position: absolute; bottom: -25px; font-size: 10px; color: var(--text-muted); left: 50%; transform: translateX(-50%); white-space: nowrap; }
.portal-bars > div:last-child { background: var(--navy); }
.portal-recipe { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 20px; padding: 24px 0; border-bottom: 1px solid var(--border); }
.portal-recipe h3 { font-size: 17px; margin: 0 0 8px; }
.portal-recipe p { color: var(--text-muted); font-size: 13px; margin: 0; }
.portal-recipe-money { text-align: right; }
.portal-recipe-money strong { display: block; font-size: 23px; color: var(--text-strong); }
.portal-recipe details { grid-column: 1/-1; }
.portal-recipe summary { cursor: pointer; font-size: 13px; color: var(--text-muted); padding: 8px 0; }
.portal-empty { text-align: center; padding: 55px 24px; border: 1px dashed var(--border); border-radius: var(--r-lg); }
.portal-empty > .icon { width: 32px; height: 32px; color: var(--text-muted); margin-bottom: 15px; }
.portal-empty h2 { font-size: 20px; margin: 0 0 10px; }
.portal-empty p { color: var(--text-muted); max-width: 50ch; margin: 0 auto 20px; line-height: 1.6; }
.portal-note { color: var(--text-muted); font-size: 12px; line-height: 1.6; margin: 14px 0; }
.portal-compare { width: 100%; accent-color: var(--teal); height: 7px; }
[data-portal] .td input { max-width: 100%; }
[data-portal] :focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
[data-portal] .page-title { font-size: 32px; }
[data-portal] .table { overflow: hidden; }
[data-portal] .td-primary [data-action="open-order"] { text-align: left; overflow-wrap: anywhere; }
@media (max-width: 1199px) { .portal-buy-grid { grid-template-columns: minmax(0,1fr); } .portal-basket { position: static; } }
@media (max-width: 760px) {
  .portal-split { grid-template-columns: 1fr; }
  .portal-context { grid-template-columns: minmax(0, 1fr); gap: var(--s4); margin-bottom: var(--s6); }
  .portal-mode a { flex: 1; }
  .portal-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .portal-stat { padding: 18px 10px 18px 0; }
  .portal-stat + .portal-stat { padding-left: 16px; }
  .portal-stat:nth-child(3) { border-left: 0; padding-left: 0; border-top: 1px solid var(--border); }
  .portal-stat:nth-child(4) { border-top: 1px solid var(--border); }
  .portal-stat dd { font-size: 23px; }
  .portal-queue a { padding: 18px 16px; gap: 12px; }
  .portal-task-copy strong { font-size: 14px; }
  .portal-task-icon { width: 34px; height: 34px; }
  .portal-queue .badge { display: none; }
  [data-portal] .page-title { font-size: 27px; }
  .portal-form { padding: 18px; }
  .portal-counter input { max-width: 160px; }
  .portal-local { min-height: 0; width: 100%; justify-self: start; justify-content: flex-start; }
}
@media print { [data-portal] .sidebar, [data-portal] .topbar, [data-portal] .workbar, .portal-context, [data-portal] .page-actions, [data-portal] button { display:none!important; } [data-portal] .content { margin:0; } [data-portal] .page { max-width:none; padding:0; } }
.portal-mobile-order { display: none; }
@media (max-width: 760px) {
  .portal-mode { width: 100%; }
  .portal-mobile-order { position: fixed; display: flex; justify-content: space-between; align-items: center; gap: 12px; bottom: 16px; left: 16px; right: 16px; padding: 16px; background: var(--surface); color: var(--text-strong); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); border-radius: var(--r); z-index: 30; font-size: 13px; text-decoration: none; }
  .portal-mobile-order span { display: flex; gap: 8px; align-items: center; }
  [data-portal] .page { padding-bottom: 110px; }
}
@media (max-width: 760px) {
  .portal-tabs { flex-wrap: wrap; overflow: visible; width: 100%; }
  .portal-tabs .btn { flex: 1 1 auto; padding-inline: var(--s3); }
}

/* Consistent control baselines across all venue and corporate views. */
[data-portal] .page-header { column-gap: var(--s6); margin-bottom: var(--s6); }
[data-portal] .page-actions { align-items: flex-end; gap: var(--s3); }
[data-portal] .page-actions:not(.has-fields) { padding-top: var(--s6); }
[data-portal] .page-actions:empty { display: none; }
[data-portal] .page-actions .field { min-width: 10rem; }
.portal-toolbar .toolbar-line { align-items: flex-end; gap: var(--s4); }
.portal-toolbar .toolbar-line > .field { flex: 0 1 13rem; }
.portal-toolbar .search { flex: 1 1 20rem; }
.orders-mobile-sort { display: none; }
.portal-form > .portal-note { margin-top: var(--s2); margin-bottom: var(--s6); max-width: 75ch; }
.portal-order-add-items { margin-top: var(--s4); }
.portal-order-add-items > summary { cursor: pointer; min-height: var(--touch); padding: var(--s3) 0; color: var(--text-strong); font-weight: 600; }
.portal-order-email-details > summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; color: var(--text-strong); }
.portal-order-email-details > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.portal-order-add-items > .table { margin-top: var(--s2); }
.portal-form-actions { border-top: 1px solid var(--border); padding-top: var(--s5); }
.portal-cell-value { min-width: 0; }
.portal-cell-value > .input { width: 100%; min-width: 0; }
.portal-qty { width: 100%; }
.portal-qty .btn { flex: 0 0 var(--touch); }
.portal-qty .input { flex: 1 1 0; width: 0; min-width: 3rem; }
[data-portal] input[type="file"].input { padding: var(--s2); }
[data-portal] input[type="file"]::file-selector-button { margin-right: var(--s3); padding: var(--s2) var(--s3); border: 1px solid var(--border-strong); border-radius: var(--r-xs); background: var(--surface-2); color: var(--text-strong); font: inherit; cursor: pointer; }
@media (min-width: 761px) and (max-width: 1279px) {
  .portal-context { grid-template-columns: minmax(0, 1fr) max-content; row-gap: var(--s3); }
  .portal-local { grid-column: 1 / -1; min-height: 0; }
}
@media (max-width: 1023px) {
  .orders-mobile-sort { display: block; margin-bottom: var(--s4); }
  .orders-mobile-sort .field { max-width: 20rem; }
  [data-portal] .page-header { display: block; }
  [data-portal] .page-actions { margin-top: var(--s4); }
  [data-portal] .page-actions:not(.has-fields) { padding-top: 0; }
  [data-portal] .td[data-label] { align-items: center; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: var(--s3); padding: var(--s2) 0; }
  [data-portal] .td[data-label]::before { align-self: center; }
  [data-portal] .td:has(.portal-qty) { grid-template-columns: minmax(0, 1fr) minmax(9rem, 1.1fr); }
  [data-portal] .td[data-label=""] { display: block; }
  [data-portal] .td[data-label] .cell-meta { text-align: left; margin-top: var(--s1); }
  [data-portal] .td .input { min-height: var(--touch); }
}
/* Portal tables choose their shape from their own width, not the viewport: the grid
   only when every column has room, otherwise the stacked record used on phones.
   Tables with six or more columns (data-wide) need more room before they become a grid. */
[data-portal] #portal-view .table:not(.buy-table, .buy-alternatives-scroll) { container: portal-table / inline-size; }
@container portal-table (max-width: 759px) {
  [data-portal] .table > .thead { display: none; }
  [data-portal] .table .tr { display: block; min-height: 0; padding: var(--s4); }
  [data-portal] .table .tr > .td { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: center; gap: var(--s3); padding: var(--s2) 0; overflow: visible; text-align: left; }
  [data-portal] .table .tr > .td::before { display: block; align-self: center; }
  [data-portal] .table .tr > :is(.td-primary, .td:not([data-label]), .td[data-label=""]) { display: block; padding: 0 0 var(--s2); }
  [data-portal] .table .tr > :is(.td-primary, .td:not([data-label]), .td[data-label=""])::before { display: none; }
  [data-portal] .table .tr > .td:has(.portal-qty) { grid-template-columns: minmax(0, 1fr) minmax(9rem, 1.1fr); }
  [data-portal] .table .td[data-label] .cell-meta { text-align: left; margin-top: var(--s1); }
}
@container portal-table (max-width: 979px) {
  [data-portal] .table[data-wide] > .thead { display: none; }
  [data-portal] .table[data-wide] .tr { display: block; min-height: 0; padding: var(--s4); }
  [data-portal] .table[data-wide] .tr > .td { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: center; gap: var(--s3); padding: var(--s2) 0; overflow: visible; text-align: left; }
  [data-portal] .table[data-wide] .tr > .td::before { display: block; align-self: center; }
  [data-portal] .table[data-wide] .tr > :is(.td-primary, .td:not([data-label]), .td[data-label=""]) { display: block; padding: 0 0 var(--s2); }
  [data-portal] .table[data-wide] .tr > :is(.td-primary, .td:not([data-label]), .td[data-label=""])::before { display: none; }
  [data-portal] .table[data-wide] .tr > .td:has(.portal-qty) { grid-template-columns: minmax(0, 1fr) minmax(9rem, 1.1fr); }
  [data-portal] .table[data-wide] .td[data-label] .cell-meta { text-align: left; margin-top: var(--s1); }
}
@media (max-width: 639px) {
  .portal-toolbar .search, .portal-toolbar .toolbar-line > .field { flex: 1 1 100%; }
  [data-portal] .page-actions.has-fields .field { flex: 1 1 100%; }
  [data-portal] .page-actions.has-fields > .btn { flex: 1 1 auto; }
  .portal-form { padding: var(--s4); }
  .portal-form .field > label { line-height: 1.5; }
}

/* Record actions stay close to the information they change. */
.portal-record-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
/* Receiving record status: invoice and credit-claim facts sit together; text values align with button values. */
.receiving-facts { margin-top: var(--s3); grid-template-columns: repeat(2, minmax(0, 16rem)); }
.receiving-facts .fact-value { display: flex; align-items: center; min-height: 2.125rem; }
.portal-cost-preview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s5); padding: var(--s5) 0; margin: var(--s5) 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.portal-cost-preview span { display: block; color: var(--text-muted); font-size: 12px; margin-bottom: var(--s2); }
.portal-cost-preview strong { color: var(--text-strong); font-size: 20px; }
.portal-version { padding: var(--s4) 0; }
.portal-version h4 { margin: 0 0 var(--s2); }
.portal-version .table { margin-top: var(--s3); }
.portal-check { display: flex; align-items: center; gap: var(--s3); margin: var(--s5) 0; }
.portal-check input { width: 20px; height: 20px; flex: 0 0 20px; accent-color: var(--teal); }
[data-portal] input[readonly] { background: var(--surface-2); color: var(--text-muted); }
#portal-feedback { scroll-margin-top: 80px; }
#invoice-lines .tr[hidden] { display: none; }
@media (max-width: 639px) {
  .portal-cost-preview { grid-template-columns: 1fr; gap: var(--s4); }
  .portal-cost-preview > div { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); }
  .portal-cost-preview span { margin: 0; }
  .portal-cost-preview strong { font-size: 17px; text-align: right; }
  .portal-record-actions .btn { min-height: var(--touch); }
}

/* Recipe workspace: selected components, explicit yield and kitchen output. */
.rx-filters { display:grid; grid-template-columns:minmax(0,2fr) repeat(3,minmax(0,1fr)); gap:var(--s4); align-items:end; margin:var(--s5) 0; }
.rx-section { padding:var(--s6) 0; border-bottom:1px solid var(--border); }
.rx-section:first-child { padding-top:0; }
.rx-section:last-of-type { border-bottom:0; }
.rx-section h2 { color:var(--text-strong); }
.rx-section > .field, .rx-step > .field { margin:var(--s4) 0; }
.rx-section textarea, .rx-step textarea { min-height:96px; width:100%; resize:vertical; }
.rx-inline { display:flex; flex-wrap:wrap; align-items:end; gap:var(--s3); }
.rx-inline > .field { flex:1; min-width:90px; }
.rx-inline > .field input, .rx-inline > .field select { width:100%; }
.rx-line-cost { padding-bottom:var(--s3); color:var(--text-strong); font-weight:600; }
.rx-picker { padding:var(--s5); margin:var(--s4) 0; background:var(--surface-2); border:1px solid var(--border); border-radius:var(--r-md); }
.rx-detail { margin:var(--s4) 0; padding:var(--s4) 0; border-top:1px solid var(--border); }
.rx-detail summary, .rx-line-details summary { cursor:pointer; min-height:44px; display:list-item; padding:var(--s3) 0; color:var(--text-strong); }
.rx-step { padding:var(--s5) 0; border-top:1px solid var(--border); }
.rx-photo img, .rx-step-photo { max-width:240px; max-height:180px; object-fit:contain; border-radius:var(--r-md); }
.rx-photo .field { margin:var(--s4) 0; }
.rx-card-options { display:flex; justify-content:space-between; align-items:center; gap:var(--s5); flex-wrap:wrap; margin-bottom:var(--s5); }
.rx-card-scaling { margin-bottom:var(--s5); padding-bottom:var(--s5); border-bottom:1px solid var(--border); }
.rx-card-scaling > .portal-note { margin-top:var(--s2); }
.rx-card-scale-fields { display:flex; align-items:end; gap:var(--s4); flex-wrap:wrap; margin-top:var(--s4); }
.rx-card-scale-fields .field { flex:0 1 200px; min-width:0; }
#rx-card-scale-error:empty { display:none; }
@media(max-width:767px) { .rx-card-scale-fields .field { flex:1 1 120px; } }
@media print { .rx-card-scaling { display:none!important; } }
.rx-recipe-card { background:var(--surface); padding:var(--s7); border:1px solid var(--border); border-radius:var(--r-lg); }
.rx-recipe-card > .table { margin-block:var(--s5); }
.rx-recipe-card > .section-title { margin-top:var(--s5); margin-bottom:var(--s2); }
.rx-card-photo { max-width:220px; max-height:180px; object-fit:contain; border-radius:var(--r-md); }
.rx-card-steps li { padding:var(--s4); break-inside:avoid; }
.rx-card-steps p, .rx-preserve { white-space:pre-wrap; }
.rx-selection { display:flex; flex-direction:column; gap:var(--s3); margin:var(--s5) 0; border:1px solid var(--border); padding:var(--s4); }
.rx-selection label { min-height:44px; display:flex; gap:var(--s3); align-items:center; }
@media(max-width:767px) { .rx-filters { grid-template-columns:1fr 1fr; } .rx-recipe-card { padding:var(--s4); } .rx-card-photo { max-width:140px; } .rx-section { padding:var(--s5) 0; } .rx-picker { padding:var(--s3); } }
@media(max-width:420px) { .rx-filters { grid-template-columns:1fr; } }
@media print { body:has(.rx-recipe-card) #portal-feedback, body:has(.rx-recipe-card) .page-header, .rx-card-options { display:none!important; } .rx-recipe-card { border:0; padding:0; } .rx-recipe-card .table-foot { display:none; } .rx-recipe-card .tr { break-inside:avoid; } }

/* Fast recipe entry, with the shared Items suggestion pattern. */
.rx-entry-wrap { border:1px solid var(--border); border-radius:var(--r-md); }
.rx-entry-table { width:100%; table-layout:fixed; border-collapse:collapse; font-size:var(--text-sm,14px); }
.rx-entry-table th { padding:var(--s3); color:var(--text-subtle); font-size:11px; text-align:left; font-weight:600; background:var(--surface-2); }
.rx-entry-table th:first-child { border-radius:var(--r-md) 0 0 0; }
.rx-entry-table th:nth-child(2) { width:116px; }
.rx-entry-table th:nth-child(3) { width:116px; }
.rx-entry-table th:nth-child(4) { width:92px; text-align:right; }
.rx-entry-table th:last-child { width:112px; border-radius:0 var(--r-md) 0 0; }
.rx-entry-table td { padding:var(--s3); border-top:1px solid var(--border); vertical-align:middle; }
.rx-entry-name { overflow-wrap:anywhere; }
.rx-entry-name strong { font-size:14px; color:var(--text-strong); }
.rx-entry-name .cell-meta { font-size:11px; line-height:1.5; margin-top:2px; }
.rx-entry-table .input, .rx-entry-table select { width:100%; min-width:0; min-height:38px; padding:8px 10px; }
.rx-entry-cost { text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; }
.rx-entry-table select.input { padding-right:32px; }
.rx-entry-actions { white-space:nowrap; }
.rx-entry-actions .btn { width:44px; min-width:44px; min-height:44px; padding:4px; font-size:22px; }
.rx-entry-empty td { padding:var(--s3); }
.rx-entry-search { position:relative; }
.rx-entry-search .suggest { margin:0; list-style:none; }
.rx-entry-search .suggest[hidden], .rx-entry-detail[hidden] { display:none; }
.rx-entry-search .suggest-option { font-size:14px; }
.rx-entry-foot { display:flex; align-items:baseline; justify-content:space-between; gap:var(--s3); margin-top:var(--s2); }
.rx-entry-foot .portal-note { margin:0; font-size:12px; }
.rx-entry-foot .btn { flex-shrink:0; }
.rx-line-details { padding:var(--s2); }
.rx-line-details .portal-record-actions { margin-bottom:var(--s3); }
.rx-line-error { display:block; color:var(--danger,var(--text-strong)); font-size:11px; line-height:1.4; }
.rx-line-error:empty { display:none; }
/* Invoice edit: a rejected quantity is marked and explained beside the field. */
#edit-rows .input[aria-invalid="true"] { border-color: var(--bad); }
#edit-rows .edit-qty-error { display: block; margin-top: var(--s1); color: var(--bad); overflow-wrap: anywhere; }
#edit-rows .edit-qty-error:empty { display: none; }
@media (min-width: 1024px) {
  #edit-rows .edit-qty-error { grid-row: 2; grid-column: 2 / -1; margin-top: 0; }
}
.rx-entry-table [aria-invalid="true"] { border-color:var(--danger); }
@media(max-width:639px) {
 .rx-entry-table, .rx-entry-table tbody { display:block; }
 .rx-entry-table thead { position:absolute; width:1px; height:1px; clip-path:inset(50%); overflow:hidden; }
 .rx-entry-row { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); }
 .rx-entry-table .rx-entry-name { grid-column:1/3; padding-bottom:0; }
 .rx-entry-row td:not(.rx-entry-name) { border-top:0; padding-top:var(--s2); }
 .rx-entry-quantity:before { content:'Quantity'; }
 .rx-entry-unit:before { content:'Unit'; }
 .rx-entry-cost:before { content:'Cost'; }
 .rx-entry-quantity:before,.rx-entry-unit:before,.rx-entry-cost:before { display:block; color:var(--text-subtle); font-size:11px; margin-bottom:var(--s1); }
 .rx-entry-cost span { display:block; padding-top:12px; }
 .rx-entry-actions { grid-column:3; grid-row:1; align-self:start; text-align:right; padding-inline:0; }
 .rx-entry-quantity,.rx-entry-unit,.rx-entry-cost { grid-row:2; }
 .rx-entry-table .rx-entry-unit { padding-inline:4px; }
 .rx-entry-table .rx-entry-unit select { padding-left:8px; padding-right:26px; background-position:right 8px center; }
 .rx-entry-table .input,.rx-entry-table select,.rx-entry-actions .btn { min-height:44px; }
 .rx-entry-empty,.rx-entry-detail { display:block; }
 .rx-entry-empty td,.rx-entry-detail td { display:block; }
 .rx-entry-foot { flex-wrap:wrap; }
}

/* Ingredient order: dedicated handles leave text and number inputs editable. */
.rx-entry-name { position:relative; padding-left:44px!important; }
.rx-drag-handle { position:absolute; left:6px; top:50%; transform:translateY(-50%); display:grid; place-items:center; width:32px; height:38px; padding:0; border:0; border-radius:var(--r-sm); background:transparent; color:var(--text-subtle); cursor:grab; touch-action:none; user-select:none; }
.rx-drag-handle:hover { color:var(--text-strong); background:var(--surface-3); }
.rx-drag-handle:focus-visible { outline:2px solid var(--border-focus); outline-offset:1px; }
.rx-drag-handle:disabled { opacity:.35; cursor:default; }
.rx-reordering, .rx-reordering * { cursor:grabbing!important; user-select:none!important; }
@media(max-width:639px) {
 .rx-entry-table .rx-entry-name { padding-left:50px!important; min-height:50px; }
 .rx-drag-handle { left:2px; width:44px; height:44px; }
}

/* Lift the complete row while neighbouring rows make room in real time. */
.rx-entry-row.rx-drag-source { background:var(--surface-3); outline:1px dashed var(--border-strong); outline-offset:-2px; }
.rx-entry-row.rx-drag-source > td { visibility:hidden; }
.rx-drag-preview { position:fixed; z-index:1000; pointer-events:none; background:var(--surface); border-radius:var(--r-sm); box-shadow:var(--shadow-lg),0 0 0 1px var(--border-strong); overflow:hidden; will-change:transform; }
.rx-drag-preview .rx-entry-table { margin:0; }
.rx-drag-preview td { border:0; }
.rx-drag-preview .rx-drag-handle { color:var(--text-strong); }
.rx-drag-preview.rx-drag-outside { opacity:.65; }

/* Venue access uses the same form controls as organisation selection. */
.user-venues { margin:1.5rem 0 0; padding:1rem; border:1px solid var(--border); border-radius:var(--r-sm); min-width:0; }
.user-venues legend { font-weight:600; color:var(--text-strong); padding:0 .5rem; }
.user-venue-selections { display:flex; flex-wrap:wrap; gap:.5rem; margin:.75rem 0; }
.user-venue-selections:empty { margin:0; }
.user-venue-selections .btn { white-space:normal; text-align:left; }
.user-venue-options { max-height:240px; overflow-y:auto; overscroll-behavior:contain; margin-top:.75rem; }
.user-venue-option { display:flex; align-items:center; gap:.75rem; min-height:44px; padding:.5rem .75rem; cursor:pointer; border-radius:var(--r-sm); }
.user-venue-option:hover, .user-venue-option:focus-within { background:var(--surface-2); }
.user-venue-option input { flex-shrink:0; width:18px; height:18px; accent-color:var(--teal); }

/* Recipes: one compact register and a keyboard-first entry workspace. */
.rx-list-toolbar { display:flex; align-items:center; justify-content:space-between; gap:var(--s4); flex-wrap:wrap; }
.rx-list-toolbar .portal-tabs { margin:0; }
.rx-register { border:1px solid var(--border); border-radius:var(--r-lg); background:var(--surface); }
.rx-register-head, .rx-register-row { display:grid; grid-template-columns:minmax(230px,2fr) minmax(120px,1fr) minmax(120px,1fr) 90px 120px; gap:var(--s4); align-items:center; padding:var(--s4) var(--s5); }
.rx-register-head { border-radius:var(--r-lg) var(--r-lg) 0 0; background:var(--surface-2); color:var(--text-muted); font-size:12px; }
.rx-register-head .btn { padding:0; justify-content:flex-start; font-size:12px; color:var(--text-muted); text-align:left; }
.rx-register-head .btn:not(:first-child) { justify-content:flex-end; text-align:right; }
.rx-register-head > span:last-child { text-align:right; }
.rx-register-bases .rx-register-head, .rx-register-bases .rx-register-row { grid-template-columns:minmax(230px,2fr) minmax(120px,1fr) minmax(140px,1fr) 120px; }
.rx-register-record + .rx-register-record { border-top:1px solid var(--border); }
.rx-register-name { min-width:0; }
.rx-register-name h2 { margin:0; font-family:Inter,sans-serif; font-size:15px; line-height:1.4; }
.rx-register-name h2 .btn { padding:0; min-height:44px; white-space:normal; text-align:left; color:var(--text-strong); font-weight:600; justify-content:flex-start; }
.rx-register-name h2 .btn::before { content:'›'; margin-right:var(--s2); color:var(--text-muted); }
.rx-register-name h2 .btn[aria-expanded="true"]::before { transform:rotate(90deg); }
.rx-register-name .cell-meta { margin:0 0 0 var(--s4); font-size:12px; }
.rx-register .rx-review-state { font-size:12px; padding:0 var(--s2); margin-left:var(--s2); min-height:32px; font-weight:400; background:transparent; color:var(--text-muted); }
.rx-register .rx-review-state.badge-warn { color:var(--warn); }
.rx-register-value { text-align:right; font-variant-numeric:tabular-nums; color:var(--text-strong); font-size:14px; }
.rx-register-value strong { font-weight:600; }
.rx-register-actions { display:flex; justify-content:flex-end; gap:var(--s1); }
.rx-register-actions .btn { min-height:44px; padding:var(--s2) var(--s3); }
.rx-more { position:relative; }
.rx-more > summary { list-style:none; display:flex; justify-content:center; align-items:center; min-width:44px; min-height:44px; cursor:pointer; border-radius:var(--r-xs); font-size:21px; }
.rx-more > summary::-webkit-details-marker { display:none; }
.rx-more > summary:hover { background:var(--surface-2); }
.rx-more > summary:focus-visible { outline:2px solid var(--brand); outline-offset:2px; }
.rx-more-menu { position:absolute; top:100%; right:0; z-index:30; width:230px; padding:var(--s2); background:var(--surface); border:1px solid var(--border); border-radius:var(--r); box-shadow:var(--shadow-md); }
.rx-more-menu .btn { width:100%; text-align:left; justify-content:flex-start; }
.rx-expanded { padding:var(--s5); background:var(--surface-2); border-top:1px solid var(--border); }
.rx-expanded[hidden] { display:none; }
.rx-expanded h3 { margin:0 0 var(--s3); font-size:14px; color:var(--text-strong); }
.rx-expanded .table { background:var(--surface); }
.rx-entry-tools { display:flex; align-items:center; justify-content:space-between; gap:var(--s3); flex-wrap:wrap; margin-bottom:var(--s3); }
.rx-entry-tools .subnav { margin:0; }
.rx-entry-tools .btn { min-height:44px; }
.rx-entry-tools .portal-note { margin:0; font-size:12px; }
.rx-entry-search .suggest > li > .btn { width:100%; justify-content:flex-start; }
.rx-editor { padding-bottom:0; }
.rx-editor .rx-savebar { position:sticky; bottom:0; z-index:20; margin:0 calc(-1 * var(--s5)); padding:var(--s3) var(--s5); background:var(--surface); border-top:1px solid var(--border); gap:var(--s2); border-radius:0 0 var(--r-lg) var(--r-lg); }
.rx-save-summary { margin-right:auto; display:flex; flex-direction:column; gap:var(--s1); font-size:13px; }
.rx-save-summary > span { color:var(--text-muted); font-size:12px; }
.rx-save-summary > strong { color:var(--text-strong); font-weight:600; }
.rx-editor input, .rx-editor select { scroll-margin-bottom:140px; }
@media(max-width:1100px) {
 .rx-register-head, .rx-register-row { grid-template-columns:minmax(180px,2fr) 110px 110px 75px 115px; gap:var(--s2); padding:var(--s3) var(--s4); }
}
@media(max-width:767px) {
 .rx-register-head { display:none; }
 .rx-register-row, .rx-register-bases .rx-register-row { grid-template-columns:repeat(3,minmax(0,1fr)); padding:var(--s4); gap:var(--s3); }
 .rx-register-name { grid-column:1/-1; }
 .rx-register-value { text-align:left; }
 .rx-register-value::before { content:attr(data-label); display:block; color:var(--text-muted); font-size:11px; margin-bottom:var(--s2); }
 .rx-register-actions { grid-column:1/-1; justify-content:flex-end; }
 .rx-register-bases .rx-register-value { grid-column:span 1; }
 .rx-expanded { padding:var(--s4); }
 .rx-editor .rx-savebar { margin:0 calc(-1 * var(--s4)); padding:var(--s3) var(--s4); }
 .rx-save-summary { flex-basis:100%; flex-direction:row; justify-content:space-between; }
 .rx-savebar .btn { flex:1; font-size:12px; padding:var(--s2); }
}
@media print { .rx-savebar { display:none!important; } }
.rx-register-row { padding-top:var(--s3); padding-bottom:var(--s3); }
.rx-register-name { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; column-gap:var(--s2); }
.rx-register-name .cell-meta { grid-column:1/-1; }
.rx-register .rx-review-state { min-height:44px; margin:0; }

.rx-register-bases .rx-register-head > span { text-align:right; }

.draft-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); }

/* Source PDF identity keeps its full reading width on compact screens. */
#pdf-sheet .sheet-title { overflow-wrap: anywhere; }
@media (max-width: 639px) {
  #pdf-sheet .sheet-head { position: relative; flex-direction: column; }
  #pdf-sheet .sheet-head-copy { width: 100%; padding-right: var(--s8); }
  #pdf-sheet .sheet-head > .row { width: 100%; justify-content: space-between; }
  #pdf-sheet .sheet-close { position: absolute; top: var(--s5); right: var(--s5); }
}

/* Shared action sheet and import preview; registered in COMPONENTS.md. */
dialog.sheet.action-sheet { width: min(520px, calc(100vw - 32px)); }
dialog.sheet.action-sheet-wide { width: min(960px, calc(100vw - 32px)); }
.action-preview-table { overflow: auto; max-height: 50vh; border: 1px solid var(--border); border-radius: var(--r-sm); }
.action-preview-table table { border-collapse: collapse; width: 100%; font-size: 14px; }
.action-preview-table th, .action-preview-table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.action-preview-table th { position: sticky; top: 0; background: var(--surface-2); }
.action-preview-table th.num, .action-preview-table td.num { text-align: right; white-space: nowrap; }
/* Entries blocking a price-list publication: name, reason and a link to the item on one line each. */
.price-review-blocking { display: grid; gap: var(--s2); margin: var(--s2) 0 0; padding: 0; list-style: none; }
.price-review-blocking li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s3); }
.price-review-blocking li > span:first-child { font-weight: 600; color: var(--text-strong); }
@media (max-width: 639px), (pointer: coarse) {
  .btn-sm, .icon-btn, .toggle-chip, .chip-x, .tag-x { min-height: 44px; min-width: 44px; }
}

@media (max-width: 639px), (pointer: coarse) {
  main button, dialog button { min-height: 44px; }
}

.sort-cell { display: flex; min-width: 0; }
.sort-cell > button.th { width: 100%; }

.action-preview-table th { font-size: 0.6875rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted); }

@media (max-width:639px) { dialog.sheet.action-sheet { width:100%; } }

/* Compact order summary: detailed terms and confirmation belong to review. */
.buy-supplier-heading { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
.buy-supplier-heading h3 { min-width: 0; overflow-wrap: anywhere; display: inline-flex; align-items: center; gap: var(--s1); }
.buy-supplier-heading > strong:last-child { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.buy-supplier-heading small { display: block; font-weight: 400; color: var(--text-muted); font-size: 12px; }
.buy-supplier-compact { padding: var(--s4) 0; }
.buy-supplier-compact .portal-note { margin: var(--s1) 0; }
.buy-supplier-compact .buy-warning, .buy-supplier-compact .buy-cutoff { margin: var(--s1) 0 0; }
.buy-supplier-issue { display: inline-flex; color: var(--warn); }
.buy-supplier-issue .icon { width: 16px; height: 16px; }
.buy-supplier-items { display: inline-flex; align-items: center; gap: 2px; min-height: 32px; margin: var(--s1) 0; padding: 0; color: var(--text-muted); font-size: 12px; text-align: left; }
.buy-supplier-items .icon { width: 14px; height: 14px; }
.buy-attention-label { color: var(--warn); font-size: 12px; }
.buy-basket-warning { display: flex; align-items: flex-start; gap: var(--s2); margin: var(--s3) 0 0; padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--warn-wash); }
.buy-basket-warning .icon { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; }
.buy-delivery-summary { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); font-size: 12px; color: var(--text-muted); }
.buy-delivery-summary .btn { padding: var(--s1) var(--s2); min-height: 32px; font-size: 12px; }
.buy-basket-footer > .btn { margin-top: var(--s3); }
.buy-basket-footer > .portal-note:last-child { text-align: center; margin: var(--s2) 0 0; font-size: 11px; }
@media (max-width: 767px), (pointer: coarse) { .buy-delivery-summary .btn { min-height: 44px; } }

.buy-basket-sheet-body { display: grid; gap: 0; padding: 0; }
.buy-basket-sheet-line { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: var(--s4); padding: var(--s4) var(--s5); }
.buy-basket-sheet-line + .buy-basket-sheet-line { border-top: 1px solid var(--border); }
.buy-basket-sheet-line.is-unavailable { align-items: start; background: var(--warn-wash); }
.buy-basket-sheet-copy { display: grid; min-width: 0; gap: 2px; }
.buy-basket-sheet-copy > strong { overflow-wrap: break-word; color: var(--text-strong); }
/* Remove sits under the item details, as in Review order. */
.buy-basket-sheet-copy [data-buy="basket-remove"] { justify-self: start; min-height: 32px; margin: var(--s1) 0 0 calc(-1 * var(--s2)); padding: var(--s1) var(--s2); color: var(--danger); font-size: 11px; }
.buy-basket-sheet-copy .buy-warning { display: flex; align-items: flex-start; gap: var(--s2); margin: var(--s2) 0; }
.buy-basket-sheet-copy .buy-warning .icon { flex: 0 0 auto; width: 16px; height: 16px; margin-top: 2px; }
.buy-basket-sheet-actions { display: flex; align-items: center; gap: var(--s3); }
.buy-basket-sheet-quantity { display: grid; grid-template-columns: 40px minmax(112px,150px) 40px; align-items: stretch; gap: var(--s1); }
.buy-basket-sheet-quantity .btn { min-width: 40px; min-height: 40px; padding: var(--s1); }
.buy-basket-sheet-quantity label { display: grid; grid-template-columns: minmax(52px,1fr) auto; align-items: center; min-width: 0; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); overflow: hidden; }
.buy-basket-sheet-quantity input { width: 100%; min-width: 0; border: 0; border-radius: 0; padding: var(--s2); text-align: right; font-weight: 700; }
.buy-basket-sheet-quantity label > span:last-child { padding-right: var(--s2); color: var(--text-muted); font-size: 12px; font-weight: 600; }
@media (max-width: 639px) {
  .buy-basket-sheet-line { grid-template-columns: minmax(0,1fr); gap: var(--s3); padding: var(--s4); }
  .buy-basket-sheet-actions { justify-content: space-between; }
  .buy-basket-sheet-copy [data-buy="basket-remove"] { min-height: 44px; }
  .buy-basket-sheet-quantity { grid-template-columns: 44px minmax(100px,1fr) 44px; flex: 1; }
  .buy-basket-sheet-quantity .btn { min-width: 44px; min-height: 44px; }
  .buy-supplier-items { min-height: 44px; }
}

.buy-review-fields { border: 0; margin: 0; padding: 0; min-width: 0; }

/* Pending comparisons keep their trigger dimensions and remain cancellable. */
.buy-row-actions [aria-busy="true"], .buy-opportunities [aria-busy="true"] { opacity: 0.65; }

/* Inline comparison: one outlined source and drawer, with a compact header. */
.buy-table .tr.is-comparing { box-shadow: inset 1px 0 var(--border-strong), inset -1px 0 var(--border-strong), inset 0 1px var(--border-strong); }
.buy-table .tr.is-comparing + .buy-comparison-row { box-shadow: inset 1px 0 var(--border-strong), inset -1px 0 var(--border-strong), inset 0 -1px var(--border-strong); background: var(--surface); }
/* Keep items distinct: firmer dividers in the table, and a green bar on the left of every item in the order,
   so neighbouring selected rows still read as separate items (colour is not the only cue). */
.buy-table .tbody > .tr + .tr { border-top-color: var(--border-strong); }
.buy-table .tbody > .tr.is-selected { box-shadow: inset 4px 0 0 var(--good); }
.buy-table .tbody > .tr.is-selected.is-comparing { box-shadow: inset 4px 0 0 var(--good), inset -1px 0 var(--border-strong), inset 0 1px var(--border-strong); }
/* Narrow layouts: each item is its own card. The product name anchors the card, and a source line
   without an alternatives button no longer reserves button height. */
@container buy-table (max-width: 799px) {
  .buy-group > .buy-table { border: 0; border-radius: 0; background: none; box-shadow: none; overflow: visible; }
  .buy-table > .tbody { display: grid; gap: var(--s2); }
  .buy-table .tbody > .tr + .tr { border-top: 0; }
  /* Each card clips its own content, as the table box did, except while offer terms are open. */
  .buy-table .tbody > .tr { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow-xs); overflow: hidden; }
  .buy-table .tbody > .tr:has(.buy-offer-details[open]) { overflow: visible; }
  .buy-table .tbody > .tr.is-selected { background: var(--good-wash); border-color: color-mix(in oklab, var(--good) 30%, var(--border)); box-shadow: inset 4px 0 0 var(--good), var(--shadow-xs); }
  .buy-table .tbody > .tr.is-comparing { border-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
  .buy-table .tbody > .tr.is-comparing + .buy-comparison-row { margin-top: calc(-1 * var(--s2)); border: 1px solid var(--border-strong); border-top: 0; border-radius: 0 0 var(--r) var(--r); overflow: hidden; }
  .buy-table .tbody > .buy-comparison-row:not(.tr) { border-bottom: 0; }
  .buy-table .buy-item-heading > strong { font-size: 15px; }
  .buy-table .tr:has([data-buy="compare"][hidden]) .buy-price-source { min-height: 0; }
}
.buy-compare { margin: 0 1px 1px; padding-top: var(--s2); background: var(--info-wash); }
.buy-row-actions [data-buy="compare"] { justify-self: center; min-width: 36px; font-size: 13px; font-weight: 600; }
.buy-row-actions [data-buy="compare"][aria-expanded="true"] { background: var(--info-wash); border-color: var(--info); color: var(--info); }
@media (max-width: 767px) {
  .buy-row-actions [data-buy="compare"] { min-width: 44px; }
}

.buy-comparison-header { display: flex; justify-content: flex-end; margin-bottom: var(--s2); }
.buy-comparison-header .btn { min-height: 32px; padding: var(--s1) var(--s2); }
.buy-item-actions .btn { min-height: 28px; padding: var(--s1) 0; font-size: 11px; }
@media (max-width: 767px) {
  .buy-compare { padding-top: var(--s2); }
  .buy-comparison-header .btn, .buy-item-actions .btn { min-height: 44px; }
}

/* Shared quantity stepper: decrease, editable amount/unit with clear, increase. */
.buy-quantity-control { display: grid; grid-template-columns: 32px minmax(0,1fr) 32px; align-items: center; gap: var(--s1); width: 100%; }
/* The unit track is fixed so units line up down the list, and wide enough for PUNNET or carton. */
.buy-quantity-field { display: grid; grid-template-columns: minmax(0,1fr) 3rem 32px; align-items: center; min-width: 0; min-height: 40px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); }
.buy-quantity-field:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.buy-quantity-field:has([aria-invalid="true"]) { border-color: var(--bad); }
.buy-quantity .buy-quantity-field .input { min-width: 0; width: 100%; flex: 1 1 32px; padding: var(--s2) var(--s1); border: 0; box-shadow: none; outline: none; background: transparent; text-align: center; font-size: 13px; font-weight: 700; color: var(--text-strong); appearance: textfield; }
.buy-quantity-field .input::-webkit-inner-spin-button, .buy-quantity-field .input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.buy-quantity-unit { grid-column: 2; min-width: 0; padding-right: var(--s1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 600; color: var(--text-strong); }
.buy-quantity-field.is-suggested .buy-quantity-unit, .buy-quantity-field .input::placeholder { color: var(--text-muted); font-weight: 400; opacity: 1; }
.buy-quantity [data-quantity-action] { min-height: 40px; width: 32px; padding: 0; }
.buy-quantity-field [data-quantity-action] { grid-column: 3; }
.buy-quantity [data-quantity-action] .icon { width: 16px; height: 16px; }
@media (max-width: 767px) {
  .buy-quantity-control { grid-template-columns: 44px minmax(0,1fr) 44px; max-width: 300px; }
  .buy-quantity [data-quantity-action] { width: 44px; min-height: 44px; }
  .buy-quantity-field { min-height: 44px; grid-template-columns: minmax(0,1fr) 3rem 44px; }

}

/* Shared venue/corporate selector stays below the app navigation. */
[data-portal] { --portal-bar-offset: calc(var(--topbar-h) + var(--safe-top)); --portal-sticky-top: calc(var(--portal-bar-offset) + var(--portal-context-h, 0px) + var(--s4)); }
#portal-context { position: sticky; top: var(--portal-bar-offset); z-index: 45; display: flow-root; padding-top: var(--s2); margin-bottom: var(--s7); background: var(--bg); }
#portal-context:empty { display: none; }
#portal-context > .portal-context { margin-bottom: 0; }
[data-portal] #portal-view :is(input, select, textarea, [tabindex="-1"], [data-buy-row]), [data-portal] #portal-feedback, [data-portal] .buy-compare { scroll-margin-top: var(--portal-sticky-top); }
@media (min-width: 1024px) { [data-portal] { --portal-bar-offset: var(--topbar-h); } }
@media (min-width: 1200px) { .portal-basket { top: var(--portal-sticky-top); } }
@media (min-width: 1351px) {
  .buy-basket { margin-top: var(--buy-basket-start, 0px); top: calc(var(--portal-sticky-top) + var(--buy-list-bar-h, 0px)); max-height: calc(100dvh - var(--portal-sticky-top) - var(--buy-list-bar-h, 0px) - var(--portal-action-height, 0px) - var(--s6) - var(--safe-bottom)); }
}
@media print { #portal-context { display: none !important; } }

/* Compact order cards keep the buying decision above supporting evidence. */
.buy-history-label { display: none; }
@media (max-width: 1023px) {
  .page:has(#buy-workspace) { padding-top: 0; }
  .page:has(#buy-workspace) .page-header { margin-bottom: var(--s3); }
  .page:has(#buy-workspace) .page-title { font-size: 22px; }
  .page:has(#buy-workspace) .page-header .eyebrow,
  .page:has(#buy-workspace) .page-lede { display: none; }
  .page:has(#buy-workspace) #portal-context { margin-bottom: var(--s4); padding-top: var(--s2); }
  .page:has(#buy-workspace) #portal-context > .portal-context { grid-template-columns: minmax(0,1fr) max-content max-content; align-items: center; gap: var(--s2); padding-bottom: var(--s2); }
  .page:has(#buy-workspace) .portal-context .field > label,
  .page:has(#buy-workspace) .portal-context .field-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .page:has(#buy-workspace) .portal-context select,
  .page:has(#buy-workspace) .portal-mode { height: 48px; }
  .page:has(#buy-workspace) .portal-local { grid-column: auto; min-height: 0; width: auto; margin: 0; font-size: 11px; }
  .page:has(#buy-workspace) .portal-tabs { margin-bottom: var(--s4); }
  .buy-controls { gap: var(--s2); margin-bottom: var(--s3); }
  .buy-list-summary { margin-bottom: var(--s3); }
  .buy-list-summary > span:last-child { display: none; }
  .buy-history-hint { display: none; }
  .buy-group h2 { margin-bottom: var(--s2); }
  .buy-quantity-control { grid-template-columns: 44px minmax(0,1fr) 44px; max-width: none; }
  .buy-quantity [data-quantity-action] { width: 44px; min-height: 44px; }
  .buy-quantity-field { min-height: 44px; grid-template-columns: minmax(0,1fr) 3rem 44px; }
  .buy-price-main { grid-area: price; margin-top: var(--s2); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s2); }
  .buy-price-main > strong { font-size: 16px; line-height: 1.4; }
  [data-portal] .buy-price-main > .cell-meta { margin: 0; }
  .buy-price-main > .buy-was-price { margin-left: 0; }
  .buy-history-label { display: inline; }
  .buy-row-actions [data-buy="compare"]::after { content: " alternatives"; }
  .buy-row-actions [data-buy="compare"][title="1 alternatives"]::after { content: " alternative"; }
}
/* The item grid needs about 800px. Narrower tables use the compact card below, including
   desktop windows around 1024px; below 1024px the table is always narrower. */
/* The group measures the table's width, so container rules can also restyle the table itself. */
.buy-group { container: buy-table / inline-size; }
/* Below 1024px the shared table falls back to label/value records. A Buy list still 800px or wider
   (a tablet or narrow desktop window without the sidebar) keeps the full item table instead. */
@media (max-width: 1023px) {
  @container buy-table (min-width: 800px) {
    .buy-table > .thead { display: grid; grid-template-columns: var(--cols); align-items: center; height: 2.75rem; padding: 0; background: var(--surface-2); border-bottom: 1px solid var(--border); }
    .buy-table .tr { display: grid; grid-template-columns: var(--cols); align-items: start; min-height: 3.75rem; padding: 0; }
    [data-portal] .buy-table .td, [data-portal] .buy-table .td[data-label] { display: block; min-width: 0; overflow: hidden; padding: var(--s3); text-align: left; }
    [data-portal] .buy-table .td::before { display: none; }
    [data-portal] .buy-table .td[data-label] .cell-meta { text-align: left; margin-top: 0.125rem; }
    .buy-table .buy-history-label { display: none; }
    .buy-table .buy-price-main { display: block; margin-top: 0; }
    .buy-table .buy-price-main > strong { font-size: inherit; line-height: inherit; }
    .buy-table .buy-price-main > .buy-was-price { margin-left: var(--s2); }
  }
}
@container buy-table (max-width: 799px) {
  .buy-table > .thead { display: none; }
  [data-portal] .buy-table .tr > .td { overflow: visible; }
  .buy-table .tr { display: grid; grid-template-columns: minmax(0,1fr) 232px; grid-template-areas: "product quantity" "price history" "offer history" "source alternatives" "opportunities opportunities"; align-items: center; column-gap: var(--s3); row-gap: 0; padding: var(--s3); }
  [data-portal] .buy-table .td,
  [data-portal] .buy-table .td[data-label] { display: block; min-width: 0; padding: 0; }
  .buy-table .td::before { display: none; }
  [data-portal] .buy-table .td-primary { grid-area: product; display: grid; grid-template-columns: minmax(0,1fr) 44px; column-gap: var(--s2); align-items: start; }
  .buy-table .buy-item-heading { grid-column: 1; grid-row: 1; display: grid; grid-template-rows: auto 1.4em; font-size: 13px; line-height: 1.4; }
  .buy-table .td-primary > .cell-meta { grid-column: 1; grid-row: 2; margin-top: 2px; }
  .buy-table .buy-item-actions { grid-column: 2; grid-row: 1 / 3; align-self: start; }
  .buy-table .buy-item-actions .btn { min-width: 44px; min-height: 44px; padding: var(--s1); }
  .buy-table .buy-item-actions:has(.btn:disabled) { visibility: hidden; }
  .buy-table .buy-pending { grid-column: 1 / -1; grid-row: 3; }
  .buy-table .td[data-label="Order quantity"] { grid-area: quantity; }
  .buy-quantity-control { grid-template-columns: 44px minmax(0,1fr) 44px; max-width: none; }
  .buy-quantity [data-quantity-action] { width: 44px; min-height: 44px; }
  .buy-quantity-field { min-height: 44px; grid-template-columns: minmax(0,1fr) 3rem 44px; }
  [data-portal] .buy-table .td[data-label="Price, ex GST"],
  .buy-table .td[data-label="Price, ex GST"] > div { display: contents; }
  .buy-price-main { grid-area: price; margin-top: var(--s2); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s2); }
  .buy-price-main > strong { font-size: 16px; line-height: 1.4; }
  [data-portal] .buy-price-main > .cell-meta { margin: 0; }
  .buy-price-main > .buy-was-price { margin-left: 0; }
  .buy-table .buy-price-source { grid-area: source; justify-self: start; align-self: center; display: inline-flex; align-items: center; min-height: 28px; margin-top: var(--s1); text-align: left; font-size: 11px; }
  .buy-table .td[data-label="Last purchased"] { grid-area: history; margin-top: var(--s2); font-size: 11px; color: var(--text-muted); }
  .buy-history-label { display: inline; }
  [data-portal] .buy-table .td[data-label="Last purchased"] .cell-meta { display: inline; margin: 0; }
  .buy-table .td[data-label="Last purchased"] .cell-meta::before { content: " · "; }
  .buy-table .td[data-label="Last purchased"] .buy-price-source::before { content: "·"; display: inline-block; margin: 0 0.3em; text-decoration: none; color: var(--text-muted); }
  .buy-table .td[data-label="Alternatives"] { grid-area: alternatives; justify-self: end; margin-top: var(--s1); }
  .buy-table .buy-row-actions { justify-items: end; }
  .buy-table .buy-row-actions .btn { min-height: 44px; padding: var(--s2); }
  .buy-row-actions [data-buy="compare"]::after { content: " alternatives"; }
  .buy-row-actions [data-buy="compare"][title="1 alternatives"]::after { content: " alternative"; }
  [data-portal] .buy-table .td[data-label="Alternatives"]:has([data-buy="compare"][hidden]) { display: none; }
  .buy-table .tr:has([data-buy="compare"][hidden]) .buy-price-source { grid-column: 1 / -1; }
  .buy-table .buy-opportunities { grid-area: opportunities; margin-top: var(--s2); }
  .buy-table [data-buy-offer] { grid-area: offer; margin-top: var(--s1); }
  .buy-table .buy-opportunities:empty { display: none; }
}
/* Room for the fixed unit track beside a three-decimal quantity. */
@container buy-table (350px <= width < 800px) {
  .buy-table .tr { grid-template-columns: minmax(0,1fr) 248px; }
}
@media (max-width: 639px) {
  .page:has(#buy-workspace) #portal-context > .portal-context { grid-template-columns: minmax(0,1fr) max-content; row-gap: var(--s1); }
  .page:has(#buy-workspace) .portal-mode a { padding: var(--s2); }
  .page:has(#buy-workspace) .portal-local { grid-column: 1 / -1; justify-self: end; }
  .buy-controls { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .buy-search { grid-column: 1 / -1; }
  .buy-controls .field { gap: var(--s1); font-size: 11px; }
  .buy-controls select { padding-left: var(--s2); padding-right: var(--s5); font-size: 12px; }
  .buy-table .tr { grid-template-areas: "product product" "price quantity" "offer offer" "history history" "source alternatives" "opportunities opportunities"; }
  .buy-table .td[data-label="Order quantity"] { margin-top: var(--s2); }
}
@media (max-width: 359px) {
  .buy-table .tr { grid-template-columns: minmax(0,1fr); grid-template-areas: "product" "price" "offer" "quantity" "history" "source" "alternatives" "opportunities"; }
  .buy-quantity-control { max-width: 280px; }
  .buy-table .td[data-label="Alternatives"] { justify-self: start; }
}

/* List membership is independent of the green in-order state. */
[data-portal] .buy-table .td-primary { position: relative; padding-left: 48px; }
.buy-list-check { grid-area: auto; position: absolute; top: 0; left: 0; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.buy-list-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--info); }
#buy-list-bar { display: flow-root; position: sticky; top: calc(var(--portal-sticky-top) - var(--s4)); z-index: 35; margin-top: calc(-1 * var(--s4)); padding-top: var(--s4); background: var(--bg); }
#buy-list-bar:empty { display: none; }
.buy-list-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s4); padding: var(--s2) var(--s3); margin-bottom: var(--s3); border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); }
.buy-list-toolbar > div { display: flex; flex-wrap: wrap; gap: var(--s2); }
.buy-list-toolbar strong { font-size: 13px; }
.buy-saved-lists { list-style: none; padding: 0; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.buy-saved-lists > li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4); }
.buy-saved-lists > li + li { border-top: 1px solid var(--border); }
@media (max-width: 1023px) {
  #buy-list-bar { margin-top: calc(-1 * var(--s3)); }
  .buy-list-toolbar .btn { min-height: 44px; }
}
@container buy-table (max-width: 799px) {
  [data-portal] .buy-table .td-primary { padding-left: 36px; }
  .buy-list-check { left: -8px; top: -10px; }
}

.buy-list-toolbar > strong, .buy-saved-lists > li > div:first-child { min-width: 0; overflow-wrap: anywhere; }

/* Match the header tracks to the item rows, then centre over the quantity field. */
.buy-table .thead { padding-inline: 0; }
.buy-table .buy-quantity-heading { justify-content: center; }
.buy-table .thead > .th:last-child { padding-inline: var(--s3); justify-content: center; }

/* Purchase-order review, with one item group per supplier. */
.buy-review-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin: var(--s5) 0; }
.buy-review-heading h2 { font-size: 26px; letter-spacing: -.03em; }
[data-portal] .buy-review-heading h2:focus-visible { outline: none; }
.buy-review-heading .portal-note { margin: var(--s2) 0 0; }
.buy-review-heading > span { font-size: 12px; }
.buy-review-supplier { padding: 0; margin-bottom: var(--s4); border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.buy-review-supplier-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.buy-review-supplier-head h3 { font-size: 16px; color: var(--text-strong); }
.buy-review-supplier-head > div:last-child { text-align: right; flex-shrink: 0; }
.buy-review-supplier-head > div:last-child > strong { font-size: 18px; }
.buy-review-item, .buy-review-item-head { display: grid; grid-template-columns: minmax(0,1fr) 196px 110px 110px; gap: var(--s4); align-items: start; padding: var(--s3) var(--s5); }
.buy-review-item-head { color: var(--text-muted); font-size: 11px; background: var(--surface-2); }
.buy-review-item > :not(:first-child), .buy-review-item-head > :not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.buy-review-item + .buy-review-item { border-top: 1px solid var(--border); }
.buy-review-item > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.buy-review-item [data-buy="review-remove"] { min-height: 32px; margin-top: var(--s1); padding: var(--s1) var(--s2); color: var(--danger); font-size: 11px; }
.buy-review-quantity { display: grid; grid-template-columns: 36px minmax(0,1fr) 36px; gap: var(--s1); align-items: stretch; }
.buy-review-quantity .btn { min-width: 36px; min-height: 36px; padding: var(--s1); }
.buy-review-quantity label { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; min-width: 0; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); }
.buy-review-quantity input { width: 100%; min-width: 0; height: 34px; border: 0; border-radius: var(--r-sm); padding: var(--s1); text-align: right; font-weight: 700; }
.buy-review-quantity label > span:last-child { padding-right: var(--s1); color: var(--text-muted); font-size: 11px; }
.buy-review-quantity-error { display: block; margin-top: var(--s1); color: var(--danger); text-align: left; }
.buy-review-quantity-error[hidden] { display: none; }
.buy-review-supplier .buy-review-source summary { min-height: 24px; padding-top: var(--s1); color: var(--text-muted); font-size: 11px; }
.buy-review-delivery { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: var(--s5); padding: var(--s4) var(--s5); border-top: 1px solid var(--border); }
.buy-review-delivery .field { margin: 0; }
.buy-review-delivery textarea { min-height: 76px; }
.buy-review-delivery .buy-warning, .buy-review-delivery .portal-note { margin: var(--s2) 0; }
.buy-review-charges { display: flex; align-items: start; justify-content: space-between; gap: var(--s4); padding: var(--s3) var(--s5); border-top: 1px solid var(--border); }
.buy-review-charges summary { padding-top: 0; }
.buy-review-charges .buy-warning { margin: 0; }
.buy-review-charge-summary { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); justify-content: flex-end; font-size: 12px; color: var(--text-muted); text-align: right; }
.buy-review-charge-summary strong { color: var(--text); margin-left: var(--s1); }
.buy-review-charge-summary small { flex-basis: 100%; font-size: 11px; }
.buy-review-footer { justify-content: space-between; }
.buy-review-total { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: var(--s4); }
.buy-review-total > span { font-size: 13px; font-weight: 600; }
.buy-review-total > span small { font-weight: 400; color: var(--text-muted); }
.buy-review-total > strong { font-size: 24px; font-variant-numeric: tabular-nums; color: var(--text-strong); }
.buy-review-total > small { grid-column: 1 / -1; color: var(--text-muted); font-size: 11px; }
.buy-review-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.buy-review-send-note { flex-basis: 100%; min-height: 1.5em; font-size: 11px; line-height: 1.5; color: var(--text-muted); text-align: right; margin: 0; }
.buy-review-send-note [role="alert"] { color: var(--bad); }
.buy-review #buy-error:not(:empty) { border: 1px solid var(--border); padding: var(--s3) var(--s4); margin-bottom: var(--s4); border-radius: var(--r-sm); background: var(--warn-wash); }
@media (max-width: 639px) {
 .buy-review-heading { margin: var(--s3) 0; }
 .buy-review-heading h2 { font-size: 22px; }
 .buy-review-heading > span { display: none; }
 .buy-review-supplier-head, .buy-review-item, .buy-review-delivery, .buy-review-charges { padding: var(--s3); }
 .buy-review-item-head { display: none; }
 .buy-review-item { grid-template-columns: minmax(0,1fr) auto; gap: var(--s2) var(--s3); }
 .buy-review-item > div:first-child { grid-column: 1 / -1; }
 .buy-review-item > [data-label="Quantity"] { text-align: left; }
 .buy-review-quantity { grid-template-columns: 44px minmax(0,1fr) 44px; }
 .buy-review-quantity .btn { min-width: 44px; min-height: 44px; }
 .buy-review-quantity input { height: 42px; }
 .buy-review-item [data-buy="review-remove"] { min-height: 44px; }
 .buy-review-item > [data-label="Unit price"] { display: none; }
 .buy-review-delivery { grid-template-columns: minmax(0,1fr); gap: var(--s3); }
 .buy-review-charges { gap: var(--s2); }
 .buy-review-footer { padding: var(--s3); gap: var(--s2); }
 .buy-review-total { width: 100%; justify-content: space-between; }
 .buy-review-actions { display: grid; grid-template-columns: auto minmax(0,1fr) minmax(0,1fr); width: 100%; gap: var(--s1); }
 .buy-review-actions .btn { min-height: 44px; padding: var(--s2); white-space: normal; font-size: 12px; text-align: center; }
 .buy-review-send-note { min-height: 4.5em; text-align: left; }
}
.buy-review-charges > div:first-child { min-width: 100px; }
.buy-review-mobile-unit-price { display: none; }
@media (max-width: 639px) {
 .buy-review-mobile-unit-price { display: inline; color: var(--text-muted); }
}

/* Explicit access assignments reuse standard fields and buttons. */
.user-access-row { display:flex; align-items:center; gap:var(--s3); padding:var(--s3) 0; border-bottom:1px solid var(--border); }
.user-access-row > div:first-child { flex:1; min-width:0; overflow-wrap:anywhere; }
.user-access-row select { width:auto; max-width:180px; }
@media(max-width:639px) { .user-access-row { flex-wrap:wrap; } .user-access-row > div:first-child { flex-basis:100%; } }

/* Users reuse the standard list and sheet; the form participates in sheet layout. */
#user-editor > form { display:contents; }
.user-access-fields { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1.7fr) minmax(0,1fr); gap:var(--s4); }
#user-editor .sheet-foot > .draft-status { margin-right:auto; }
@media(max-width:639px) {
  .user-access-fields { grid-template-columns:1fr; }
  #user-editor .sheet-foot > .draft-status { flex-basis:100%; }
}

#user-editor #org-hint { margin-block:var(--s3); }
.user-row-actions { flex-wrap:nowrap; }
.user-action-menu, .action-menu { width:12rem; padding:var(--s2); }
.user-action-menu .btn, .action-menu .btn { display:flex; width:100%; justify-content:flex-start; min-height:44px; }
.user-action-menu .btn-danger, .action-menu .btn-danger { margin-top:var(--s2); }
.action-field { margin-top:var(--s4); }

#user-editor #access-title + .hint { margin-top:var(--s2); }

/* Shared recipe-style dropdown menu in every portal. Native select remains the field. */
select:not([multiple]):is(:not([size]),[size="0"],[size="1"]) {
  min-height:var(--touch); padding-left:var(--s3); border:1px solid var(--border-strong);
  border-radius:var(--r-sm); background-color:var(--surface); color:var(--text); box-shadow:var(--shadow-xs);
}
select:not([multiple]):is(:not([size]),[size="0"],[size="1"]):focus { outline:none; border-color:var(--brand); box-shadow:var(--ring); }
select:disabled { cursor:not-allowed; opacity:.55; }
.select-menu { padding:4px; border-radius:var(--r); border:1px solid var(--border); overscroll-behavior:contain; }
.select-menu-search { position:sticky; top:-4px; z-index:1; padding:var(--s1); background:var(--surface); }
.select-menu-option { display:flex; align-items:center; gap:var(--s2); min-height:32px; padding:5px var(--s2); border-radius:var(--r-sm); color:var(--text); font-size:14px; line-height:1.4; cursor:pointer; overflow-wrap:anywhere; }
.select-menu-check { flex:0 0 14px; font-weight:700; }
.select-menu-option.is-active { background:oklch(0.55 0.19 260); color:oklch(0.99 0.005 260); }
.select-menu-option[aria-disabled="true"] { opacity:.5; cursor:not-allowed; }
.select-menu-group { padding:var(--s2); color:var(--text-subtle); font-size:12px; font-weight:600; }
@media(pointer:coarse) { .select-menu-option { min-height:44px; } }

/* Authentication uses the existing card, button, notice and typography tokens. */
.auth-page { min-height:100dvh; display:grid; place-items:center; padding:var(--s6) var(--s4); }
.auth-card { width:100%; max-width:460px; }
.auth-card .card-body { padding:var(--s7); }
.auth-logo { display:block; width:100px; height:auto; margin-bottom:var(--s7); }
.auth-card .page-title { margin-top:var(--s2); }
.auth-card .page-lede { margin-top:var(--s3); }
.auth-providers { display:grid; gap:var(--s3); margin-block:var(--s6); }
.auth-providers .btn { width:100%; min-height:48px; }
.auth-footnote { border-top:1px solid var(--border); margin-top:var(--s6); padding-top:var(--s5); color:var(--text-muted); font-size:var(--text-sm); line-height:1.6; }
@media(max-width:480px) { .auth-card .card-body {padding:var(--s5);} }

/* Read-only item identities reuse the source table, with mobile labelled rows. */
#source-fields .data-table-group th { white-space: normal; }
#source-fields td { overflow-wrap: anywhere; }
.record-details-table { table-layout: fixed; }
.record-details-table th:first-child { width: 26%; }
.record-details-table th:last-child { width: 23%; }
.record-details-table td, .record-details-table th { overflow-wrap: anywhere; white-space: normal; }
.record-details-table tbody th[scope="row"] { color: var(--text); font-size: inherit; font-weight: 500; letter-spacing: normal; text-transform: none; }
.record-details-table .btn { white-space: normal; text-align: left; }
@media (max-width: 639px) {
  .record-details-table thead { display: none; }
  .record-details-table, .record-details-table tbody, .record-details-table tr, .record-details-table td, .record-details-table th { display: block; width: 100% !important; }
  .record-details-table tr { padding-block: var(--s3); border-bottom: 1px solid var(--border); }
  .record-details-table th, .record-details-table td { padding: var(--s1) 0; border: 0; }
  .record-details-table td:empty { display: none; }
  .record-details-table .data-table-group { padding-top: var(--s4); }
}

/* Bulk maintenance reuses the standard sheet. Long source values and controls
   must fit the scrollable body on phones rather than widen its grid. */
.item-bulk-sheet .stack {
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}
.item-bulk-sheet .sheet-body > * {
  min-width: 0;
  max-width: 100%;
}
.item-bulk-sheet .sheet-body { padding-top: var(--s4); }
.item-bulk-panel { gap: var(--s4); }
.item-bulk-intro { display: grid; gap: var(--s1); }
.item-bulk-intro h3 { font-size: 1rem; letter-spacing: -0.012em; }
.item-bulk-intro .section-lede { margin-top: 0; }
.item-bulk-export-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s3) var(--s4);
  align-items: end;
}
.item-bulk-export-grid > .field { min-width: 0; }
.item-bulk-actions { justify-content: flex-start; }
.item-bulk-panel > .status:empty { display: none; }
.item-bulk-history { padding-top: var(--s3); border-top: 1px solid var(--border); }
.item-bulk-history > .stack { margin-top: var(--s3); }
.file-picker {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
  padding: var(--s1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.file-picker .btn { flex: none; min-height: 2.25rem; padding-inline: var(--s3); }
.file-picker-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text-subtle);
  font-size: 0.84375rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-picker.has-file .file-picker-name { color: var(--text-strong); font-weight: 600; }
.file-picker:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
/* A file dragged over the picker: the same highlight as focus, on a tinted field. */
.file-picker.is-dragover { border-color: var(--brand); border-style: dashed; background: var(--brand-wash); box-shadow: var(--ring); }
.item-bulk-sheet .data-table {
  width: 100%;
  table-layout: fixed;
}
.item-bulk-sheet .data-table th,
.item-bulk-sheet .data-table td,
.item-bulk-sheet .hint {
  white-space: normal;
  overflow-wrap: anywhere;
}
@media (max-width: 639px) {
  .item-bulk-actions .btn { flex: 1 1 0; }
}

/* Retained entry evidence must remain readable on narrow list rows. */
.item-unit-correction .stack { grid-template-columns: minmax(0, 1fr); min-width: 0; }
.item-unit-correction .sheet-body > * { min-width: 0; overflow-wrap: anywhere; }
.unit-correction-table { width: 100%; table-layout: fixed; }
.unit-correction-table th, .unit-correction-table td { white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 639px) {
  .unit-correction-table thead { display: none; }
  .unit-correction-table, .unit-correction-table tbody, .unit-correction-table tr,
  .unit-correction-table td, .unit-correction-table th { display: block; width: 100%; }
  .unit-correction-table tr { padding-block: var(--s3); border-bottom: 1px solid var(--border); }
  .unit-correction-table td, .unit-correction-table th { padding: var(--s2) 0; border: 0; }
  .unit-correction-table td::before { content: attr(data-label); display: block; margin-bottom: var(--s1); color: var(--text-muted); font-size: .75rem; }
}

.price-entry-status .cell-meta {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}
.price-entry-status .cell-meta a { text-decoration: underline; }

/* Manual price-list draft uses the shared toolbar and save-action tokens. */
.price-list-savebar {
  position: sticky;
  bottom: 0;
  z-index: 30;
  padding: var(--s3) var(--s4);
  margin-top: var(--s3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}

/* Item-detail pack containment on narrow screens. */
#item-pack .badge {
  max-width: 100%;
  height: auto;
  min-height: 1.5rem;
  white-space: normal;
}
[data-page="item-detail"] .pack-say .field { min-width:0; max-width:100%; }
[data-page="item-detail"] .pack-say .field > .pack-slot { max-width:100%; }

/* The item comparison card remains readable inside a half-width column. */
.item-comparison-section + .item-comparison-section,
.item-comparison-settings { margin-top: var(--s5); padding-top: var(--s5); border-top: 1px solid var(--border); }
.item-comparison-browse { display: inline-block; margin-top: var(--s3); font-size: 0.875rem; }
.item-comparison-table { margin-top: var(--s4); }
.item-comparison-row { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr)); gap: var(--s3); padding-block: var(--s4); border-bottom: 1px solid var(--border); align-items: start; }
.item-comparison-head { color: var(--text-muted); font-size: 0.75rem; padding-block: var(--s2); }
.item-comparison-name, .item-comparison-price { min-width: 0; overflow-wrap: anywhere; font-size: 0.8125rem; }
.item-comparison-name > a { font-weight: 600; color: var(--text-strong); }
.item-comparison-name .badge { margin-top: var(--s2); }
.item-comparison-price strong { display: block; font-variant-numeric: tabular-nums; }
.item-comparison-section .tag { white-space: normal; }
@media (max-width: 639px) {
 .item-comparison-head { display: none; }
 .item-comparison-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
 .item-comparison-name { grid-column: 1 / -1; }
 .item-comparison-price::before { content: attr(data-label); display: block; margin-bottom: var(--s1); color: var(--text-muted); font-size: 0.75rem; }
}

.item-classification { align-items: start; }
.item-comparison-section .section-title, .item-comparison-settings .section-title { font-size: 0.875rem; }
.item-comparison-table .cell-meta { white-space: normal; overflow: visible; text-overflow: clip; }

/* Reviewed item actions: keep every label and count together. */
.review-facts { margin: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s5); }
.review-facts > div { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding-block: var(--s2); border-bottom: 1px solid var(--border); }
.review-facts dt { min-width: 0; overflow-wrap: anywhere; }
.review-facts dd { margin: 0; flex-shrink: 0; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-strong); }
@media (max-width: 639px) { .review-facts { grid-template-columns: minmax(0, 1fr); } }

.manufacturer-item-selections .btn { max-width: 100%; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: left; padding-block: var(--s2); }

/* Manufacturer table deal details follow the compact, horizontal actions. */
.manufacturer-product-deal { display: grid; gap: var(--s1); min-width: 0; text-align: left; overflow-wrap: anywhere; }
.td[data-label] .manufacturer-product-deal > .cell-meta { margin-top: 0; text-align: left; }

/* Distributor purchase-order email: standard card and form fields. */
.order-email-fields { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: var(--s4); }
/* A checkbox group is one .field: a fieldset without browser chrome, its legend styled as the field label.
   A rendered legend sits outside the grid, so its margin stands in for the field gap. */
fieldset.field { border: 0; margin: 0; padding: 0; min-inline-size: 0; }
fieldset.field > legend.field-label { padding: 0; margin-bottom: var(--s2); }

/* System API reference: keep the route list and examples inside the page. */
#api-panel,
#api-list {
  min-width: 0;
  max-width: 100%;
}
#api-list details,
#api-list summary {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}
#api-list summary {
  white-space: normal;
}
#api-list pre {
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  white-space: pre;
  overflow-wrap: normal;
}

/* Shared fixed footer for active buying and delivery workflows. */
.portal-action-bar {
  --action-sidebar: 0px;
  --action-outer: max(0px, (100% - var(--action-sidebar) - var(--content-max)) / 2);
  position: fixed; z-index: 36;
  left: calc(var(--action-sidebar) + var(--action-outer) + var(--page-gutter) + var(--safe-left));
  right: calc(var(--action-outer) + var(--page-gutter) + var(--safe-right));
  bottom: calc(var(--s3) + var(--safe-bottom));
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4);
  margin: 0; padding: var(--s4) var(--s5);
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.page:has(.portal-action-bar:not(.portal-action-bar-demo)) { padding-bottom: calc(var(--portal-action-height, 160px) + var(--s6) + var(--safe-bottom)); }
html:has(.portal-action-bar:not(.portal-action-bar-demo)) { scroll-padding-bottom: calc(var(--portal-action-height, 160px) + var(--s6) + var(--safe-bottom)); }
.portal-action-bar-demo { position: static; }
.portal-form-actions.portal-action-bar { margin: 0; }
.portal-action-bar > .draft-status { margin-right: auto; }
@media (min-width: 1024px) { .portal-action-bar { --action-sidebar: var(--sidebar); } }
@media (max-width: 639px) {
  .portal-action-bar { padding: var(--s3); gap: var(--s2); }
  .portal-action-bar > .draft-status { flex-basis: 100%; }
}
@media print { .portal-action-bar { display: none !important; } }
[data-portal-local].portal-local { min-height: 0; width: auto; flex: 0 0 auto; gap: var(--s2); font-size: 11px; }
.topbar [data-portal-local] { flex-direction: column; align-items: flex-end; gap: 0; line-height: 16px; }
.topbar [data-portal-local] .badge { font-size: 10px; }
#buy-order-slot { min-width: 0; justify-self: end; }
#buy-order-slot:empty { display: none; }
#portal-return-slot { grid-column: 3; min-width: 0; justify-self: end; }
#portal-return-slot .btn, #buy-order-slot > [data-buy="review-board"] { min-height: 44px; }
.buy-order-action { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: var(--s1) var(--s3); }
.buy-order-summary { display: grid; color: var(--text-strong); font-size: 13px; }
.buy-order-summary > span { color: var(--text-muted); font-size: 11px; }
.buy-order-action > .btn { min-width: 140px; min-height: 44px; }
.buy-order-reason { grid-column: 1 / -1; margin: 0; text-align: left; font-size: 11px; color: var(--text-muted); }
@media (max-width: 1350px) { #buy-order-slot:has([data-buy="review-board"]) { grid-column: 1 / -1; justify-self: end; } }
@media (max-width: 1279px) { #portal-return-slot { grid-column: 1 / -1; } }
@media (min-width: 1351px) {
  #buy-order-slot { grid-column: 3; }
  .portal-context:has(#buy-order-slot) { grid-template-columns: minmax(12rem,22rem) max-content minmax(0,1fr); }
}
@media print { .buy-order-action { display: none !important; } }

/* Retained email activity is supporting evidence beside the order stage. */
.order-email-activity { display: flex; align-items: center; gap: var(--s1); }
.order-email-activity .icon { flex: 0 0 14px; width: 14px; height: 14px; }
@media (max-width: 639px) {
 .action-preview-table.is-stacked-mobile table,
 .action-preview-table.is-stacked-mobile tbody { display: block; }
 .action-preview-table.is-stacked-mobile thead { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
 .action-preview-table.is-stacked-mobile tr { display: block; border-bottom: 1px solid var(--border); }
 .action-preview-table.is-stacked-mobile tr:last-child { border-bottom: 0; }
 .action-preview-table.is-stacked-mobile td { display: grid; grid-template-columns: 100px minmax(0,1fr); gap: var(--s3); padding: var(--s2) var(--s3); border: 0; overflow-wrap: anywhere; }
 .action-preview-table.is-stacked-mobile td::before { content: attr(data-label); font-size: 11px; color: var(--text-muted); }
}

/* Receiving headings accept announcement focus; interactive controls retain their outlines. */
#receiving-record h2[tabindex="-1"]:focus { outline: none; }

/* Invoice references and reconciliation controls retain their complete labels on phones. */
.matched-invoice-links { display: flex; flex-wrap: wrap; min-width: 0; gap: var(--s1); }
.matched-invoice-links .btn, #captured-invoices [data-action="match-invoice"] { white-space: normal; overflow-wrap: anywhere; text-align: left; max-width: 100%; }
.invoice-match-sheet .sheet-body > * { min-width: 0; overflow-wrap: anywhere; }
.invoice-match-sheet .table .field { margin: 0; }
.invoice-match-sheet [data-repair-row] .field { grid-template-columns: minmax(0, 1fr); }
.invoice-match-sheet [data-repair-row] select { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.invoice-match-sheet > form { display: contents; }
.invoice-match-sheet .sheet-foot { flex-wrap: wrap; }
dialog.sheet.invoice-match-sheet.is-comparing { width: min(72rem, calc(100% - 2 * var(--s4))); }
.invoice-match-sheet.is-comparing .sheet-body { display: flex; flex-direction: column; gap: var(--s5); }
.invoice-match-choice .field, .invoice-match-choice .hint { margin-bottom: 0; }
.invoice-match-summary { margin: var(--s2) 0 0; color: var(--text-strong); font-weight: 600; }
.invoice-match-summary:empty { display: none; }
/* A field after a table keeps the standard gap (receiving and claim forms). */
.portal-form .table + .field { margin-top: var(--s4); }
.invoice-match-sheet .table + .field, .invoice-match-sheet .table + .field + .field, #receipt-disposition { margin-top: var(--s4); }
.invoice-match-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s5); align-items: start; }
/* Until an order is chosen the invoice uses the full width instead of sitting beside an empty panel. */
.invoice-match-comparison:has(> #invoice-po-comparison[hidden]) { grid-template-columns: minmax(0, 1fr); }
.invoice-match-comparison > section { min-width: 0; }
.invoice-match-panel-heading { margin-bottom: var(--s3); }
.invoice-match-panel-heading h3, .invoice-match-alternative h3, .invoice-match-claims h3 { font-size: 1rem; color: var(--text-strong); }
/* Credit claims generated from the matched invoice. */
.invoice-match-claims { border-top: 1px solid var(--border); padding-top: var(--s5); }
.invoice-match-claims h3 { margin-bottom: var(--s3); }
.invoice-claim + .invoice-claim { margin-top: var(--s5); }
.invoice-claim-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.invoice-claim-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s3); }
.invoice-claim-foot .hint { margin: 0; }
@media (min-width: 640px) { .invoice-claim .td:last-child, .invoice-claim .th:last-child { text-align: right; } }
.invoice-match-panel-heading .hint { margin-bottom: 0; }
.invoice-match-comparison .td, .invoice-match-comparison .th { overflow-wrap: anywhere; }
.invoice-match-comparison .th { white-space: normal; }
.invoice-match-alternative { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); border-top: 1px solid var(--border); padding-top: var(--s5); }
.invoice-match-alternative .hint { margin-bottom: 0; }
.invoice-match-alternative .btn { flex-shrink: 0; }
.invoice-match-sheet [data-invoice-error]:empty { display: none; }
@media (max-width: 959px) {
 .invoice-match-comparison { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 639px) {
 .invoice-match-alternative { flex-direction: column; align-items: flex-start; }
}

.invoice-match-group + .invoice-match-group { margin-top: var(--s4); }
.invoice-match-group h4 { margin: 0 0 var(--s2); font-size: .8125rem; color: var(--text-muted); }
.invoice-match-total { display: flex; justify-content: space-between; gap: var(--s3); margin: var(--s3) 0 0; padding: var(--s3) var(--s4) 0; }
/* Price and total columns read as figures: right-aligned with tabular numerals on wider layouts. */
@media (min-width: 640px) { .invoice-match-group .th:nth-last-child(-n+2), .invoice-match-group .td:nth-last-child(-n+2) { justify-content: flex-end; text-align: right; font-variant-numeric: tabular-nums; } }
.invoice-match-total strong { color: var(--text-strong); white-space: nowrap; }

/* Purchase-order selection reuses native checkboxes and the shared toolbar. */
.order-draft-selection { flex-wrap:wrap; margin-bottom:var(--s3); align-items:center; }
.order-draft-selection .check { align-items:center; min-height:44px; }
.order-draft-selection .page-actions { margin-left:auto; }
.order-draft-check { float:left; align-items:center; justify-content:center; min-width:44px; min-height:44px; margin-right:var(--s2); }

/* Portal chrome on phones: one compact context row, opaque bars, and a footer that meets the screen edge. */
[data-portal] .topbar, [data-portal] .workbar { background: var(--bg); }
[data-portal] select, [data-portal] .input { text-overflow: ellipsis; }
[data-portal] .portal-cell-value > .btn-ghost:only-child { padding-inline: 0; }
@media (max-width: 760px) {
  [data-portal] #portal-context { margin-bottom: var(--s4); }
  [data-portal] #portal-context > .portal-context { grid-template-columns: minmax(0, 1fr) max-content; align-items: center; gap: var(--s2); padding-bottom: var(--s2); }
  [data-portal] .portal-context .field > label,
  [data-portal] .portal-context .field-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  [data-portal] .portal-context .portal-mode { width: auto; }
  [data-portal] .portal-context .portal-mode a { padding: var(--s2); gap: var(--s1); font-size: 12px; }
  [data-portal] .portal-context .portal-mode .icon { display: none; }
  [data-portal] #portal-context #portal-return-slot { grid-column: 1 / -1; }
}
@media (max-width: 639px) {
  .portal-action-bar { bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; padding-bottom: calc(var(--s3) + var(--safe-bottom)); }
  .orders-mobile-sort .field { max-width: none; }
}
@media (max-width: 480px) {
  .topbar [data-portal-local] > span:not(.badge) { display: none; }
}
/* Purchase order totals read as one block beside the item table's money columns, not across the page. */
.order-detail-totals { max-width: 26rem; margin-left: auto; }
/* Order email card: long addresses wrap; phone actions share one width. */
#order-email-panel strong { overflow-wrap: anywhere; }
@media (max-width: 639px) {
  #order-email-panel .portal-form-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
}
/* Recipes and Review order headings use the shared table heading style and wrap instead of overlapping. */
.rx-register-head, .rx-register-head .btn, .buy-review-item-head { font-family: var(--font-ui); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-subtle); }
.rx-register-head .btn { min-height: 0; white-space: normal; line-height: 1.3; }
/* Review lines: Remove aligns with the item name; the terms label stays on one line. */
.buy-review-item [data-buy="review-remove"] { padding-left: 0; }
.buy-review-charges summary { white-space: nowrap; }
@media (max-width: 639px) {
  .buy-review-item > [data-label="Total"] { align-self: start; line-height: 44px; }
  .buy-review-mobile-unit-price { display: block; margin-top: var(--s1); font-size: 12px; }
}
/* Phone action rows: the status line takes its own row and the buttons share the next one evenly. */
@media (max-width: 639px) {
  [data-portal] .portal-form-actions > .draft-status { flex-basis: 100%; text-align: left; }
  [data-portal] .portal-form-actions:has(> .draft-status) > .btn { flex: 1 1 0; }
  .buy-saved-lists .portal-record-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
}
/* Narrow phones: four or more tabs form an even grid (2 + 2, 3 + 2) instead of leaving one tab alone. */
@media (max-width: 560px) {
  .portal-tabs:has(> .btn:nth-child(4)) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .portal-tabs:has(> .btn:nth-child(5)) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .portal-tabs:has(> .btn:nth-child(4)) > .btn { min-width: 0; padding-inline: var(--s2); }
}
@media (max-width: 400px) {
  .portal-tabs .btn { padding-inline: var(--s2); font-size: 12px; }
}

/* Invoice corrections reuse the standard sheet and the source PDF viewer. */
dialog.sheet.invoice-correction-sheet { width: min(76rem, calc(100% - 2 * var(--s4))); }
.invoice-correction-sheet .sheet-body { overflow-wrap: anywhere; }
.invoice-correction-comparison { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s5); }
.invoice-correction-comparison > section { min-width: 0; }
.invoice-correction-source { position: sticky; top: 0; align-self: start; }
.invoice-correction-pdf { height: 32rem; min-height: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--r-sm); margin-top: var(--s3); }
.invoice-correction-comparison .data-table { table-layout: fixed; width: 100%; }
.invoice-correction-comparison .data-table th, .invoice-correction-comparison .data-table td { overflow-wrap: anywhere; }
@media (max-width: 959px) {
 .invoice-correction-comparison { grid-template-columns: minmax(0, 1fr); }
 .invoice-correction-source { position: static; }
 .invoice-correction-pdf { height: 24rem; }
}

.invoice-correction-sheet .sheet-foot .btn-group { justify-content: flex-end; }
