/* niftyMRP UI — industrial workshop treatment.
   Tokens first: light is the source theme, dark re-derives every token.
   Type: Archivo (variable) carries the UI; IBM Plex Mono carries the data
   (part numbers, order numbers, quantities). Accent: viridian; copper is a
   rare highlight (brand, key figures). Semantic ok/warn/crit are separate. */

@font-face {
  font-family: "Archivo";
  src: url("../fonts/Archivo-var.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("../fonts/PlexMono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("../fonts/PlexMono-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  /* Tells the UA which palette to render native chrome (scrollbars, date
     pickers, focus rings) in — without it a light-forced page on a dark OS
     gets dark native controls. Re-declared in every theme block below. */
  color-scheme: light;

  --ground: #f1f3f0;
  --panel: #fcfdfc;
  --panel-raised: #ffffff;
  --ink: #1d2823;
  --ink-strong: #101815;
  --muted: #64716a;
  --line: #dfe4df;
  --line-soft: #e9ede9;

  --accent: #177355;
  --accent-strong: #0f5c43;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --copper: #af6234;

  --ok: #1c7a3d;      --ok-soft: #e2f1e6;
  --warn: #a3660a;    --warn-soft: #f8eeda;
  --crit: #b3362b;    --crit-soft: #f9e8e5;
  --info: #23617e;    --info-soft: #e3eef4;
  --violet: #5b4a9e;  --violet-soft: #ebe7f6;
  --flow-build: #1baf7a; --flow-order: #2a78d6; --flow-stock: #eda100; --flow-missing: #d03b3b;

  --side-bg: #15201b;
  --side-ink: #b9c6be;
  --side-dim: #6d7f75;
  --side-active: #1e2f27;
  --side-line: #24332b;

  --shadow: 0 1px 2px rgba(16, 24, 21, .05), 0 4px 14px rgba(16, 24, 21, .04);
  --shadow-pop: 0 6px 24px rgba(16, 24, 21, .16);
  --radius: 6px;
  --sidebar-w: 212px;
  /* Fluid page gutter: 16px on a phone, 28px once there's room for it. */
  --gutter: clamp(16px, 4vw, 28px);
  --tap: 44px;          /* minimum comfortable touch target */
  /* One height for every button, select and text field, so a row of them
     lines up; small buttons get their own. Touch raises both to --tap. */
  --ctl: 36px;
  --ctl-sm: 28px;
  --tabbar-h: 0px;      /* becomes real only on phones (see Responsive) */

  --sans: "Archivo", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Plex Mono", ui-monospace, "Cascadia Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #131816;
    --panel: #1a211d;
    --panel-raised: #1f2823;
    --ink: #d7ded9;
    --ink-strong: #f0f4f1;
    --muted: #8a968f;
    --line: #2b352f;
    --line-soft: #242d28;

    --accent: #3fae87;
    --accent-strong: #55c29b;
    --accent-ink: #0c1511;
    --accent-soft: #1d3a2f;
    --copper: #d08d5c;

    --ok: #52b475;      --ok-soft: #1c3325;
    --warn: #d9a04b;    --warn-soft: #382c17;
    --crit: #e07a6e;    --crit-soft: #3d221e;
    --info: #6aa9c4;    --info-soft: #1c2f38;
    --violet: #a394d8;  --violet-soft: #2b2540;
    --flow-build: #199e70; --flow-order: #3987e5; --flow-stock: #c98500; --flow-missing: #d03b3b;

    --side-bg: #0e1512;
    --side-ink: #a7b4ac;
    --side-dim: #5d6b63;
    --side-active: #1a2620;
    --side-line: #1d2823;

    --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 4px 14px rgba(0, 0, 0, .18);
    --shadow-pop: 0 8px 28px rgba(0, 0, 0, .5);
  }
}
/* The viewer's explicit toggle wins over the OS preference, both directions. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #131816; --panel: #1a211d; --panel-raised: #1f2823;
  --ink: #d7ded9; --ink-strong: #f0f4f1; --muted: #8a968f;
  --line: #2b352f; --line-soft: #242d28;
  --accent: #3fae87; --accent-strong: #55c29b; --accent-ink: #0c1511;
  --accent-soft: #1d3a2f; --copper: #d08d5c;
  --ok: #52b475; --ok-soft: #1c3325; --warn: #d9a04b; --warn-soft: #382c17;
  --crit: #e07a6e; --crit-soft: #3d221e; --info: #6aa9c4; --info-soft: #1c2f38;
  --violet: #a394d8; --violet-soft: #2b2540;
  --flow-build: #199e70; --flow-order: #3987e5; --flow-stock: #c98500; --flow-missing: #d03b3b;
  --side-bg: #0e1512; --side-ink: #a7b4ac; --side-dim: #5d6b63;
  --side-active: #1a2620; --side-line: #1d2823;
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 4px 14px rgba(0, 0, 0, .18);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, .5);
}
:root[data-theme="light"] {
  color-scheme: light;
  --ground: #f1f3f0; --panel: #fcfdfc; --panel-raised: #ffffff;
  --ink: #1d2823; --ink-strong: #101815; --muted: #64716a;
  --line: #dfe4df; --line-soft: #e9ede9;
  --accent: #177355; --accent-strong: #0f5c43; --accent-ink: #ffffff;
  --accent-soft: #e2efe9; --copper: #af6234;
  --ok: #1c7a3d; --ok-soft: #e2f1e6; --warn: #a3660a; --warn-soft: #f8eeda;
  --crit: #b3362b; --crit-soft: #f9e8e5; --info: #23617e; --info-soft: #e3eef4;
  --violet: #5b4a9e; --violet-soft: #ebe7f6;
  --flow-build: #1baf7a; --flow-order: #2a78d6; --flow-stock: #eda100; --flow-missing: #d03b3b;
  --side-bg: #15201b; --side-ink: #b9c6be; --side-dim: #6d7f75;
  --side-active: #1e2f27; --side-line: #24332b;
  --shadow: 0 1px 2px rgba(16, 24, 21, .05), 0 4px 14px rgba(16, 24, 21, .04);
  --shadow-pop: 0 6px 24px rgba(16, 24, 21, .16);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 400 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---- Shell ---- */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--side-bg); color: var(--side-ink);
  display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100vh; height: 100dvh;
}
.sidebar .brand {
  display: block; padding: 18px 16px 14px; color: #fff; font-size: 17px; font-weight: 800;
  letter-spacing: .14em; font-family: var(--mono);
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand::after { content: "_"; color: var(--copper); }
.sidebar nav {
  flex: 1; overflow-y: auto; padding-bottom: 10px;
  /* The page is light, the sidebar always dark: without these the browser
     draws its light scrollbar on it. Thin, sidebar-coloured, no track. */
  color-scheme: dark; scrollbar-width: thin; scrollbar-color: var(--side-line) transparent;
}
.sidebar nav:hover { scrollbar-color: var(--side-dim) transparent; }
.sidebar nav a {
  display: block; padding: 7px 16px 7px 14px; color: var(--side-ink);
  border-left: 2px solid transparent; font-weight: 500;
}
.sidebar nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.sidebar nav a.active {
  background: var(--side-active); color: #fff; border-left-color: var(--copper);
}
.sidebar .navgroup {
  padding: 16px 16px 5px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .16em; color: var(--side-dim);
}
.sidebar .userbox {
  padding: 12px 16px; border-top: 1px solid var(--side-line); font-size: 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.sidebar .userbox button {
  background: none; border: none; color: var(--side-dim); cursor: pointer;
  padding: 0; font: inherit;
}
.sidebar .userbox button:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
/* Dev server only: the branch and port this page is served from. */
.devbar {
  background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--line);
  padding: 2px var(--gutter); font: 600 12px/1.6 ui-monospace, monospace;
  overflow-wrap: anywhere;
}
/* A staging copy: louder than a dev strip, since a customer is looking at it. */
.devbar.staging { background: var(--warn); color: var(--panel); text-align: center; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 28px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.theme-toggle {
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); border-radius: 999px; width: 32px; height: 32px;
  padding: 0; cursor: pointer; font-size: 15px; line-height: 1;
  flex: none;   /* never let the flex row shrink this into a sliver */
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.content {
  padding: var(--gutter) var(--gutter) calc(60px + var(--tabbar-h));
  max-width: 1280px;
}

/* ---- Global search ---- */
.gsearch { position: relative; flex: 1; max-width: 460px; }
.gsearch input {
  width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--ground); color: var(--ink); font: inherit;
}
.gsearch::before {
  content: "⌕"; position: absolute; left: 12px; top: 5px;
  font-size: 17px; color: var(--muted);
}
.gsearch .results {
  position: absolute; top: 42px; left: 0; right: 0; background: var(--panel-raised);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  max-height: 70vh; overflow-y: auto; display: none;
}
.gsearch .results.open { display: block; }
/* Focused, the field widens over the controls to its right (search.js). */
.gsearch { z-index: 1; }
/* No max-width: the base input rule's 100% isn't animated, so the field
   snapped back on blur instead of shrinking. */
.gsearch input { transition: width .2s ease; max-width: none; }
.gsearch .results { transition: right .2s ease; }
.topbar.searching .gsearch input { width: calc(100% + var(--search-grow, 0px)); }
.topbar.searching .gsearch .results { right: calc(-1 * var(--search-grow, 0px)); }
.topbar > :is(.recnav, .feedback-open, .theme-toggle) {
  transition: opacity .15s ease .1s, visibility 0s .1s;   /* back as the field leaves */
}
.topbar.searching > :is(.recnav, .feedback-open, .theme-toggle) {
  opacity: 0; visibility: hidden; transition: opacity .15s ease, visibility 0s .15s;
}
.gsearch .results .group {
  padding: 8px 12px 3px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .14em; color: var(--muted);
}
.gsearch .results a { display: block; padding: 7px 12px; color: var(--ink); }
.gsearch .results a:hover, .gsearch .results a.sel {
  background: var(--accent-soft); text-decoration: none;
}
.gsearch .results .pn { font-weight: 600; font-family: var(--mono); font-size: 13px; }
.gsearch .results .sub { color: var(--muted); font-size: 12px; }

/* ---- Headings, panels ---- */
h1 {
  font-size: 21px; font-weight: 700; letter-spacing: -.01em; color: var(--ink-strong);
  margin: 0 0 18px; text-wrap: balance;
}
h2 {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted); margin: 0 0 12px;
}
.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.pagehead h1, .pagehead h2 { margin: 0; }
.pagehead .spacer { flex: 1; }
/* The page's scroll bar is drawn like the sidebar's: thin, no track. */
html { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent; }
/* The record pager in the top bar, on a record opened from a list (recnav.js). */
.recnav { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 13px; }
.recnav-list { display: inline-flex; align-items: center; min-height: var(--ctl-sm); margin-right: 6px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.recnav-list:hover { color: var(--ink); }
.recnav-step { min-width: var(--h); text-align: center; padding-inline: 0; font-size: 16px; }
.recnav-step:not([href]) { pointer-events: none; }
.recnav-step[aria-disabled] { opacity: .4; }
/* recnav.js measures a scroll bar's width with this. */
.scrollbar-probe { position: absolute; top: -200px; width: 100px; height: 50px; overflow-y: scroll; scrollbar-width: thin; }
.recnav-pos { font-variant-numeric: tabular-nums; color: var(--muted); padding-inline: 4px; white-space: nowrap; }
/* A phone's top bar has no room for the list's name; Back goes to the list. */
@media (max-width: 599px) { .recnav-list { display: none; } .recnav { gap: 4px; } }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel > h2:first-child { margin-top: 0; }
/* A panel holding something that blocks work (a bought part with no supplier).
   Pulses twice on load so the eye finds it; reduced motion keeps just the red. */
.panel.panel-alert {
  border-color: var(--crit); box-shadow: 0 0 0 1px var(--crit), var(--shadow);
  animation: panel-alert-pulse 0.9s ease-in-out 2;
}
/* A folded to-do above a list ("parts need a supplier"); open it to see the rows. */
details.panel.needs-supplier { border-color: var(--crit); }
details.panel:is(.needs-supplier, .needs-buying) > summary { cursor: pointer; font-weight: 600; min-height: 44px;
  display: flex; align-items: center; gap: 8px; }
details.panel:is(.needs-supplier, .needs-buying)[open] > summary { margin-bottom: 8px; }
details.panel:is(.needs-supplier, .needs-buying) > summary::-webkit-details-marker { display: none; }
details.panel:is(.needs-supplier, .needs-buying) > summary { list-style: none; }
details.panel:is(.needs-supplier, .needs-buying) > summary::after {
  content: "Show ▾"; margin-left: auto; padding-left: 12px; flex: none; white-space: nowrap; font-weight: 400; font-size: 13px; color: var(--muted); }
details.panel:is(.needs-supplier, .needs-buying)[open] > summary::after { content: "Hide ▴"; }
details.panel.needs-buying { border-color: var(--warn); }
@keyframes panel-alert-pulse {
  50% { background: var(--crit-soft); box-shadow: 0 0 0 4px var(--crit-soft), 0 0 0 5px var(--crit); }
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 899px) { .grid2 { grid-template-columns: 1fr; } }

/* ---- Bulk-action bar above a selectable table ---- */
.tablebar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.tablebar .spacer { flex: 1; }
.tablebar [data-sel-count] { font-size: 13px; }
.tablebar button[disabled] { opacity: .5; cursor: not-allowed; }

/* Wraps a list's bulk actions so a phone can float them (≤599 below). */
.selbar { display: contents; }
.hometag { margin-left: 6px; }
/* A tablet's panel is the narrowest a table has to fit. */
@media (min-width: 600px) and (max-width: 899px) {
  .table-wrap :is(th, td) { padding-left: 7px; padding-right: 7px; }
}
/* Parts on a tablet: the unit rides on the on-hand figure, as on a phone,
   and the home bin waits for the part page, so the table fits its panel. */
@media (min-width: 600px) and (max-width: 1279px) {
  table.partcards :is(th, td):nth-child(5):not([colspan]) { display: none; }
  table.partcards td[data-unit]::after { content: "\00a0" attr(data-unit); color: var(--muted); font-size: 12px; }
}
@media (min-width: 600px) and (max-width: 1279px) {
  table.partcards :is(th, td):nth-child(6):not([colspan]) { display: none; }
}
@media (min-width: 600px) and (max-width: 1023px) {
  table.partcards :is(th, td):nth-child(10):not([colspan]) { display: none; }
}

/* "Select all N matching" — appears beside the count once a whole page is ticked. */
.tablebar .sel-banner:empty { display: none; }
.linkish {
  padding: 0; border: 0; background: none; color: var(--accent);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.linkish:hover { background: none; color: var(--accent-strong); text-decoration: underline; }

/* ---- List filters (listing.py, templates/_listing.html) ----
   Each column filters itself from a row under its heading: a text box, a
   dropdown of checkboxes, a date or number range. Conditions that belong to no
   one column live in the slim bar above the table, with saved views. */
/* The toolbar: bulk actions left, Filters + saved views right, and a second
   line of chips naming the active filters while the filters are folded. */
.tools-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
/* A <label> (for the toggle) dressed as its neighbour buttons, not as a field label. */
.listtools .filters-btn {
  margin: 0; display: inline-flex; align-items: center;
  font: 600 12px/1.4 var(--sans); text-transform: none; letter-spacing: 0; color: var(--ink);
}
.filters-btn .fcount { color: var(--accent); white-space: pre; }
.filters-toggle:checked ~ .listtools .filters-btn {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.fchips { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.fchips:not(:has(a)) { display: none; }
/* No bulk actions to sit beside: the chips take the left of the one line. */
.listtools:not(:has([data-sel-count])) .fchips { order: -1; flex: 1 1 auto; }
.filters-toggle:checked ~ .listtools .chip:not(.chip-link),
.filters-toggle:checked ~ .listtools .chip-clear { display: none; }

/* The filters themselves, folded until the toggle opens them. */
.listbar {
  display: none; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.filters-toggle:checked ~ .listbar { display: flex; }
.filters-toggle:checked ~ .listbar:not(:has(.fin, .ftoggle, .chip-clear)) { display: none; }
#lf { display: contents; }
.js .fapply { display: none; }
.listbar .fin { width: auto; max-width: 220px; }
.listbar input.fin { width: 190px; }
.listbar .fpop { min-width: 140px; }

/* An on/off condition reads as a pill you press, not a form checkbox. */
.ftoggle {
  display: inline-flex; align-items: center; gap: 7px; margin: 0; cursor: pointer;
  padding: 5px 12px 5px 9px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--ink);
  background: var(--panel-raised);
}
.ftoggle.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }

/* The filter row. Controls take their column's width rather than setting it,
   so the headings, not the inputs, decide the layout. */
/* Above the headings: the heading row's rule still closes the header, so the
   filters need no line of their own. */
thead tr.filter-row { display: none; }
.filters-toggle:checked ~ * thead tr.filter-row { display: table-row; }
thead tr.filter-row td {
  padding: 0 5px 6px; vertical-align: bottom; border-bottom: 0;
}
thead tr.filter-row td:first-child { padding-left: 10px; }
.fin {
  display: block; width: 100%; min-width: 0; height: 30px; padding: 4px 8px;
  font: inherit; font-size: 12.5px; text-transform: none; letter-spacing: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-raised); color: var(--ink);
}
input.fin::placeholder { color: var(--muted); opacity: .7; }
.fin.on { border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--accent-soft) 60%, var(--panel-raised)); }
.fpop { position: relative; min-width: 0; }
summary.fsum {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 4px;
  overflow: hidden; white-space: nowrap; color: var(--muted);
}
summary.fsum::-webkit-details-marker { display: none; }
summary.fsum.on { color: var(--accent-strong); font-weight: 600; }
summary.fsum::after { content: "▾"; margin-left: auto; font-size: 10px; color: var(--muted); flex: none; }
summary.fsum.num { justify-content: flex-end; }
summary.fsum.num::after { margin-left: 4px; }
.fpop[open] > summary.fsum { border-color: var(--accent); }
.fpop-menu {
  margin-top: 4px; padding: 10px 12px; text-align: left;
  background: var(--panel-raised); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink);
}
@media (min-width: 600px) {
  .js .fpop-menu { position: fixed; z-index: 70; margin: 0; box-shadow: var(--shadow-pop);
    max-height: 60vh; overflow-y: auto; }
}
/* A checkbox with its words beside it, in body text rather than label caps. */
.check {
  display: inline-flex; align-items: center; gap: 8px; margin: 0; cursor: pointer;
  font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--ink);
}
/* Customer forms: a ticked "Ship to the billing address" hides the second address. */
.ship-to { margin-bottom: 12px; }
.ship-to .ship-field { margin-top: 8px; }
.ship-to:has(.ship-same:checked) .ship-field { display: none; }
/* Options read as text, not as the uppercase field labels a <label> gets. */
.fpop-menu label.check {
  display: flex; gap: 8px; padding: 5px 2px; margin: 0; white-space: nowrap;
  font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--ink);
}
.fpop-row { display: flex; gap: 10px; }
.fpop-row label { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.fpop-row label .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.fpop-row input { width: 150px; font-size: 13px; padding: 5px 8px; }
.fpop-menu p { margin: 8px 0 0; }
.fpresets { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-size: 12.5px; }
.fclear { display: inline-block; margin-top: 8px; font-size: 12.5px; color: var(--crit); }
.fpresets .fclear { margin-top: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong);
  font-size: 12.5px; font-weight: 500; line-height: 1.5;
}
.chip > span[aria-hidden] { font-size: 14px; line-height: 1; opacity: .6; padding: 0 2px; }
.chip:hover { text-decoration: none; color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 22%, var(--accent-soft)); }
.chip:hover > span[aria-hidden] { opacity: 1; }
.chip-clear { font-size: 12.5px; margin-left: 2px; }

.views-menu { position: relative; }
.views-menu > summary { list-style: none; white-space: nowrap; }
.views-menu > summary::-webkit-details-marker { display: none; }
.views-menu > summary::after { content: " ▾"; font-size: 10px; color: var(--muted); }
.views-menu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  width: min(320px, calc(100vw - 2 * var(--gutter)));
  background: var(--panel-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); padding: 8px;
}
.views-menu .menu-group {
  padding: 8px 8px 4px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .14em; color: var(--muted);
}
.views-menu .menu-row { display: flex; align-items: center; border-radius: var(--radius); }
.views-menu .menu-row > a { flex: 1; min-width: 0; padding: 7px 8px; color: var(--ink); }
.views-menu .menu-row:hover { background: var(--ground); }
.views-menu .menu-row > a:hover { text-decoration: none; }
.views-menu .menu-row.active { background: var(--accent-soft); }
.views-menu .menu-row.active > a { color: var(--accent-strong); font-weight: 600; }
.views-menu .menu-del {
  padding: 2px 8px; border: 0; background: none; color: var(--muted); font-size: 15px; line-height: 1;
}
.views-menu .menu-del:hover { color: var(--crit); background: none; }
.views-menu .menu-empty { margin: 4px 8px 8px; }
.views-menu .menu-save { border-top: 1px solid var(--line-soft); margin-top: 6px; padding: 10px 8px 2px; }
.views-menu .menu-save .formrow { flex-wrap: nowrap; gap: 8px; margin-bottom: 8px; }
.views-menu .menu-save input[name=name] { flex: 1; min-width: 0; }
.views-menu .menu-save p { margin: 6px 0 0; }

/* ---- Pager ---- */
.pager {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 13px;
}
.pager-count { color: var(--muted); }
.pager-count b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.pager-pages, .pager-per { display: flex; align-items: center; gap: 2px; }
.pager-per { margin-left: auto; gap: 2px; }
.pager-per > .muted { margin-right: 6px; font-size: 12px; }
.pg {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 9px; border-radius: var(--radius);
  color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap;
}
a.pg:hover { background: var(--ground); text-decoration: none; color: var(--ink); }
.pg.cur { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pg.off { color: var(--muted); opacity: .45; }
.pg.gap { color: var(--muted); min-width: 18px; padding: 0; }
.pg.pos { display: none; color: var(--muted); }
[data-swap][aria-busy="true"] { opacity: .55; transition: opacity .15s .1s; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); border-bottom-color: var(--line);
}
tr:last-child td { border-bottom: none; }

/* Sortable headings. The heading text becomes a button (so it is reachable by
   keyboard and announces itself); it inherits the <th> type so the table looks
   unchanged until you hover. The arrow is drawn from aria-sort, which keeps
   the accessible state and the visible state impossible to disagree about —
   and keeps the glyph out of th.textContent, which initResponsiveTables()
   copies onto every cell as its card label. */
th > .th-sort {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 0; margin: 0; border: 0; background: none; border-radius: 3px;
  font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit;
  text-align: inherit; cursor: pointer;
}
th.num > .th-sort { justify-content: flex-end; }
th > a.th-sort { text-decoration: none; }
th > .th-sort:hover { background: none; color: var(--ink); text-decoration: none; }
th > .th-sort::after {
  content: "↕"; font-size: 10px; letter-spacing: 0; opacity: .35;
  transition: opacity .12s;
}
th > .th-sort:hover::after { opacity: .7; }
th[aria-sort="ascending"] > .th-sort::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] > .th-sort::after { content: "↓"; opacity: 1; }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--accent); }
th > .th-sort:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Phone-only sort control: in card mode the headings are hidden, so the same
   sort is offered above the cards. Built only for card-mode tables. */
.sortbar { display: none; align-items: center; gap: 8px; margin: 0 0 10px; }
.sortbar label { margin: 0; }
.sortbar select { flex: 1; min-width: 0; }
.sortbar .sortbar-dir { white-space: nowrap; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 34%, transparent); }
td.num, th.num { text-align: right; }
td.num { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 13px; }
a.mono { white-space: nowrap; }   /* a record number never breaks at its hyphen */
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---- Forms ---- */
input, select, textarea {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; font-size: 13.5px; background: var(--panel-raised); color: var(--ink);
  max-width: 100%;
}
input, select { height: var(--ctl); }
input[type="file"] { height: auto; }
/* Checkboxes/radios must escape the boxed text-input treatment above, and are
   drawn by us rather than the UA: a native control follows the OS scheme, so a
   light-forced page on a dark OS rendered white-on-black boxes. */
input[type="checkbox"], input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 17px; height: 17px; padding: 0; margin: 0;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--panel-raised); box-shadow: none;
  vertical-align: -3px; position: relative; cursor: pointer;
  transition: background .12s, border-color .12s;
}
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:hover:not(:disabled), input[type="radio"]:hover:not(:disabled) {
  border-color: var(--accent);
}
input[type="checkbox"]:checked, input[type="checkbox"]:indeterminate, input[type="radio"]:checked {
  background: var(--accent); border-color: var(--accent);
}
/* The tick is a rotated corner rather than a glyph, so it stays crisp at any
   size and needs no icon font. */
input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 50%; top: 46%;
  width: 30%; height: 58%;
  border: solid var(--accent-ink); border-width: 0 2px 2px 0;
  transform: translate(-50%, -55%) rotate(45deg);
}
input[type="checkbox"]:indeterminate::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 56%; height: 2px; background: var(--accent-ink);
  transform: translate(-50%, -50%);
}
input[type="radio"]:checked::after {
  content: ""; position: absolute; inset: 3px;
  border-radius: 50%; background: var(--accent-ink);
}
input[type="checkbox"]:disabled, input[type="radio"]:disabled {
  opacity: .5; cursor: not-allowed; background: var(--line-soft);
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
}
input:disabled, select:disabled, textarea:disabled {
  opacity: .5; cursor: not-allowed;
  background: var(--line-soft); color: var(--muted);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
/* Edited but not yet saved (savebar.js): the field, a checkbox's label, a
   mark on the row, and a note on a folded <details> that holds one. */
input.changed, select.changed, textarea.changed {
  border-color: var(--warn); background: var(--warn-soft); }
label.changed { background: var(--warn-soft); color: var(--warn); border-radius: 4px;
  box-shadow: 0 0 0 3px var(--warn-soft); }
tr.row-changed > td:first-child { box-shadow: inset 3px 0 var(--warn); }
/* A row marked for removal (savebar.js, [data-mark-remove]): struck out in red
   until Save. The toggle is a label; the no-JS path is its form's own button. */
html:not(.js) .mark-remove { display: none; }
label.btn { margin-bottom: 0; }   /* a label's 4px gap would lift it off the row's centre line */
label.mark-remove { position: relative; cursor: pointer; text-transform: none; letter-spacing: normal; }
label.mark-remove:has(:checked) { color: var(--ink); border-color: var(--line); }
label.mark-remove:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
label.mark-remove .when-on, label.mark-remove:has(:checked) .when-off { display: none; }
label.mark-remove:has(:checked) .when-on { display: inline; }
label.mark-remove.changed { box-shadow: none; background: var(--panel-raised); color: var(--ink); }
tr:has(input[data-mark-remove=""]:checked) > td { background: var(--crit-soft); color: var(--crit); }
tr:has(input[data-mark-remove=""]:checked) > td:first-child { box-shadow: inset 3px 0 var(--crit); }
tr:has(input[data-mark-remove=""]:checked) :is(.loc-path-text, td .leaf) {
  text-decoration: line-through; color: var(--crit); }
/* data-mark-remove="folder": the row goes but its path stays as a folder
   (/locations) — previewed as one, not struck out like a deletion. */
.badge.when-folder { display: none; }
tr:has(input[data-mark-remove="folder"]:checked) .when-folder { display: inline-block; }
tr:has(input[data-mark-remove="folder"]:checked) > td {
  background: color-mix(in srgb, var(--line-soft) 45%, transparent); color: var(--muted); }
tr:has(input[data-mark-remove="folder"]:checked) td :is(input:is([type="text"], :not([type])), .loc-active) {
  opacity: .45; }
tr:has(input[data-mark-remove=""]:checked) td input:is([type="text"], :not([type])) {
  text-decoration: line-through; color: var(--crit); opacity: .7;
  border-color: color-mix(in srgb, var(--crit) 35%, var(--line)); }
details.has-changes:not([open]) > summary::after {
  content: " · unsaved changes"; color: var(--warn); font-weight: 600; }
.line-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.line-bar .spacer { flex: 1; }
input.line-note { width: 100%; min-width: 110px; }
table.results td.res-num { width: 120px; }
.row-actions { white-space: nowrap; text-align: right; }
.field-value { display: flex; align-items: center; min-height: 38px; }

/* ---- Sales order page ----
   The header carries the order's state: a small Draft → Confirmed → Shipped
   track (the last leg filled with the share of units shipped) and the total. */
.so-head { align-items: center; }
.so-title h1 { font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.so-customer { display: inline-block; margin-top: 2px; font-size: 14px; font-weight: 500; }
.so-meta { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-left: 12px; }
.so-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
/* Documents sit as one joined control: they're the same kind of thing. */
.btn-group { display: inline-flex; }
.btn-group > .btn + .btn { margin-left: -1px; }
.btn-group > .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.btn-group > .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.so-actions button[disabled] { opacity: .5; cursor: not-allowed; }

.so-track { display: grid; grid-template-columns: auto 28px auto 44px auto; align-items: center;
  column-gap: 6px; --dot: 9px; font-size: 12px; }
.so-track .stop { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
.so-track .stop::before {
  content: ""; width: var(--dot); height: var(--dot); border-radius: 50%; box-sizing: border-box;
  border: 1.5px solid var(--line); background: var(--panel); flex: none;
}
.so-track .stop.reached::before { border-color: var(--accent); background: var(--accent); }
.so-track .stop.current { color: var(--ink-strong); font-weight: 600; }
.so-track .stop.current::before { box-shadow: 0 0 0 3px var(--accent-soft); }
.so-track .leg { position: relative; height: 2px; background: var(--line); border-radius: 1px; }
.so-track .leg i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 1px; }

.so-total { display: flex; flex-direction: column; line-height: 1.25; }
.so-total b { font-size: 15px; font-weight: 600; color: var(--copper); font-variant-numeric: tabular-nums; }
.so-total small { font-size: 12px; color: var(--muted); }
.so-total small.late { color: var(--crit); font-weight: 600; }

.so-info { padding-top: 14px; padding-bottom: 14px; }
.so-info .so-notes { flex: 1 1 240px; }
.so-info .so-notes textarea { width: 100%; min-height: 38px; resize: vertical; display: block; }

/* A name in a list that links to its record without shouting like the order number. */
a.quiet-link { color: inherit; }
a.quiet-link:hover { color: var(--accent); }
table.so-lines td.desc { min-width: 120px; }
table.so-lines input.qty { width: 68px; }
@media (min-width: 600px) { table.so-lines :is(th, td) { padding-left: 6px; padding-right: 6px; } }
table.so-lines input.money { width: 96px; }
/* Line quantities and prices are typed, never nudged: no spinner arrows. */
:is(table.so-lines, .add-line) input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
:is(table.so-lines, .add-line) input[type="number"]::-webkit-inner-spin-button,
:is(table.so-lines, .add-line) input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* Supply refs break between number, badge and qty, never inside one. */
table.so-lines .supply .nowrap { white-space: normal; }
table.so-lines .supply a.mono, table.so-lines .supply .badge, table.so-lines .supply button { white-space: nowrap; }
table.so-lines .supply-ref + br + .supply-ref { margin-top: 4px; }
/* A row's remove button stays out of the way until the row is in play. */
.btn-danger.btn-quiet { border-color: transparent; background: transparent; }
tr:hover .btn-danger.btn-quiet, .btn-danger.btn-quiet:focus-visible { border-color: color-mix(in srgb, var(--crit) 35%, var(--line)); }
.add-line {
  margin: 22px -18px -18px; padding: 16px 18px 18px;
  background: var(--ground); border-top: 1px solid var(--line-soft);
  border-radius: 0 0 var(--radius) var(--radius);
}
@media (max-width: 599px) {
  .so-head .spacer { display: none; }
  .so-meta { margin-left: 0; width: 100%; justify-content: space-between; }
  .so-actions { justify-content: flex-start; width: 100%; }
  .line-bar .ship-hint { flex-basis: 100%; order: 9; }
}
input.qty { width: 92px; text-align: right; font-family: var(--mono); font-size: 13px; }
input.money { width: 116px; text-align: right; font-family: var(--mono); font-size: 13px; }
label {
  display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); margin-bottom: 4px;
}
/* Inline reference value in a label ("Counted qty · now 6") — the number in
   ink so it reads as data, without adding a second line that breaks formrow
   alignment. */
.label-hint { font-weight: 400; }
.label-hint [data-current-qty] { color: var(--ink); font-weight: 600; }
/* A label that wraps a checkbox or radio is a sentence to read, not a field
   caption: ordinary case and ink. */
label:where(:has(> input[type="checkbox"], > input[type="radio"])):where(:not([class]), .small) {
  text-transform: none; letter-spacing: normal; font-weight: 500; font-size: 13px; color: var(--ink);
  cursor: pointer;
}
label:where(:not([class]), .small) > input:where([type="checkbox"], [type="radio"]) { margin-right: 6px; }
fieldset {
  margin: 0; padding: 10px 14px 12px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
}
legend { padding: 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
input[type="file"]::file-selector-button {
  margin: -2px 10px -2px -4px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--ink); font: 600 12px/1.4 var(--sans); cursor: pointer;
}
.field { margin-bottom: 14px; }
/* Fields in a row drop their own margin, so the row owes the next one its gap. */
.formrow:has(> .field):not(:last-child, .pagehead > *) { margin-bottom: 14px; }
/* "Save" then "Cancel" written one after the other, in a plain block. */
button.btn-primary + a.btn { margin-left: 5px; }
.formrow { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.formrow .field { margin-bottom: 0; }

button, .btn {
  /* The padding makes up the height (--h) around one 1.4em line, so a link,
     <label> or <summary> dressed as a button is exactly as tall as a real
     one and its text sits in the middle. */
  --h: var(--ctl);
  display: inline-block; padding: calc((var(--h) - 1.4em) / 2 - 1px) 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-raised); color: var(--ink);
  font: 600 13px/1.4 var(--sans); cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--ground); text-decoration: none; color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
.btn-danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 35%, var(--line)); }
.btn-danger:hover { background: var(--crit-soft); }
/* The padding sum can land a hair under --h at fractional pixel ratios. */
:is(a, label, summary, span).btn { min-height: var(--h); }
td :is(button, .btn) { white-space: nowrap; }
.btn-sm { --h: var(--ctl-sm); padding-inline: 9px; font-size: 12px; }
/* Controls that share a bar share a height. */
.tablebar :is(button, .btn) { --h: var(--ctl-sm); padding-inline: 9px; font-size: 12px; }
:is(.line-bar, .bom-bar) .btn-sm { --h: var(--ctl); padding-inline: 12px; }
.topbar .feedback-open { --h: 32px; margin-left: auto; }
/* The record pager (recnav.js) sits before Suggest and takes the free space. */
.topbar .recnav + .feedback-open { margin-left: 0; }
.topbar .recnav-step { --h: 32px; }
/* Room for a scroll bar the page doesn't have (recnav.js), so the top bar's
   right end is where it is on a long page. */
.topbar > :last-child { margin-right: var(--scrollbar-room, 0px); }
form.inline { display: inline; }

/* ---- Badges & state ---- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  white-space: nowrap;   /* a badge is one token; never break it mid-word */
}
.badge.draft { background: var(--line-soft); color: var(--muted); }
.badge.ordered, .badge.open, .badge.confirmed { background: var(--info-soft); color: var(--info); }
.badge.partial { background: var(--warn-soft); color: var(--warn); }
.badge.received, .badge.shipped, .badge.complete, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled, .badge.late { background: var(--crit-soft); color: var(--crit); }
.badge.manufactured { background: var(--violet-soft); color: var(--violet); }
.badge.purchased { background: var(--info-soft); color: var(--info); }
.badge.consumable { background: var(--warn-soft); color: var(--warn); }
.shortqty { color: var(--crit); font-weight: 600; }
/* Supplier contact on /receiving (receiving/_contact.html): one line each,
   inline after the prompt on the receive page. */
.contact { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.contact a { overflow-wrap: anywhere; }
.receive-contact { margin: 0 0 14px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.receive-contact .contact { flex-direction: row; flex-wrap: wrap; gap: 4px 14px; }
/* A late order's row: a crit edge down its left and a soft wash. */
tr.late > td { background: var(--crit-soft); }
tr.late > td:first-child { box-shadow: inset 3px 0 0 var(--crit); }
.okqty { color: var(--ok); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--crit-soft); color: var(--crit); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
/* Records named in a message link to themselves; same colour as the text. */
.flash a { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ---- Dashboard tiles ----
   5 to 7 tiles (the late ones only when something is late). One row when they
   all fit at about 130px each, else two even rows (7 = 4 + 3), else two
   columns with an odd last tile across both — never one tile alone on a row.
   Sized by the column's width (.tilebox), not the window's: the sidebar comes
   and goes. The counts are read from the children, so the template sets none. */
.tilebox { container: tiles / inline-size; margin-bottom: 20px; }
.tiles { --cols: 2; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 10px; }
@container tiles (max-width: 409.98px) {
  .tiles > .tile:last-child:nth-child(odd) { grid-column: span 2; }
}
@container tiles (min-width: 410px) { .tiles:not(:has(> :nth-child(7))) { --cols: 3; } }
@container tiles (min-width: 550px) { .tiles:has(> :nth-child(7)) { --cols: 4; } }
@container tiles (min-width: 690px) { .tiles:not(:has(> :nth-child(6))) { --cols: 5; } }
@container tiles (min-width: 830px) { .tiles:has(> :nth-child(6)):not(:has(> :nth-child(7))) { --cols: 6; } }
@container tiles (min-width: 970px) { .tiles:has(> :nth-child(7)) { --cols: 7; } }
.tile {
  display: block; text-decoration: none; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 12px 10px; box-shadow: var(--shadow);
}
a.tile:hover { border-color: var(--accent); text-decoration: none; }
a.tile:hover .l { color: var(--accent); }
.tile.late { border-color: var(--crit); background: var(--crit-soft); }
.tile.late .n, .tile.late .l { color: var(--crit); }
.tile .n {
  font-family: var(--mono); font-size: 21px; font-weight: 600;
  color: var(--copper); font-variant-numeric: tabular-nums; line-height: 1.2;
}
.tile .l {
  color: var(--muted); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .09em; margin-top: 1px;
}

/* ---- BOM tree (bomtree.js) ----
   A row per line. The figures sit in fixed-width columns anchored to the right
   edge, so they line up however deep a row is indented; when the panel is too
   narrow for that (a phone, or beside the history column) they drop under the
   name instead. Sized by the panel, not the window: a container query. */
.bom-bar { margin-bottom: 10px; row-gap: 8px; }
.bom-build {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  font-size: 13px; font-weight: 600; color: var(--ink);
  text-transform: none; letter-spacing: 0;
}
.bom-build input.qty { width: 84px; font-weight: 600; }
.bom-build span { color: var(--muted); font-weight: 400; }

.bomtree { container: bom / inline-size; transition: opacity .15s; }
.bomtree.is-loading { opacity: .45; }
.bom-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px;
  padding: 10px 14px; margin-bottom: 8px; border-radius: 8px;
  background: var(--ok-soft); color: var(--ink);
}
.bom-summary.short { background: var(--crit-soft); }
.bom-summary p { margin: 0; }
.bom-verdict b { font-weight: 600; color: var(--ok); }
.bom-summary.short .bom-verdict b { color: var(--crit); }
.bom-verdict { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.bom-verdict a { font-weight: 600; white-space: nowrap; }
.bom-cost { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bom-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.bom-tools:empty { display: none; }
.bom-only {
  display: inline-flex; align-items: center; gap: 7px; margin: 0; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--ink);
  text-transform: none; letter-spacing: 0;
}

.bomtree ul { list-style: none; margin: 0; padding: 0; }
/* The guide line drops from the parent's chevron. */
.bomtree ul ul { margin-left: 15px; padding-left: 7px; border-left: 1px solid var(--line); }
.bomtree li.folded > ul { display: none; }
.bomtree.only-short ul ul > li:not(.has-short) { display: none; }

.bomtree .node, .bom-head {
  display: grid; grid-template-columns: minmax(0, 1fr) 76px 54px 58px 78px 88px 84px;
  column-gap: 12px; align-items: baseline; padding: 7px 10px 7px 6px;
}
.bom-head {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.bom-head span:first-child { padding-left: 26px; }
.bom-head span:nth-child(n+2):not(:nth-child(6)) { text-align: right; }
.bomtree .node { border-bottom: 1px solid var(--line-soft); }
.bomtree .node:hover { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.bomtree .c-name { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.bomtree .label { min-width: 0; overflow-wrap: anywhere; }
.bomtree .is-asm .desc { font-weight: 600; color: var(--ink-strong); }
.bomtree .refdes {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; white-space: nowrap;
}
.bomtree .toggle {
  position: relative; flex: 0 0 20px; width: 20px; height: 20px; align-self: flex-start;
  border: none; border-radius: 4px; background: none; padding: 0; cursor: pointer;
  color: var(--muted); min-width: 0; min-height: 0;
}
.bomtree button.toggle:hover { background: var(--line); color: var(--ink); }
.bomtree button.toggle::before {
  content: ""; position: absolute; left: 6px; top: 5px; width: 6px; height: 6px;
  border: solid currentColor; border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg); transition: transform .12s;
}
.bomtree button.toggle[aria-expanded="false"]::before { transform: translate(-2px, 2px) rotate(-45deg); }
.bomtree .figs { display: contents; }
.bomtree .figs > span, .bomtree .c-cost {
  text-align: right; font-family: var(--mono); font-size: 13px;
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink);
}
.bomtree .c-per { color: var(--muted); }
.bomtree .uom { font-family: var(--sans); font-size: 12px; }
.bomtree .c-need { font-weight: 600; color: var(--ink-strong); }
.bomtree .zero { color: var(--muted); }
.bomtree .is-short .c-have { color: var(--crit); font-weight: 600; }
.bomtree .is-root .c-cost { font-weight: 600; color: var(--ink-strong); }
.bom-pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; white-space: nowrap;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  background: var(--ok-soft); color: var(--ok);
}
.bom-pill.short { background: var(--crit-soft); color: var(--crit); }
.bom-pill.off { background: var(--line-soft); color: var(--muted); }

/* Beside the history column: the same columns, tighter, units left to the tooltip. */
@container bom (max-width: 819px) {
  .bomtree .node, .bom-head {
    grid-template-columns: minmax(0, 1fr) 40px 42px 44px 56px 74px 74px; column-gap: 8px;
  }
  .bom-head { letter-spacing: .03em; }
  .bom-head span:nth-child(2) { font-size: 0; }
  .bom-head span:nth-child(2)::after { content: "Per"; font-size: 10.5px; }
  .bomtree .uom { display: none; }
  .bomtree ul ul { margin-left: 12px; padding-left: 4px; }
}
/* A phone: the figures go under the name. */
@container bom (max-width: 539px) {
  .bom-head { display: none; }
  .bomtree > ul { border-top: 1px solid var(--line); }
  .bomtree ul ul { margin-left: 9px; padding-left: 5px; }
  .bomtree .node {
    grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; row-gap: 3px;
    grid-template-areas: "name state" "figs cost"; padding: 8px 4px 8px 2px;
  }
  .bomtree .c-name { grid-area: name; }
  .bomtree .c-state { grid-area: state; justify-self: end; }
  .bomtree .c-cost { grid-area: cost; align-self: end; }
  .bomtree .figs {
    grid-area: figs; display: flex; flex-wrap: wrap; gap: 1px 12px; padding-left: 26px;
  }
  .bomtree .figs > .c-order.zero { display: none; }   /* nothing on order: say nothing */
  .bomtree .uom { display: inline; }
  .bomtree .figs > span, .bomtree .c-cost { font-size: 12.5px; }
  .bomtree .figs > span:empty { display: none; }
  .bomtree .figs > span[data-label]::before {
    content: attr(data-label) "\00a0"; font-family: var(--sans); font-weight: 400; color: var(--muted);
  }
}

/* Edit / add: two folded forms side by side; the open one takes the row. */
.bom-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; margin-top: 14px; }
.bom-actions > details.addbox { margin-top: 0; }
.bom-actions > details[open] { flex: 1 1 100%; min-width: 0; }
details.addbox.editbox > summary::before, details.addbox.editbox[open] > summary::before {
  content: "✎"; font-size: 13px;
}
table.bom-edit input:not(.qty) { width: 100%; min-width: 80px; }

/* ---- Location tree (/locations): names are paths, shown folded like a file manager ---- */
.loctree tr[hidden] { display: none; }
.loctree .loc-name {
  padding-left: calc(10px + var(--depth, 0) * 22px); white-space: nowrap;
}
.loctree .loc-name > * { vertical-align: middle; }
.loctree .twisty { display: inline-block; width: 22px; }
.loctree .toggle {
  width: 18px; height: 18px; line-height: 15px; text-align: center; position: relative;
  border: 1px solid var(--line); border-radius: 4px; background: var(--panel-raised);
  cursor: pointer; font-size: 11px; padding: 0; color: var(--muted);
}
.loctree .loc-icon {
  width: 16px; height: 16px; margin-right: 4px; fill: none; stroke: var(--muted);
  stroke-width: 1.4; stroke-linejoin: round;
}
.loctree .leaf { font-weight: 600; }
.loctree tr.folder .leaf { color: var(--muted); }
.loctree tr.inactive .leaf { text-decoration: line-through; color: var(--muted); }
.loctree .loc-desc { min-width: min(200px, 100%); }
.loctree .loc-path { width: 100%; min-width: min(170px, 100%); font-family: var(--mono); font-size: 13px; }
.loctree .loc-name .badge { margin-left: 6px; }
.loctree .loc-path-text { font-family: var(--mono); font-size: 13px; color: var(--muted); padding-left: 11px; }
.loctree tr.folder td { background: color-mix(in srgb, var(--line-soft) 45%, transparent); }
/* Every row's action sits in one slot of one width, so the column reads as a
   column: Make it a bin / Make it a folder / Remove / Keep, or an empty slot. */
.loctree .loc-actions > div {
  display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center;
  gap: 6px 10px; min-width: 208px; white-space: nowrap;
}
.loctree .loc-act {
  display: inline-flex; justify-content: center; align-items: center; box-sizing: border-box;
  width: 116px; padding-inline: 8px; font: 600 12px/1.4 var(--sans);
}
.loctree span.loc-act { visibility: hidden; }
.loctree .loc-act.btn-danger:not(:hover):not(:focus-visible) { border-color: var(--line); }
.loctree .loc-active {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; cursor: pointer;
  text-transform: none; letter-spacing: normal; font: 500 13px/1.4 var(--sans); color: var(--muted);
}
@media (max-width: 899px) {
  .loctree .loc-actions > div, .loctree .loc-path, .loctree .loc-desc { min-width: 0; }
  .loctree span.loc-act { display: none; }
  .loctree .loc-actions > div { white-space: normal; }
}
.loctree .loc-add {
  display: inline-block; width: 20px; height: 20px; margin-left: 6px; line-height: 18px;
  text-align: center; border-radius: 4px; border: 1px solid transparent; position: relative;
  font-weight: 600; text-decoration: none; color: var(--muted); opacity: .55;
}
.loctree tr:hover .loc-add, .loctree .loc-add:focus-visible { opacity: 1; border-color: var(--line); color: var(--accent); }
.loctree tr.loc-new td { background: var(--accent-soft); }
.loctree tr.loc-new td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.loctree tr.loc-new .leaf { font-weight: 500; font-style: italic; color: var(--muted); }
.loctree tr.loc-new .loc-act { width: 84px; }
table.is-cards.loctree tr.loc-new { background: var(--accent-soft); }

/* ---- Part picker & searchable dropdowns (same popup, different data source) ---- */
.ppicker, .combo { position: relative; display: inline-block; }
.ppicker input { width: min(290px, 100%); }
.combo input { width: min(240px, 100%); }
.ppicker .opts, .combo .opts {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 40;
  background: var(--panel-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); display: none; max-height: 260px; overflow-y: auto;
}
.ppicker .opts.open, .combo .opts.open { display: block; }
.ppicker .opts div, .combo .opts div { padding: 7px 10px; cursor: pointer; }
.ppicker .opts div:hover, .ppicker .opts div.sel,
.combo .opts div:hover, .combo .opts div.sel { background: var(--accent-soft); }
/* "+ Create ‹name›" sits under the matches, fenced off so it reads as an action
   rather than one more result. .busy/.error replace the list while creating. */
.combo .opts div.create { border-top: 1px solid var(--line); color: var(--accent); }
.combo .opts div.create:only-child { border-top: 0; }
.combo .opts div.create .note { color: var(--muted); font-size: .85em; margin-left: 6px; }
.combo .opts div.create.hint { color: var(--muted); }
.combo .opts div.create.hint:hover { background: none; }
.combo .opts div.busy, .combo .opts div.error { color: var(--muted); cursor: default; }
.combo .opts div.error { color: var(--crit); }

details summary { cursor: pointer; }

/* ---- Save bar (savebar.js): one place to save, on every page that edits ----
   With JS on it replaces the forms' own Save buttons ([data-save]). */
.js [data-save] { display: none !important; }
.savebar {
  position: fixed; z-index: 140; left: 0; right: 0; bottom: calc(14px + var(--tabbar-h));
  width: max-content; max-width: calc(100vw - 20px); margin-inline: auto;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px;
  padding: 8px 10px 8px 14px; border: 1px solid var(--warn); border-radius: 10px;
  background: var(--panel-raised); color: var(--ink); box-shadow: var(--shadow-pop);
}
.savebar[hidden] { display: none; }
.savebar-count {
  border: 0; background: none; padding: 4px 2px; color: var(--warn); font-weight: 600;
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.savebar-count:hover { background: none; color: var(--ink); }
.savebar-count::before { content: "● "; }
.savebar-actions { display: inline-flex; align-items: center; gap: 8px; }
.savebar kbd {
  font: 600 10.5px/1 var(--mono); margin-left: 6px; padding: 2px 4px;
  border-radius: 4px; background: color-mix(in srgb, var(--accent-ink) 20%, transparent);
}
.savebar.savebar-note { border-color: var(--line); }
.savebar.savebar-note .savebar-count { color: var(--muted); text-decoration: none; cursor: default; }
.savebar.savebar-note .savebar-count::before { content: ""; }
.savebar.savebar-note .savebar-actions { display: none; }
.savebar.busy .savebar-count { text-decoration: none; }
.savebar.savebar-after { border-color: var(--line); }
.savebar.savebar-after .savebar-count { color: var(--muted); text-decoration: none; pointer-events: none; }
.savebar.savebar-after .savebar-count::before { content: ""; }
.savebar.savebar-after [data-act="discard"], .savebar.savebar-after [data-act="save"] { display: none; }
body.has-unsaved .content { padding-bottom: calc(120px + var(--tabbar-h)); }
.unsaved-dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 22px;
  background: var(--panel-raised); color: var(--ink); width: 520px; max-width: 92vw;
  box-shadow: var(--shadow-pop);
}
.unsaved-dialog::backdrop { background: rgba(10, 16, 13, .45); }
.unsaved-dialog h2 { margin-top: 0; }
.change-list { list-style: none; margin: 0 0 16px; padding: 0; max-height: 50vh; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; }
.change-list li + li { border-top: 1px solid var(--line); }
.change-jump {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: none;
  padding: 8px 12px; font-weight: 400; line-height: 1.4;
}
.change-jump:hover { background: var(--ground); }
.change-jump s { color: var(--muted); }
.change-jump .now { color: var(--warn); font-weight: 600; }
@media (min-width: 900px) { .savebar { left: var(--sidebar-w); } }
@media (pointer: coarse) { .savebar kbd { display: none; } }

/* ---- Feedback dialog ---- */
.feedback-dialog, .create-dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 22px;
  background: var(--panel-raised); color: var(--ink); width: 440px; max-width: 92vw;
  box-shadow: var(--shadow-pop);
}
.feedback-dialog::backdrop, .create-dialog::backdrop { background: rgba(10, 16, 13, .45); }
.create-dialog { width: 560px; }
.create-dialog h2 { margin-top: 0; }
.create-dialog .flash { margin-bottom: 12px; }
.req {
  color: var(--crit); font-size: 10.5px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; margin-left: 4px;
}
.feedback-dialog textarea { width: 100%; resize: vertical; }

/* ---- Attachments ---- */
.attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.attachment { position: relative; display: inline-flex; align-items: center; gap: 4px; }
.attachment img {
  height: 56px; max-width: 120px; object-fit: cover; display: block;
  border: 1px solid var(--line); border-radius: 6px;
}
.attachment .att-remove {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; padding: 0;
  border-radius: 50%; border: 1px solid var(--line); background: var(--panel-raised);
  color: var(--muted); font-size: 12px; line-height: 1; cursor: pointer; display: none;
}
.attachment:hover .att-remove { display: block; }
.attachment[draggable="true"] { cursor: grab; }
.attachment.dragging { opacity: .4; cursor: grabbing; }
/* Upload affordance: a ghost thumbnail at the end of the row, same footprint
   as the images it creates. The invisible file input stretches over the whole
   tile so clicking and dropping files both hit the native control. */
.att-add {
  position: relative; overflow: hidden; cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: 56px; min-width: 64px; padding: 0 12px; margin: 0;
  border: 1px dashed color-mix(in srgb, var(--muted) 55%, var(--line));
  border-radius: 6px; color: var(--muted);
  transition: color .12s, border-color .12s, background .12s;
}
.att-add:hover, .att-add:focus-within {
  color: var(--accent); border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 55%, transparent);
}
.att-add:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.att-add .plus { font-size: 16px; line-height: 1; }
.att-add input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

/* ---- Lightbox (initLightbox): a full-viewport modal; clicks on the dim
   stage around the image close it. ---- */
.lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0;
  padding: 0; border: 0; background: transparent; color: #f2f5f3;
}
.lightbox[open] { display: flex; flex-direction: column; }
.lightbox::backdrop { background: rgba(6, 10, 8, .9); }
.lb-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(6, 10, 8, .6);
}
.lb-caption {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px;
}
.lb-close { margin-left: auto; font-size: 18px; line-height: 1; padding: 4px 11px; }
.lb-stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 0 56px 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.lb-stage img {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block;
  border-radius: 4px; background: #fff; box-shadow: 0 8px 40px rgba(0, 0, 0, .5);
}
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 64px; padding: 0; border-radius: 8px;
  border: 0; background: rgba(255, 255, 255, .1); color: #f2f5f3;
  font-size: 32px; line-height: 1;
}
.lb-nav:hover { background: rgba(255, 255, 255, .22); color: #fff; }
.lb-prev { left: 6px; }
.lb-next { right: 6px; }
.lb-nav[hidden] { display: none; }
@media (max-width: 599px) {
  .lb-stage { padding-left: 8px; padding-right: 8px; }
  .lb-caption { flex-basis: 100%; }
  .lb-nav { top: auto; bottom: calc(24px + env(safe-area-inset-bottom)); transform: none; }
}

/* ---- Login ---- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: var(--gutter);
}
.login-box {
  width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 30px; box-shadow: var(--shadow);
}
.login-box h1 {
  text-align: center; font-family: var(--mono); letter-spacing: .14em; font-weight: 600;
}
.login-box h1::after { content: "_"; color: var(--copper); }
.login-box input { width: 100%; }
.login-box button { width: 100%; margin-top: 10px; }

/* ---- Units of measure ----
   A unit's meaning is a relationship, so the row reads as an equation:
   "1 <code> = <factor> <reference>". Keep those parts aligned across rows
   and let the mono face carry every code and number. */
.uom-intro { max-width: 62ch; margin: -8px 0 20px; line-height: 1.5; }
.uom-intro code { font-family: var(--mono); font-size: 12px; color: var(--ink); }

.uom-table td { vertical-align: middle; }
.uom-table input.uom-code { width: 76px; }
.uom-table input.uom-name { width: 100%; min-width: 120px; }

/* The definition cell: the lead is right-aligned in a fixed width and the
   factor and select are fixed too, so the "=" and both controls line up down
   the table whatever the code's length. The factor fits all 8 places. */
.uom-eq { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.uom-eq .lead { color: var(--muted); font-size: 12.5px; }
.uom-eq .lead .mono { color: var(--ink); font-size: 13px; }
.uom-eq input.uom-factor { width: 132px; }
.uom-eq select.uom-ref { width: 108px; }
.uom-table .uom-eq .lead { flex: none; min-width: 10ch; text-align: right; }
/* A base unit has no factor: the select takes its place ("1 ft = base unit"). */
.uom-table .uom-eq input.uom-factor:disabled { display: none; }
.uom-table .uom-eq input.uom-factor:disabled + select.uom-ref { width: 248px; }

/* One dimension after another: a heavier rule where the next one starts. */
.uom-table tr.uom-first > td { border-top: 2px solid var(--line); }
.uom-table tbody td { padding-top: 8px; padding-bottom: 8px; }

/* Resolved value against the dimension's base unit. */
.uom-inbase { white-space: nowrap; }
.uom-per { font-family: var(--sans); font-size: 12px; color: var(--muted); }
.uom-base { color: var(--muted); font-family: var(--sans); font-size: 12px;
  text-transform: uppercase; letter-spacing: .08em; }

/* Between the phone's cards and a wide window the panel is narrow (from
   900px the sidebar takes its share): drop the derived column and tighten
   the rest, so the definition never scrolls sideways. */
@media (min-width: 600px) and (max-width: 1279px) {
  .uom-table th:nth-child(4), .uom-table td.uom-inbase { display: none; }
  .uom-table th, .uom-table td { padding-left: 6px; padding-right: 6px; }
  .uom-table input.uom-name { min-width: 64px; }
  .uom-table .uom-eq .lead { min-width: 8ch; }
  .uom-table input.uom-code { width: 58px; padding-inline: 6px; }
  .uom-actions { flex-wrap: wrap; white-space: normal; }
  .uom-table .uom-eq { gap: 6px; }
  .uom-table .uom-eq input.uom-factor { width: 104px; appearance: textfield; -moz-appearance: textfield; }
  .uom-table .uom-eq input.uom-factor::-webkit-inner-spin-button { appearance: none; -webkit-appearance: none; }
  .uom-table .uom-eq select.uom-ref { width: 84px; }
  .uom-table .uom-eq input.uom-factor:disabled + select.uom-ref { width: 194px; }
}

/* The row's Active box (its heading labels it), the no-JS Save, then what
   uses the unit (what a rename carries along) or Delete when nothing does. */
.uom-actions { display: flex; align-items: center; gap: 6px 14px; white-space: nowrap; }
.uom-toggle { display: inline-flex; align-items: center; margin: 0; cursor: pointer; }
.uom-used { font-size: 12.5px; }
.uom-actions .btn-danger:not(:hover):not(:focus-visible) { border-color: var(--line); }

/* Add-unit form is one horizontal band under the table, not a squeezed column. */
.uom-add .formrow { align-items: flex-end; }
.uom-add .field.grow { flex: 1; min-width: 160px; }

/* Demand tree + build-next: badges name the demand relationship. */
.badge.shared   { background: var(--warn-soft); color: var(--warn); }
.badge.unplanned { background: var(--crit-soft); color: var(--crit); }
.badge.nosupplier { background: var(--crit-soft); color: var(--crit); }
a.badge.nosupplier { text-decoration: none; }
.badge.short { background: var(--crit-soft); color: var(--crit); }
.badge.low { background: var(--warn-soft); color: var(--warn); }
a.badge.short, a.badge.low { text-decoration: none; }
.nowrap { white-space: nowrap; }
.badge.kit { background: var(--info-soft); color: var(--info); }
.badge.ship     { background: var(--info-soft); color: var(--info); }
.badge.unblocks { background: var(--violet-soft); color: var(--violet); }
.badge.feeds    { background: var(--line-soft); color: var(--muted); }

/* Change orders: what the floor found wrong, until Engineering clears it. */
.badge.co { background: var(--crit-soft); color: var(--crit); }
a.badge.co:hover { text-decoration: none; filter: brightness(.95); }
.badge.hold { background: var(--crit); color: #fff; }
.sidebar .navcount {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--copper); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.co-note { white-space: pre-wrap; font-size: 15px; margin: 0 0 10px; }
/* ---- A part's documents (parts/_documents.html): a card per revision, each
   file's type a tile — a PDF's first page or the image itself as a thumbnail,
   else a coloured file shape. Tones say what a file is for: red drawings for people, copper
   flats for the laser, blue 3D models, violet print files. ---- */
.docs-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; margin-bottom: 12px; }
.docs-head h2 { margin: 0; }
.docs-head p { margin: 0; }
/* A bundle: the part's files at one revision, as one card — a rev tab on
   the left edge, the files as rows. The latest has the fold to upload the
   next revision of them all. */
.bundles { display: grid; gap: 14px; }
.bundle {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-raised);
  overflow: hidden;
}
.bundle-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--ground); border-bottom: 1px solid var(--line-soft);
}
.bundle-rev {
  display: inline-flex; align-items: baseline; gap: 4px; padding: 3px 10px; border-radius: 6px;
  font: 700 18px/1.2 var(--mono); color: var(--accent-ink); background: var(--accent);
  white-space: nowrap;
}
.bundle-rev small { font: 600 10px/1 var(--sans); text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
/* The revision built to carries the accent; the others stand back. */
.bundle.is-building { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.bundle.is-other .bundle-rev { background: var(--muted); }
.bundle-gap {
  margin: 0; padding: 8px 12px; font-size: 13px; color: var(--warn);
  background: var(--warn-soft); border-bottom: 1px solid var(--line-soft);
}
.docs-head .buildto { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.buildto label { font-size: 13px; color: var(--muted); }
.bundle-meta { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; font-size: 13px; }
.docs { list-style: none; margin: 0; padding: 0; }
.doc {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 4px 14px;
  align-items: start; padding: 12px;
}
.doc + .doc { border-top: 1px solid var(--line-soft); }
.doc:target { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.bundle-fold { border-top: 1px solid var(--line-soft); padding: 4px 12px; }
.bundle-fold > summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 600; color: var(--accent-strong); padding: 6px 0;
}
.bundle-fold > summary::-webkit-details-marker { display: none; }
.bundle-fold > summary::before { content: "+"; font-size: 15px; line-height: 1; width: 10px; }
.bundle-fold[open] > summary::before { content: "−"; }
.bundle-fold > summary:hover { text-decoration: underline; }
.bundle-fold[open] { padding-bottom: 12px; }
.bundle-fold .doc-form { margin-top: 4px; }
.dropzone.dz-compact { padding: 14px 12px; background: var(--panel-raised); }
.doc-tile-group, .doc > .doc-tile { grid-row: 1 / span 2; }
.doc-tile {
  position: relative; display: grid; place-items: center; width: 64px; height: 80px;
  border-radius: 4px 14px 4px 4px; text-decoration: none; overflow: hidden;
  font: 700 12px/1 var(--mono); letter-spacing: .04em;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 12%, var(--panel-raised));
  border: 1px solid color-mix(in srgb, var(--tone) 30%, var(--line));
}
.doc-tile::before {          /* the folded corner */
  content: ""; position: absolute; top: -1px; right: -1px; width: 16px; height: 16px;
  background: linear-gradient(225deg, var(--panel-raised) 50%, color-mix(in srgb, var(--tone) 30%, var(--line)) 50%);
  border-bottom-left-radius: 4px;
}
a.doc-tile:hover { text-decoration: none; border-color: var(--tone); }
.doc-thumb { --tone: var(--line); background: #fff; border-color: var(--line); border-radius: 4px; }
.doc-thumb::before { display: none; }
.doc-thumb img { width: 100%; height: 100%; object-fit: contain; }
.doc-thumb:hover img { opacity: .85; }
.doc-thumb .ftag { position: absolute; left: 4px; bottom: 4px; }
.tone-pdf { --tone: var(--crit); }
.tone-dxf { --tone: var(--copper); }
.tone-model { --tone: var(--info); }
.tone-print { --tone: var(--violet); }
.tone-zip { --tone: var(--ok); }
.tone-image, .tone-other { --tone: var(--muted); }
/* A file type as a small label: on a thumbnail, and in the guide. */
.ftag {
  display: inline-block; padding: 1px 5px; border-radius: 3px; font: 700 10px/1.4 var(--mono);
  font-style: normal; letter-spacing: .04em; color: var(--panel-raised); background: var(--tone);
}
.doc-main { min-width: 0; }
.doc-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.doc-title h3 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink-strong); }
.tabpanel .doc-title h3 { margin: 0; }
.doc-rev {
  display: inline-block; padding: 1px 7px; border-radius: 4px; white-space: nowrap;
  font-size: 11.5px; color: var(--muted); background: var(--ground); border: 1px solid var(--line);
}
.doc-rev b { font-family: var(--mono); font-size: 12.5px; color: var(--ink-strong); }
.doc-file { margin: 4px 0 0; font-size: 13px; overflow-wrap: anywhere; }
.doc-file .muted { font-size: 12px; white-space: nowrap; }
.doc-note { margin: 4px 0 0; font-size: 13px; }
.doc-use { margin: 2px 0 0; }
.doc-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.doc-form {
  padding: 12px; border-radius: 8px; background: var(--ground); border: 1px solid var(--line-soft);
}
.doc-form > .field { margin-bottom: 12px; }
.doc-form .formrow { margin-bottom: 12px; }
.doc-form input.wide { width: 100%; }
.doc-form input.rev { width: 11em; }
.doc-clears { border: 0; margin: 0 0 12px; padding: 0; }
.doc-clears legend { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 4px; padding: 0; }
.doc-clears label.check {
  display: flex; gap: 8px; align-items: flex-start; margin: 4px 0;
  font: 400 13px/1.4 var(--sans); text-transform: none; letter-spacing: 0; color: var(--ink);
}
.doc-cos { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* Adding documents: a drop zone over the file input (JS lays the input over
   the whole zone and lists what was picked; without it the input shows). */
.doc-add .doc-form { background: transparent; border: 0; padding: 0; }
.dropzone {
  position: relative; display: grid; gap: 4px; justify-items: center; text-align: center;
  padding: 22px 16px; margin: 0 0 12px; border: 2px dashed var(--line); border-radius: 10px;
  background: var(--ground); cursor: pointer;
  font: 400 13px/1.4 var(--sans); text-transform: none; letter-spacing: 0; color: var(--muted);
  transition: border-color .12s, background .12s;
}
.dropzone .dz-title { font-size: 14px; font-weight: 700; color: var(--accent-strong); }
.dropzone .dz-files { font-family: var(--mono); font-size: 12px; color: var(--ink); overflow-wrap: anywhere; }
.dropzone .dz-files:empty { display: none; }
.dropzone:hover, .dropzone.is-over, .dropzone:focus-within {
  border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 60%, transparent);
}
.dropzone.has-files { border-style: solid; border-color: var(--accent); }
.dropzone.dz-ready input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone:not(.dz-ready) input[type="file"] { margin-top: 6px; }
.doc-guide {
  list-style: none; margin: 0 0 14px; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 6px 16px;
}
.doc-guide li { display: grid; gap: 2px; font-size: 12.5px; color: var(--muted); }
.doc-guide b { color: var(--ink); font-size: 12px; }
.doc-guide span { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.doc-guide .ftag + .ftag { margin-left: 6px; }

@media (max-width: 599px) {
  .bundle-head { flex-wrap: wrap; }
  .doc { grid-template-columns: 52px minmax(0, 1fr); gap: 4px 12px; }
  .doc-tile { width: 52px; height: 66px; }
  .doc-tile-group, .doc > .doc-tile { grid-row: 1; }
  .doc-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .doc-use { display: none; }
}
@media (pointer: coarse), (max-width: 599px) {
  .bundle-fold > summary { min-height: 44px; }
}

/* A PO's package (po/detail.html): what goes to the supplier. */
.pkg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-bottom: 10px; }
.pkg-head h2 { margin: 0; }
.pkg-head p { margin: 0; flex: 1 1 260px; }
.pkg { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pkg > li {
  display: grid; grid-template-columns: minmax(0, 14em) minmax(0, 1fr); gap: 4px 16px;
  padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 13px;
}
.pkg > li:first-child { border-top: 0; }
.pkg-files { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.pkg-files a {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 4px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel-raised); color: var(--ink); text-decoration: none;
}
.pkg-files a:hover { border-color: var(--accent); }
.pkg-files .doc-rev { padding: 0 5px; font-size: 11px; }
@media (max-width: 599px) {
  .pkg > li { grid-template-columns: 1fr; }
}

/* Drawing markup (static/js/markup.js): the canvas lies over the page image
   at the same size. The tools are a dock last in the box, stuck to the foot of
   the window (above the phone tab bar) while any of the drawing is in view, so
   they're in reach on page 30 and in thumb reach on a phone. */
.markup-head { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin: 0 0 8px; }
.markup-head[hidden], .markup-head [data-markup-count]:empty { display: none; }
.markup-dock {
  position: sticky; bottom: calc(10px + var(--tabbar-h)); z-index: 3;
  width: fit-content; max-width: 100%; margin: 0 auto; padding: 4px 6px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .16);
}
.markup-top { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; }
/* width 0: the hint takes the buttons' width, never sets it. */
.markup-hint {
  flex: 1 1 0; width: 0; margin: 0; padding: 0 4px; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.markup-btns, .markup-dock [role="group"] { display: flex; align-items: center; gap: 2px; }
.markup-btns [role="group"] { padding-right: 4px; margin-right: 4px; border-right: 1px solid var(--line); }
.markup-dock button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.markup-zoom { flex: none; }
.markup-zoom [data-zoom="fit"] { min-width: 4.2em; font-variant-numeric: tabular-nums; }
/* Zoom is the pages' width (markup.js); past 100% they scroll sideways. */
.markup-pages { --zoom: 1; overflow-x: auto; }
.markup-dock svg {
  width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.markup-btns [aria-pressed="true"] { background: var(--crit); border-color: var(--crit); color: #fff; }
.markup-page { position: relative; width: calc(var(--zoom) * 100%); margin: 0 auto 12px; border: 1px solid var(--line); background: #fff; }
.markup-page img { display: block; width: 100%; height: auto; }
.markup-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
/* Text typed onto the page: sized and placed by markup.js to match what it draws. */
.markup-page textarea.markup-edit {
  position: absolute; z-index: 2; min-height: 0; margin: 0; padding: 0; border: 1px dashed #2563eb;
  border-radius: 0; background: rgb(255 255 255 / .85); color: #d4202a; font: bold 16px/1.2 sans-serif;
  resize: none; overflow: hidden; white-space: pre; box-shadow: none;
}
.markup-page .markup-pno { position: absolute; top: 4px; right: 6px; font-size: 12px; color: var(--muted); }
.badge.incorporated { background: var(--ok-soft); color: var(--ok); }
.badge.dropped { background: var(--line-soft); color: var(--muted); }
.co-list { list-style: none; padding: 0; margin: 0; }
.co-list > li { padding: 8px 0; border-top: 1px solid var(--line-soft); }
.co-list > li:first-child { border-top: 0; }
.co-list .actions { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* Build next — the two "why now" columns. Each relationship gets its own line
   so the badge reads as a label for the list beside it, not as one more chip in
   a run of chips. */
.reason { line-height: 1.65; }
.reason-line + .reason-line { margin-top: 2px; }

/* Segmented view switch (work orders: tree / list). */
.viewswitch { display: inline-flex; margin-right: 8px; }
.viewswitch .btn { border-radius: 0; color: var(--muted); }
.viewswitch .btn + .btn { margin-left: -1px; }
.viewswitch .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.viewswitch .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.viewswitch [aria-current] { background: var(--ink); border-color: var(--ink);
  color: var(--panel); cursor: default; position: relative; }

/* Flow view: a Sankey of WO output (layout in sankey.py). It shrinks to fit
   its panel down to 640px, then scrolls inside it — any smaller and the
   labels are unreadable on a phone. */
.flow-wrap { overflow-x: auto; }
.flow { display: block; width: 100%; min-width: 640px; height: auto; font: 12px var(--sans); }
/* Band colours say what the flow is (legend above the diagram). Chart hues,
   not the UI's muted tokens: those failed the colour-blind checks against
   each other. "No WO yet" is the status red, with a dashed node as its
   second cue. */
.flow-band { opacity: .4; transition: opacity .12s; }
.flow-band.build, .flow-swatch.build { fill: var(--flow-build); background: var(--flow-build); }
.flow-band.order, .flow-swatch.order { fill: var(--flow-order); background: var(--flow-order); }
.flow-band.stock, .flow-swatch.stock { fill: var(--flow-stock); background: var(--flow-stock); }
.flow-band.unplanned, .flow-swatch.unplanned { fill: var(--flow-missing); background: var(--flow-missing); }
.flow-band:hover { opacity: .65; }
.flow-node.wo { fill: var(--ink); }
.flow-node.so { fill: var(--flow-order); }
.flow-node.stock { fill: var(--flow-stock); }
.flow-node.need { fill: var(--crit-soft); stroke: var(--flow-missing); stroke-width: 1.5;
  stroke-dasharray: 4 3; }
.flow-label, .flow-sub, .flow-qty, .flow-head { paint-order: stroke; stroke: var(--panel);
  stroke-width: 3px; stroke-linejoin: round; }
.flow-qty { pointer-events: none; }   /* labels inside a node's link stay clickable */
.flow-label { fill: var(--ink); font-weight: 600; font-family: var(--mono); }
.flow-sub { fill: var(--muted); font-weight: 400; font-family: var(--sans); }
.flow-qty { fill: var(--ink); font-size: 10px; text-anchor: end; dominant-baseline: middle; }
/* A WO's readiness after its qty: what it still waits on, worst first. */
.flow-ready { font-family: var(--sans); font-weight: 600; }
.flow-ready.ready { fill: var(--ok); }
.flow-ready.building { fill: var(--muted); font-weight: 400; }
.flow-ready.ordered { fill: var(--info); }
.flow-ready.draft { fill: var(--warn); }
.flow-ready.missing { fill: var(--crit); }
.flow-head { fill: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; }
.flow .end { text-anchor: end; }
.flow a:hover .flow-label, .flow a:focus .flow-label { fill: var(--accent); }
.flow a:focus { outline: none; }
.flow a:focus-visible .flow-node { stroke: var(--accent); stroke-width: 3; }
/* Tracing (app.js initFlowTrace): everything off the pointed-at chain fades. */
.flow.tracing .flow-band:not(.lit) { opacity: .07; }
.flow.tracing .flow-qty:not(.lit), .flow.tracing .flow-n:not(.lit) { opacity: .25; }
.flow.tracing .flow-band.lit { opacity: .7; }
/* Flow's action list: the orders no work order covers, one build per product. */
.needs-wo { border: 1px solid color-mix(in srgb, var(--crit) 35%, var(--line));
  background: var(--crit-soft); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; }
.needs-wo h3 { margin: 0 0 2px; font-size: 14px; }
.needs-wo p { margin: 0 0 8px; }
.needs-wo ul { list-style: none; margin: 0; padding: 0; }
.needs-wo li { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 6px 0; border-top: 1px solid color-mix(in srgb, var(--crit) 15%, transparent); }
.needs-wo li:first-child { border-top: 0; }
.parts-short { border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); background: var(--warn-soft); }
.parts-short li { border-top-color: color-mix(in srgb, var(--warn) 15%, transparent); }
.short-what { flex: 1 1 420px; line-height: 1.9; }
.short-part { white-space: nowrap; margin-right: 10px; }
.needs-wo li { scroll-margin-top: 96px; }   /* clear of the sticky topbar when jumped to */
.needs-wo li:target { outline: 2px solid var(--crit); outline-offset: 4px; border-radius: 2px; }
.flow-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none;
  margin: 0 0 10px; padding: 0; font-size: 13px; }
.flow-legend li { display: flex; align-items: center; gap: 7px; }
.flow-swatch { display: inline-block; width: 18px; height: 10px; border-radius: 2px;
  opacity: .75; vertical-align: middle; }
.flow-swatch.unplanned { outline: 1.5px dashed var(--flow-missing); outline-offset: 1px; }
.flow-table { margin-top: 12px; }
.flow-table summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); }
.flow-table table { margin-top: 8px; }

.wogroup { margin-bottom: 14px; }
.wogroup:last-child { margin-bottom: 0; }
.sohead { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.wotree { list-style: none; margin: 0; padding-left: 4px; }
.wotree ul { list-style: none; margin: 0 0 0 7px; padding-left: 18px;
  border-left: 1px solid var(--line-soft); }
.wotree li { padding: 3px 0; }

/* ---- Part page: tabs in the middle, history on the right ---- */
/* No width cap here: whatever a wide screen has past the 1280px layout is
   shared half and half between the tabs and the history. */
.content:has(.part-layout) { max-width: none; }
.part-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
@media (min-width: 1280px) {
  /* 320px when the grid is 1012px wide (a 1280px window); half of every px
     past that. The cap keeps an ultra-wide history readable. */
  .part-layout { grid-template-columns: minmax(0, 1fr) clamp(320px, calc(50% - 186px), 760px); }
  /* The history scrolls beside the tabs, under the sticky topbar. */
  .part-history { position: sticky; top: 72px; }
  .part-history .timeline { max-height: calc(100dvh - 92px); overflow-y: auto; overscroll-behavior: contain; }
}

/* The strip wraps rather than scrolls: a scroll box here showed a scroll
   bar for the 1px the active underline overlaps. The underline is an inset
   shadow, so nothing sticks out. --tab-mark is the active tab's bar. */
.tablist {
  display: flex; flex-wrap: wrap; gap: 2px 4px; margin-bottom: 18px;
  box-shadow: inset 0 -1px var(--line);
}
.tab {
  --tab-mark: transparent;
  display: flex; flex-direction: column; justify-content: center; gap: 2px; flex: none;
  min-height: var(--tap); padding: 8px 14px 10px; color: var(--muted); white-space: nowrap;
  border-radius: var(--radius) var(--radius) 0 0; box-shadow: inset 0 -3px var(--tab-mark);
  transition: background-color .12s, box-shadow .12s;
}
.tab:hover { text-decoration: none; color: var(--ink); background: var(--line-soft); }
.tab:hover:not([aria-selected="true"], .is-current) { --tab-mark: var(--line); }
.tab-label { font-size: 14px; font-weight: 600; color: var(--ink); }
.tab-fig { font-size: 12px; font-variant-numeric: tabular-nums; }
.tab.tab-warn .tab-fig { color: var(--warn); font-weight: 600; }
.tab.tab-crit .tab-fig { color: var(--crit); font-weight: 600; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab.is-current, .tab[aria-selected="true"] { --tab-mark: var(--accent); color: var(--accent-strong); }
.tab.is-current .tab-label, .tab[aria-selected="true"] .tab-label { color: var(--ink-strong); }
/* A phone gets tiles that stretch to fill each row: every tab in view, none
   scrolled off, no gap at the end of a row. */
@media (max-width: 599px) {
  .tablist { gap: 6px; box-shadow: none; }
  .tab {
    flex: 1 1 auto; padding: 6px 10px 8px; border-radius: var(--radius); background: var(--panel);
    box-shadow: inset 0 0 0 1px var(--line), inset 0 -3px var(--tab-mark);
  }
  .tab.is-current, .tab[aria-selected="true"] { background: var(--accent-soft); }
}
/* Links that set one filter (accounting's Show / When): a row of pills, the
   current one filled. */
.pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pills-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin-right: 2px;
}
.pill {
  display: inline-flex; align-items: center; height: var(--ctl-sm); padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  color: var(--ink); font-size: 13px; white-space: nowrap;
}
.pill:hover { text-decoration: none; background: var(--line-soft); }
.pill[aria-current="true"] {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 600;
}

/* Accounting: the filters a bookkeeper uses every time, then Export with
   what it adds up to and the settings it writes. */
.acct-intro { max-width: 70ch; margin-top: -6px; }
.acct-bar {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.acct-quick { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.acct-export { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.acct-export form { margin: 0; }
.acct-export button[disabled] { opacity: .55; cursor: not-allowed; }
.acct-warn { color: var(--warn); }
.acct-steps { margin: 0 0 14px; padding-left: 22px; line-height: 1.7; }

/* Landing on #suppliers keeps the tab strip in view above the panel. */
.tabpanel, .tabpanel [id] { scroll-margin-top: 140px; }

/* Without JS: the :target panel, else the default one. initTabs adds
   .tabs-ready and switches with [hidden] instead. */
.ptabs:not(.tabs-ready) > .tabpanel:not([data-default]) { display: none; }
.ptabs:not(.tabs-ready):has(> .tabpanel:target, > .tabpanel :target) > .tabpanel { display: none; }
.ptabs:not(.tabs-ready):has(> .tabpanel:target, > .tabpanel :target) > .tabpanel:is(:target, :has(:target)) { display: block; }
.ptabs:not(.tabs-ready):has(> .tabpanel:target, > .tabpanel :target) .tab.is-current {
  --tab-mark: transparent; color: var(--muted); background: none; }
.ptabs:not(.tabs-ready):is(:has(#details:target, #details :target) .tab[href="#details"],
  :has(#bom:target, #bom :target) .tab[href="#bom"],
  :has(#suppliers:target, #suppliers :target) .tab[href="#suppliers"],
  :has(#stock:target, #stock :target) .tab[href="#stock"],
  :has(#orders:target, #orders :target) .tab[href="#orders"],
  :has(#documents:target, #documents :target) .tab[href="#documents"],
  :has(#cad:target, #cad :target) .tab[href="#cad"]) {
  --tab-mark: var(--accent); color: var(--accent-strong); }
@media (max-width: 599px) {
  .ptabs:not(.tabs-ready):is(:has(#details:target, #details :target) .tab[href="#details"],
    :has(#bom:target, #bom :target) .tab[href="#bom"],
    :has(#suppliers:target, #suppliers :target) .tab[href="#suppliers"],
    :has(#stock:target, #stock :target) .tab[href="#stock"],
    :has(#orders:target, #orders :target) .tab[href="#orders"],
    :has(#documents:target, #documents :target) .tab[href="#documents"],
    :has(#cad:target, #cad :target) .tab[href="#cad"]) { background: var(--accent-soft); }
  .ptabs:not(.tabs-ready):has(> .tabpanel:target, > .tabpanel :target) .tab.is-current { background: var(--panel); }
}

/* First paint with JS on: base.html's head script names the #fragment's tab
   on <html> (data-tab) before anything is drawn. :target can't do this: it
   matches only once the parser reaches the panel, so a long page painted its
   default tab first and then jumped. initTabs takes over at DOMContentLoaded. */
html:is([data-tab="details"], [data-tab="bom"], [data-tab="suppliers"], [data-tab="stock"], [data-tab="orders"], [data-tab="documents"], [data-tab="cad"]) .ptabs:not(.tabs-ready) > .tabpanel { display: none; }
html[data-tab="details"] .ptabs:not(.tabs-ready) > #details,
html[data-tab="bom"] .ptabs:not(.tabs-ready) > #bom,
html[data-tab="suppliers"] .ptabs:not(.tabs-ready) > #suppliers,
html[data-tab="stock"] .ptabs:not(.tabs-ready) > #stock,
html[data-tab="orders"] .ptabs:not(.tabs-ready) > #orders,
html[data-tab="documents"] .ptabs:not(.tabs-ready) > #documents,
html[data-tab="cad"] .ptabs:not(.tabs-ready) > #cad { display: block; }
html:is([data-tab="details"], [data-tab="bom"], [data-tab="suppliers"], [data-tab="stock"], [data-tab="orders"], [data-tab="documents"], [data-tab="cad"]) .ptabs:not(.tabs-ready) .tab.is-current {
  --tab-mark: transparent; color: var(--muted); background: none; }
html[data-tab="details"] .ptabs:not(.tabs-ready) .tab[href="#details"],
html[data-tab="bom"] .ptabs:not(.tabs-ready) .tab[href="#bom"],
html[data-tab="suppliers"] .ptabs:not(.tabs-ready) .tab[href="#suppliers"],
html[data-tab="stock"] .ptabs:not(.tabs-ready) .tab[href="#stock"],
html[data-tab="orders"] .ptabs:not(.tabs-ready) .tab[href="#orders"],
html[data-tab="documents"] .ptabs:not(.tabs-ready) .tab[href="#documents"],
html[data-tab="cad"] .ptabs:not(.tabs-ready) .tab[href="#cad"] {
  --tab-mark: var(--accent); color: var(--accent-strong); }
@media (max-width: 599px) {
  html:is([data-tab="details"], [data-tab="bom"], [data-tab="suppliers"], [data-tab="stock"], [data-tab="orders"], [data-tab="documents"], [data-tab="cad"]) .ptabs:not(.tabs-ready) .tab.is-current { background: var(--panel); }
  html[data-tab="details"] .ptabs:not(.tabs-ready) .tab[href="#details"],
  html[data-tab="bom"] .ptabs:not(.tabs-ready) .tab[href="#bom"],
  html[data-tab="suppliers"] .ptabs:not(.tabs-ready) .tab[href="#suppliers"],
  html[data-tab="stock"] .ptabs:not(.tabs-ready) .tab[href="#stock"],
  html[data-tab="orders"] .ptabs:not(.tabs-ready) .tab[href="#orders"],
  html[data-tab="documents"] .ptabs:not(.tabs-ready) .tab[href="#documents"],
  html[data-tab="cad"] .ptabs:not(.tabs-ready) .tab[href="#cad"] { background: var(--accent-soft); }
}

.tabpanel h3 { font-size: 13px; font-weight: 600; color: var(--ink-strong); margin: 18px 0 8px; }
.tabpanel h3:first-of-type { margin-top: 4px; }
.sp-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }

/* An add form, folded until wanted: its summary reads as a button. */
details.addbox { margin-top: 14px; }
details.addbox > summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 600; color: var(--accent-strong);
  padding: 6px 12px; border: 1px dashed var(--line); border-radius: var(--radius);
}
details.addbox > summary::-webkit-details-marker { display: none; }
details.addbox > summary::before { content: "+"; font-size: 15px; line-height: 1; }
details.addbox[open] > summary::before { content: "−"; }
details.addbox > summary:hover { border-color: var(--accent); background: var(--accent-soft); }
details.addbox[open] > summary { margin-bottom: 10px; }
.field.grow { flex: 1; min-width: 160px; }
.views-menu .menu-form .formrow { flex-wrap: nowrap; margin-top: 8px; }
.views-menu .menu-form select { width: 100%; }

.figures { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 0 0 16px; }
.figures > div { min-width: 0; }
.figures dt { font-size: 11.5px; color: var(--muted); }
.figures dd { margin: 0; font-size: 17px; font-weight: 600; color: var(--ink-strong);
  font-variant-numeric: tabular-nums; }
.figures .warn dd { color: var(--warn); }
.figures .crit dd { color: var(--crit); }
.figures dd.fig-sub { font-size: 12px; font-weight: 400; color: var(--muted); }
/* The netting sum: + − = sit before each term, so it reads as one line. */
.figures.netting > div[data-op] { position: relative; }
.figures.netting > div[data-op]::before { content: attr(data-op); position: absolute; left: -19px;
  top: 14px; color: var(--muted); font-size: 15px; }
.net-verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0 0 16px;
  padding: 10px 12px; border-left: 3px solid var(--line); background: var(--ground, transparent); }
.net-verdict p { margin: 0; flex: 1 1 240px; }
.net-verdict form { margin: 0; }
.net-verdict.net-short { border-color: var(--crit); background: var(--crit-soft); }
.net-verdict.net-low { border-color: var(--warn); background: var(--warn-soft); }
.net-verdict.net-ok { border-color: var(--accent); }

/* The history. Chips are radios (_timeline.html); one rule pair per kind
   (timeline.KINDS) hides the rest and the days left without any. */
.tl-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tl-chip {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; cursor: pointer;
  padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 12.5px; font-weight: 500; color: var(--ink); text-transform: none; letter-spacing: 0;
}
.tl-chip:hover { border-color: var(--muted); }
.tl-n { color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-filter input:checked + .tl-chip {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.tl-filter input:focus-visible + .tl-chip { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (pointer: coarse), (max-width: 599px) { .tl-chip { min-height: 36px; padding: 4px 12px; } }

.timeline:has(#tlk-stock:checked) :is(.tl-item:not([data-kind~="stock"]), .tl-day:not(:has([data-kind~="stock"]))),
.timeline:has(#tlk-orders:checked) :is(.tl-item:not([data-kind~="orders"]), .tl-day:not(:has([data-kind~="orders"]))),
.timeline:has(#tlk-bom:checked) :is(.tl-item:not([data-kind~="bom"]), .tl-day:not(:has([data-kind~="bom"]))),
.timeline:has(#tlk-suppliers:checked) :is(.tl-item:not([data-kind~="suppliers"]), .tl-day:not(:has([data-kind~="suppliers"]))),
.timeline:has(#tlk-documents:checked) :is(.tl-item:not([data-kind~="documents"]), .tl-day:not(:has([data-kind~="documents"]))),
.timeline:has(#tlk-changes:checked) :is(.tl-item:not([data-kind~="changes"]), .tl-day:not(:has([data-kind~="changes"]))),
.timeline:has(#tlk-onshape:checked) :is(.tl-item:not([data-kind~="onshape"]), .tl-day:not(:has([data-kind~="onshape"]))),
.timeline:has(#tlk-edits:checked) :is(.tl-item:not([data-kind~="edits"]), .tl-day:not(:has([data-kind~="edits"]))) {
  display: none; }

.tl-more { display: none; margin-top: 12px; }
@media (max-width: 1279px) {
  .timeline:has(#tlk-all:checked):not(:has(#tl-more:checked))
    :is(.tl-later, .tl-day:not(:has(.tl-item:not(.tl-later)))) { display: none; }
  .timeline:has(#tlk-all:checked) #tl-more:not(:checked) + .tl-more { display: inline-flex; }
}
.tl-day + .tl-day { margin-top: 14px; }
.tl-date {
  margin: 0 0 6px; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted);
}
.tl-items { list-style: none; margin: 0; padding: 0; }
.tl-item { position: relative; display: flex; gap: 10px; padding: 6px 0 6px 2px; }
/* The thread down the left, through each dot. */
.tl-item::before {
  content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 1px; background: var(--line);
}
.tl-item:first-child::before { top: 12px; }
.tl-item:last-child::before { bottom: calc(100% - 12px); }
.tl-item > .tl-dot { margin-top: 4px; position: relative; }
.tl-dot {
  flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); box-shadow: 0 0 0 2px var(--panel);
}
.tl-dot.tl-stock { background: var(--warn); }
.tl-dot.tl-orders { background: var(--info); }
.tl-dot.tl-bom { background: var(--violet); }
.tl-dot.tl-suppliers { background: var(--accent); }
.tl-dot.tl-documents { background: var(--copper); }
.tl-dot.tl-changes { background: var(--crit); }
.tl-dot.tl-onshape { background: var(--ink); }
.tl-body { min-width: 0; flex: 1; font-size: 13px; line-height: 1.45; }
.tl-what { overflow-wrap: anywhere; }
.tl-delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.tl-detail { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.tl-meta { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.tl-foot { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--line-soft); }
/* Given room (≥1280px past the base layout, or stacked under the tabs), the
   time and who move to the right of each entry, and an entry reads as a row. */
.part-history { container-type: inline-size; }
@container (min-width: 480px) {
  .tl-filter { margin-bottom: 18px; }
  .tl-item { padding: 7px 8px 7px 2px; border-radius: 6px; }
  .tl-item:hover { background: var(--line-soft); }
  .tl-item:hover > .tl-dot { box-shadow: 0 0 0 2px var(--line-soft); }
  .tl-body { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 20px; }
  .tl-meta { grid-column: 2; grid-row: 1 / span 2; text-align: right; white-space: nowrap; padding-top: 1px; }
}
/* While it scrolls beside the tabs, each day's heading stays in view. */
@media (min-width: 1280px) {
  .tl-date { position: sticky; top: -18px; z-index: 1; background: var(--panel);
    margin: 0 -4px 2px; padding: 6px 4px 4px; }
}

/* ==========================================================================
   Responsive
   --------------------------------------------------------------------------
   Scale:  ≤599 phone (drawer + tab bar, tables become cards)
           600–899 large phone / tablet (drawer via hamburger, tables scroll)
           900–1279 laptop (sidebar returns, grid2 splits)
           ≥1280 desktop · ≥1700 wide
   The drawer is a checkbox, so navigation works with JavaScript disabled.
   ========================================================================== */

/* Doubled class on purpose: the typed control rules above are [type="…"]
   selectors, which outrank a single class — an un-doubled .vis-hidden left the
   nav-toggle checkbox laid out as a real 17px box, a bar across the top of
   every page. */
.vis-hidden, .vis-hidden.vis-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---- Hamburger + scrim (inert until the drawer breakpoint) ---- */
.navbtn {
  display: none; flex: none; align-items: center; justify-content: center;
  width: 38px; height: 38px; margin: 0 -4px 0 0; padding: 0;
  border-radius: var(--radius); color: var(--muted); cursor: pointer;
}
.feedback-open { display: inline-flex; align-items: center; gap: 6px; min-height: var(--h); }
.feedback-open svg {
  width: 15px; height: 15px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.navbtn svg, .tabbar svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.navbtn:hover { color: var(--ink); background: var(--ground); }
.navbtn:focus-visible, .tab-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.nav-scrim { display: none; }

/* ---- Phone-only bottom tab bar ---- */
.tabbar { display: none; }
.tabbar a, .tabbar .tab-more {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 7px 2px 6px; min-height: 54px; cursor: pointer;
  color: var(--muted); font-size: 10px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; text-decoration: none;
}
.tabbar a:hover { text-decoration: none; color: var(--ink); }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 1.9; }

/* ---- Tables: horizontal scroller (the universal safety net) ---- */
.table-wrap {
  overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  /* Classic pure-CSS scroll shadows: the edge fades only while there's more
     table out of view, so the row silently advertises that it scrolls. */
  background:
    linear-gradient(to right, var(--panel) 30%, transparent) 0 0 / 28px 100% no-repeat,
    linear-gradient(to left,  var(--panel) 30%, transparent) 100% 0 / 28px 100% no-repeat,
    radial-gradient(farthest-side at 0 50%,   rgba(16, 24, 21, .13), transparent) 0 0 / 11px 100% no-repeat,
    radial-gradient(farthest-side at 100% 50%, rgba(16, 24, 21, .13), transparent) 100% 0 / 11px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}
/* Only once the table has actually become cards — between 600 and 899 a
   card-eligible table is still a table, and still needs its scroller. */
.wrap-cards.is-cards { overflow: visible; background: none; }
/* initResponsiveTables() collects each labelled cell's contents into .c-val.
   Outside card mode the wrapper must be invisible to layout. */
.c-val { display: contents; }

/* ==========================  ≤1279  ====================================== */
@media (max-width: 1279px) {
  .content { max-width: none; }
}

/* ==========================  ≤899 — drawer  ============================== */
@media (max-width: 899px) {
  .navbtn { display: inline-flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh; z-index: 200;
    width: min(280px, 84vw); transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow-pop);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #nav-toggle:checked ~ .layout .sidebar { transform: translateX(0); }

  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 199;
    background: rgba(10, 16, 13, .45); opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  #nav-toggle:checked ~ .layout .nav-scrim { opacity: 1; pointer-events: auto; }
  /* Freeze the page behind an open drawer. Purely a nicety — if :has() is
     unsupported the drawer still opens and closes correctly. */
  html:has(#nav-toggle:checked) { overflow: hidden; }

  .topbar { padding: 8px var(--gutter); gap: 8px; }
  .gsearch { max-width: none; min-width: 0; }
  .feedback-open .lbl { display: none; }

}

/* ==========================  ≤599 — phone  =============================== */
@media (max-width: 599px) {
  :root { --tabbar-h: calc(54px + env(safe-area-inset-bottom)); }

  /* The markup dock: icons only, so every tool fits one row of 44px targets. */
  .markup-btns .lbl {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .markup-dock button { min-width: 44px; min-height: 44px; padding: 0; }

  /* "More" in the tab bar owns the drawer down here, so drop the hamburger. */
  .navbtn { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
    background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }

  h1 { font-size: clamp(18px, 4.6vw, 21px); }
  .panel { padding: 14px 12px; margin-bottom: 14px; }
  .pagehead { gap: 10px; }
  .pagehead .spacer { display: none; }
  .pagehead > h1, .pagehead > form, .pagehead > .formrow { width: 100%; }
  .pagehead > form.formrow { gap: 8px; }
  .pagehead > form.formrow > input[type="search"] { flex: 1 1 120px; min-width: 0; }
  .pagehead > form.formrow > select { flex: 1 1 100px; min-width: 0; }
  .pagehead > form.formrow > button { flex: 0 0 auto; }

  /* Unfolded on a phone, the bar's filters and the header's filter row (a
     card of its own) stack full width. */
  .listbar { flex-direction: column; align-items: stretch; }
  .listbar .fin, .listbar input.fin { width: 100%; max-width: none; }
  .listbar .ftoggle { align-self: flex-start; }
}
table.is-cards thead { display: block; }
table.is-cards thead tr:not(.filter-row) { display: none; }
table.is-cards thead tr.filter-row { display: none; margin-bottom: 12px; }
.filters-toggle:checked ~ * table.is-cards thead tr.filter-row { display: block; }
/* Top-aligned: an open dropdown makes the cell tall, and a centred label
   would slide down beside it. */
table.is-cards thead tr.filter-row td { padding: 5px 0; border: 0; align-items: flex-start; }
/* One label column, so every filter starts on the same edge. */
table.is-cards thead tr.filter-row td::before { flex: 0 0 92px; padding-top: 14px; }
table.is-cards thead tr.filter-row td.fc-empty { display: none; }
table.is-cards thead tr.filter-row td > * { flex: 1 1 60%; min-width: 0; }
@media (max-width: 599px) {
  .fin { height: auto; min-height: var(--tap); font-size: 16px; }
  .fpop-row input { width: 100%; }
  .fpop-row label { flex: 1; }

  /* Pager: prev / "3 / 13" / next across the width; numbered links go. */
  .pager { gap: 10px; }
  .pager-count { flex: 1 1 100%; }
  .pager-pages { flex: 1 1 100%; justify-content: space-between; }
  .pager-pages .pg.num, .pager-pages .pg.gap { display: none; }
  .pager-pages .pg.pos { display: inline-flex; }
  .pager-per { margin-left: 0; }

  /* Forms stack: text fields take the row, numeric fields stay narrow so a
     qty and its unit still read as one thing. */
  .formrow > .field { flex: 1 1 100%; min-width: 0; }
  .formrow > .field:has(input.qty), .formrow > .field:has(input.money) { flex: 0 0 auto; }
  .formrow > .field input:not(.qty, .money, [type="checkbox"], [type="radio"]),
  .formrow > .field select, .formrow > .field textarea { width: 100%; }
  .ppicker, .combo { display: block; width: 100%; }
  .ppicker input, .combo input { width: 100%; }   /* beat the min(240px,…) cap */

  .wotree ul { padding-left: 12px; }

  /* A unit's card: the equation on one line under its label. The new unit's
     wraps, its select full width. */
  .uom-eq { white-space: normal; flex-wrap: wrap; }
  .uom-add .formrow > .field:has(.uom-eq) { flex: 1 1 100%; min-width: 0; }
  .uom-table input.uom-code { width: 100%; }
}
table.is-cards.uom-table td.uom-def > .c-val { flex-basis: 100%; text-align: left; }
@media (max-width: 599px) {
  .uom-table .uom-eq { flex-wrap: nowrap; }
  .uom-table .uom-eq .lead { min-width: 0; text-align: left; }
  .uom-table .uom-eq input.uom-factor { flex: 1 1 0; min-width: 0; width: auto; }
  .uom-table .uom-eq select.uom-ref,
  .uom-table .uom-eq input.uom-factor:disabled + select.uom-ref { flex: 1 1 0; min-width: 0; width: auto; }
  .uom-table tr.uom-first > td { border-top: none; }
}

/* ---- Row-per-card tables ----
   initResponsiveTables() copies each <th> onto its cells as data-label, so
   this works on every current and future table without template churn. */
table.is-cards, table.is-cards tbody, table.is-cards tr, table.is-cards td { display: block; }
.sortbar:has(+ .table-wrap.is-cards) { display: flex; }
table.is-cards tr {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-raised); padding: 10px 12px; margin-bottom: 10px;
}
table.is-cards tr:last-child { margin-bottom: 0; }
table.is-cards.loctree tr { margin-left: calc(var(--depth, 0) * 14px); }
table.is-cards.loctree .loc-name { padding-left: 0; }
table.is-cards.loctree tr.folder { background: color-mix(in srgb, var(--line-soft) 45%, var(--panel)); }
table.is-cards.loctree tr.folder td { background: none; }
table.is-cards.loctree .loc-actions > div { justify-content: flex-start; min-width: 0; }
table.is-cards.loctree span.loc-act { display: none; }
table.is-cards.loctree .loc-name { white-space: normal; }
table.is-cards tbody tr:hover td { background: none; }
table.is-cards tr.late { border-color: var(--crit); background: var(--crit-soft); }
table.is-cards tr.late > td { background: none; box-shadow: none; }
table.is-cards .contact { align-items: flex-end; }
table.is-cards td {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 2px 14px;
  padding: 4px 0; border: none; text-align: left; overflow-wrap: anywhere;
}
/* One flex item for the whole value: badges and links wrap inside it rather
   than each being shrunk to a single character. The flex-basis lets a long
   value drop onto its own full-width line when it can't sit beside a label. */
table.is-cards td:not(.c-title) > .c-val {
  display: block; flex: 1 1 62%; min-width: 0; text-align: right;
}
table.is-cards td { width: auto !important; } /* a column width set inline means nothing on a card */
table.is-cards td::before {
  content: attr(data-label); flex: none; font-family: var(--sans);
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted);
}
table.is-cards td.c-plain::before, table.is-cards td.c-title::before,
table.is-cards td.c-check::before { content: none; }
table.is-cards tr { position: relative; }
table.is-cards td.c-check {
  position: absolute; top: 9px; right: 11px; display: block; padding: 0;
}
table.is-cards td.c-empty, table.is-cards td.c-hide { display: none; }
/* The identifying cell leads the card at full width, like a card heading. */
table.is-cards td.c-title {
  display: block; font-size: 15px; padding: 0 44px 6px 0;
  border-bottom: 1px solid var(--line-soft); margin-bottom: 6px;
}
table.is-cards td.c-title .mono { font-size: 15px; }
table.is-cards td.num { font-size: 14px; justify-content: space-between; }
/* Action cells (buttons, checkboxes) get room rather than a cramped column. */
table.is-cards td.c-actions { justify-content: flex-start; flex-wrap: wrap; gap: 8px;
  padding-top: 8px; }
table.is-cards td.c-actions::before { flex-basis: 100%; }

/* Cards wider than a phone (a table with data-cards-below, on a tablet):
   the fields sit two abreast, so a card is half as tall and a value isn't a
   panel's width away from its label. */
@media (min-width: 600px) {
  table.is-cards tbody tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 36px; align-items: center; }
  table.is-cards tbody td:is(.c-title, .c-actions, .c-plain) { grid-column: 1 / -1; }
  table.is-cards tbody td::before { white-space: nowrap; }
  table.is-cards tbody td:not(.c-title) > .c-val { flex: 1 1 0; }
}
/* ---- Compact cards ----
   A list a phone is used to look things up in gets its own card rather than
   a label per line: the identity, then the figures side by side. A quantity
   carries its unit (data-unit on the cell), so "8 ea" is one thing. The
   whole card opens the record; the checkbox sits above that link. */
table.is-cards:is(.partcards, .stockcards) tr {
  display: flex; flex-wrap: wrap; align-items: baseline;
  padding: 10px 12px; margin-bottom: 8px;
  transition: border-color .12s, background-color .12s;
}
table.is-cards:is(.partcards, .stockcards, .linecards) tbody td {
  display: block; padding: 0; margin: 0; border: 0; min-width: 0; font-size: 14px;
}
table.is-cards:is(.partcards, .stockcards, .linecards) tbody td::before { content: none; }
table.is-cards:is(.partcards, .stockcards, .linecards) tbody td > .c-val {
  display: inline; flex: none; text-align: inherit;
}
table.is-cards:is(.partcards, .stockcards, .linecards) tbody td:is(.c-hide, .c-plain) { display: none; }
table.is-cards:is(.partcards, .stockcards, .linecards) tbody td.c-plain[colspan] { display: block; }
table.is-cards:is(.partcards, .stockcards, .linecards) td[data-unit]::after {
  content: "\00a0" attr(data-unit);
  font: 400 12.5px/1 var(--sans); color: var(--muted);
}
table.is-cards:is(.partcards, .stockcards) a.mono { font-size: 15px; font-weight: 700; }
table.is-cards:is(.partcards, .stockcards) a.mono::after { content: ""; position: absolute; inset: 0; }
table.is-cards:is(.partcards, .stockcards) tr:active { border-color: var(--accent); }
@media (max-width: 599px) {
  .hometag {
    display: inline-block; margin-left: 4px; padding: 0 6px; border: 1px solid var(--line);
    border-radius: 999px; font-size: 10.5px; line-height: 16px; vertical-align: 1px;
  }
}

/* A part: number + type, description, then on hand / demand / on order. */
table.is-cards.partcards td.pc-num { order: 1; max-width: calc(100% - 40px); }
table.is-cards.partcards td.pc-type { order: 2; margin-left: auto; padding-left: 10px; }
table.is-cards.partcards tr:has(td.c-check) td.pc-type { margin-right: 34px; }
table.is-cards.partcards td.pc-desc { order: 3; flex: 0 0 100%; margin-top: 1px; color: var(--ink); }
table.is-cards.partcards td.pc-stat {
  order: 5; flex: 1 1 30%; display: grid; grid-template-columns: auto 1fr;
  align-items: baseline; justify-content: start; gap: 0; margin-top: 8px; padding-top: 7px;
  border-top: 1px solid var(--line-soft);
  font-size: 16px; font-weight: 600; color: var(--ink-strong);
}
table.is-cards.partcards td.pc-onhand { order: 4; }
table.is-cards.partcards td.pc-onorder { order: 6; }
table.is-cards.partcards td.pc-stat::before {
  content: attr(data-label); grid-row: 2; grid-column: 1 / -1; margin-top: 1px;
  font: 600 10px/1.5 var(--sans); text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted);
}
table.is-cards.partcards td.pc-stat.c-empty > .c-val::after { content: "—"; }
table.is-cards.partcards td:is(.pc-zero, .c-empty) > .c-val { color: var(--muted); font-weight: 400; }
table.is-cards.partcards td.shortqty { color: var(--crit); }
/* Centred on the number's line; its right edge on the card's padding. */
table.is-cards.partcards td.c-check { top: 10px; right: 12px; z-index: 1; line-height: 0; }
table.is-cards.partcards td.c-check input { vertical-align: top; margin: 0; }
table.is-cards.partcards td.c-check::after { content: ""; position: absolute; inset: -10px; z-index: -1; }
table.is-cards.partcards tr:has(td.c-check input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--panel-raised));
}

/* A stock row: part and description, the quantity on the right, its bin under. */
table.is-cards.stockcards td.sc-part { order: 1; margin-right: 8px; }
table.is-cards.stockcards td.sc-desc { order: 2; flex: 1 1 0; }
table.is-cards.stockcards td.sc-qty {
  order: 3; margin-left: 12px; white-space: nowrap;
  font-size: 16px; font-weight: 600; color: var(--ink-strong);
}
table.is-cards.stockcards td.sc-loc {
  order: 4; flex: 0 0 100%; margin-top: 2px;
  font-size: 12.5px; color: var(--muted);
}

/* A short two-column table (a part's bins): one line each, name … figure,
   ruled rather than boxed. Too few rows to need the sort control. */
table.is-cards.linecards tr {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 9px 0; margin: 0; border: 0; border-radius: 0; background: none;
  border-bottom: 1px solid var(--line-soft);
}
table.is-cards.linecards tr:last-child { border-bottom: 0; }
table.is-cards.linecards td.num {
  flex: none; white-space: nowrap; font-size: 16px; font-weight: 600; color: var(--ink-strong);
}
.sortbar:has(+ .table-wrap > table.linecards) { display: none; }
@media (max-width: 599px) {

  /* Search results: number, type and stock on one line, the name under it. */
  table.results, table.results tbody { display: block; }
  table.results tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px;
    padding: 10px 2px; border-bottom: 1px solid var(--line-soft); }
  table.results td { display: block; padding: 0; border: 0; }
  table.results td.res-name { order: 5; flex: 1 1 100%; }
  table.results td:last-child:not(:first-child) { margin-left: auto; }
  /* Bulk actions stay out of the way until a card is ticked, then float
     above the tab bar, where the thumb is, without moving the list. */
  .selbar { display: none; }
  .panel:has(tbody input[type="checkbox"]:checked) .selbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    position: fixed; z-index: 140; left: var(--gutter); right: var(--gutter);
    bottom: calc(10px + var(--tabbar-h));
    padding: 7px 7px 7px 14px; border: 1px solid var(--accent); border-radius: 12px;
    background: var(--panel-raised); box-shadow: var(--shadow-pop);
  }
  .selbar [data-sel-count] { font-weight: 600; color: var(--ink-strong); }
  .selbar .btn-sm, .selbar button { padding-inline: 12px; }
  .selbar [data-sel-required]:not(.btn-danger) {
    background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  }
  .panel:has(.selbar):has(tbody input[type="checkbox"]:checked) { margin-bottom: 76px; }
  /* The toolbar's own line: Filters and Saved views, half the width each,
     over the sort control, with one rhythm between the rows. */
  .listtools { gap: 10px 8px; margin-bottom: 10px; padding-bottom: 0; border-bottom: 0; }
  .listtools .tools-right { flex: 1 1 100%; margin-left: 0; }
  .listtools .tools-right > * { flex: 1 1 50%; min-width: 0; }
  .listtools .filters-btn { justify-content: center; }
  .listtools .views-menu > summary { display: block; text-align: center; }
}

/* ==========================  touch  ====================================== */
/* A phone-width window gets the same sizing whatever points at it: the phone
   layout is built around 44px controls, and a narrow desktop window (or a
   preview pane) otherwise mixed 27, 35, 36 and 40px ones in a row. */
@media (pointer: coarse), (max-width: 599px) {
  :root { --ctl: var(--tap); --ctl-sm: var(--tap); }
  button, summary, .fin { min-height: var(--tap); }
  /* A plain fold heading is a list item, which puts its text at the top of a
     taller box: padding makes up the height instead, so it sits mid-target. */
  summary:not([class]) { padding-block: calc((var(--tap) - 1.5em) / 2); }
  .topbar :is(.feedback-open, .recnav-step) { --h: var(--tap); }
  /* 16px is the threshold below which iOS Safari force-zooms on focus. */
  input, select, textarea, input.qty, input.money, input.mono, .loctree .loc-path { font-size: 16px; }
  input.qty { width: 100px; }
  input.money { width: 124px; }
  .listtools .filters-btn { font-size: 13px; }
  /* A "small" button is only small in ink — it still gets a full target. */
  /* min-width catches the glyph-only buttons ("✕", "＋") that are otherwise
     a comfortable height and an uncomfortable 20px wide. */
  .btn-sm, .tablebar :is(button, .btn) { min-width: var(--tap); padding-inline: 14px; font-size: 13px; }
  .feedback-open { min-width: var(--tap); text-align: center; }
  /* 24px is the WCAG 2.2 SC 2.5.8 minimum; a checkbox scaled to 44 looks
     broken, and the row padding around it carries the rest of the target. */
  input[type="checkbox"], input[type="radio"] {
    width: 24px; height: 24px; vertical-align: -7px;
  }
  .theme-toggle { width: var(--tap); height: var(--tap); }
  .pg { min-width: var(--tap); height: var(--tap); }
  .chip { min-height: 36px; padding: 4px 10px 4px 14px; }
  .views-menu .menu-row > a { padding: 12px 10px; }
  .views-menu .menu-del { min-width: var(--tap); }
  /* Sorting is a primary action on a tablet, so the heading gets a full
     target rather than the 15px of ink it draws. */
  th > .th-sort { min-height: var(--tap); min-width: var(--tap); }
  .uom-actions { gap: 10px; }

  .sidebar nav a { padding-top: 11px; padding-bottom: 11px; }
  .sidebar .userbox button { min-height: var(--tap); }
  /* Same opt-out as .att-remove: the blanket 44px would stretch this square
     into an oval, and a 44px bordered box per row makes a deep BOM unreadable.
     Keep 30px of ink; the ::after carries the target out to 44. */
  .loctree .toggle {
    position: relative; min-width: 0; min-height: 0;
    width: 30px; height: 30px; line-height: 27px; font-size: 13px;
  }
  .loctree .toggle::after { content: ""; position: absolute; inset: -7px; }
  /* The BOM's chevron stays 20px of ink, or a deep branch runs out of room. */
  .bomtree button.toggle::after { content: ""; position: absolute; inset: -12px; }
  .loctree .twisty { width: 38px; }
  .loctree .loc-add { opacity: 1; width: 30px; height: 30px; line-height: 28px; border-color: var(--line); }
  .loctree .loc-add::after { content: ""; position: absolute; inset: -7px; }
  .ppicker .opts div, .combo .opts div { padding: 12px 12px; }
  .gsearch .results a { padding: 12px; }
  /* Hover-only reveals are unreachable without a mouse. */
  .attachment .att-remove {
    /* Explicitly opt out of the blanket 44px button sizing above — left alone
       it stretches this badge into an oval that covers the thumbnail. */
    display: block; min-width: 0; min-height: 0;
    width: 28px; height: 28px; top: -8px; right: -8px; font-size: 15px; line-height: 26px;
  }
  /* Keep the badge small but the target big: the ::after extends the hit area
     to ~46px without inflating the glyph over a 56px thumbnail. */
  .attachment .att-remove::after { content: ""; position: absolute; inset: -8px; }
}

/* ==========================  dialogs → bottom sheets  ==================== */
@media (max-width: 599px) {
  .feedback-dialog, .create-dialog {
    width: 100%; max-width: 100%; margin: 0 auto;
    position: fixed; inset: auto 0 0 0;
    border-radius: 14px 14px 0 0; border-bottom: none;
    max-height: 92dvh; overflow-y: auto; padding: 18px 16px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .feedback-dialog .formrow, .create-dialog .formrow { gap: 10px; }
}

/* ==========================  ≥1700 — wide desktop  ======================= */
@media (min-width: 1700px) {
  /* Data-dense tables earn the extra width; the cap only stops prose from
     running to 200 characters a line. */
  .content { max-width: 1560px; }
}
/* A markup is read, not recognised: show it big enough to read. */
#markups .attachment img { width: 320px; max-width: 100%; height: auto; object-fit: contain; }
input.rev { width: 110px; font-family: var(--mono); }

/* ====================  Suggestions (feedback*.html)  ===================== */
/* A suggestion's status is a pill: a soft wash of its tone with a solid dot.
   The tones are the app's own (suggestions.STATUS picks one per status). */
.sg-pill {
  --t: var(--muted); --t-soft: var(--line-soft);
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px;
  border-radius: 999px; background: var(--t-soft); color: var(--t);
  font-size: 12px; font-weight: 600; line-height: 1.3; white-space: nowrap;
}
.sg-pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.sg-pill.sm { font-size: 11px; padding: 1px 8px 1px 6px; gap: 5px; }
.sg-pill.sm i { width: 6px; height: 6px; }
.tone-info   { --t: var(--info);   --t-soft: var(--info-soft); }
.tone-warn   { --t: var(--warn);   --t-soft: var(--warn-soft); }
.tone-violet { --t: var(--violet); --t-soft: var(--violet-soft); }
.tone-accent { --t: var(--accent); --t-soft: var(--accent-soft); }
.tone-ok     { --t: var(--ok);     --t-soft: var(--ok-soft); }
.tone-crit   { --t: var(--crit);   --t-soft: var(--crit-soft); }
.tone-muted  { --t: var(--muted);  --t-soft: var(--line-soft); }
.sg-id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sg-flag {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--copper);
}
.sg-flag.reply { color: var(--violet); }
.sg-avatar {
  display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong);
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
}

/* ---- The list ---- */
.sg-pagehead { align-items: flex-end; }
.sg-pagehead h1 { margin-bottom: 4px; }
.sg-lede { margin: 0; max-width: 60ch; }
.sg-pagehead .feedback-open svg { width: 16px; height: 16px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; margin-right: 6px; vertical-align: -3px; }
.sg-tabs {
  display: flex; gap: 2px; margin: 0 0 14px; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.sg-tabs::-webkit-scrollbar { display: none; }
.sg-tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 12px 10px;
  color: var(--muted); font-weight: 600; font-size: 13.5px; white-space: nowrap;
  box-shadow: inset 0 -2px transparent; min-height: var(--ctl);
}
.sg-tab:hover { color: var(--ink); text-decoration: none; }
.sg-tab.on { color: var(--ink-strong); box-shadow: inset 0 -2px var(--accent); }
.sg-tab-n {
  min-width: 20px; padding: 0 6px; border-radius: 9px; background: var(--line-soft);
  color: var(--muted); font-size: 11px; line-height: 18px; text-align: center;
}
.sg-tab.on .sg-tab-n { background: var(--accent-soft); color: var(--accent-strong); }
.sg-tab-n.hot { background: var(--copper); color: #fff; }
.sg-tab.on .sg-tab-n.hot { background: var(--copper); color: #fff; }
.sg-sort { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--radius);
  background: var(--line-soft); }
.sg-sort a { padding: 3px 10px; border-radius: 4px; color: var(--muted); font-size: 12.5px;
  font-weight: 600; line-height: calc(var(--ctl-sm) - 10px); }
.sg-sort a:hover { color: var(--ink); text-decoration: none; }
.sg-sort a.on { background: var(--panel-raised); color: var(--ink-strong); box-shadow: var(--shadow); }

.sg-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.sg-card {
  position: relative; padding: 14px 16px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel-raised);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.sg-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: var(--shadow); }
.sg-card:has(.sg-card-title:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.sg-card.is-unseen { box-shadow: inset 3px 0 var(--copper); }
.sg-card.is-reply { box-shadow: inset 3px 0 var(--violet); background:
  linear-gradient(90deg, var(--violet-soft), var(--panel-raised) 60%); }
.sg-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.sg-card-top .sg-id { margin-left: auto; }
.sg-card-title {
  display: block; color: var(--ink-strong); font-size: 15.5px; font-weight: 650;
  line-height: 1.35; text-wrap: pretty;
}
.sg-card-title:hover { color: var(--ink-strong); text-decoration: none; }
.sg-card-title:focus-visible { outline: none; }
.sg-card-title::after { content: ""; position: absolute; inset: 0; border-radius: 8px; }
.sg-excerpt {
  margin: 4px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  white-space: pre-line;
}
.sg-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 10px;
  color: var(--muted); font-size: 12.5px;
}
.sg-who { display: inline-flex; align-items: center; gap: 7px; color: var(--ink); font-weight: 500; }
.sg-page { font-size: 11.5px; }
.sg-count { display: inline-flex; align-items: center; gap: 4px; }
.sg-count svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linejoin: round; }
.sg-assess { display: inline-flex; gap: 6px; margin-left: auto; }
.sg-verdict, .sg-rec {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 4px;
  font-size: 11.5px; font-weight: 600; border: 1px solid currentColor;
}
.sg-verdict.v-safe { color: var(--ok); }
.sg-verdict.v-suspicious { color: var(--warn); }
.sg-verdict.v-malicious { color: var(--crit); background: var(--crit-soft); }
.sg-verdict.v-safe::before { content: "✓"; }
.sg-verdict.v-suspicious::before, .sg-verdict.v-malicious::before { content: "!"; font-weight: 800; }
.sg-rec.r-implement { color: var(--accent); }
.sg-rec.r-defer { color: var(--info); }
.sg-rec.r-skip { color: var(--muted); }
.sg-empty { display: grid; justify-items: center; gap: 4px; padding: 44px 16px 36px;
  text-align: center; color: var(--muted); }
.sg-empty svg { width: 44px; height: 44px; fill: none; stroke: var(--copper); stroke-width: 1.3;
  stroke-linecap: round; stroke-linejoin: round; margin-bottom: 6px; }
.sg-empty p { margin: 0; max-width: 46ch; }
.sg-empty b { color: var(--ink); }

/* ---- One suggestion ---- */
.sg-back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 14px;
  color: var(--muted); font-size: 13px; font-weight: 600; min-height: 28px; }
.sg-back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.sg-detail-head { margin-bottom: 20px; }
.sg-detail-head .sg-card-top { margin-bottom: 10px; }
.sg-detail-head .sg-card-top .sg-id { margin-left: 0; }
.sg-detail-head h1 { font-size: 24px; line-height: 1.25; margin: 0 0 8px; max-width: 40ch; }
.sg-byline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 0; }
.sg-byline b { color: var(--ink); }
.sg-byline .mono { font-size: 12.5px; }
.sg-callout {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 18px;
  padding: 12px 16px; border-radius: 8px; background: var(--t-soft); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--t) 30%, transparent);
}
.sg-callout b { color: var(--t); }
.sg-callout a { margin-left: auto; font-weight: 600; color: var(--t); }

.sg-layout { display: grid; gap: 24px; align-items: start; }
@media (min-width: 1100px) {
  .sg-layout { grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; }
  .sg-side { position: sticky; top: 72px; }
}
.sg-main { min-width: 0; }

.sg-timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.sg-timeline::before {
  content: ""; position: absolute; left: 15px; top: 16px; bottom: 16px; width: 2px;
  background: var(--line);
}
.sg-ev { position: relative; display: flex; gap: 14px; padding-bottom: 20px; }
.sg-ev-dot { position: relative; z-index: 1; width: 32px; height: 32px; font-size: 11.5px;
  box-shadow: 0 0 0 4px var(--ground); }
.sg-ev-dot.is-admin { background: var(--ink-strong); color: var(--panel); }
.sg-ev-dot.is-bot { background: var(--violet-soft); color: var(--violet); }
.sg-ev-dot.is-bot svg { width: 18px; height: 18px; fill: currentColor; }
.sg-ev-mark { display: grid; place-items: center; flex: none; background: var(--ground);
  border-radius: 50%; }
.sg-ev-mark::after { content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: var(--t); box-shadow: 0 0 0 4px var(--t-soft); }
.sg-ev-body { flex: 1; min-width: 0; padding-top: 5px; }
.sg-ev.is-status .sg-ev-body { padding-top: 6px; }
.sg-ev-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
  color: var(--muted); font-size: 13px; }
.sg-ev-head b { color: var(--ink-strong); font-weight: 650; }
.sg-ev-head time { font-size: 12px; }
.sg-private {
  padding: 0 7px; border-radius: 4px; border: 1px dashed var(--violet); color: var(--violet);
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
}
.sg-bubble {
  margin-top: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-raised); white-space: pre-wrap; overflow-wrap: anywhere;
  line-height: 1.55; font-size: 14px;
}
.sg-bubble.sg-quote { font-size: 15px; border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
  box-shadow: var(--shadow); }
.sg-bubble.is-question { background: var(--violet-soft); border-color: color-mix(in srgb, var(--violet) 35%, transparent); }
.sg-ev.is-internal .sg-bubble { border-style: dashed; border-color: color-mix(in srgb, var(--violet) 45%, var(--line));
  background: color-mix(in srgb, var(--violet-soft) 45%, var(--panel-raised)); }
.sg-ev.is-unseen .sg-bubble { box-shadow: inset 3px 0 var(--copper); }
.sg-shots { margin-top: 10px; }
.sg-shots .attachment img { height: 88px; max-width: 180px; border-radius: 6px; border: 1px solid var(--line); }

.sg-composer {
  margin: 4px 0 0 46px; padding: 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel);
}
.sg-composer.is-reply { border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-soft); }
.sg-composer textarea { width: 100%; resize: vertical; min-height: 76px; display: block; }
.sg-composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.sg-composer-row .spacer { flex: 1; }
.sg-withdraw { margin: 14px 0 0 46px; }
.sg-closed { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 4px 0 0 46px; }

.sg-side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.sg-side-card { padding: 16px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); box-shadow: var(--shadow); }
.sg-side-card h2 { margin-bottom: 12px; }
.sg-side-card > :last-child { margin-bottom: 0; }
.sg-steps { list-style: none; margin: 0; padding: 0; }
.sg-steps li {
  position: relative; padding: 0 0 16px 28px; color: var(--muted); font-size: 13.5px; font-weight: 500;
}
.sg-steps li:last-child { padding-bottom: 0; }
.sg-steps li::before {
  content: ""; position: absolute; left: 0; top: 1px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--panel); box-sizing: border-box;
}
.sg-steps li:not(:last-child)::after {
  content: ""; position: absolute; left: 7px; top: 19px; bottom: 1px; width: 2px; background: var(--line);
}
.sg-steps li.done { color: var(--ink); }
.sg-steps li.done::before { border-color: var(--accent); background: var(--accent)
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 8.2l2.3 2.3 4.7-4.8' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat; }
.sg-steps li.done:not(:last-child)::after { background: var(--accent); }
.sg-steps li.current { color: var(--ink-strong); font-weight: 650; }
.sg-steps li.current::before { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
  background: radial-gradient(circle, var(--accent) 3px, var(--panel) 3.5px); }
.sg-steps li.end { color: var(--t); font-weight: 650; }
.sg-steps li.end::before { border-color: var(--t); background: var(--t-soft); }
.sg-steps small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 400; }

.sg-facts { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; margin: 0 0 10px;
  align-items: center; font-size: 13px; }
.sg-facts dt { color: var(--muted); }
.sg-facts dd { margin: 0; display: flex; align-items: center; gap: 8px; }
.sg-effort { display: inline-flex; gap: 3px; }
.sg-effort i { width: 6px; height: 14px; border-radius: 2px; background: var(--line); }
.sg-effort i.on { background: var(--copper); }
.sg-decide textarea { width: 100%; resize: vertical; display: block; font-size: 13.5px; line-height: 1.5; }
.sg-drafted { margin: 6px 0 0; padding-left: 20px; color: var(--violet); font-size: 12px; position: relative; }
.sg-drafted::before { content: "✦"; position: absolute; left: 4px; }
.sg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 10px; }
.sg-actions button { flex: 1 1 auto; }
.sg-decide p.small { margin: 0; }
.sg-flag-btn {
  margin-top: 12px; padding: 0; border: 0; background: none; color: var(--crit);
  font-size: 12.5px; font-weight: 600; cursor: pointer; min-height: 28px;
}
.sg-flag-btn:hover { text-decoration: underline; }
.sg-others { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; font-size: 13px; }
.sg-others li { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.sg-others .sg-pill { flex: none; }
.sg-others a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 599px) {
  .sg-pagehead .feedback-open { width: 100%; justify-content: center; }
  .sg-detail-head h1 { font-size: 20px; }
  .sg-composer, .sg-withdraw, .sg-closed { margin-left: 0; }
  .sg-assess { margin-left: 0; }
  .sg-card { padding: 12px 14px; }
}
@media print {
  .sg-composer, .sg-withdraw, .sg-decide, .sg-back, .sg-tabs, .sg-sort { display: none; }
  .sg-layout { display: block; }
}

/* ===============================  Print  ================================ */
/* Orders print as PDFs (documents.py); this is for printing a page as it
   looks — a stock list, a part's BOM. Light ink on white whatever the theme,
   none of the chrome, nothing that only works on screen. Last in the file so
   it outranks every breakpoint above. */
@media print {
  :root, :root[data-theme] {
    color-scheme: light;
    --ground: #fff; --panel: #fff; --panel-raised: #fff;
    --ink: #000; --ink-strong: #000; --muted: #4a544f;
    --line: #c4cbc6; --line-soft: #dde2de;
    --accent: #0f5c43; --accent-strong: #0f5c43; --accent-ink: #fff;
    --accent-soft: #e2efe9; --copper: #af6234;
    --ok: #1c7a3d; --ok-soft: #e2f1e6; --warn: #a3660a; --warn-soft: #f8eeda;
    --crit: #b3362b; --crit-soft: #f9e8e5; --info: #23617e; --info-soft: #e3eef4;
    --violet: #5b4a9e; --violet-soft: #ebe7f6;
    --shadow: none; --shadow-pop: none;
    --tabbar-h: 0px;
  }
  body { background: #fff; font-size: 11pt; }
  /* Chrome and controls. A sortable table's headings are buttons, so they stay. */
  .sidebar, .topbar, .tabbar, .devbar, .nav-scrim, .savebar, dialog, .lightbox,
  .listbar, .tools-right, .chip-clear, thead tr.filter-row, .pager-pages, .pager-per,
  button:not(.th-sort), .btn, [data-save], .flash[data-flash], .no-print,
  /* Forms for adding something (a line, a part, a supplier, a document) are
     .formrow forms, and so is their heading's next sibling. A tracked form
     holds a record's values, so it prints. */
  form.formrow:not([data-track-changes]),
  :is(h2, h3):has(+ form.formrow:not([data-track-changes])),
  /* What's folded on screen stays folded; an open one loses its handle. */
  details:not([open]), summary,
  /* Fields there's nothing to read in: an upload, a typeahead, an empty box. */
  input[type="file"], .field:has(input[type="file"]), .att-add, .ppicker,
  .field:has(> :is(input, textarea):placeholder-shown),
  .field:has(> input[value=""]), .field:has(> textarea:empty), .field:has(> .ppicker),
  .field:has(> input:not([value], [type="checkbox"], [type="radio"], [type="hidden"])),
  .markup-dock, [data-sel-count],
  /* A part prints the tab on screen; its history is for finding things. */
  .tablist, .part-history { display: none !important; }
  .part-layout { display: block; }
  th > .th-sort::after { content: none !important; }
  /* Printers drop background colours unless asked, and a checked box is a
     white tick on an accent fill: draw it in ink on white instead. */
  input[type="checkbox"], input[type="radio"] {
    background: #fff !important; border: 1.5px solid var(--ink) !important;
    outline: none !important; box-shadow: none !important;
  }
  input[type="checkbox"]:checked::after { border-color: var(--ink); }
  input[type="checkbox"]:indeterminate::after { background: none; height: 0; border-top: 2px solid var(--ink); }
  input[type="radio"]:checked::after { background: none; border: 5px solid var(--ink); }
  /* What the list is filtered to, as plain outlined chips, only when it is
     (the screen hides them while the filter bar is open; paper has no bar). */
  .listtools:not(:has(.chip)) { display: none !important; }
  .listtools { border: 0; padding: 0; margin-bottom: 8pt; }
  .fchips::before { content: "Filtered by"; font-size: 12.5px; font-weight: 600; }
  .listtools .chip {
    display: inline-flex !important; background: none; color: var(--ink);
    border: 1px solid var(--muted); padding: 1px 8px;
  }
  .chip > span[aria-hidden] { display: none; }
  .layout { display: block; min-height: 0; }
  .content { padding: 0; max-width: none; }
  .panel { border: none; padding: 0; margin-bottom: 14pt; box-shadow: none; }
  .table-wrap { overflow: visible; background: none; }
  table { break-inside: auto; }
  tr, img { break-inside: avoid; }
  thead { display: table-header-group; }   /* repeated on every page */
  h1, h2 { break-after: avoid; }
  a { color: inherit; }
  /* A field prints as the value it holds, not as a box to type into. */
  input:not([type="checkbox"], [type="radio"]), select, textarea {
    border: 0 !important; background: none !important; box-shadow: none !important;
    padding-left: 0 !important; padding-right: 0 !important;
    min-height: 0; height: auto; appearance: none; resize: none; color: var(--ink);
    field-sizing: content; min-width: 0 !important; max-width: 100%; font-size: inherit;
  }
  input:not([type="checkbox"], [type="radio"]), select { width: auto !important; }
  .field input, .field select { text-align: left; }
  td input:not([type="checkbox"], [type="radio"]) { max-width: 9em; }   /* can't wrap */
  th, td { padding-left: 5px !important; padding-right: 5px !important; }
  input::-webkit-calendar-picker-indicator { display: none; }
  ::placeholder { color: transparent !important; }
  /* BOM tree. Its fold chevrons are buttons, but they hold the name's indent
     (hidden, an assembly sat left of its own siblings) and say what's folded
     shut, so they print. Tints don't: the verdict and the stock pills are
     outlined instead, a shortage in a heavier line so it reads without colour. */
  .bomtree button.toggle { display: block !important; }
  .bomtree .node { break-inside: avoid; }
  .bom-summary, .bom-summary.short {
    background: none; border: 1px solid var(--muted); padding: 6px 10px;
  }
  .bom-summary.short { border: 1.5px solid var(--crit); }
  .bom-pill, .bom-pill.short, .bom-pill.off {
    background: none; border: 1px solid currentColor; padding: 0 7px;
  }
  .bom-pill.short { border-width: 1.5px; }
  .bom-pill.off { border-style: dashed; }
  /* "Short only" hides rows on paper as on screen, so the sheet says so. */
  .bomtree.only-short .bom-cost::after { content: " · Short lines only"; font-weight: 600; color: var(--ink); }
  .bomtree .is-short .c-have { text-decoration: underline; }
  /* A sheet is narrower than the wide layout needs, and paper has no tooltip
     for the unit the tight one drops: tight columns, with room for the unit. */
  @container bom (min-width: 540px) {
    .bomtree .node, .bom-head {
      grid-template-columns: minmax(0, 1fr) 64px 42px 44px 56px 82px 70px; column-gap: 8px;
    }
    .bom-head { letter-spacing: .03em; }
    .bomtree .uom { display: inline; }
    .bomtree .figs > span, .bomtree .c-cost { font-size: 12px; }
  }
}
