/* ==========================================================================
   Design tokens
   --------------------------------------------------------------------------
   Three layers, and nothing below this block should ever hardcode a value:
     1. Primitives  (--n-*, --brand-*)  raw palette, never used directly
     2. Semantics   (--surface, --text, --action, ...) what a thing means
     3. Legacy aliases (--navy, --card, --muted, ...) kept so the ~800 lines of
        existing rules below keep working; retiring them is Track B tidy-up.
   The dark theme re-points semantics only — it must never restate a primitive.
   ========================================================================== */
:root {
  /* -- Primitives: neutral ramp (slightly cool, reads as "product" not "print") */
  --n-0:   #ffffff;
  --n-25:  #fbfcfd;
  --n-50:  #f6f8fa;
  --n-100: #eef1f5;
  --n-200: #e2e7ed;
  --n-300: #cdd5de;
  --n-400: #98a3b0;
  --n-500: #5c6672;
  --n-600: #4d5661;
  --n-700: #363d47;
  --n-800: #232931;
  --n-900: #161a20;
  --n-950: #0e1116;

  /* -- Primitives: brand. Orange is the only saturated colour with a job. */
  --brand-50:  #fff4ec;
  --brand-100: #ffe4d1;
  --brand-500: #f86800;
  --brand-600: #dd5a00;
  --brand-700: #b34800;
  --brand-800: #8f3a00;
  /* Navy survives as a structural/heading colour, not as a surface. */
  --navy-700: #12395c;
  --navy-800: #0d2c48;

  /* -- Primitives: status */
  --green-600: #157347;  --green-50: #e8f6ee;
  --amber-700: #8a5a08;  --amber-50: #fdf0da;
  --red-600:   #b3261e;  --red-50:   #fdeceb;
  --blue-700:  #0b5cad;  --blue-50:  #e8f1fb;
  --violet-700:#6a3593;  --violet-50:#f2e8fa;

  /* -- Semantics: surfaces & text */
  --bg:            var(--n-50);
  --surface:       var(--n-0);
  --surface-2:     var(--n-50);
  --surface-3:     var(--n-100);
  --border:        var(--n-200);
  --border-strong: var(--n-300);
  --text:          var(--n-800);
  --text-muted:    var(--n-500);
  --text-subtle:   var(--n-400);
  --text-heading:  var(--navy-800);

  /* -- Semantics: interaction */
  /* --brand-700, not the brighter --brand-600: white on #dd5a00 measures 3.80:1, which
     fails AA for the 14px semibold that button labels actually use. #b34800 is 5.46:1. */
  --action:        var(--brand-700);
  --action-hover:  var(--brand-800);
  --action-fg:     #ffffff;
  --action-soft:   var(--brand-50);
  --action-soft-fg:var(--brand-700);
  --link:          var(--blue-700);
  --focus:         var(--brand-600);

  /* -- Semantics: status */
  --success: var(--green-600); --success-bg: var(--green-50);
  --warn:    var(--amber-700); --warn-bg:    var(--amber-50);
  --danger:  var(--red-600);   --danger-bg:  var(--red-50);
  --info:    var(--blue-700);  --info-bg:    var(--blue-50);

  /* -- Type scale. 16px base: iOS Safari zooms any field under 16px on focus. */
  --fs-2xs: 11px;
  --fs-xs:  12px;
  --fs-sm:  14px;
  --fs-base:16px;
  --fs-lg:  18px;
  --fs-xl:  22px;
  --fs-2xl: 28px;
  --lh-tight: 1.25;
  --lh:       1.5;

  /* -- Space scale (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  /* -- Radius & elevation */
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-full: 999px;
  --e-1: 0 1px 2px rgba(16,24,40,.06);
  --e-2: 0 4px 12px -2px rgba(16,24,40,.10), 0 2px 4px -2px rgba(16,24,40,.05);
  --e-3: 0 16px 32px -8px rgba(16,24,40,.16), 0 4px 8px -4px rgba(16,24,40,.06);

  /* -- Legacy aliases (see header note) */
  --navy: var(--text-heading);
  --navy-light: var(--navy-700);
  --accent: var(--brand-500);
  --accent-dark: var(--brand-600);
  --teal: var(--info);
  --teal-dark: var(--link);
  --teal-bg: var(--info-bg);
  --card: var(--surface);
  --muted: var(--text-muted);
  --hover: var(--surface-3);
  --fg: var(--text);
  --radius: var(--r-md);
}

:root[data-theme="dark"] {
  --bg:            var(--n-950);
  --surface:       #171b22;
  --surface-2:     #1d222a;
  --surface-3:     #242a33;
  --border:        #2b323c;
  --border-strong: #3a424e;
  --text:          #e7eaee;
  --text-muted:    #98a3b0;
  --text-subtle:   #6f7a87;
  --text-heading:  #e7eaee;

  --action:        var(--brand-500);
  --action-hover:  #ff7d1f;
  --action-fg:     #17120d;
  --action-soft:   #3a2410;
  --action-soft-fg:#ffab6b;
  --link:          #6cb2f2;
  --focus:         var(--brand-500);

  --success: #4cc07d; --success-bg: #12301f;
  --warn:    #e0a44a; --warn-bg:    #362713;
  --danger:  #ff6b60; --danger-bg:  #3a1d1b;
  --info:    #6cb2f2; --info-bg:    #14283d;

  --e-1: 0 1px 2px rgba(0,0,0,.40);
  --e-2: 0 4px 12px -2px rgba(0,0,0,.50), 0 2px 4px -2px rgba(0,0,0,.30);
  --e-3: 0 16px 32px -8px rgba(0,0,0,.60), 0 4px 8px -4px rgba(0,0,0,.40);

  --navy-700: #2b5f92;
}

@keyframes field-invalid-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
@keyframes field-invalid-glow {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 0%, transparent); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 45%, transparent); }
}
.field-invalid {
  animation: field-invalid-shake 0.4s ease-in-out, field-invalid-glow 1.1s ease-in-out 2;
  border-color: var(--danger) !important;
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule is display:none at zero specificity, so any class
   that sets display beats it — .btn is inline-flex, which meant every `el.hidden =
   true` on a button was silently ignored and the control stayed on screen. Restated
   here with !important so `hidden` means hidden regardless of what else the element is. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont,
               "Inter", system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, .brand-panel, .stat .value, .btn {
  font-family: "Segoe UI Variable Display", "Segoe UI Variable Text", "Segoe UI",
               -apple-system, BlinkMacSystemFont, "Inter", system-ui, Arial, sans-serif;
}
h1, h2, h3 { line-height: var(--lh-tight); letter-spacing: -0.011em; color: var(--text-heading); }

a { color: var(--teal-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* One visible focus ring for every interactive element. Previously only table rows had
   one, which left keyboard users with the UA default — invisible against the sidebar and
   the filled buttons. Uses an outline (not a box-shadow) so it survives overflow:hidden. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus, var(--accent-dark));
  outline-offset: 2px;
  border-radius: 3px;
}

/* WCAG 2.2 SC 2.5.8 floor for anything clickable, raised to the 44px touch standard on
   phones. Applied via min-height rather than padding so table-cell layouts don't shift. */
.btn, .group-toggle, .topbar-icon-btn, .help-toggle, .nav-toggle, .popover-trigger,
.card-link, .ml-6 {
  min-height: 28px;
}
.card-link, .ml-6 { display: inline-flex; align-items: center; }
/* Checkboxes and radios have no padding to grow into, so the control itself has to
   carry the whole target. 24px is the SC 2.5.8 minimum; the UA default is 13px. */
input[type=checkbox], input[type=radio] {
  width: 24px; height: 24px; min-height: 24px; accent-color: var(--action); cursor: pointer;
}
@media (pointer: coarse), (max-width: 860px) {
  .btn, .group-toggle, .topbar-icon-btn, .help-toggle, .popover-trigger,
  .card-link, .ml-6 {
    min-height: 44px;
  }
  .btn, .popover-trigger { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar nav a, .sidebar nav summary.section-label { min-height: 44px; }
}

.layout { display: flex; min-height: 100vh; }

/* Light sidebar (2026-08-14 refresh). Chrome is neutral so the single saturated
   colour in the UI — orange — always means "this is the action". */
.sidebar {
  width: 244px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  color: var(--text);
  flex-shrink: 0;
  padding: var(--sp-4) 0;
}

.sidebar .brand-panel {
  margin: 0 var(--sp-4) var(--sp-5) var(--sp-4);
  padding: 0 var(--sp-1);
  background: none;
  border-radius: 0;
}
.sidebar .brand-panel img {
  display: block;
  width: 50%;
  height: auto;
}

.sidebar nav { padding: 0 var(--sp-3); }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: 1px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.nav-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: var(--accent); z-index: 9999; opacity: 0;
  transition: width 0.2s ease-out, opacity 0.15s ease-out;
}
.nav-progress.loading { opacity: 1; width: 80%; transition: width 4s cubic-bezier(0.1, 0.6, 0.2, 1), opacity 0.15s ease-out; }
.sidebar nav a:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.sidebar nav a.active { background: var(--action-soft); color: var(--action-soft-fg); font-weight: 600; }
.nav-locked {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm);
  color: var(--text-subtle); cursor: not-allowed;
}
.nav-locked .nav-icon { opacity: 0.5; }
.nav-icon { flex-shrink: 0; width: 16px; height: 16px; display: flex; opacity: 0.75; }
.nav-icon svg { width: 16px; height: 16px; }
.sidebar nav a:hover .nav-icon, .sidebar nav a.active .nav-icon { opacity: 1; }
.sidebar nav .section-label {
  padding: var(--sp-5) var(--sp-3) var(--sp-2) var(--sp-3);
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.nav-section { border: none; }
.nav-section > summary.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  padding-right: 16px;
}
.nav-section > summary.section-label::-webkit-details-marker { display: none; }
.nav-chevron {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.nav-section[open] > summary .nav-chevron { transform: rotate(45deg); }
.nav-pinned > .section-label { display: block; }

/* Tables need the width; forms read badly past ~70 characters, so .form-narrow and
   .auth-box keep their own tighter caps rather than inheriting this one. */
.main { flex: 1; padding: var(--sp-6) var(--sp-8); max-width: 1440px; width: 100%; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.header-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.page-header h1 { font-size: var(--fs-xl); margin: 0; font-weight: 650; }
.page-header .sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--sp-1); max-width: 78ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e-1);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
}

.card h2 { font-size: var(--fs-lg); margin: 0 0 var(--sp-3) 0; font-weight: 650; }

table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { text-align: left; padding: var(--sp-3) var(--sp-3); border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
th {
  color: var(--text-muted); font-weight: 600; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
  background: var(--surface); border-bottom: 1px solid var(--border-strong);
}
/* Zebra striping removed in the 2026-08-14 refresh: with 8-column tables it fought the
   status badges for attention, and hover alone reads the row perfectly well. */
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
tr[data-href] { cursor: pointer; }
tr[data-href]:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: -2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--action);
  color: var(--action-fg);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--e-1);
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.btn:hover { background: var(--action-hover); color: var(--action-fg); text-decoration: none; }
.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.secondary:hover { background: var(--surface-2); color: var(--text); }
/* --surface, not #fff: in dark mode --danger is a light red, so white-on-red would
   drop under 3:1. Pairing the fill with the page surface inverts correctly in both. */
.btn.danger { background: var(--danger); border-color: transparent; color: var(--surface); }
.btn.danger:hover { background: var(--danger); filter: brightness(0.9); }
.btn.small { padding: var(--sp-1) var(--sp-3); font-size: var(--fs-xs); }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }

input, select, textarea {
  font-family: inherit;
  /* 16px is deliberate, not a style choice: iOS Safari zooms the whole page when a
     field under 16px receives focus, which made every tap on a phone jump the layout. */
  font-size: var(--fs-base);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:hover:not([disabled]), select:hover:not([disabled]), textarea:hover:not([disabled]) {
  border-color: var(--text-subtle);
}
::placeholder { color: var(--text-subtle); }
/* Numeric entry inside a table cell. Inputs are width:100% by default, which is right
   in a form and far too wide in a stocktake row of sixty-odd lines. */
.input-tight { width: 104px; max-width: 100%; padding: var(--sp-1) var(--sp-2); text-align: right; font-variant-numeric: tabular-nums; }

label { display: block; font-size: var(--fs-sm); color: var(--text); margin-bottom: var(--sp-1); margin-top: var(--sp-3); font-weight: 600; }

.form-row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.form-row[hidden] { display: none; }
.form-row > div { flex: 1; min-width: 160px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge svg { width: 12px; height: 12px; }
.badge.open { background: var(--info-bg); color: var(--info); }
.badge.closed { background: var(--surface-3); color: var(--text-muted); }
.badge.shortage { background: var(--danger-bg); color: var(--danger); }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.stage-cutting { background: var(--warn-bg); color: var(--warn); }
.badge.stage-sewing { background: var(--info-bg); color: var(--info); }
.badge.stage-finishing-qc { background: var(--violet-50); color: var(--violet-700); }
.badge.stage-packing-ready { background: var(--success-bg); color: var(--success); }
/* Amber, deliberately unlike .open — a draft is not yet real work. */
.badge.draft { background: var(--warn-bg); color: var(--warn); }
/* Same amber as .draft — an estimate is also "not yet confirmed real data". */
.badge.estimate { background: var(--warn-bg); color: var(--warn); font-weight: 700; cursor: help; }

.negative { color: var(--danger); font-weight: 600; }

.flash {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  margin-bottom: var(--sp-4); font-size: var(--fs-sm);
  border: 1px solid transparent;
}
.flash.undo-toast { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.flash.success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.flash.error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.flash.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.flash.info { background: var(--info-bg); color: var(--info); border-color: var(--info); }

.empty { color: var(--text-muted); padding: var(--sp-5) 0; }

.scan-queue-banner { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.scan-queue-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: var(--fs-sm); }
.scan-queue-failed-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 8px; }
.scan-queue-failed-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: var(--fs-sm); background: var(--danger-bg); color: var(--danger); padding: 8px 10px; border-radius: var(--r-md); }
.scan-queue-toggle { background: none; border: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.scan-queue-pending-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.scan-queue-pending-list li { font-size: var(--fs-sm); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); background: var(--surface-3); color: var(--text); }

.auth-tagline { padding: 0 var(--sp-5); margin-top: var(--sp-4); color: var(--text-muted); font-size: var(--fs-sm); line-height: var(--lh); }

.auth-main { display: flex; align-items: center; justify-content: center; }
.auth-box { width: 100%; max-width: 400px; }
.auth-box .auth-title { font-size: var(--fs-xl); margin: 0 0 16px 0; }
.auth-box .foot-link { margin-top: 16px; font-size: var(--fs-sm); color: var(--muted); text-align: center; }
.hint-note { font-size: var(--fs-xs); color: var(--muted); margin-top: 3px; }
.hint-note.error-text { color: var(--danger); }
.hint-note.success-text { color: var(--success); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  margin: var(--sp-4) var(--sp-3) 0;
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs);
}
.sidebar-footer .who { color: var(--text); font-weight: 600; margin-bottom: var(--sp-1); }
.sidebar-footer .role-badge {
  display: inline-block; margin-left: var(--sp-1); padding: 1px 7px; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text-muted);
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: 0.02em; vertical-align: middle;
}
.sidebar-footer a {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-1) 0; color: var(--text-muted); font-size: var(--fs-sm);
}
.sidebar-footer a:hover { color: var(--text); text-decoration: none; }
.sidebar-footer form { margin: 0; }
.sidebar-footer button.link {
  background: none; border: none; padding: var(--sp-1) 0; font: inherit; cursor: pointer;
  color: var(--text-muted); text-align: left; width: 100%;
  display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm);
}
.sidebar-footer button.link:hover { color: var(--text); }

/* Sidebar stand-ins for the topbar controls, which are display:none below 860px. Hidden
   on desktop so those widths don't get two Search boxes and two Log Out buttons. */
.sidebar nav a.nav-narrow-only,
.sidebar-footer .nav-narrow-only { display: none; }
.sidebar-footer-actions { margin-top: 10px; }
.sidebar-footer-actions svg { width: 16px; height: 16px; flex-shrink: 0; }
@media (max-width: 860px) {
  .sidebar nav a.nav-narrow-only { display: flex; }
  .sidebar-footer .nav-narrow-only { display: block; }
  .sidebar-footer-actions a,
  .sidebar-footer-actions button.link { min-height: 44px; }
}

.stat-row { display: flex; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--e-1); padding: var(--sp-4) var(--sp-5); min-width: 140px; flex: 1;
}
.stat-card.good { border-color: var(--success); }
.stat-card.bad { border-color: var(--danger); }
.stat-value { font-size: var(--fs-2xl); font-weight: 700; color: var(--navy); }
.stat-label { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; margin-bottom: 18px; }
.analytics-grid .card { margin: 0; }
.period-pills { display: flex; gap: 6px; }
.period-pills a { padding: 4px 12px; border-radius: var(--r-full); font-size: var(--fs-sm); border: 1px solid var(--border); color: var(--muted); text-decoration: none; }
.period-pills a.active { background: var(--action-soft); color: var(--action-soft-fg); border-color: var(--action-soft-fg); font-weight: 600; }
.section-toggle { display: flex; gap: 8px; margin-bottom: 4px; }
.btn.secondary.small.toggle-active { background: var(--action-soft); color: var(--action-soft-fg); border-color: var(--action-soft-fg); }
.stat-pill { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 3px 10px; border-radius: var(--r-full); font-size: var(--fs-sm); background: var(--surface-3); }
.stat-pill.good { background: var(--success-bg); color: var(--success); }
.stat-pill.bad { background: var(--danger-bg); color: var(--danger); }
.stat-pill.muted { color: var(--muted); }
.supplier-perf-header { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.supplier-perf-header h2 { margin: 0; }
.supplier-perf-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.badge-cell { white-space: nowrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e-1);
  padding: var(--sp-4) var(--sp-5);
  min-width: 150px;
  flex: 1;
}
.stat .value { font-size: var(--fs-2xl); font-weight: 700; color: var(--navy); }
.stat .label { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat.warn .value { color: var(--danger); }

.attention-row { display: flex; gap: 14px; margin-bottom: 28px; flex-wrap: wrap; }
.stat.attention {
  padding: 16px 20px;
  border-width: 2px;
  text-decoration: none;
  color: inherit;
}
.stat.attention .value { font-size: var(--fs-2xl); }
.stat.attention.warn { border-color: var(--danger); }
.stat.attention:hover { border-color: var(--navy); }
.stat.attention.warn:hover { border-color: var(--danger); }

.trend { font-size: var(--fs-2xs); margin-top: 4px; font-weight: 600; }
.trend.up { color: var(--danger); }
.trend.down { color: var(--success); }
.trend.flat { color: var(--muted); font-weight: 400; }

.attention-row .stat, .dashboard-section .stat {
  display: flex; flex-direction: column; align-items: center; text-align: center;
}

.dashboard-section { margin-bottom: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
.dashboard-section:first-of-type { padding-top: 0; border-top: none; }
.dashboard-section h3 {
  font-size: var(--fs-xl); letter-spacing: normal; text-transform: none;
  color: var(--navy); margin: 0 0 14px 0; font-weight: 700;
}
.dashboard-section .stat-row { margin-bottom: 0; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; margin-bottom: 18px; }
.dashboard-grid .card { margin-bottom: 0; }

.stage-funnel { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.funnel-step {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--e-1); padding: var(--sp-4) var(--sp-5); text-align: center; flex: 1; min-width: 140px;
}
.funnel-count { font-size: var(--fs-xl); font-weight: 700; color: var(--navy); margin-bottom: 6px; }
.funnel-arrow { color: var(--muted); font-size: var(--fs-lg); flex: 0 0 auto; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar select { width: auto; min-width: 180px; }

/* Previous / Next under a paged list (_pager.html). Wraps on phones. */
.pager { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 14px; color: var(--text-muted); }
.pager-links { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* A card a pager links back to (#history on Offcuts): clear of the phone's sticky header.
   Chromium focuses a #fragment target and draws a dark ring around the whole card; it's
   not interactive (nothing to Tab to), so the ring is only noise. */
.anchor-target { scroll-margin-top: 72px; }
.anchor-target:focus { outline: none; }

.line-item-table input, .line-item-table select { padding: var(--sp-1) var(--sp-2); }
.line-item-table td { vertical-align: middle; }

/* Two-step Group -> Variant material picker (PO lines, Supplier Items) */
.material-picker { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }

.stage-tracker { display: flex; gap: 4px; margin: 8px 0; }
.stage-tracker .step {
  flex: 1;
  text-align: center;
  padding: 6px 4px;
  font-size: var(--fs-2xs);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text-subtle);
}
.stage-tracker .step.done { background: var(--success-bg); color: var(--success); font-weight: 600; }
.stage-tracker .step.current { background: var(--action); color: var(--action-fg); font-weight: 700; }

.period-bar { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 18px; flex-wrap: wrap; }
.period-bar .presets { display: flex; gap: 6px; flex-wrap: wrap; }
.period-bar .presets a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.period-bar .presets a:hover { background: var(--surface-2); text-decoration: none; }
.period-bar .presets a.active { background: var(--action-soft); border-color: var(--action-soft-fg); color: var(--action-soft-fg); font-weight: 600; }
.period-bar form { display: flex; gap: 8px; align-items: flex-end; }
.period-bar form label { margin-top: 0; }
.period-bar form input { width: 140px; }

.trend-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.trend-row .trend-label { width: 64px; flex-shrink: 0; font-size: var(--fs-xs); color: var(--muted); }
.trend-row .trend-bar-track { flex: 1; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; height: 10px; }
.trend-row .trend-bar { height: 100%; background: var(--action); border-radius: var(--r-full); }
.trend-row .trend-value { width: 100px; flex-shrink: 0; text-align: right; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

.positive { color: var(--success); font-weight: 600; }

/* ---- Utilities & small components (replaces one-off inline styles) ---- */
.form-narrow { max-width: 420px; }
.form-actions { margin-top: 18px; }
.btn-block { width: 100%; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.checkbox-group { display: flex; flex-wrap: wrap; column-gap: 24px; }
.checkbox-group .checkbox-row { margin-top: 8px; }
input[type=checkbox], input[type=radio] { flex: 0 0 auto; }
.table-scroll { overflow-x: auto; }
.actions-col { white-space: nowrap; }
.actions-col > * + * { margin-left: var(--sp-2); }
.inline { display: inline; }
.password-field { position: relative; }
.password-field input { padding-right: 40px; }
.eye-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 4px; line-height: 0;
  color: var(--muted);
}
.eye-toggle:hover { color: var(--text); }
.eye-toggle .eye-off { display: none; }
.eye-toggle.showing .eye-on { display: none; }
.eye-toggle.showing .eye-off { display: inline; }
.cpicker { position: relative; }
.cpicker-btn {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: var(--sp-2) var(--sp-3); font-size: var(--fs-base);
  font-family: inherit; color: var(--text); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cpicker-btn:hover { border-color: var(--text-subtle); }
.cpicker-list {
  position: absolute; top: 100%; left: 0; z-index: 200; min-width: 100%; max-height: 260px;
  overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); box-shadow: var(--e-2); margin-top: 2px;
}
.cpicker-opt {
  padding: var(--sp-2) var(--sp-3); cursor: pointer; font-size: var(--fs-sm);
  white-space: nowrap; border-bottom: 1px solid var(--border);
}
.cpicker-opt:last-child { border-bottom: none; }
.cpicker-opt:hover, .cpicker-opt.focused { background: var(--action-soft); color: var(--action-soft-fg); }
.popover { display: inline-block; position: relative; }
.popover-trigger { cursor: pointer; }
.popover-panel { position: absolute; top: 100%; right: 0; z-index: 5; margin-top: var(--sp-2); box-shadow: var(--e-3); min-width: 240px; }
.popover-divider { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.is-offline-disabled { pointer-events: none; opacity: .5; }
.text-optional { font-weight: 400; }
.settings-header-row { display: flex; gap: 24px; margin-bottom: var(--sp-5); align-items: center; }
.settings-header-section { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-4); }
.settings-header-section h1 { font-size: var(--fs-xl); margin: 0; font-weight: 650; }
/* Wraps rather than pushing past the screen edge: Users has three buttons, which
   overflowed a phone by ~150px when this row couldn't wrap. */
.settings-header-section .header-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.settings-content { width: 100%; min-width: 0; }
.row-muted { opacity: 0.55; }
.logo-preview { margin: 6px 0 10px; }
.logo-preview img { max-width: 160px; max-height: 80px; border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px; background: var(--card); }
.card-link { font-size: var(--fs-xs); font-weight: 400; }
.label-note { font-weight: 400; font-size: var(--fs-xs); color: var(--muted); }
.ml-6 { margin-left: 6px; }
.stat-link { display: flex; flex-direction: column; justify-content: center; text-decoration: none; color: inherit; }
.stat-link .value { font-size: var(--fs-base); }
.form-row-end { align-items: flex-end; }
.form-row-totals { align-items: flex-end; margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.col-tight { flex: 0; }
.col-qty { max-width: 100px; }
.line-action { display: flex; gap: 6px; align-items: center; }
.pick-lining-none { color: var(--muted); }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-14 { margin-top: 14px; }
.mt-22 { margin-top: 22px; }
.mb-14 { margin-bottom: 14px; }
.mb-24 { margin-bottom: 24px; }
.help-text { margin: 0 0 14px 0; font-size: var(--fs-xs); color: var(--muted); }
.sub-tight { margin: -4px 0 10px 0; }
.bom-subrow td { padding-top: 0; }
.bom-subrow td:first-child { color: var(--muted); font-size: var(--fs-xs); }
.num-input { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.w-sm { width: 130px; }
.w-md { width: 210px; }

/* ---- QR/barcode scan pages ---- */
.scan-viewport {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: #000;
  border-radius: var(--r-md);
  overflow: hidden;
}
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute;
  inset: 12%;
  border: 3px solid var(--accent);
  border-radius: var(--r-lg);
  pointer-events: none;
}
.scan-canvas-hidden { display: none; }

/* ---- Desktop topbar (theme toggle lives here; mirrored in .mobile-topbar below 860px) ---- */
.content-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 var(--sp-8);
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

/* ---- Global search (topbar; hidden with .topbar on mobile, where the sidebar's
       Search link is the way in instead) ---- */
.topbar-search { position: relative; flex: 1; max-width: 460px; margin: 0; }
.topbar-search input[type=search] {
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-3) 0 var(--sp-8);
  margin: 0;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
}
.topbar-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  color: var(--muted);
  pointer-events: none;
}
.topbar-search-icon svg { width: 15px; height: 15px; }

/* ---- Topbar profile / logout icon buttons ---- */
.topbar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.topbar-icon-btn:hover, .topbar-icon-btn.active { color: var(--fg); background: var(--hover); }
.topbar-icon-btn svg { width: 18px; height: 18px; }
.topbar-logout { display: contents; }
.notif-bell { position: relative; }
.notif-bell-sidebar { position: relative; }
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #e53e3e;
  color: #fff;
  font-size: 9px;
  font-weight: bold;
  line-height: 1;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

/* ---- Grouped table sections (supplier list, grouped by type) ---- */
.group-row td {
  background: var(--surface-2);
  font-weight: 700;
  font-size: var(--fs-2xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 14px;
}

/* ---- Collapsible material groups (Stock Levels, Stocktake) ---- */
.group-summary-row td { background: var(--surface-2); font-weight: 600; }
.group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
}
.group-toggle svg { width: 11px; height: 11px; flex-shrink: 0; transition: transform .15s ease; }
.group-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.group-count { font-weight: 500; font-size: var(--fs-xs); color: var(--muted); }
.group-member-row td:first-child { padding-left: 30px; color: var(--muted); font-size: var(--fs-sm); }

/* ---- Stock Levels: category sections, search bar, action menu ---- */
.stock-search-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 var(--sp-3);
  height: 40px;
  box-shadow: var(--e-1);
}
.stock-search-bar:focus-within { border-color: var(--brand-600); box-shadow: 0 0 0 3px var(--brand-50); }
.stock-search-icon { color: var(--text-subtle); display: flex; align-items: center; flex-shrink: 0; }
.stock-search-icon svg { width: 16px; height: 16px; }
#stock-search { border: none; background: none; outline: none; flex: 1; font-size: var(--fs-sm); color: var(--text); }
#stock-search::placeholder { color: var(--text-subtle); }
.stock-search-status { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.stock-alert-banner { margin-bottom: 14px; }

.category-section { margin-bottom: 12px; }
.category-section[open] > .category-summary .category-chevron svg { transform: rotate(180deg); }
.category-summary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  list-style: none;
  cursor: pointer;
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  user-select: none;
  margin-bottom: 0;
}
.category-section[open] > .category-summary { border-radius: var(--r-md) var(--r-md) 0 0; border-bottom: none; }
.category-summary::-webkit-details-marker { display: none; }
.category-summary::marker { display: none; }
.category-summary:hover { background: var(--surface-3); }
.category-chevron { display: flex; align-items: center; color: var(--text-subtle); }
.category-chevron svg { width: 14px; height: 14px; transition: transform .2s ease; }
.category-name { font-weight: 700; font-size: var(--fs-sm); color: var(--text-heading); flex: 1; }
.category-badge { margin-left: var(--sp-1); }
.category-section > .table-scroll { border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--r-md) var(--r-md); overflow: hidden; }
.category-section > .table-scroll table { margin-bottom: 0; border-radius: 0; }
.category-section > .table-scroll table th:first-child,
.category-section > .table-scroll table td:first-child { border-left: none; }

.btn.icon-btn { padding: 0 var(--sp-2); min-width: 32px; justify-content: center; letter-spacing: 0.05em; }
.row-actions-menu { position: relative; }
.row-actions-menu .popover-panel { right: 0; left: auto; min-width: 220px; }
.menu-action-link {
  display: block;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-sm);
  margin-bottom: 4px;
}
.menu-action-link:hover { background: var(--surface-2); }
.menu-action-label { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 6px 0 4px; }

/* ---- Suppliers list: fixed-width columns, one Items Sold line per material ---- */
.suppliers-table { table-layout: fixed; }
.suppliers-table td { overflow-wrap: break-word; }
.stacked-items > div { padding: 1px 0; }
.stacked-items > div:not(:last-child) { border-bottom: 1px dashed var(--border); }

/* ---- Draft autosave indicator ---- */
.autosave-status {
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-left: 12px;
  display: inline-block;
  vertical-align: middle;
}

/* ---- Theme toggle switch (Settings > My Account) ---- */
.theme-toggle {
  position: relative;
  width: 52px;
  height: 30px;
  min-height: 30px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.theme-toggle .tt-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle .tt-icon svg { width: 14px; height: 14px; }
.theme-toggle .tt-sun { left: 8px; color: var(--warn); }
.theme-toggle .tt-moon { right: 8px; color: var(--text-muted); }
.theme-toggle .tt-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e-1);
  transition: transform 0.2s ease;
}
:root[data-theme="dark"] .theme-toggle .tt-thumb { transform: translateX(22px); }

.mobile-topbar .help-toggle { margin-left: auto; }

/* ---- Profile page preference row ---- */
.pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}
.pref-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  color: var(--fg);
}
.pref-label svg { width: 16px; height: 16px; color: var(--muted); }

/* ---- Help/FAQ trigger (topbar, next to the theme toggle) ---- */
.help-toggle {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-toggle:hover { background: var(--surface-3); color: var(--text); }
.help-toggle svg { width: 15px; height: 15px; }

/* ---- Help/FAQ slide-out panel ---- */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
}
.help-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: var(--e-3);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s ease;
}
.help-panel.open { transform: translateX(0); }

/* ---- Edit-user slide-out panel ---- */
.edit-user-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 200; display: none; }
.edit-user-overlay.open { display: block; }
.edit-user-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 95vw;
  background: var(--card); border-left: 1px solid var(--border); box-shadow: var(--e-3);
  z-index: 201; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease;
}
.edit-user-panel.open { transform: translateX(0); }
.edit-user-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.edit-user-panel-header h2 { margin: 0; font-size: var(--fs-lg); }
.edit-user-panel-body { flex: 1; overflow-y: auto; padding: 20px; }

/* ---- Users table tweaks ---- */
.users-table { font-size: var(--fs-xs); }
.users-table select { font-size: var(--fs-xs); }
/* Selects default to width:100%, and the table squeezes the Role column to almost
   nothing beside the nowrap action buttons, clipping "Manager" to "Ma". The floor
   fits the longest role name plus the arrow. */
.users-table .role-select { width: auto; min-width: 8rem; }
/* Edit / Reset PW / Delete stay on one line so every row is one line high. Below the
   container breakpoint the table becomes cards, so this never forces a scroll. */
.users-table .line-action { flex-wrap: nowrap; }
/* As a flex box the cell drops out of the table row, so its bottom border sat offset
   from the rest of the row. In table mode keep it a real cell. */
@container users-card (min-width: 721px) {
  .users-table td.line-action { display: table-cell; white-space: nowrap; }
  .users-table td.line-action > * { margin-right: 6px; vertical-align: middle; }
}
.users-table td.col-joined { white-space: nowrap; }
/* Stacked cards whenever the Users card itself is too narrow for the table (~710px),
   not only on phones. Beside the Settings menu that happens on laptop-sized screens
   too (861-1250px), where the table otherwise ran off the edge. Mirrors the phone
   card layout for data-tables further down; labels come from table.js. */
.users-card { container: users-card / inline-size; overflow-x: auto; }
@container users-card (max-width: 720px) {
  .users-table, .users-table tbody { display: block; }
  .users-table thead { display: none; }
  .users-table tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    box-shadow: var(--e-1);
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-3);
  }
  .users-table tbody tr:hover td { background: none; }
  .users-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    border: none;
    padding: var(--sp-1) 0;
    text-align: right;
  }
  .users-table tbody td::before {
    content: attr(data-label);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
  .users-table tbody td:first-child {
    display: block;
    font-weight: 650;
    font-size: var(--fs-base);
    padding-bottom: var(--sp-2);
    margin-bottom: var(--sp-1);
    border-bottom: 1px solid var(--border);
    text-align: left;
  }
  .users-table tbody td:first-child::before { content: none; }
  .users-table tbody td:not([data-label]) { justify-content: flex-end; }
}
.user-meta { font-size: var(--fs-xs); color: var(--text-muted); }
.role-select.role-dirty { outline: 2px solid var(--action); outline-offset: 1px; }
.help-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.help-panel-header h2 { margin: 0; font-size: var(--fs-base); color: var(--navy); }
.help-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
}
.help-close:hover { background: var(--bg); color: var(--navy); }
.help-close svg { width: 14px; height: 14px; }
.help-search { position: relative; padding: 12px 18px; flex-shrink: 0; }
.help-search input[type=search] { width: 100%; height: 38px; padding: 0 var(--sp-3) 0 var(--sp-8); margin: 0; }
.help-search-icon { position: absolute; left: 29px; top: 50%; transform: translateY(-50%); display: flex; color: var(--muted); pointer-events: none; }
.help-search-icon svg { width: 14px; height: 14px; }
.help-body { flex: 1; overflow-y: auto; padding: 4px 18px 24px; }
.help-section h3 {
  font-size: var(--fs-2xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 8px;
}
.help-section:first-child h3 { margin-top: 6px; }
.help-item { margin-bottom: 14px; }
.help-q { font-weight: 600; font-size: var(--fs-sm); margin-bottom: 3px; }
.help-a { font-size: var(--fs-sm); color: var(--text); line-height: 1.5; }
.help-empty { color: var(--muted); font-size: var(--fs-sm); text-align: center; margin-top: 24px; }
@media (max-width: 640px) { .help-panel { width: 100vw; max-width: 100vw; } }

/* ---- Mobile topbar / off-canvas nav (hidden on desktop) ---- */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
  z-index: 110;
}
.mobile-topbar .mobile-mark { width: 24px; height: 24px; object-fit: contain; }
.mobile-topbar .mobile-title { color: var(--text); font-weight: 700; font-size: var(--fs-base); letter-spacing: -0.01em; }
.nav-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-sm);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  margin-left: calc(var(--sp-2) * -1);
}
.nav-toggle:hover { background: var(--surface-3); color: var(--text); }
.nav-toggle svg { width: 20px; height: 20px; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 105;
}
.sidebar-backdrop.show { display: block; }

/* ---- Tablet ---- */
@media (max-width: 960px) {
  .main { padding: 20px; }
  .stat { min-width: 130px; }
}

/* ---- Mobile / narrow window: off-canvas sidebar ---- */
@media (max-width: 860px) {
  .mobile-topbar { display: flex; }
  .topbar { display: none; }
  .layout { display: block; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 264px;
    max-width: 82vw;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 108;
    padding-top: 20px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--e-3); }
  .main:not(.auth-main) { padding: 72px var(--sp-4) var(--sp-6); max-width: 100%; }
  .page-header { flex-wrap: wrap; gap: var(--sp-3); }
  .stat-row { flex-direction: column; }
  .stat { min-width: 0; }
  .attention-row { flex-direction: column; }
  .stage-funnel { flex-direction: column; align-items: stretch; }
  .funnel-arrow { text-align: center; transform: rotate(90deg); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row > div { min-width: 100%; }
  .card { overflow-x: auto; }
  .toolbar input[type=text], .toolbar select { width: 100%; min-width: 0; }
  .period-bar { flex-direction: column; align-items: stretch; }
  .period-bar form { flex-wrap: wrap; }
  .period-bar form input { width: 100%; }

  /* Auth pages have no nav to hide behind a drawer — stack instead */
  .auth-layout .sidebar {
    position: static;
    transform: none;
    width: 100%;
    max-width: 100%;
    padding: 24px 0;
    box-shadow: none;
  }
  .auth-layout .brand-panel { max-width: 240px; margin-left: auto; margin-right: auto; }
  .auth-layout .auth-tagline { text-align: center; }
  .auth-main { padding: 28px 16px; }
}

@media (max-width: 480px) {
  .main:not(.auth-main) { padding: 68px var(--sp-3) var(--sp-5); }
  .card { padding: var(--sp-4); }
  /* Type does NOT shrink here any more. It used to drop to 12.5px, which is exactly
     the wrong direction on the smallest screen — density comes from tighter padding. */
  th, td { padding: var(--sp-2) var(--sp-2); }
  .page-header h1 { font-size: var(--fs-lg); }
}

/* ---- Dark theme ----------------------------------------------------------
   Deliberately almost empty. Every surface above resolves through a semantic
   token, so the theme is defined once in :root[data-theme="dark"] at the top of
   this file. The two rules below are the only genuine exceptions: --violet-*
   has no dark counterpart in the primitive ramp, and the scan viewport is a
   camera feed that stays black in both themes.
   Anything added here that isn't one of those is a token that needs fixing. */
:root[data-theme="dark"] {
  --violet-50: #33244a;
  --violet-700: #c99bf0;
}

/* ==========================================================================
   Shared data table (table.js)
   Opt in with `data-table` on the <table>. Toolbar, sort affordances, infinite
   scroll sentinel and the sub-640px card layout all come from here.
   ========================================================================== */
.table-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}
.table-search { position: relative; flex: 1 1 260px; max-width: 380px; }
.table-search input[type=search] {
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-3) 0 var(--sp-8);
  margin: 0;
  border-radius: var(--r-sm);
}
.table-search-icon {
  position: absolute; left: var(--sp-3); top: 50%; transform: translateY(-50%);
  display: flex; color: var(--text-muted); pointer-events: none;
}
.table-search-icon svg { width: 15px; height: 15px; }
.table-status {
  font-size: var(--fs-sm); color: var(--text-muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* Views / columns / density controls (table.js, Track B P3). They sit beside the
   status readout rather than above the search box, so the toolbar stays one row. */
.table-controls { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: nowrap; }
.table-view-select {
  height: 32px; margin: 0; padding: 0 var(--sp-2);
  font-size: var(--fs-sm); border-radius: var(--r-sm); max-width: 200px;
}
.table-popover .popover-panel { right: 0; max-height: 60vh; overflow-y: auto; }
.check-row {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); font-weight: 500; text-transform: none;
  letter-spacing: normal; color: var(--text); padding: var(--sp-1) 0; cursor: pointer;
}

/* Compact is a per-device choice (see table.js): the same list is read at arm's
   length on a phone and across a desk on the office screen. */
table[data-table][data-density="compact"] th,
table[data-table][data-density="compact"] td { padding: var(--sp-1) var(--sp-3); }

/* Bulk selection (table.js + bulk.js, Track B P1). The tick column is deliberately
   narrow and unlabelled — a blank heading is what keeps it out of sorting and out of
   the column chooser, both of which skip columns with no heading text. */
.select-col { width: 1%; white-space: nowrap; padding-right: var(--sp-2) !important; }
/* Size deliberately left to the app-wide input[type=checkbox] rule, which already
   sets the 24px SC 2.5.8 floor these controls need. */
.select-col input[type=checkbox] { margin: 0; display: block; }

/* The action bar sits above the list and appears only once something is ticked, so
   the page doesn't carry a permanently empty strip of controls. Sticky, because a
   selection made 200 rows down has to stay actionable without scrolling back. */
.bulk-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--action-soft);
  border: 1px solid var(--action);
  border-radius: var(--r-md);
  box-shadow: var(--e-1);
}
.bulk-count {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--action-soft-fg);
  font-variant-numeric: tabular-nums;
}
.bulk-bar.is-offline-disabled { opacity: 0.55; pointer-events: none; }
.bulk-panel { position: absolute; z-index: 6; margin-top: var(--sp-2); box-shadow: var(--e-3); min-width: 320px; max-width: 460px; }
.bulk-panel-title { font-size: var(--fs-sm); font-weight: 650; margin-bottom: var(--sp-2); }
.bulk-panel-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-1) 0; font-size: var(--fs-sm);
}
.bulk-panel-row select { margin: 0; max-width: 200px; }

/* Inline cell editing (inline-edit.js). The affordance stays quiet until hover or
   focus — an underline under every editable number would read as 47 links. */
.cell-edit {
  background: none; border: 1px dashed transparent; border-radius: var(--r-sm);
  padding: 2px var(--sp-1); margin: -2px calc(var(--sp-1) * -1);
  font: inherit; color: inherit; text-align: inherit; cursor: text;
  min-height: 28px; width: 100%;
}
td.num .cell-edit { text-align: center; }
.cell-edit:hover { border-color: var(--border-strong); background: var(--surface-2); }
.cell-edit:focus-visible { border-style: solid; }
td[aria-disabled="true"] .cell-edit { cursor: not-allowed; opacity: 0.6; }
.cell-edit-input {
  width: 100%; min-width: 80px; height: 30px; margin: 0;
  padding: 0 var(--sp-2); font-size: var(--fs-sm); border-radius: var(--r-sm);
}
td.num .cell-edit-input { text-align: center; }
/* Same SC 2.5.8 floor the rest of the app's controls take on a touch screen — an
   editable cell is a tap target like any other. */
@media (pointer: coarse), (max-width: 860px) {
  .cell-edit { min-height: 44px; }
  .cell-edit-input { height: 44px; }
  .table-view-select { height: 44px; }
}

.table-sentinel { margin-top: var(--sp-3); text-align: center; }
.table-sentinel .btn { margin: var(--sp-2) 0; }
@media (max-width: 640px) { .table-sentinel .btn { width: 100%; } }

/* Header stays visible while a long list scrolls. The offset matches .topbar so a
   sticky header never hides behind the app chrome (WCAG 2.4.11 Focus Not Obscured). */
table[data-table] thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after {
  content: "";
  display: inline-block;
  width: 0; height: 0;
  margin-left: var(--sp-2);
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
  opacity: 0;
  transition: opacity .12s, transform .12s;
}
th.sortable:hover::after { opacity: .35; }
th[aria-sort="ascending"]::after { opacity: 1; }
th[aria-sort="descending"]::after { opacity: 1; transform: rotate(180deg); }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--text); }

/* Horizontal-scroll range (card layout takes over below 640px): pin the identity
   column so a row never scrolls away from the thing that names it. */
@media (min-width: 641px) and (max-width: 860px) {
  table[data-table] th:first-child,
  table[data-table] td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
  }
  table[data-table] thead th:first-child { z-index: 3; }
  table[data-table] .group-summary-row td:first-child { background: var(--surface-2); }
}

/* Phone: one card per row, every value labelled from the <thead> (data-table tables, or
   .stack-phone for a plain table without the search/sort behaviour). A 7-column table
   in a 350px viewport is a horizontal-scroll trap otherwise. */
@media (max-width: 640px) {
  :is(table[data-table], table.stack-phone) { display: block; }
  :is(table[data-table], table.stack-phone) thead { display: none; }
  :is(table[data-table], table.stack-phone) tbody { display: block; }
  :is(table[data-table], table.stack-phone) tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    box-shadow: var(--e-1);
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-3);
  }
  :is(table[data-table], table.stack-phone) tbody tr:hover td { background: none; }
  :is(table[data-table], table.stack-phone) tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    border: none;
    padding: var(--sp-1) 0;
    text-align: right;
  }
  :is(table[data-table], table.stack-phone) tbody td::before {
    content: attr(data-label);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
  /* First cell is the card's title, not a labelled field. */
  :is(table[data-table], table.stack-phone) tbody td:first-child {
    font-weight: 650;
    font-size: var(--fs-base);
    padding-bottom: var(--sp-2);
    margin-bottom: var(--sp-1);
    border-bottom: 1px solid var(--border);
    text-align: left;
  }
  :is(table[data-table], table.stack-phone) tbody td:first-child::before { content: none; }
  :is(table[data-table], table.stack-phone) tbody td:not([data-label]) { justify-content: flex-end; }
  /* The tick column is first in the markup but it isn't the card's title — it sits
     above it as its own labelled row, so the material name still reads as the heading.
     Ordered after the :not([data-label]) rule above, which it ties with on specificity. */
  :is(table[data-table], table.stack-phone) tbody td.select-col {
    font-weight: 500;
    font-size: var(--fs-sm);
    justify-content: flex-start;
    gap: var(--sp-3);
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: var(--sp-1);
  }
  :is(table[data-table], table.stack-phone) tbody td.select-col::before {
    content: "Select";
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }
  :is(table[data-table], table.stack-phone) tbody td.select-col + td {
    font-weight: 650;
    font-size: var(--fs-base);
    padding-bottom: var(--sp-2);
    margin-bottom: var(--sp-1);
    border-bottom: 1px solid var(--border);
    text-align: left;
  }
  :is(table[data-table], table.stack-phone) tbody td.select-col + td::before { content: none; }
  :is(table[data-table], table.stack-phone) .group-member-row td:first-child { padding-left: 0; }
  :is(table[data-table], table.stack-phone) .group-summary-row td[colspan] { border-bottom: none; }
  /* Action cells stack their buttons full-width rather than crowding one line. */
  :is(table[data-table], table.stack-phone) tbody td:last-child:has(.btn) { flex-wrap: wrap; gap: var(--sp-2); }
  .table-tools { gap: var(--sp-2); }
  .table-search { max-width: 100%; }
}

/* ==========================================================================
   Toasts
   Replaces the in-flow .flash banner that used to push the page down on every
   redirect. .flash itself is still used for genuine in-page notices (the
   stocktake negative-balance warning, the offline banners) and is unchanged.
   ========================================================================== */
.toast-stack {
  position: fixed;
  z-index: 300;
  bottom: var(--sp-5);
  right: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: min(440px, calc(100vw - var(--sp-8)));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  box-shadow: var(--e-3);
  font-size: var(--fs-sm);
  background: var(--surface);
  color: var(--text);
  pointer-events: auto;
  /* Visible by default and animated IN, rather than hidden by default and revealed by
     JS: requestAnimationFrame is throttled in background tabs, so a JS-gated reveal can
     leave the toast permanently invisible. Entrance is decoration; visibility is not. */
  /* No fill-mode: outside the animation's active window the element falls back to its
     own styles (opaque). `both` would hold the transparent `from` frame whenever the
     animation doesn't actually run, which is the failure mode this is guarding. */
  animation: toast-in .18s ease;
  transition: opacity .18s ease, transform .18s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.toast.leaving { opacity: 0; transform: translateY(8px); }
.toast-msg { flex: 1; min-width: 0; }
.toast.success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.toast.error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.toast form { margin: 0; }
.toast-close {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; min-height: 28px;
  padding: 0; border: none; border-radius: var(--r-sm);
  background: none; color: inherit; opacity: .65; cursor: pointer;
}
.toast-close:hover { opacity: 1; background: rgba(128,128,128,.16); }
.toast-close svg { width: 14px; height: 14px; }

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; transition: none; opacity: 1; transform: none; }
}

/* On a phone the bottom-right corner is where the thumb rests, so toasts come from
   the top instead — clear of the fixed topbar. */
@media (max-width: 640px) {
  .toast-stack {
    top: calc(56px + var(--sp-3));
    bottom: auto;
    left: var(--sp-3);
    right: var(--sp-3);
    max-width: none;
  }
  @keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
  }
  .toast.leaving { transform: translateY(-8px); }
}

/* ---- Sticky action bar (Stocktake, and any other long single-submit form) ---- */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e-2);
}
.sticky-actions-buttons { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.progress-pill {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.progress-pill.has-counts { background: var(--action-soft); color: var(--action-soft-fg); }
@media (max-width: 640px) {
  .sticky-actions { border-radius: var(--r-md); }
  .sticky-actions-buttons { flex: 1; }
  .sticky-actions-buttons .btn { flex: 1; }
}

/* ---- Breadcrumbs ---- */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}
.breadcrumbs a {
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumbs a:hover { color: var(--text); text-decoration: underline; }
.breadcrumbs-sep { color: var(--text-subtle); user-select: none; }

/* ---- Command palette (Ctrl-K / Cmd-K) ---- */
.cmd-palette {
  border: none;
  outline: none;
  background: transparent;
  padding: 0;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  margin: 0;
  position: fixed;
  inset: 0;
  z-index: 500;
}
.cmd-palette::backdrop {
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
}
.cmd-palette-inner {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, 94vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--e-3);
  overflow: hidden;
}
.cmd-palette-search-row {
  display: flex;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  gap: var(--sp-2);
}
.cmd-palette-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: var(--fs-lg);
  color: var(--text);
  outline: none;
  min-width: 0;
}
.cmd-palette-input::placeholder { color: var(--text-subtle); }
.cmd-palette-results {
  overflow-y: auto;
  padding: var(--sp-2) 0;
}
.cmd-palette-group { padding-bottom: var(--sp-1); }
.cmd-palette-group-label {
  padding: var(--sp-2) var(--sp-4) var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-subtle);
}
.cmd-palette-item {
  display: flex;
  align-items: center;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.cmd-palette-item:hover { background: var(--surface-3); }
.cmd-palette-item.active { background: var(--action-soft); color: var(--action-soft-fg); }
.cmd-palette-footer {
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  display: flex;
  gap: var(--sp-4);
}
.cmd-palette-footer kbd {
  font-family: inherit;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  font-size: var(--fs-2xs);
}
@keyframes palette-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.cmd-palette[open] .cmd-palette-inner {
  animation: palette-in .15s ease;
}

/* ---- Notes / activity log panel ---- */
.note-log { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.note-entry {
  display: flex;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
}
.note-entry-avatar {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.note-entry.is-system .note-entry-avatar {
  background: var(--surface-2);
  color: var(--text-subtle);
}
.note-entry-body { flex: 1; min-width: 0; }
.note-entry-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: 2px;
}
.note-entry-meta strong { color: var(--text); font-weight: 600; }
.note-entry.is-system .note-entry-text { color: var(--text-muted); font-style: italic; }
.note-add-form { display: flex; gap: var(--sp-2); align-items: flex-end; margin-top: var(--sp-2); }
.note-add-form textarea {
  flex: 1;
  min-height: 60px;
  resize: vertical;
  margin: 0;
}
.note-add-form .btn { flex-shrink: 0; align-self: flex-end; }

/* ---- Pattern checkbox list (cut sheet form) ---- */
.pattern-checks { display: flex; flex-direction: column; gap: var(--sp-2); }
.check-item {
  display: flex; align-items: center; gap: var(--sp-2);
  cursor: pointer; font-size: var(--fs-sm); padding: var(--sp-1) 0;
}
.check-item input[type="checkbox"] {
  width: 16px; height: 16px; flex-shrink: 0;
  accent-color: var(--action); cursor: pointer; margin: 0;
}


/* ---- Work order detail: mobile-only layout ---- */
/* Hide print/order buttons on small screens (staff use phones; only back nav needed) */
@media (max-width: 640px) {
  .wo-desktop-only { display: none !important; }
}

/* Mobile-first stage advance: full-width button, easy tap target */
@media (max-width: 640px) {
  .stage-tracker { flex-wrap: wrap; }
  .stage-tracker .step { flex: 1 1 auto; min-width: 0; text-align: center; font-size: var(--fs-xs); padding: 6px 4px; }
}

/* Full-width advance button on mobile for easy tapping */
@media (max-width: 640px) {
  .wo-advance-btn { width: 100%; padding: 14px; font-size: var(--fs-base); }
}

/* ---- Stock levels: committed stock indicator ---- */
.committed-col { color: var(--warning, #f59e0b); font-weight: 600; }

/* ---- Settings: SMTP env var reference table ---- */
.settings-env-table { width: auto; margin-top: var(--sp-2); }
.settings-env-table td, .settings-env-table th { padding: 4px 12px 4px 0; font-size: var(--fs-sm); }
.settings-env-table code { background: var(--surface-2); border-radius: 3px; padding: 1px 5px; font-family: monospace; font-size: var(--fs-xs); }

/* ---- ETA chip (shortage list + stock levels) ---- */
.eta-chip { display: inline-block; font-size: var(--fs-xs); font-weight: 600; color: var(--action); white-space: nowrap; }
td.center { text-align: center; }
th.center { text-align: center; }

/* ---- Shortage list: driving orders column ---- */
.shortage-drivers { font-size: var(--fs-xs); min-width: 180px; }
.driver-link { display: block; color: var(--text); text-decoration: none; padding: 1px 0; }
.driver-link:hover { color: var(--action); }
.driver-qty { color: var(--text-muted); margin-left: 4px; }

/* ---- Production analytics: stage bottleneck bar chart ---- */
.bottleneck-chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 140px;
  padding: var(--sp-3) 0 0;
  overflow-x: auto;
}
.bottleneck-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-width: 52px;
  gap: 4px;
}
.bottleneck-bar-wrap {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: flex-end;
}
.bottleneck-bar {
  width: 100%;
  background: var(--action);
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease;
  min-height: 4px;
}
.bottleneck-bar-mid { background: var(--warning, #f59e0b); }
.bottleneck-bar-high { background: var(--danger, #ef4444); }
.bottleneck-count {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
}
.bottleneck-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}

/* ---- Analytics tab bar (Financial / Production / Material Usage / …) ---- */
.analytics-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.analytics-tabs::-webkit-scrollbar { display: none; }
.analytics-tab {
  padding: 8px 16px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.analytics-tab:hover { color: var(--text); }
.analytics-tab.active { color: var(--action); border-bottom-color: var(--action); font-weight: 600; }

/* ---- Period chips (7d / 30d / 90d) used on analytics pages ---- */
/* Wraps so a long row (All departments + each department) never pushes a phone page sideways. */
.period-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.period-chips a {
  padding: 4px 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  border: 1px solid var(--border);
  color: var(--muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.period-chips a:hover { color: var(--text); }
.period-chips a.active { background: var(--action-soft); color: var(--action-soft-fg); border-color: var(--action-soft-fg); font-weight: 600; }

/* ---- OEE floor capture (employees' phones, app/templates/oee/floor) ---- */
body.floor { background: var(--bg); margin: 0; }
.floor-header {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--border);
}
.floor-company { font-weight: 650; }
.floor-who { margin-left: auto; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.floor-main { max-width: 560px; margin: 0 auto; padding: var(--sp-4); }
.floor-center { text-align: center; }
.floor-label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.floor-big { font-size: var(--fs-xl); font-weight: 700; margin: var(--sp-1) 0; overflow-wrap: anywhere; }
.floor-sub { color: var(--muted); margin-top: var(--sp-1); }
.floor-btn { min-height: 52px; font-size: var(--fs-lg); display: flex; align-items: center; justify-content: center; }
.floor-current { border-left: 6px solid var(--accent); }
.floor-current.is-paused { border-left-color: var(--warn); }
.floor-pause > summary { list-style: none; cursor: pointer; }
.floor-pause > summary::-webkit-details-marker { display: none; }
.floor-number { font-size: var(--fs-lg); min-height: 48px; }
.floor-lines { list-style: none; margin: 0; padding: 0; }
.floor-lines li { padding: var(--sp-3) 0; border-top: 1px solid var(--border); }
.floor-lines li:first-child { border-top: 0; }
.floor-flag { color: var(--warn); font-weight: 600; margin-top: var(--sp-1); }
.floor select, .floor input[type=text], .floor input[type=number], .floor textarea { width: 100%; box-sizing: border-box; }

/* ---- OEE daily review and reports (app/templates/oee/review.html, reports.html) ---- */
.oee-waiting { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.oee-review-heading { margin-top: var(--sp-4); }
.oee-employee-head { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: space-between; align-items: flex-start; }
.oee-employee-head h2 { margin: 0; }
.oee-employee-status { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; justify-content: flex-end; }
.oee-review-lines td .badge { margin: 2px 0; }
.oee-gaps { list-style: none; margin: 0; padding: 0; }
.oee-gaps li { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; padding: var(--sp-2) 0; border-top: 1px solid var(--border); }
.oee-gaps li:first-child { border-top: 0; }
.oee-gaps select { width: auto; }
.oee-pause-form { border-top: 1px solid var(--border); padding-top: var(--sp-2); }
.oee-progress { width: 100%; height: 8px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.oee-progress > span { display: block; height: 100%; background: var(--success); }
.oee-tabs { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.oee-filters { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end; }
.oee-filters > div { min-width: 140px; flex: 1 1 140px; }
.oee-chart { width: 100%; height: auto; display: block; }
.oee-chart text { fill: var(--muted); font-size: 11px; }
.oee-chart .grid { stroke: var(--border); stroke-width: 1; }
.oee-legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--muted); }
.oee-legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
.oee-notice { line-height: 1.55; }
.oee-notice h2 { margin-top: var(--sp-4); }
@media print {
  .oee-no-print, .sidebar, .topbar, .oee-tabs, .oee-filters { display: none !important; }
  .oee-print-only { display: block !important; }
}
.oee-print-only { display: none; }
/* OEE trend chart series, in fixed order (OEE, Availability, Performance, Quality).
   Validated with the dataviz palette checker in both modes, 2026-10-11; light mode's
   aqua and yellow sit under 3:1 on the surface, so the chart always has a legend,
   end-of-line labels and a table view. */
:root { --oee-s1: #2a78d6; --oee-s2: #eb6834; --oee-s3: #1baf7a; --oee-s4: #eda100; }
:root[data-theme="dark"] { --oee-s1: #3987e5; --oee-s2: #d95926; --oee-s3: #199e70; --oee-s4: #c98500; }
.oee-bar { height: 10px; border-radius: 0 4px 4px 0; background: var(--oee-s1); min-width: 2px; }
.oee-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-3); }
.oee-summary .card { margin: 0; }
.oee-day-nav { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.oee-day-nav input[type=date] { width: auto; min-width: 11rem; }
