/* TAG order portal — design system.
   Material Design 3, as a stylesheet: the colour roles are a tonal palette
   generated from TAG's green (#1f6f5c, Google's material-color-utilities),
   the type scale is M3's on Roboto, and the shared classes the templates use
   (.btn, .field, .card, .pill, .table, .banner, .nav-link, .dialog) are the
   M3 components -- filled/outlined/text buttons, outlined text fields,
   outlined cards, chips, data tables, navigation drawer and rail, top app
   bar, dialog -- with state layers and the M3 elevation levels. Tokens
   first, then the shell, then the components, then the order pages. */

:root {
  /* M3 colour roles (light scheme, seed #1f6f5c). */
  --md-primary: #006b57;
  --md-on-primary: #ffffff;
  --md-primary-container: #7df8d6;
  --md-on-primary-container: #002019;
  --md-secondary: #4b635b;
  --md-on-secondary: #ffffff;
  --md-secondary-container: #cde9de;
  --md-on-secondary-container: #072019;
  --md-tertiary: #416277;
  --md-on-tertiary: #ffffff;
  --md-tertiary-container: #c5e7ff;
  --md-on-tertiary-container: #001e2d;
  --md-error: #ba1a1a;
  --md-on-error: #ffffff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;
  --md-surface: #f8faf7;
  --md-surface-dim: #d8dbd8;
  --md-surface-bright: #f8faf7;
  --md-surface-container-lowest: #ffffff;
  --md-surface-container-low: #f2f4f1;
  --md-surface-container: #eceeeb;
  --md-surface-container-high: #e6e9e6;
  --md-surface-container-highest: #e1e3e0;
  --md-on-surface: #191c1b;
  --md-on-surface-variant: #3f4945;
  --md-outline: #6f7975;
  --md-outline-variant: #bfc9c4;
  --md-inverse-surface: #2e312f;
  --md-inverse-on-surface: #eff1ee;
  --md-inverse-primary: #5edbbb;
  /* Extended roles M3 leaves to the product: success, warning, info. */
  --md-success: #006c4b;
  --md-success-container: #baf3d6;
  --md-on-success-container: #002114;
  --md-warning: #7a5900;
  --md-warning-container: #ffdea7;
  --md-on-warning-container: #271900;
  --md-info: #00639a;
  --md-info-container: #cfe6ff;
  --md-on-info-container: #001d33;

  /* The names the rest of this file and the templates grew up with, mapped
     onto the roles above so every page takes the scheme at once. */
  --bg: var(--md-surface);
  --surface: var(--md-surface-container-lowest);
  --surface-2: var(--md-surface-container-low);
  --border: var(--md-outline-variant);
  --border-strong: var(--md-outline);
  --text: var(--md-on-surface);
  --muted: var(--md-on-surface-variant);
  --accent: var(--md-primary);
  --accent-hover: #005141;
  --accent-soft: var(--md-secondary-container);
  /* The colour that says "this is who you are ordering for". */
  --brand: var(--accent);
  --ok: var(--md-success);
  --ok-soft: var(--md-success-container);
  --warn: var(--md-warning);
  --warn-soft: var(--md-warning-container);
  --danger: var(--md-error);
  --danger-soft: var(--md-error-container);
  --info: var(--md-info);
  --info-soft: var(--md-info-container);

  /* Shape. */
  --shape-xs: 4px;    /* text fields */
  --shape-sm: 8px;    /* chips, menus */
  --shape-md: 12px;   /* cards */
  --shape-lg: 16px;
  --shape-xl: 28px;   /* dialogs */
  --shape-full: 999px;
  --radius: var(--shape-md);

  /* Elevation (M3 levels 1-3). */
  --elev-1: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px 1px rgba(0, 0, 0, .15);
  --elev-2: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 6px 2px rgba(0, 0, 0, .15);
  --elev-3: 0 1px 3px rgba(0, 0, 0, .3), 0 4px 8px 3px rgba(0, 0, 0, .15);
  --shadow: var(--elev-1);

  /* Type: Roboto (base.html loads it), M3 scale. */
  --font: Roboto, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --type-display-small: 400 36px/44px var(--font);
  --type-headline-small: 400 24px/32px var(--font);
  --type-title-large: 400 22px/28px var(--font);
  --type-title-medium: 500 16px/24px var(--font);
  --type-title-small: 500 14px/20px var(--font);
  --type-body-large: 400 16px/24px var(--font);
  --type-body-medium: 400 14px/20px var(--font);
  --type-body-small: 400 12px/16px var(--font);
  --type-label-large: 500 14px/20px var(--font);
  --type-label-medium: 500 12px/16px var(--font);
  --type-label-small: 500 11px/16px var(--font);

  /* Motion. */
  --motion-short: 150ms cubic-bezier(.2, 0, 0, 1);

  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--type-body-medium);
  letter-spacing: .25px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: 0; }
p { margin: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; }
}

.mono { font-family: var(--mono); letter-spacing: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.kbd {
  font-family: var(--mono);
  font-size: .75em;
  background: var(--md-surface-container);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}

/* Layout helpers ---------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* App shell ---------------------------------------------------------- */
.shell { min-height: 100vh; }

/* Navigation drawer (M3 standard drawer): surface-container-low, items as
   56px full-rounded rows, the active one on secondary-container. */
.sidebar {
  background: var(--md-surface-container-low);
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transform: translateX(0);
  transition: transform .2s ease;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px 24px;
  font: var(--type-title-medium);
  color: var(--text);
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--md-on-primary);
  font: var(--type-label-large);
}
.sidebar-nav { padding: 0 12px; display: flex; flex-direction: column; gap: 0; }
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 24px 0 16px;
  border-radius: var(--shape-full);
  color: var(--muted);
  font: var(--type-label-large);
  letter-spacing: .1px;
  overflow: hidden;
}
.nav-link::before { content: ""; position: absolute; inset: 0; background: currentColor; opacity: 0; transition: opacity var(--motion-short); }
.nav-link:hover { text-decoration: none; color: var(--text); }
.nav-link:hover::before { opacity: .08; }
.nav-link:focus-visible { outline-offset: -2px; }
.nav-link.nav-link-active { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.nav-link svg { width: 24px; height: 24px; flex: none; stroke-width: 1.8; position: relative; }
.nav-link span { position: relative; }
.nav-badge {
  margin-left: auto;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--shape-full);
  background: var(--md-error);
  color: var(--md-on-error);
  font: var(--type-label-small);
  display: inline-flex; align-items: center; justify-content: center;
}

.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top app bar (M3 small): 64px, flat on surface. */
.topbar {
  background: var(--md-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px 0 24px;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.menu-btn {
  display: none;
  border: 0;
  background: transparent;
  border-radius: var(--shape-full);
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  flex: none;
  cursor: pointer;
  color: var(--muted);
}
.menu-btn:hover { background: var(--md-surface-container-high); }
.menu-btn svg { width: 24px; height: 24px; }

/* The organization being ordered for, as an outlined chip in the brand's
   colour: it reads as the page's context rather than one more control. */
.org-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  background: var(--md-surface-container-lowest);
  border: 1px solid var(--org-accent, var(--brand));
  border-radius: var(--shape-sm);
  padding: 0 12px;
  height: 36px;
  font: var(--type-label-large);
  min-width: 0;
}
.org-label { color: var(--muted); flex: none; font-weight: 400; }
/* An organization's logo, set by staff in the admin: 28px tall whatever its shape. */
.org-logo { height: 28px; width: auto; max-width: 120px; object-fit: contain; flex: none; }
.org-current { font-weight: 700; color: var(--brand); flex: none; }
.org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-weight: 400; color: var(--muted); }
/* Undo the form-field box (`select` under Forms below): inside the chip the
   select is just the bold code and name, not a second bordered control. */
.org-switcher select.org-select {
  min-width: 0;
  max-width: 320px;
  width: auto;
  min-height: 0;
  height: auto;
  padding: 0 4px 0 0;
  box-shadow: none;
  text-overflow: ellipsis;
  border: 0;
  background-color: transparent;
  font: inherit;
  font-weight: 700;
  color: var(--brand);
  cursor: pointer;
}
.org-switcher .btn-sm { min-height: 24px; padding: 0 8px; }
.org-switcher [hidden] { display: none; }
.org-change { font-weight: 500; flex: none; }
.org-switcher-empty { border-style: dashed; border-color: var(--border); color: var(--muted); font-weight: 400; }
.org-switcher-empty a { font-weight: 500; }
@media (max-width: 700px) {
  .org-label { display: none; }
  .org-switcher select.org-select { max-width: 52vw; }
}

.user-info { display: flex; align-items: center; gap: 12px; font: var(--type-body-small); color: var(--muted); }
.user-info form { margin: 0; }
.link-btn {
  background: none;
  border: 0;
  padding: 0 8px;
  height: 32px;
  border-radius: var(--shape-full);
  color: var(--accent);
  font: var(--type-label-large);
  cursor: pointer;
}
.link-btn:hover { background: var(--md-secondary-container); }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(25, 28, 27, .32);
  z-index: 25;
}

/* Pages use the whole window: a fixed gutter, no maximum width. */
.content { flex: 1; width: 100%; min-width: 0; padding: 24px 24px 32px; }
@media (max-width: 700px) {
  .content { padding: 16px 16px 24px; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--elev-1); border-radius: 0 16px 16px 0; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .overlay { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: flex; }
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 { font: var(--type-headline-small); }
.page-head p { color: var(--muted); font: var(--type-body-medium); margin-top: 4px; }
.page-head-actions { display: flex; gap: 10px; flex: none; }
/* An order's SYSPRO status and carrier: a line under the title, not a card. */
.page-head p.page-head-status { color: var(--text); }

/* Messages (Django flash): tonal containers in flow. ------------------- */
.messages { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.messages li {
  border-radius: var(--shape-md);
  padding: 12px 16px;
  font: var(--type-body-medium);
  background: var(--md-success-container);
  color: var(--md-on-success-container);
}
.messages li.error { background: var(--md-error-container); color: var(--md-on-error-container); }
.messages li.warning { background: var(--md-warning-container); color: var(--md-on-warning-container); }

/* Card (M3 outlined card) ------------------------------------------------ */
.card {
  background: var(--md-surface-container-lowest);
  border: 1px solid var(--border);
  border-radius: var(--shape-md);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font: var(--type-title-medium); }
.card-head p { color: var(--muted); font: var(--type-body-small); margin-top: 2px; }
.card-body { padding: 20px; }
.card-body.card-body-tight { padding: 0; }
.card-body.card-body-tight .table-wrap { border-radius: 0 0 var(--shape-md) var(--shape-md); }

/* Buttons (M3 common buttons) ------------------------------------------
   .btn alone and .btn-secondary are OUTLINED, .btn-primary is FILLED,
   .btn-ghost is a TEXT button. The state layer is `::before`: 8% on hover,
   12% on focus/press, in the button's own foreground colour. */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--md-outline);
  background: transparent;
  color: var(--accent);
  border-radius: var(--shape-full);
  padding: 0 24px;
  min-height: 40px;
  font: var(--type-label-large);
  letter-spacing: .1px;
  cursor: pointer;
  overflow: hidden;
  text-decoration: none;
  transition: box-shadow var(--motion-short), background-color var(--motion-short);
  -webkit-tap-highlight-color: transparent;
}
.btn::before { content: ""; position: absolute; inset: 0; background: currentColor; opacity: 0; transition: opacity var(--motion-short); pointer-events: none; }
.btn:hover { text-decoration: none; }
.btn:hover::before { opacity: .08; }
.btn:focus-visible::before, .btn:active::before { opacity: .12; }
.btn:focus-visible { outline-offset: 2px; }
.btn:disabled { cursor: not-allowed; color: rgba(25, 28, 27, .38); border-color: rgba(25, 28, 27, .12); background: transparent; box-shadow: none; }
.btn:disabled::before { display: none; }
.btn > * { position: relative; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--md-on-primary); }
.btn-primary:hover { box-shadow: var(--elev-1); }
.btn-primary:disabled { background: rgba(25, 28, 27, .12); color: rgba(25, 28, 27, .38); }
.btn-secondary { background: transparent; border-color: var(--md-outline); color: var(--accent); }
.btn-ghost { background: none; border-color: transparent; color: var(--accent); padding: 0 12px; }
.btn-sm { min-height: 32px; padding: 0 16px; font: var(--type-label-medium); }
.btn-ghost.btn-sm { padding: 0 10px; }
.btn-lg { min-height: 48px; padding: 0 28px; font: var(--type-label-large); font-size: 15px; }
/* A button with two faces: `.btn-label` at rest, `.btn-busy` (spinner + what
   it is doing) while it is locked by a request -- disabled by hx-disabled-elt
   or `is-busy` set by order-entry.js. Pressing it shows the change at once. */
.btn .btn-busy { display: none; align-items: center; gap: 8px; }
.btn.is-busy .btn-label, .btn[data-quote-shipping]:disabled .btn-label { display: none; }
.btn.is-busy .btn-busy, .btn[data-quote-shipping]:disabled .btn-busy { display: inline-flex; }
.btn.is-busy { opacity: .85; cursor: progress; pointer-events: none; }
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: currentColor;
  animation: spin .8s linear infinite;
}
.btn-secondary .spinner, .btn[data-quote-shipping]:disabled .spinner { border-color: var(--border); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* Forms (M3 outlined text fields) ---------------------------------------
   A `.field` whose label is followed by the control gets the label in the
   outline's notch -- the populated/focused look -- so every form on the
   portal reads as the same component without touching the markup. */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; position: relative; }
.field-label { font: var(--type-label-large); color: var(--muted); }
.field-error { color: var(--danger); font: var(--type-body-small); padding-left: 16px; }
.field-hint { color: var(--muted); font: var(--type-body-small); padding-left: 16px; }
.field:has(> .field-label + .input), .field:has(> .field-label + .select),
.field:has(> .field-label + select), .field:has(> .field-label + textarea),
.field:has(> .field-label + input) { gap: 4px; padding-top: 0; }
.field:has(> .field-label + .input) > .field-label, .field:has(> .field-label + .select) > .field-label,
.field:has(> .field-label + select) > .field-label, .field:has(> .field-label + textarea) > .field-label,
.field:has(> .field-label + input) > .field-label {
  position: absolute; top: -8px; left: 12px; z-index: 1;
  padding: 0 4px; background: var(--surface);
  font: var(--type-body-small); color: var(--muted);
}
.field:focus-within > .field-label { color: var(--accent); }
.field:has([aria-invalid="true"]) > .field-label { color: var(--danger); }
.input, .select,
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="number"], input[type="date"], input[type="tel"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--shape-xs);
  padding: 0 16px;
  min-height: 48px;
  font: var(--type-body-large);
  letter-spacing: .5px;
  color: var(--text);
  width: 100%;
  transition: border-color var(--motion-short), box-shadow var(--motion-short);
}
.input:hover, .select:hover, select:hover, textarea:hover { border-color: var(--text); }
.input:focus, .select:focus,
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus,
input[type="search"]:focus, input[type="number"]:focus, input[type="date"]:focus,
input[type="tel"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
textarea.input, textarea { min-height: 96px; padding: 12px 16px; resize: vertical; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus, .select[aria-invalid="true"]:focus { box-shadow: inset 0 0 0 1px var(--danger); }
.input::placeholder { color: var(--muted); opacity: .8; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0 6px 0 0; vertical-align: -3px; }

/* Table (M3 data table) -------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font: var(--type-body-medium); letter-spacing: .25px; }
.table th, .table td { padding: 12px 16px; text-align: left; vertical-align: middle; }
.table th {
  color: var(--text);
  font: var(--type-title-small);
  letter-spacing: .1px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { border-bottom: 1px solid var(--border); }
.table tbody tr { transition: background-color var(--motion-short); }
.table tbody tr:hover { background: var(--md-surface-container-low); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* Chips (.pill: a compact M3 chip for status and tags) ------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  border-radius: var(--shape-sm);
  padding: 0 10px;
  font: var(--type-label-medium);
  letter-spacing: .5px;
  white-space: nowrap;
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}
.pill-ok { background: var(--md-success-container); color: var(--md-on-success-container); }
.pill-warn { background: var(--md-warning-container); color: var(--md-on-warning-container); }
.pill-danger { background: var(--md-error-container); color: var(--md-on-error-container); }
.pill-info { background: var(--md-info-container); color: var(--md-on-info-container); }
.pill-muted { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* Mixed-case pool: the Note column's pill is a button that opens the pool's
   popover, an M3 menu surface placed under it by order-entry.js. */
.pool-pill { border: 0; cursor: pointer; font-family: inherit; }
.pool-pill:hover { box-shadow: inset 0 0 0 100px rgba(25, 28, 27, .08); }
.pool-pill:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.pool-popover {
  position: fixed; z-index: 40; min-width: 260px; max-width: min(360px, calc(100vw - 16px));
  padding: 12px 14px; border-radius: var(--shape-md);
  background: var(--md-surface-container-high); color: var(--text);
  box-shadow: var(--elev-2);
  font: var(--type-body-small);
}
.pool-popover[hidden] { display: none; }
.pool-popover-title { font: var(--type-title-small); margin-bottom: 8px; }
.pool-popover-table { width: 100%; border-collapse: collapse; }
.pool-popover-table td, .pool-popover-table th { padding: 3px 0; text-align: left; font-weight: normal; }
.pool-popover-table td + td { padding-left: 12px; }
.pool-popover-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.pool-popover-table tfoot th, .pool-popover-table tfoot td { border-top: 1px solid var(--border); font-weight: 600; }
.pool-popover-verdict { margin: 8px 0 0; }
.pool-popover-verdict.is-short { color: var(--md-on-warning-container); }
.pool-popover-verdict.is-ok { color: var(--md-on-success-container); }

/* Order units: the unit label on a one-unit line, and the per-piece figure
   under a per-box price (lines, finder, catalogue). */
.uom-label { font: var(--type-label-large); }
.price-per-piece { display: block; font: var(--type-body-small); white-space: nowrap; }

/* Banners: tonal containers --------------------------------------------- */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--shape-md);
  padding: 12px 16px;
  font: var(--type-body-medium);
  margin-bottom: 20px;
  background: var(--md-surface-container);
  color: var(--text);
}
.banner-warn { background: var(--md-warning-container); color: var(--md-on-warning-container); }
.banner-danger { background: var(--md-error-container); color: var(--md-on-error-container); }
.banner-info { background: var(--md-info-container); color: var(--md-on-info-container); }
.banner a { font-weight: 500; color: inherit; text-decoration: underline; }

/* Tabs (M3 primary tabs) --------------------------------------------------- */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  position: relative;
  display: inline-flex; align-items: center;
  height: 48px;
  padding: 0 16px;
  font: var(--type-title-small);
  letter-spacing: .1px;
  color: var(--muted);
  white-space: nowrap;
}
.tab::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: transparent; }
.tab:hover { color: var(--text); text-decoration: none; background: var(--md-surface-container-low); }
.tab-active { color: var(--accent); }
.tab-active::after { background: var(--accent); }

/* Empty state -------------------------------------------------------------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font: var(--type-body-medium);
}

/* Sticky order summary -------------------------------------------------------- */
.sticky-summary {
  position: sticky;
  top: 80px;
  align-self: start;
}
@media (max-width: 900px) {
  .sticky-summary { position: static; }
}

/* Full-height pages ----------------------------------------------------------
   Opt-in via `{% block body_class %}app-fullheight{% endblock %}`. The page is
   sized to the viewport and one pane inside it scrolls, instead of the document
   growing and the whole page scrolling. Order entry needs this: on an iPad in
   landscape there is ~740px of usable height, and a document-scrolling page
   puts the order total and the Submit button below the fold on every order.

   `min-height: 0` on each flex child is what makes it work -- a flex item's
   default `min-height: auto` refuses to shrink below its content, so without
   it the table pushes the page taller instead of scrolling inside. */
.app-fullheight, .app-fullheight body { height: 100%; }
.app-fullheight .shell { height: 100dvh; min-height: 0; }
.app-fullheight .main { min-height: 0; height: 100dvh; }
.app-fullheight .content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  max-width: none;
}
.app-fullheight .topbar { position: static; }

/* Icon rail: the nav labels cost 176px of width that an 11" iPad does not have
   to spare once two data-dense panes are on screen. Icons keep the same targets. */
/* M3 navigation rail: 80px, each destination a 56x32 pill around its icon. */
@media (max-width: 1480px) and (min-width: 901px) {
  .app-fullheight { --sidebar-w: 80px; }
  .app-fullheight .sidebar-nav { padding: 4px 12px; gap: 12px; }
  .app-fullheight .nav-link { justify-content: center; height: 32px; width: 56px; padding: 0; margin: 0 auto; border-radius: var(--shape-lg); }
  .app-fullheight .nav-link span, .app-fullheight .sidebar-brand > span:last-child { display: none; }
  .app-fullheight .nav-badge { display: none; }
  .app-fullheight .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
}

/* Order entry ---------------------------------------------------------------- */
/* Says again, above the form, who this order is for. */
.org-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--org-accent, var(--brand)) 10%, var(--md-surface-container-lowest));
  border-radius: var(--shape-md);
  padding: 10px 16px;
  margin-bottom: 16px;
  font: var(--type-body-medium);
}
.org-banner strong { color: var(--org-accent, var(--brand)); font-weight: 500; }
.org-banner a { font-weight: 500; white-space: nowrap; }
/* The Submit button takes the organization's accent, so the last thing clicked
   says who the order is for. Entry page only (`app-fullheight`): the rest of the
   portal keeps its own green. Hover darkens whatever the colour is. */
.shell { --org-accent-hover: color-mix(in srgb, var(--org-accent) 85%, #000); } /* invalid, so unused, with no accent */
.app-fullheight .btn-primary { background: var(--org-accent, var(--accent)); }
.app-fullheight .btn-primary:disabled { background: rgba(25, 28, 27, .12); }
.app-fullheight .org-banner { margin: 12px 24px 0; }

/* The page is one scrolling column -- the form -- with the bar pinned to its
   foot. The form is the column rather than `display: contents` on it: a form
   with `display: contents` has been dropped from the accessibility tree by
   more than one browser, and this one holds the whole order. `margin-top:
   auto` on the bar keeps it at the bottom when the order is short; `sticky`
   keeps it on screen when the lines scroll. */
.order-form { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; scroll-padding-bottom: 280px; }

/* Cards: the same surface for the order, ship-to, shipping, total and
   ship-date panels, each named by a small label in its corner. */
.order-card {
  position: relative; /* keeps an absolutely-positioned child (a visually-hidden label) from stretching the document */
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--md-surface-container-lowest);
  border: 1px solid var(--border);
  border-radius: var(--shape-md);
  min-width: 0;
}
/* Card titles are M3 title-small in sentence case -- no tracked-out caps. */
.order-card-label { font: var(--type-title-small); letter-spacing: .1px; color: var(--text); }
/* The label and anything that qualifies it (the address's tag) sit together;
   a button in the row (Recalculate) goes to the far end. */
.order-card-label-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.order-card-label-row .btn { margin-left: auto; }
.order-card-foot { font: var(--type-body-small); letter-spacing: .4px; }

/* The head strip: the order card and the ship-to card side by side. */
.order-head { display: flex; flex-wrap: wrap; gap: 16px; padding: 12px 24px 0; }
.order-head > .order-card { flex: 1 1 360px; }
.order-title { font: var(--type-title-large); margin: 0; }
/* Who else has the draft open (spec 5.9). One line that never wraps, so the
   title row is the same height with a pill or without; extra pills scroll
   out of sight rather than push the lines down. */
.presence-pills { display: inline-flex; flex-wrap: nowrap; gap: 6px; min-height: 24px; align-items: center; min-width: 0; overflow: hidden; }
.presence-pills .pill { flex: none; white-space: nowrap; }
.presence-row { font: var(--type-body-small); }
.order-po { margin: 6px 0 0; max-width: 320px; }
.order-card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }
.ship-to-body { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.ship-to-address { font: var(--type-body-large); letter-spacing: .25px; }
.ship-to-address .pill { margin-bottom: 4px; }
.ship-to-empty { align-items: center; }
.ship-to-body .btn { flex: none; }

.order-notices { padding: 0 24px; display: flex; flex-direction: column; gap: 10px; }
.order-notices:empty { display: none; }
.order-notices .banner { margin: 12px 0 0; }
/* What a background save found that this page does not show, and Show. */
.draft-banner[hidden] { display: none; }
.draft-banner-text { flex: 1 1 auto; }

/* The address lightbox ------------------------------------------------------ */
/* M3 basic dialog: 28px corners, headline-small. The surface is the cards'
   white, not M3's surface-container-high: on this palette that grey is the
   sidebar's, and a grey dialog with transparent inputs over white cards
   read as the backdrop lying on top of it (20 Oct 2026). */
.dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--shape-xl);
  box-shadow: var(--elev-3);
  background: var(--md-surface-container-lowest);
  color: var(--text);
}
.dialog::backdrop { background: rgba(25, 28, 27, .32); }
.dialog-body { padding: 24px; max-height: calc(100vh - 64px); overflow: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dialog-head h2 { font: var(--type-headline-small); }
.dialog .field > .field-label { background: var(--md-surface-container-lowest); }
.dialog .input, .dialog .select { background: transparent; }
.address-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.address-choice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--shape-md);
  background: var(--md-surface-container-lowest);
  font: var(--type-body-medium);
}
.address-choice-current { border-color: var(--accent); background: var(--md-secondary-container); }
.address-add summary { cursor: pointer; font: var(--type-label-large); color: var(--accent); margin-bottom: 12px; }
.address-add .field { margin-bottom: 10px; }

/* The lines ------------------------------------------------------------------ */
.order-lines {
  flex: none; /* a flex child that scrolls (below 1180px) would otherwise be squeezed to nothing */
  padding: 16px 24px 0;
}
/* No `overflow: hidden` on the table: it would make the table the sticky
   header's scrollport, and the header would then not stick. */
.order-lines .table { background: var(--md-surface-container-lowest); border: 1px solid var(--border); border-radius: var(--shape-md); border-collapse: separate; border-spacing: 0; }
.order-lines .table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--md-surface-container-low);
}
.order-lines .table thead th:first-child { border-top-left-radius: var(--shape-md); }
.order-lines .table thead th:last-child { border-top-right-radius: var(--shape-md); }
.order-lines .table tbody:last-child tr:last-child td { border-bottom: 0; }
.order-lines .empty { background: var(--md-surface-container-lowest); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--shape-md) var(--shape-md); }

/* The table has to fit the pane without a horizontal scroll (a scrolling
   table would also unstick its header): tighter cells than the portal's
   other tables, inputs that shrink with the column, and a note column that
   is allowed to be wide rather than tall. */
.lines-table th, .lines-table td { padding: 10px 10px; }
.lines-table th { white-space: normal; font: var(--type-label-large); letter-spacing: .1px; color: var(--muted); }
/* Dense fields inside the lines: 40px, M3's smallest text field. */
.lines-table .input, .lines-table .select { min-height: 40px; padding: 0 10px; font: var(--type-body-medium); letter-spacing: .25px; }
.lines-table th:first-child, .lines-table td:first-child { padding-left: 16px; }
.lines-table td { vertical-align: top; }
.lines-table input[name="qty"] { width: 76px; }
.lines-table select[name="uom"] { width: 100px; }
.lines-table input[name="memo"] { width: 100%; min-width: 110px; max-width: 180px; }
.lines-table th:nth-child(10) { min-width: 120px; }
.lines-table td:nth-child(10) { font: var(--type-body-small); letter-spacing: .4px; color: var(--muted); }
/* One weight column: what the shipping quote weighs for the line, with the
   unit weight (from SYSPRO) small underneath. */
/* Who added the line, and when: small and muted, as the note column is. */
.lines-table td.added-by { font: var(--type-body-small); letter-spacing: .4px; color: var(--muted); }
.lines-table .line-weight { white-space: nowrap; }
.lines-table .line-unit-weight { display: block; font: var(--type-body-small); }
.lines-table .muted { font-size: 12px; }

/* Rules -> Item attributes: ten columns, seven of them inline inputs, have to
   fit the pane with the Save/Confirm buttons in view. Dense 36px fields sized
   to what they hold (codes, a few digits). */
.attr-table th, .attr-table td { padding: 8px 6px; }
.attr-table th:first-child, .attr-table td:first-child { padding-left: 16px; min-width: 150px; }
.attr-table .input { min-height: 36px; padding: 0 8px; font: var(--type-body-medium); letter-spacing: .25px; width: 4.5em; }
.attr-table .input[name="category"], .attr-table .input[name="fabric"] { width: 6.5em; }
.attr-table .input[name="finishes"] { width: 8em; }
.attr-table .attr-actions { text-align: right; }
.attr-table .attr-actions form { display: flex; justify-content: flex-end; margin: 2px 0; }
.attr-table .field-error { padding-left: 0; }
/* A value the inference guessed where SYSPRO has none: tinted, not an error. */
.attr-table .input.attr-guessed { background: var(--warn-soft); border-left: 3px solid var(--warn); }

/* The cards under the lines ------------------------------------------------
   Shipping (the wide one), the total and the ship date. #quote-summary is
   `display: contents` so the two cards the quote renders sit in this grid
   beside the ship-date card, and the issue banners span it. */
.order-panels {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 16px 24px 24px;
}
.order-panels-quote { display: contents; }
.order-issues { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; }
.order-issues .banner { margin: 0; }
@media (max-width: 1180px) {
  .order-panels { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .order-card-shipping { grid-column: 1 / -1; }
  /* A tablet is narrower than the table: the lines scroll sideways on their
     own rather than dragging the cards and the bar with them. (The header
     then no longer sticks -- the price of the scroll staying local.) */
  .order-lines { overflow-x: auto; }
  .order-lines .table thead th { position: static; }
  /* The weight column is a development aid; the shipping card still shows
     the order's weight. */
  .lines-table th:nth-child(9), .lines-table td:nth-child(9) { display: none; }
  .lines-table input[name="memo"] { max-width: 140px; }
}
@media (max-width: 720px) {
  .order-panels { grid-template-columns: minmax(0, 1fr); }
  .order-card-shipping { grid-column: auto; }
}

/* Shipping card. */
.shipping-where { font: var(--type-body-small); letter-spacing: .4px; margin-top: 2px; }
.shipping-body { display: flex; flex-direction: column; gap: 10px; }
.ship-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
/* Selectable option cards: an M3 outlined card with a radio; the chosen one
   takes the secondary container like a selected list item. */
.ship-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--shape-md);
  background: var(--md-surface-container-lowest);
  cursor: pointer;
  font: var(--type-body-small);
  letter-spacing: .4px;
  color: var(--text);
  overflow: hidden;
  transition: border-color var(--motion-short), background-color var(--motion-short);
}
.ship-card::before { content: ""; position: absolute; inset: 0; background: var(--org-accent, var(--accent)); opacity: 0; transition: opacity var(--motion-short); pointer-events: none; }
.ship-card:hover::before { opacity: .08; }
.ship-card > * { position: relative; }
.ship-card:has(input:checked), .ship-card-selected {
  border-color: var(--org-accent, var(--accent));
  background: color-mix(in srgb, var(--org-accent, var(--accent)) 12%, var(--md-surface-container-lowest));
}
.ship-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.ship-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ship-card-name { font: var(--type-title-small); letter-spacing: .1px; }
.ship-card input[type="radio"] { margin: 0; accent-color: var(--org-accent, var(--accent)); width: 20px; height: 20px; flex: none; }
.ship-card-price { font: var(--type-title-large); font-variant-numeric: tabular-nums; }
.ship-card-currency { font: var(--type-label-medium); color: var(--muted); }
.ship-card-price-unquoted { font: var(--type-title-small); color: var(--muted); }
.ship-card-detail { color: var(--text); font: var(--type-body-medium); }
.ship-card-foot { font: var(--type-label-small); color: var(--muted); }

/* Before a quote: the invitation. After the order changes under one: the strip. */
.ship-invite {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 20px; border-radius: var(--shape-md); background: var(--md-surface-container-low);
  font: var(--type-body-medium);
}
.ship-invite-title { font: var(--type-title-medium); }
.ship-stale {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--shape-md);
  background: var(--md-warning-container); color: var(--md-on-warning-container); font: var(--type-body-small); letter-spacing: .4px;
}
.ship-stale strong { font: var(--type-title-small); }
.ship-stale-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 240px; }
.ship-stale .btn { flex: none; }

/* While the carrier is asked (hx-indicator on the card): the body gives way
   to two grey cards the size of the options that will replace them. */
.ship-skeleton { display: none; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.ship-skeleton-card { height: 96px; border-radius: var(--shape-md); background: var(--md-surface-container); animation: pulse 1.2s ease-in-out infinite; }
.order-card-shipping.htmx-request .shipping-body { display: none; }
.order-card-shipping.htmx-request .ship-skeleton { display: grid; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .ship-skeleton-card { animation: none; } }

/* The total card: a column of labelled figures, ruled above the total.
   `::before` is the reprice indicator -- a thin bar across the top while a
   quote is in flight (the form's hx-indicator). */
.order-card-totals { position: relative; overflow: hidden; }
.order-card-totals::before {
  content: ""; position: absolute; left: 0; top: 0; height: 3px; width: 0;
  background: var(--org-accent, var(--accent)); opacity: 0; transition: opacity .15s;
}
.order-card-totals.htmx-request::before { opacity: 1; width: 100%; animation: sweep 1.1s ease-in-out infinite; }
@keyframes sweep { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .order-card-totals.htmx-request::before { animation: none; width: 100%; } }
.totals-stack { margin: 0; display: flex; flex-direction: column; gap: 8px; font: var(--type-body-medium); }
.totals-stack > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.totals-stack dt { color: var(--muted); }
.totals-stack dd { margin: 0; font-variant-numeric: tabular-nums; }
.totals-stack > .totals-note { display: block; font: var(--type-label-small); margin-top: -4px; }
.totals-total { border-top: 1px solid var(--border); padding-top: 9px; margin-top: 3px; }
.totals-total dt { color: var(--text); font: var(--type-title-small); }
.totals-total .total { font: var(--type-headline-small); }
.totals-currency { font: var(--type-label-medium); color: var(--muted); }
.totals-warnings { margin: 0; padding-left: 18px; font: var(--type-body-small); letter-spacing: .4px; }

/* The ship-date card: a read-only date field whose popover is a month of the
   account's shipping days (order-entry.js, from the select it hides). */
.ship-date-frozen { font-size: 1rem; font-weight: 600; }
.ship-date-field[hidden] { display: none; }
/* An M3 outlined text field, read-only, with the calendar as its trailing icon. */
.date-field {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 48px; padding: 0 12px 0 16px;
  border: 1px solid var(--md-outline); border-radius: var(--shape-xs); background: var(--md-surface-container-lowest);
  font: var(--type-body-large); letter-spacing: .5px; color: var(--text); text-align: left; cursor: pointer;
}
.date-field:hover { border-color: var(--text); }
.date-field:focus-visible, .date-field[aria-expanded="true"] { outline: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.date-field-label {
  position: absolute; top: -8px; left: 12px; padding: 0 4px;
  background: var(--md-surface-container-lowest); font: var(--type-body-small); color: var(--muted);
}
.date-field[aria-expanded="true"] .date-field-label, .date-field:focus-visible .date-field-label { color: var(--accent); }
.date-field-value { flex: 1; }
.date-field-icon { width: 20px; height: 20px; fill: var(--muted); flex: none; }
/* The M3 date picker's month grid, as a menu surface. */
.ship-calendar {
  position: fixed; inset: auto; margin: 0; width: 328px; padding: 12px 12px 10px;
  border: 0; border-radius: var(--shape-lg); background: var(--md-surface-container-high); color: var(--text);
  box-shadow: var(--elev-3);
  display: flex; flex-direction: column; gap: 8px;
}
.ship-calendar:not(:popover-open) { display: none; }
.ship-calendar::backdrop { background: transparent; }
.ship-calendar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ship-calendar-month { font: var(--type-title-small); }
.ship-calendar-nav { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: transparent; font: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--text); }
.ship-calendar-nav:hover { background: rgba(25, 28, 27, .08); }
.ship-calendar-nav:disabled { opacity: .35; cursor: default; background: none; }
.ship-calendar-grid { display: grid; grid-template-columns: repeat(7, 40px); gap: 2px; font: var(--type-body-medium); text-align: center; justify-content: center; }
.ship-calendar-dow { color: var(--text); font: var(--type-body-medium); padding: 8px 0; }
.ship-calendar-day { height: 40px; line-height: 40px; color: rgba(25, 28, 27, .38); border-radius: 50%; }
.ship-calendar-day.is-today { box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
button.ship-calendar-day {
  border: 0; background: transparent; color: var(--text); padding: 0;
  font: var(--type-body-medium); cursor: pointer;
}
button.ship-calendar-day:hover { background: rgba(25, 28, 27, .08); }
button.ship-calendar-day:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.ship-calendar-day[aria-pressed="true"] {
  background: var(--org-accent, var(--accent)); color: var(--md-on-primary); box-shadow: none;
}
.ship-calendar-legend { font: var(--type-body-small); color: var(--muted); padding: 4px 4px 0; }
.ship-date-notes { display: flex; flex-direction: column; gap: 3px; }
.ship-date-notes strong { color: var(--text); }

/* The pinned bar -------------------------------------------------------------- */
/* M3 bottom app bar: surface-container, 80px, the primary action at its end. */
.order-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  min-height: 80px;
  padding: 12px 24px;
  background: var(--md-surface-container);
  box-shadow: var(--elev-2);
}
.bar-status { display: flex; align-items: center; gap: 24px; flex: 1 1 auto; min-width: 0; }
.bar-note { flex: 1 1 auto; min-width: 0; font: var(--type-body-medium); color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bar-note strong { color: var(--text); font-weight: 500; }
.bar-reason { color: var(--md-on-warning-container); display: inline-flex; align-items: center; gap: 8px; font: var(--type-label-large); background: var(--md-warning-container); padding: 6px 12px 6px 10px; border-radius: var(--shape-sm); }
.bar-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--md-warning); flex: none; }
.bar-total { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.bar-total-label { font: var(--type-label-medium); color: var(--muted); }
.bar-total-value { font: var(--type-headline-small); font-variant-numeric: tabular-nums; white-space: nowrap; }
.order-actions-buttons { display: flex; align-items: flex-start; gap: 10px; }
/* Save draft with where the draft stands under it (draft-autosave.js):
   "Saved 12:41 PM", "Not saved: ...". */
.save-draft { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.save-status { max-width: 320px; text-align: right; font: var(--type-body-small); color: var(--muted); }
.save-status:empty { display: none; }
.save-status a { color: inherit; text-decoration: underline; }
.bar-ships[hidden], .bar-sep[hidden] { display: none; }
@media (max-width: 720px) {
  .order-head, .order-lines, .order-panels, .order-notices, .order-actions { padding-left: 16px; padding-right: 16px; }
  .order-actions { gap: 12px; }
  .bar-status { flex-basis: 100%; justify-content: space-between; }
  .order-actions-buttons { flex: 1; justify-content: flex-end; }
  .order-actions-buttons .btn-lg { flex: 1; padding: 0 12px; }
  .order-actions-buttons .save-draft { flex: 1; align-items: stretch; }
}

/* The add-row and the item finder ---------------------------------------------- */
.add-row td { padding: 0; }
.add-row-trigger {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-top: 1px dashed var(--border);
  color: var(--accent);
  font: var(--type-label-large);
  letter-spacing: .1px;
  padding: 14px 16px;
  cursor: pointer;
  min-height: 48px;
  border-radius: 0 0 var(--shape-md) var(--shape-md);
}
.add-row-trigger:hover { background: var(--md-surface-container-low); }
#address-picker.htmx-request { opacity: .6; }

/* Staff "Resend invoice" (invoices/_invoice_body.html). */
.card-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dialog textarea.input { width: 100%; resize: vertical; font-family: var(--font-mono, ui-monospace, monospace); }
.resend-help { font: var(--type-body-small); margin: 8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
/* Drawn open by the server (no script): sits over the page like the modal one. */
#still-working[open] { position: fixed; inset: 0; margin: auto; height: fit-content; z-index: 50; }
#still-working p { margin: 0 0 8px; }
#still-working [data-still-working-lines] { margin-bottom: 12px; }
#submitted-first[open] { position: fixed; inset: 0; margin: auto; height: fit-content; z-index: 50; }
#submitted-first p, #submitted-first [data-submitted-dropped] p { margin: 0 0 8px; }
.submitted-first p { margin: 0 0 8px; }
.invoice-email-status { font: var(--type-body-small); margin-top: 8px; }

/* An order's items (orders/detail.html, history_detail.html #order-items):
   a wide dialog over the tabs. The head stays put; the table scrolls. */
.items-dialog { width: min(1100px, calc(100vw - 32px)); max-width: none; max-height: 85vh; }
.items-dialog[open] { display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.items-dialog-head { padding: 20px 24px 0; margin-bottom: 12px; }
.items-dialog-body { overflow: auto; padding: 0 8px 16px; }
body:has(.items-dialog[open]) { overflow: hidden; }

/* The item finder: a large M3 dialog over the order (entry.html
   #finder-dialog). Header, search and footer stay put; the body is its own
   grid -- filters, chips, count, then the rows, which are what scrolls.
   `[open]` because a dialog's closed state is the UA's `display: none`, which
   any author `display` would beat. */
.finder-dialog { width: min(1040px, calc(100vw - 32px)); height: 85vh; max-width: none; }
.finder-dialog[open] { display: grid; grid-template-rows: auto auto 1fr auto; overflow: hidden; }
/* Behind a modal the page is inert, but it would still scroll under a wheel. */
body:has(.finder-dialog[open]) { overflow: hidden; }
.finder-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px 8px; }
.finder-head h2 { font: var(--type-headline-small); margin: 0; }
.finder-x { min-width: 40px; padding: 0; font-size: 22px; }

.finder-search { display: flex; gap: 10px; align-items: center; padding: 8px 24px 12px; }
.finder-search-box { position: relative; flex: 1; }
.finder-dialog .finder-search-box input[type="search"] {
  min-height: 48px;
  border-radius: var(--shape-full);
  padding: 0 44px 0 20px;
  background: var(--md-surface-container-lowest);
  font: var(--type-body-large);
}
.finder-search-box input::-webkit-search-cancel-button { display: none; }
.finder-search-box input:placeholder-shown + .finder-search-clear { display: none; }
.finder-search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border: 0; border-radius: var(--shape-full);
  background: none; color: var(--muted); font-size: 20px; cursor: pointer;
}
.finder-search-clear:hover { background: var(--md-surface-container-highest); }

#finder-body {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  min-height: 0;
  padding: 0 24px;
}
/* A request in flight (hx-indicator on the dialog) dims the rows it will replace. */
.finder-dialog.htmx-request #finder-rows { opacity: .55; transition: opacity .15s; }

/* The seven filters, the two toggles and Clear all: one row that wraps below
   1024px. The finder's on New order and the catalogue's (filters.html). */
.facet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 8px; }
details.facet { position: relative; }
details.facet > summary {
  list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 12px 0 16px;
  border: 1px solid var(--md-outline); border-radius: var(--shape-sm);
  color: var(--md-on-surface-variant); font: var(--type-label-large);
  cursor: pointer; white-space: nowrap; user-select: none;
}
details.facet > summary::-webkit-details-marker { display: none; }
details.facet > summary::after { content: "▾"; font-size: 11px; }
details.facet > summary:hover { background: var(--md-surface-container-highest); }
details.facet[open] > summary { background: var(--md-secondary-container); color: var(--md-on-secondary-container); border-color: transparent; }
.facet-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 5;
  min-width: 200px; max-width: calc(100vw - 32px); max-height: 320px; overflow: auto;
  padding: 8px 0;
  background: var(--md-surface-container); border-radius: var(--shape-xs); box-shadow: var(--elev-2);
}
.facet-menu label { display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 16px; font: var(--type-body-large); cursor: pointer; white-space: nowrap; }
.facet-menu label:hover { background: var(--md-surface-container-highest); }
.facet-menu.is-right { left: auto; right: 0; }
.facet-menu label.is-zero { color: var(--muted); opacity: .6; }
.facet-count { margin-left: auto; padding-left: 16px; color: var(--muted); font: var(--type-label-medium); }
.facet-none { margin: 8px 16px; }
.facet-menu [data-facet-clear] { margin: 4px 8px 0; }
.finder-toggle { display: inline-flex; align-items: center; font: var(--type-body-medium); color: var(--muted); white-space: nowrap; }
/* The toggles and Clear all keep to the right of the filters, together. */
.facet-row-end { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }

/* Active filters: M3 assist chips, removable. Also the attribute chips on a row. */
.finder-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 8px; }
.finder-chips[hidden] { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--md-outline-variant); border-radius: var(--shape-sm);
  background: none; color: var(--md-on-surface); font: var(--type-label-large);
  white-space: nowrap;
}
button.chip { cursor: pointer; }
button.chip:hover { background: var(--md-surface-container-highest); }
.finder-chips-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.finder-chips-row .chip { height: 24px; padding: 0 8px; font: var(--type-label-medium); color: var(--md-on-surface-variant); }
.finder-count { margin: 0 0 8px; font: var(--type-body-small); }

/* The catalogue: the finder's filter row over the price sheet. The search box
   takes the room the class menu leaves; a request in flight dims the rows it
   will replace, as the finder's does. */
.catalogue-search { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-bottom: 12px; }
.catalogue-search .input { flex: 1 1 220px; }
.catalogue-search .select { flex: 0 0 170px; }
.catalogue-filters { padding: 0 20px 4px; }
.catalogue-filters .finder-count { margin-bottom: 12px; }
#catalogue.htmx-request #catalogue-results { opacity: .55; transition: opacity .15s; }
#catalogue-results { border-top: 1px solid var(--border); }
#catalogue-results .table-wrap { border-radius: 0; }
/* The infinite-scroll sentinel: a little room below the last row, so it has a
   height to intersect and the list does not jump when it is replaced. */
.finder-more {
  min-height: 48px; display: flex; align-items: center; justify-content: center;
  color: var(--md-on-surface-variant); font: var(--type-body-small);
}

#finder-rows {
  min-height: 0; overflow: auto; overscroll-behavior: contain;
  background: var(--md-surface-container-lowest);
  border: 1px solid var(--border); border-radius: var(--shape-md);
}

/* One result: thumb | code, description, chips | unit | price | availability |
   Add or stepper | unit select. Add and the stepper share a column (one shows
   at a time); the columns after the text are fixed widths so the rows line up
   down the list, and a row without a unit choice leaves its select cell empty. */
.finder-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 120px 96px 108px 152px;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background-color var(--motion-short);
}
.finder-row:last-of-type { border-bottom: 0; }
/* No availability cell (a customer's row): one column fewer, so Add follows the price. */
.finder-row[data-no-stock] { grid-template-columns: 56px minmax(0, 1fr) 120px 96px 152px; }
.finder-row[data-no-stock] .finder-act { grid-column: 5; }
.finder-row:hover { background: var(--md-surface-container-low); }
.finder-row-on-order { background: color-mix(in srgb, var(--md-primary) 6%, transparent); }
.finder-row[aria-selected="true"] { background: var(--md-secondary-container); }
.finder-thumb {
  grid-column: 1;
  width: 56px; height: 56px; border-radius: var(--shape-sm);
  background: var(--md-surface-container-high)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236f7975'%3E%3Cpath d='M21 19V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2zM8.5 13.5l2.5 3 3.5-4.5 4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E")
    center / 24px no-repeat;
}
/* A product photo fills the slot on white (TAG's shots are on white), and
   the placeholder icon goes. Same for the catalogue and order-line thumbs. */
.finder-thumb { overflow: hidden; }
.finder-thumb.has-photo, .item-thumb.has-photo { background: #fff; }
.finder-thumb img, .item-thumb img {
  display: block; width: 100%; height: 100%; object-fit: contain;
}
/* The thumbnail beside an item's code on the catalogue and the order lines:
   the finder's placeholder, smaller. */
.item-thumb {
  display: inline-block; vertical-align: middle; flex: none;
  width: 40px; height: 40px; margin-right: 10px; overflow: hidden;
  border-radius: var(--shape-sm);
  background: var(--md-surface-container-high)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236f7975'%3E%3Cpath d='M21 19V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2zM8.5 13.5l2.5 3 3.5-4.5 4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E")
    center / 18px no-repeat;
}
.line-item { display: flex; align-items: flex-start; }
.line-item > div { min-width: 0; }
.finder-main { grid-column: 2; min-width: 0; }
.finder-code { display: block; font-size: 13px; }
.finder-hafele { display: block; font-size: 11px; color: var(--muted); }
.finder-desc { display: block; color: var(--muted); font: var(--type-body-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* What one unit is and what it costs: `1 BOX` over `(12 pcs)`, a bold `180.00`
   over `/ box`. Each unit has its own variant; only the one for the unit the
   row is set to is shown. */
.finder-uom, .finder-price { display: grid; line-height: 1.15; font-variant-numeric: tabular-nums; }
.finder-uom b, .finder-price b { font: var(--type-body-large); font-weight: 600; line-height: 1.15; }
.finder-uom small, .finder-price small { font: var(--type-body-small); line-height: 1.15; color: var(--muted); }
.finder-price { grid-column: 4; text-align: right; }
.finder-availability { grid-column: 5; display: flex; flex-wrap: wrap; gap: 4px; }
/* The UOM column: a unit label, or the unit select for an item the account
   may order two ways (then the select is the label), with the box hint under
   either. The stepper or Add sits flush right in the last column. */
.finder-uom-cell { grid-column: 3; display: grid; gap: 2px; }
/* Under the select the hint line keeps its height even when a unit has none
   ("pieces"), so switching units does not move the row. */
.finder-uom-cell .finder-uom { grid-column: auto; min-height: 1.15em; }
.finder-row [data-unit] { min-height: 32px; width: 100%; padding: 0 4px 0 8px; font: var(--type-body-medium); letter-spacing: 0; }
/* Add or the quantity stepper, with existing-order information beside it. */
.finder-act { grid-column: 6; justify-self: end; display: flex; align-items: center; gap: 6px; }
.finder-act .stepper { flex: none; width: 116px; }
.finder-on-order { flex: none; padding: 2px 4px; color: var(--accent); font-size: 20px; line-height: 1.15; cursor: help; }
.finder-row [hidden] { display: none; }
.finder-empty { padding: 24px; text-align: center; color: var(--muted); font: var(--type-body-medium); }

/* The quantity stepper: − n +, one outlined control. */
.stepper {
  display: inline-grid; grid-template-columns: 36px minmax(0, 1fr) 36px; align-items: stretch;
  height: 36px; border: 1px solid var(--md-outline); border-radius: var(--shape-full); overflow: hidden;
}
.stepper button { border: 0; background: none; color: var(--accent); font: var(--type-title-medium); cursor: pointer; }
.stepper button:hover { background: var(--md-surface-container-highest); }
.stepper input[type="number"] {
  min-height: 0; height: 100%; width: 100%; padding: 0 2px;
  border: 0; border-left: 1px solid var(--md-outline-variant); border-right: 1px solid var(--md-outline-variant);
  border-radius: 0; background: transparent; text-align: center; font: var(--type-label-large);
  -moz-appearance: textfield;
}
.stepper input[type="number"]::-webkit-inner-spin-button,
.stepper input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input[type="number"]:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.finder-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px 16px; }
.finder-foot-actions { display: flex; flex: none; gap: 8px; margin-left: auto; }
.finder-note { margin: 0; font: var(--type-body-small); }

/* The price as unit_price.html draws it -- the catalogue. */
.picker-row-price { font-variant-numeric: tabular-nums; font: var(--type-label-large); }

/* Below 1024px the dialog is the whole viewport -- an iPad in portrait and
   every phone -- and a row wraps: the text beside the thumbnail, the price,
   label and controls on a line under it. */
@media (max-width: 1024px) {
  .finder-dialog {
    width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0;
    /* The visible height on a phone, where 100vh runs under the browser's bars. */
    height: 100dvh; max-height: 100dvh;
  }
  .finder-head { padding: 12px 16px 4px; }
  .finder-search, #finder-body { padding-left: 16px; padding-right: 16px; }
  .finder-foot { padding: 8px 16px 12px; }
  .finder-toggle:first-of-type { margin-left: 0; }
  .finder-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  .finder-main { flex: 1 1 calc(100% - 80px); }
  .finder-uom-cell { margin-left: 68px; min-width: 120px; }
  .finder-price { text-align: left; }
  .finder-row .stepper { width: 116px; }
  /* Whichever of the stepper and Add shows, at the right. */
  .finder-act { margin-left: auto; }
}


/* BOM tree ------------------------------------------------------------------ */
.tree { font-size: .87rem; }
.tree details { margin: 2px 0; }
.tree summary { cursor: pointer; padding: 3px 0; list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary:before { content: "▸"; display: inline-block; width: 1em; color: var(--muted); }
.tree details[open] > summary:before { content: "▾"; }
.tree ul { margin: 0 0 0 1.3em; padding: 0; list-style: none; border-left: 1px dashed var(--border); }
.tree li { padding: 2px 0 2px 10px; }

/* Auth pages (auth_base.html) ------------------------------------------------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 420px; }
.auth-card > .card { border: 0; background: var(--md-surface-container-lowest); box-shadow: var(--elev-1); border-radius: var(--shape-xl); }
.auth-card .card-body { padding: 28px; }
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
  font: var(--type-title-large);
}
.auth-links { text-align: center; margin-top: 16px; font: var(--type-body-medium); color: var(--muted); }

/* Catalogue: click a row to expand its BOM / stock breakdown (demo, debugging) */
.bom-toggle { cursor: pointer; }
.bom-toggle:focus-visible { outline: 2px solid var(--info-soft); outline-offset: -2px; }
.bom-caret { display: inline-block; width: 1.1em; color: var(--muted); }
.bom-caret::before { content: "▸"; }
.bom-toggle[aria-expanded="true"] .bom-caret::before { content: "▾"; }
.bom-toggle[aria-expanded="true"] td { border-bottom-color: transparent; }
.table tbody tr.bom-detail:hover { background: none; }
.bom-detail > td { background: var(--surface-2); padding: 14px 16px 18px; }
.bom-summary { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 6px; }
.bom-summary > div { display: flex; flex-direction: column; }
.bom-summary .muted { font: var(--type-label-medium); }
.bom-summary strong { font: var(--type-title-large); text-align: left; }
.bom-note { font-size: .8rem; margin: 0 0 10px; }
.bom-table { background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 6px; font-size: .8rem; }
.bom-table th, .bom-table td { padding: 6px 10px; }
.bom-table td.bom-code { padding-left: calc(10px + (var(--bom-depth, 1) - 1) * 1.25rem); white-space: nowrap; }
.bom-table tr.bom-limiting td { background: var(--warn-soft); }
.bom-table tr.bom-flagged td { background: var(--danger-soft); }
.bom-table tr.bom-repeated td.bom-code { font-style: italic; }
.bom-table td.num .muted { font-size: .72rem; }
.bom-tags { white-space: normal; }
.bom-tags .pill { margin: 1px 2px 1px 0; }
.bom-table tr.bom-flagged .pill, .bom-table tr.bom-limiting .pill { box-shadow: inset 0 0 0 1px currentColor; }
.bom-short { color: var(--md-error); font-weight: 500; }
.bom-ok { color: var(--md-success); }
.bom-qty { margin: 0 0 10px; font-size: .85rem; }
.bom-qty .input { width: 90px; display: inline-block; padding: 4px 8px; margin: 0 4px; }
.bom-issues { background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; margin: 0 0 10px; font-size: .82rem; }
.bom-issues ul { margin: 6px 0 0; padding: 0; list-style: none; }
.bom-issues li { padding: 3px 0; }
.bom-issues .mono { color: var(--muted); }
.bom-clean { margin: 0 0 10px; }
.bom-table th.num, .bom-table td.num { text-align: right; }
/* The projection refresh strip (orders/partials/planning_refresh_strip.html):
   under the Inventory planning heading while the worker re-reads SYSPRO
   (spec §4) -- an M3 linear progress indicator, indeterminate, over the
   label. Red-tinted for the one poll that says the request was abandoned. */
.refresh-strip {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 20px;
  font: var(--type-body-small); color: var(--md-on-surface-variant);
  background: var(--md-surface-container-low); border-bottom: 1px solid var(--border);
}
.refresh-strip-failed { color: var(--md-on-error-container); background: var(--md-error-container); }
.m3-progress {
  position: relative; height: 4px; border-radius: 2px; overflow: hidden;
  background: var(--md-secondary-container);
}
.m3-progress.indeterminate::before,
.m3-progress.indeterminate::after {
  content: ""; position: absolute; top: 0; bottom: 0; border-radius: inherit; background: var(--md-primary);
}
.m3-progress.indeterminate::before { animation: m3-progress-a 2s cubic-bezier(.65, .815, .735, .395) infinite; }
.m3-progress.indeterminate::after { animation: m3-progress-b 2s cubic-bezier(.165, .84, .44, 1) 1.15s infinite; }
@keyframes m3-progress-a { 0% { left: -35%; right: 100%; } 60%, 100% { left: 100%; right: -90%; } }
@keyframes m3-progress-b { 0% { left: -200%; right: 100%; } 60%, 100% { left: 107%; right: -8%; } }
@media (prefers-reduced-motion: reduce) {
  .m3-progress.indeterminate::before { animation: none; left: 0; right: 0; opacity: .6; }
  .m3-progress.indeterminate::after { display: none; }
}

/* The planning grid (orders/partials/planning_grid.html): the planners' MRP
   sheet under a line of the Inventory planning card -- 31 weekly balances per
   code, styled as the sheet styles them. Code and Description stay pinned
   (sticky, at their fixed widths) while the sheet figures, the groups, Adj
   and the weeks scroll; the head stays in view while
   the rows do. */
.mrp-grid { padding: 10px 0; }
/* The grid's row under a line of the Inventory planning card, and its toggle. */
.mrp-grid-row > td { padding: 0 12px; background: var(--surface-2); }
/* The grid's 44 columns scroll inside it rather than widening the card's table:
   no width of its own, so it takes the cell's (the row spans the table). */
.mrp-grid-row > td > .mrp-grid { width: 0; min-width: 100%; }
.table tbody tr.mrp-grid-row:hover { background: none; }
.grid-toggle { display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; width: 36px; height: 36px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0; margin: 0 8px 0 0; color: var(--accent); cursor: pointer; }
.planning-chevron { display: block; flex: 0 0 auto; width: 18px; height: 18px; stroke-width: 2.5; transform-origin: center; }
.grid-toggle[aria-expanded="true"] .planning-chevron,
.planning-components[open] > summary .planning-chevron { transform: rotate(90deg); }
.grid-toggle:hover, .planning-components > summary:hover { background: var(--surface-2); border-color: var(--accent); }
.grid-toggle[aria-expanded="true"], .planning-components[open] > summary { background: var(--surface-2); border-color: var(--accent); }
.grid-toggle:focus-visible, .planning-components > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.planning-components > summary { display: flex; align-items: center; gap: 12px; min-height: 44px; width: fit-content; box-sizing: border-box; padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; color: var(--accent); font-weight: 600; cursor: pointer; list-style: none; }
.planning-components > summary::-webkit-details-marker { display: none; }
.planning-component-count { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 6px; box-sizing: border-box; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: .8rem; }
.planning-components[open] > summary { margin-bottom: 12px; }
.mrp-grid-meta { font-size: .8rem; margin: 0 0 6px; }
.mrp-stale { color: var(--warn); font-weight: 500; margin-left: 6px; }
.mrp-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 8px; font-size: .85rem; }
.mrp-controls input[type="number"] { width: 90px; padding: 4px 8px; }
.mrp-controls input[type="date"] { width: 150px; padding: 4px 8px; }
.mrp-remainder .field-error { padding-left: 0; }
/* One row per shipment (spec 2026-11-14-shipment-verdicts §7): the first
   shipment's quantity and date, then the remainder's; the toggles follow. */
.mrp-shipment { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; flex-basis: 100%; }
.mrp-shipment > .field-error { padding-left: 0; }
/* Each shipment's verdict, at the end of its control row (spec 2026-11-14 §4). */
.mrp-verdict { font-weight: 600; }
/* Green, yellow, red (saved forecast adjustments §6.3): the pill-ok / pill-warn / pill-danger palette. */
.mrp-verdict-ok, .mrp-verdict-adjusted, .mrp-verdict-gap { padding: 1px 8px; border-radius: 999px; }
.mrp-verdict-ok { background: var(--md-success-container); color: var(--md-on-success-container); }
.mrp-verdict-adjusted { background: var(--md-warning-container); color: var(--md-on-warning-container); }
.mrp-verdict-unknown { color: var(--muted); }
.mrp-verdict-gap { font: inherit; font-weight: 600; background: var(--md-error-container); color: var(--md-on-error-container); border: 0; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.mrp-verdict-gap:hover { text-decoration-style: solid; }
/* The card's Gap cell: what the open grid says when the saved verdict differs. */
.planning-scenario { font: var(--type-body-small); color: var(--muted); }
/* A line's shipments in the card's Ships cell (sub-lines §3.4): one per line. */
.planning-shipments { list-style: none; margin: 0; padding: 0; white-space: nowrap; }
.planning-shipments li + li { margin-top: 2px; }
/* The card's Qty cell: the number with a pencil; the pencil swaps it for a
   box with a check (save) and an x (cancel). */
.planning-qty-cell { white-space: nowrap; }
.planning-qty-view[hidden], .planning-qty-form[hidden] { display: none; }
.planning-qty-form { display: inline-flex; align-items: center; justify-content: flex-end; gap: 4px; }
.planning-qty-form input[type="number"] { width: 84px; padding: 4px 8px; text-align: right; }
.qty-icon { display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; width: 28px; height: 28px; padding: 0; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--muted); cursor: pointer; }
.qty-icon:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border); color: var(--text, inherit); }
.qty-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.qty-icon:disabled { opacity: .45; cursor: default; }
.qty-icon-save { color: var(--accent); }
/* The card's log, its own collapsed group under it. */
#planning-history { margin-top: 16px; }
/* The order's forecast adjustments above the card's table (saved forecast adjustments §7). */
.planning-adjustments-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.planning-adjustments { margin: 0; }
/* Propose even split (sub-lines §4.3): the proposal panel under the card's strip. */
.even-split-slot:empty { display: none; }
.even-split-slot { margin-top: 12px; }
.even-split { border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; }
.even-split-table td { white-space: nowrap; }
.even-split-heading { font-size: 1rem; margin: 0 0 4px; }
.even-split-adjusted { margin: 0 0 4px; color: var(--md-on-warning-container); }
.even-split-actions { display: flex; gap: 8px; margin-top: 8px; }
.mrp-merge-button { margin-left: 8px; }
.mrp-grid-scroll { overflow-x: auto; overflow-y: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.mrp-grid-table { font-size: .75rem; border-collapse: separate; border-spacing: 0; }
.mrp-grid-table td, .mrp-grid-table th { padding: 4px 6px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.mrp-grid-table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-weight: 600; }
.mrp-grid-table .mrp-code, .mrp-grid-table .mrp-desc { position: sticky; z-index: 1; background: var(--surface); }
.mrp-grid-table thead .mrp-code, .mrp-grid-table thead .mrp-desc { z-index: 3; background: var(--surface-2); }
.mrp-grid-table .mrp-code { left: 0; box-sizing: border-box; width: 8rem; min-width: 8rem; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; }
.mrp-grid-table .mrp-desc { left: 8rem; box-sizing: border-box; width: 8.5rem; min-width: 8.5rem; max-width: 8.5rem; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--border-strong); }
/* The description gives way (full text in the cell's title); "x qty per" stays. */
.mrp-desc-text { display: inline-block; max-width: 5rem; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
/* The header block (On hand ... Adj) sits tight so the weeks start within
   reach: its two-word heads ("On hand", "Prev 3") wrap rather than widen. */
.mrp-grid-table .mrp-hd { padding: 4px 3px; }
.mrp-grid-table thead th.mrp-hd { white-space: normal; vertical-align: bottom; font-size: .7rem; }
/* Demand by customer group: each figure a quiet button; clicked (its group
   subtracted through Adj) it is struck through. Adj is a small number box. */
.mrp-grid-table .mrp-group-cell { padding: 2px 1px; font-size: .7rem; }
.mrp-group { font: inherit; color: inherit; background: none; border: 0; border-radius: 3px; padding: 1px 2px; cursor: pointer; white-space: nowrap; text-decoration: underline dotted var(--border-strong); text-underline-offset: 2px; }
.mrp-group:hover { background: var(--surface-2); color: var(--accent); }
.mrp-group:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.mrp-group.is-active { text-decoration: line-through; color: var(--muted); background: var(--surface-2); }
.mrp-grid-table .mrp-adj { padding: 2px 3px; }
.mrp-adj input[type="number"] { width: 3.5rem; min-height: 0; height: 1.5rem; padding: 0 4px; font: inherit; letter-spacing: normal; text-align: right; box-sizing: border-box; -moz-appearance: textfield; appearance: textfield; }
.mrp-adj input[type="number"]::-webkit-inner-spin-button, .mrp-adj input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.mrp-adj-mirror { color: var(--muted); }
/* The Adj prefill (sub-lines §5): "auto" beside the box while it holds the
   order's share of the forecast average; hidden once the value is anything else. */
.mrp-adj-auto { display: inline-block; margin-left: 3px; padding: 0 3px; border: 1px solid var(--info); border-radius: 3px; color: var(--info); font: 600 .6rem/1.4 var(--font); letter-spacing: .02em; vertical-align: 1px; cursor: help; }
.mrp-adj:not(.is-auto) .mrp-adj-auto { display: none; }
/* The Auto adjust switch, above the Adj column's own label. */
.mrp-auto-switch { display: block; font-weight: 500; white-space: nowrap; cursor: pointer; }
.mrp-auto-switch input { margin: 0 2px 0 0; vertical-align: -2px; }
/* The order's own demand group: the cell the prefill reads. */
.mrp-grid-table .mrp-own-group { box-shadow: inset 0 -2px 0 var(--info); }
.mrp-partial { color: var(--warn); font-weight: 600; }
.mrp-grid-table th.mrp-window { box-shadow: inset 0 3px 0 var(--accent); }
/* An adjusted row: its WkFc and its weeks from week 1 tinted, a thin rule
   opening the block; red, amber and receipts still read over the tint. */
.mrp-adjusted { background-color: var(--info-soft); }
.mrp-grid-table td.mrp-adjusted-first { border-left: 2px solid var(--info); }
.mrp-red { background-color: var(--danger-soft); }
/* Below 0 only once a later line of the order takes the stock (sub-lines §8):
   that line's gap, not this one's. Grey with a dotted outline, so it reads
   apart from red and from a plain cell without colour; the number stays. */
.mrp-grid-table td.mrp-later { background-color: var(--border); color: var(--text); outline: 1px dotted var(--muted); outline-offset: -2px; }
.mrp-amber { background-color: var(--warn-soft); }
.mrp-receipt { font-weight: 700; }
.mrp-forecast { font-style: italic; }
.mrp-bod { background: linear-gradient(135deg, var(--danger-soft) 50%, var(--warn-soft) 50%); }
/* A week outside the row's judged window (`_judged_windows`) is not judged:
   hatched over whatever colour the cell has; a built-on-demand cell keeps its
   half red / half orange under the hatch. */
.mrp-grid-table td.mrp-beyond { background-image: repeating-linear-gradient(45deg, transparent 0 5px, rgba(0,0,0,.07) 5px 6px); }
.mrp-grid-table td.mrp-bod.mrp-beyond { background-image: repeating-linear-gradient(45deg, transparent 0 5px, rgba(0,0,0,.07) 5px 6px), linear-gradient(135deg, var(--danger-soft) 50%, var(--warn-soft) 50%); }
/* Needs supply (spec 2026-11-13 §5.4): short in a coverable week -- not a gap.
   Amber under the hatch (the gradient is a background-image, the fill a
   background-color, so both show), with a dashed outline. */
.mrp-grid-table td.mrp-needs-po { background-color: var(--warn-soft); outline: 1px dashed var(--warn); outline-offset: -2px; }
.mrp-lt-assumed { color: var(--muted); font-style: italic; }
.mrp-earliest { font: var(--type-body-small); margin: 4px 0 0; }
/* The legend: one swatch + label per mark, wrapping. Each swatch reuses its
   cell's colours. */
.mrp-legend { font: var(--type-body-small); color: var(--muted); list-style: none; margin: 0; padding: 4px 8px 0; display: flex; flex-wrap: wrap; gap: 2px 14px; }
.mrp-legend li { display: inline-flex; align-items: center; gap: 5px; }
.mrp-legend .swatch { display: inline-block; box-sizing: border-box; width: 16px; height: 12px; border: 1px solid var(--border); background-color: var(--surface); font-size: .65rem; line-height: 10px; text-align: center; color: inherit; }
.mrp-legend .sw-red { background-color: var(--danger-soft); }
.mrp-legend .sw-later { background-color: var(--border); border: 1px dotted var(--muted); }
.mrp-legend .sw-amber { background-color: var(--warn-soft); }
.mrp-legend .sw-bod { background: linear-gradient(135deg, var(--danger-soft) 50%, var(--warn-soft) 50%); }
.mrp-legend .sw-supply { background-color: var(--warn-soft); background-image: repeating-linear-gradient(45deg, transparent 0 3px, rgba(0,0,0,.12) 3px 4px); border: 1px dashed var(--warn); }
.mrp-legend .sw-hatch { background-image: repeating-linear-gradient(45deg, transparent 0 3px, rgba(0,0,0,.12) 3px 4px); }
.mrp-legend .sw-adjusted { background-color: var(--info-soft); border-left: 2px solid var(--info); }
.mrp-legend .sw-receipt { font-weight: 700; }
.mrp-legend .sw-forecast { font-style: italic; }
.mrp-legend .sw-bar { box-shadow: inset 3px 0 0 var(--accent); }
.mrp-legend .sw-row { background-color: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
.mrp-legend .sw-lt { background-color: var(--surface-2); }
.mrp-legend .sw-built { background-color: var(--surface-2); border-style: dotted; }
.mrp-legend .sw-skipped { opacity: .45; background-color: var(--surface-2); }
.mrp-grid-table .mrp-gap-row > .mrp-code, .mrp-grid-table .mrp-gap-row > .mrp-desc { background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
/* A row whose only need is supply ordered keeps its label: a small "order" tag in its Code cell (spec 2026-11-14 §5). */
.mrp-order-tag, .mrp-legend .sw-order { display: inline-block; box-sizing: border-box; width: auto; height: auto; padding: 0 4px; border: 1px dashed var(--warn); border-radius: 3px; background: none; color: var(--md-on-warning-container); font: 600 .65rem/1.4 var(--font); letter-spacing: .02em; vertical-align: 1px; cursor: help; }
.mrp-legend .sw-auto { width: auto; height: auto; padding: 0 3px; border: 1px solid var(--info); border-radius: 3px; background: none; color: var(--info); font: 600 .6rem/1.4 var(--font); letter-spacing: .02em; }
/* In the narrow pinned Code cell the tag sits at its right edge, over the end of a long code, so it is never clipped. */
.mrp-grid-table .mrp-code .mrp-order-tag { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); background: var(--surface); }
.mrp-grid-table .mrp-code:has(.mrp-order-tag) { padding-right: 3.2em; }
/* The gap a verdict names, outlined after its click (app.js; gone on the next redraw). */
.mrp-grid-table td.mrp-cell-focus { outline: 2px solid var(--danger); outline-offset: -2px; }
.mrp-skipped { opacity: .45; }
.mrp-demand { box-shadow: inset 3px 0 0 var(--accent); }
.mrp-apply { margin: 0; }
.mrp-apply-row { margin: 8px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
/* Beside Apply while it is enabled: the grid has changes the order does not (pill-warn palette). */
.mrp-unsaved { padding: 1px 8px; border-radius: 999px; font-weight: 600; font-size: .82rem; background: var(--md-warning-container); color: var(--md-on-warning-container); }
.mrp-unsaved[hidden] { display: none; }
.mrp-errors { color: var(--danger); font-size: .82rem; margin: 6px 0 0; padding-left: 18px; }
/* Import from Excel (orders/entry.html). The file input is hidden but stays
   focusable through its label; `is-busy` shows while the sheet uploads. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.import-sheet { display: inline-flex; gap: 8px; align-items: center; }
.import-sheet [data-import-go][hidden] { display: none; }
.import-sheet:focus-within label { outline: 2px solid var(--accent, #1f6f5c); outline-offset: 2px; }
.import-sheet.is-busy label { opacity: .6; pointer-events: none; }
.import-sheet.is-busy label::after { content: " \2026"; }

/* Orders list: the invoices listed under an order row ---------------------- */
.table tbody tr.invoice-subrow:hover { background: none; }
.invoice-subrow > td { background: var(--surface-2); padding: 8px 16px 14px 32px; }
.invoice-subrow[hidden] { display: none; }
.invoice-sublist { width: 100%; margin-bottom: 10px; }
.invoice-sublist td { padding: 6px 12px 6px 0; border-bottom: 0; }
.invoice-toggle { margin-left: 8px; }
.invoice-none { margin-left: 8px; font: var(--type-label-medium); }

/* Supporting information is closed by default; warnings stay in the summary. */
.info-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.info-panel > summary { padding: 12px 16px; cursor: pointer; font-weight: 600; overflow-wrap: anywhere; }
.info-panel > summary .pill { margin-left: 8px; }
.info-panel-body { padding: 0 16px 16px; font-size: .87rem; overflow-wrap: anywhere; }
.info-panel-body > * + * { margin-top: 8px; }
.info-panel-body ul { padding-left: 20px; }
.info-panel-compact { margin-bottom: 0; }

/* Cross-order supply review: compact rows keep more affected orders in view. */
.low-stock-group { margin-top: 12px; }
.low-stock-group > .card-body { padding: 10px 12px; }
.low-stock-group .table { font-size: .85rem; }
.low-stock-group .table th, .low-stock-group .table td { padding: 6px 10px; }
.low-stock-group .table .muted { font-size: .75rem; }
.low-stock-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-bottom: 8px; }
.low-stock-actions label { font-size: .8rem; }
.low-stock-group .input { padding: 4px 6px; min-height: 30px; }
.low-stock-group input[type="date"] { width: 135px; }
.low-stock-group .btn-sm { padding: 4px 8px; }
#low-stock-grid:not(:empty) { margin-top: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--shape-md); }

/* Staff pallet-placement popup on the shipping card (10 Nov 2026). */
.pallet-debug { display: inline-block; position: relative; margin-left: 4px; }
.pallet-debug > summary { list-style: none; cursor: pointer; color: var(--accent); }
.pallet-debug > summary::-webkit-details-marker { display: none; }
.pallet-debug-panel { position: absolute; z-index: 30; left: 0; top: 1.6em; width: min(560px, 90vw); padding: 12px; background: var(--surface, #fff); color: var(--text, #111); border: 1px solid var(--border); border-radius: var(--radius, 8px); box-shadow: 0 6px 24px rgba(0,0,0,.15); font-size: .8rem; white-space: normal; }
.pallet-debug-panel > * + * { margin-top: 8px; }
.pallet-debug-table th, .pallet-debug-table td { padding: 4px 6px; }
.pallet-debug-best td { font-weight: 600; }
