:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --ok: #2fa84f;
  --pending: #b8860b;
  --err: #d33;
  --border: #d2d2d7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --card: #2c2c2e;
    --text: #f5f5f7;
    --muted: #9a9a9e;
    --border: #3a3a3c;
  }
}
/* Shared brand header — logo mark + product name, separated by a thin
   rule (2026-08-22: same cluster on every page, not just home.html).
   home.html uses the full size; the 3 tool pages use .brand-header-sub
   (75% of the full size — a lighter touch since those pages already have
   their own h1 below it). */
.brand-header {
  display: flex;
  align-items: center;
  gap: 28px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.brand-header .brand-logo-mark { height: 40px; width: auto; display: block; }
/* The source PDF is solid black ink — invert for dark mode so it isn't
   invisible against a dark background. */
@media (prefers-color-scheme: dark) {
  .brand-header .brand-logo-mark { filter: invert(1); }
}
.brand-header .brand-logo-suite {
  font-size: 26px;
  font-weight: 600;
  color: var(--muted);
  padding-left: 28px;
  border-left: 1px solid var(--border);
}
/* 75% of the values above. */
.brand-header.brand-header-sub {
  gap: 21px;
  margin-bottom: 18px;
  padding-bottom: 15px;
}
.brand-header-sub .brand-logo-mark { height: 30px; }
.brand-header-sub .brand-logo-suite { font-size: 19.5px; padding-left: 21px; }

/* The 3 tool pages' logo cluster doubles as the "go home" link (2026-08-22
   request — Trang chủ moved out of .step-nav, up into the header) — plain
   inherited colors/no underline so it still just looks like the logo, not
   a normal blue text link. */
.brand-header-link {
  display: flex;
  align-items: center;
  gap: inherit;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
}
.brand-header-link:hover .brand-logo-suite { color: var(--accent); }
.brand-header-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* Injected by authClient.js into .brand-header on every logged-in page —
   pushed to the far right via margin-left:auto so it never disturbs the
   logo cluster's own layout. */
.auth-user-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.auth-user-badge button {
  font-size: 12px;
  padding: 4px 10px;
}

* { box-sizing: border-box; }
html, body { width: 100%; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
}
.page {
  width: 100%;
  max-width: 1100px;
  padding: 32px;
  /* Reserves the band .floating-toggles (fixed, vertically centered
     against .brand-header — see its own rule) shares with the header row,
     so page content below never sits under it regardless of viewport
     width — the toggles are position:fixed and don't participate in
     .page's own layout at all, so this has to be explicit. */
  padding-top: 56px;
}
/* index.html only (Bước A/B side-by-side needs real room — see
   .steps-columns below) — generate.html/compare.html stay at the
   default .page width, unaffected. */
/* padding-top halved from the shared .page's 56px (2026-08-22 report:
   too much empty space above the header on this page specifically) — only
   safe to override here, on index.html's own exclusive class, because
   index.html also has its own #floatingToggles top override (see
   index.html's own <style> block) to match; changing the shared .page
   rule instead would shift home.html/generate.html/compare.html's header
   spacing too, which nobody asked for. */
.page-wide { max-width: 1800px; padding-top: 28px; }

/* Bước A (Inner) and Bước B (Master) side by side instead of stacked, so
   both are visible/comparable without scrolling between them (2026-08-21
   request) — each is already a fairly tall, dense panel (inputs +
   candidates grid + isometric/dieline preview + output stack), so this
   only works with .page-wide's much larger max-width above; at the
   original 1100px each column would be too cramped. */
.steps-columns {
  display: grid;
  /* Middle column is the draggable .steps-resizer below, sized to what
     used to be plain `gap` (24px) — a drag handle occupying the same
     visual seam instead of adding extra width. JS overwrites this whole
     value while dragging; these are just the 50/50 starting values
     (2026-08-22 request: default stays 50/50, but the seam becomes
     draggable so one side can be made bigger when focusing on it). */
  grid-template-columns: 1fr 24px 1fr;
  align-items: start;
}
/* min-width: 0 so a grid column can actually shrink below its content's
   natural width (e.g. the formula-calc-table) instead of blowing out the
   grid — grid items default to min-width: auto, not 0, unlike flex items. */
.step-column { min-width: 0; }

.steps-resizer {
  align-self: stretch;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.steps-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
}
.steps-resizer::after {
  content: "⋮";
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 2px;
}
.steps-resizer:hover::after,
.steps-resizer.dragging::after {
  color: var(--accent);
  border-color: var(--accent);
}
.steps-resizer:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shared collapsed-by-default "extra content" block — used by generate.html
   (manual override fields) and index.html (step descriptions + optional
   weight input) to keep the default view compact / let side-by-side
   columns of differing content stay roughly aligned. */
.advanced-details {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.advanced-details > summary {
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.advanced-details > summary::-webkit-details-marker { color: var(--accent); }
.advanced-details[open] > summary { margin-bottom: 14px; }
/* A `<details>` normally hides its own non-summary content while closed
   via the browser's own UA stylesheet — but an author rule targeting that
   content (here, .row's own `display: flex`) always wins over a
   user-agent one regardless of specificity, so the closed state needs its
   own explicit override instead of relying on the browser default. */
.advanced-details:not([open]) > .row,
.advanced-details:not([open]) > .advanced-group-heading {
  display: none;
}
/* Groups the "Advanced overrides" fields under a small label (2026-09-03
   request — the flat list of ~14 controls was hard to scan/find the right
   one in) instead of one long undifferentiated block. Plain text, no
   collapsing of its own — every field is still visible at once, just
   visually clustered by what part of the layout it affects. */
.advanced-group-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 18px 0 8px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.advanced-group-heading:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
h1 { font-size: 22px; margin: 0 0 4px; }
h2.section { font-size: 15px; margin: 32px 0 12px; scroll-margin-top: 56px; }

.section-nav {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 0;
  margin: 0 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.section-nav:empty { display: none; }
.section-nav a {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.section-nav a:hover { border-color: var(--accent); color: var(--accent); }
.subtitle { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.step-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 0 0 24px;
  flex-wrap: wrap;
}
.step-nav a, .step-nav .step-current {
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
}
.step-nav a { color: var(--accent); }
.step-nav a:hover { background: rgba(0, 113, 227, 0.1); }
.step-nav .step-current { background: var(--accent); color: white; }
.step-nav .step-sep { color: var(--muted); }
.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  margin: -12px 0 20px;
  max-width: fit-content;
  background: rgba(47, 168, 79, 0.1);
  color: var(--ok);
}
/* index.html nests #serverStatus inside .floating-toggles (2026-08-22
   request) instead of its own full-width row — the -12px/20px vertical
   margins above were sized for that old inline position and would just
   throw off vertical centering against the other 3 pill buttons here. */
.floating-toggles .server-status { margin: 0; padding: 6px 14px; white-space: nowrap; }
.server-status.down {
  background: rgba(211, 51, 51, 0.12);
  color: var(--err);
}
.server-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 100%;
}
.row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
/* Lower wrap threshold for a row packing more fields than the default
   140px/field comfortably allows on one line (e.g. L/W/H + weight + unit
   together) — narrower fields still fit their own content (short number
   inputs, short selects) fine at this width. */
.row-compact .field { min-width: 100px; }
/* Native <select> rendering (esp. macOS Safari/Chrome) can ignore the
   parent .field's flex-stretch and size itself off its own option text
   instead — explicit width:100% forces it back to matching its sibling
   inputs' width. (Height no longer needs its own rule here — the global
   input/select height:32px rule above already covers every row, not
   just row-compact ones; this file's own history of that rule's tuning
   lives in that rule's own comment now.) */
.row-compact select { width: 100%; }
.field.wide { flex-basis: 100%; }
.field label { font-size: 12px; color: var(--muted); }
.field.highlight { background: rgba(255, 204, 0, 0.18); border: 1px solid rgba(184, 134, 11, 0.5); border-radius: 8px; padding: 8px; }
.field.highlight label { color: var(--text); font-weight: 600; }
.field.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.field.checkbox-field label { font-size: 13px; color: var(--text); font-weight: 600; }
/* A checkbox toggle that lives INSIDE a .field alongside the value it
   unlocks (2026-09-04 request) — e.g. "Manually adjust" + the field it
   enables, previously 2 separate .field boxes with an overlapping label
   each ("Manually adjust the caption font size..." right above "Caption
   font size (mm)"). Plain flex row, not a nested .field (avoids doubling
   up .field's own flex/min-width/background rules one level in). */
.field-checkbox-row { display: flex; align-items: center; gap: 8px; }
.field-checkbox-row label { font-size: 13px; font-weight: 600; color: var(--text); margin: 0; }
/* Visually hidden but still in the accessibility tree (screen readers) and
   still a real <label for="..."> — the standard "sr-only" clip pattern,
   NOT display:none (which would remove it from both). Used on
   .field-checkbox-row's own label (2026-09-04 request): the text duplicated
   the field's own label right below it ("Manually adjust (if Auto isn't
   right)" sitting directly above e.g. "Item name of barcode — font size
   (mm)") — the checkbox itself stays, fully clickable, just without its
   own redundant caption next to it. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
input, select {
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
/* 32px standard height across every page (2026-08-22 request) — the same
   value tuned specifically on index.html's Qty/Flute/Box style row (3
   rounds of -2px, starting from a mismatched ~37-38px browser-native
   select-vs-input rendering), now applied everywhere so every
   text/number/date input and select on any page lines up the same way,
   not just that one row. Scoped by type — a checkbox/radio/range/file
   input's native rendering doesn't behave like a text box's (an explicit
   height here would either do nothing or visibly distort its own native
   sizing), so those are left alone; every other input + every select
   gets it. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select {
  height: 32px;
}
input[readonly] { color: var(--muted); background: rgba(127,127,127,0.08); }
input.field-error, select.field-error, textarea.field-error {
  border-color: var(--err);
  background: rgba(211, 51, 51, 0.08);
}

/* Custom +/- stepper for text inputs that need a decimal separator other
   than "." (native type="number" spinners reject a "," keystroke outright,
   so those fields fall back to type="text" + this hand-built stepper). */
.number-stepper { position: relative; }
.number-stepper input { width: 100%; box-sizing: border-box; padding-right: 26px; }
.number-stepper .stepper-btns {
  position: absolute;
  top: 2px;
  right: 2px;
  bottom: 2px;
  width: 20px;
  display: flex;
  flex-direction: column;
}
.number-stepper .stepper-btns button {
  flex: 1;
  min-width: 0;
  padding: 0;
  font-size: 8px;
  line-height: 1;
  font-weight: 400;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.number-stepper .stepper-btns button:hover { background: rgba(127, 127, 127, 0.12); color: var(--accent); }
button {
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: white;
}
button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
/* Matches input/select's own height exactly (padding: 8px 10px there) —
   the default button padding (10px 18px) plus its 1px border made
   .secondary buttons sitting next to a number input a few px taller,
   worse once long label text ("Áp dụng số nhập tay") wrapped to 2 lines
   and made it taller still (2026-08-22 report). white-space: nowrap plus
   the shorter label text together keep it on one line. */
.btn-compact { padding: 8px 16px; white-space: nowrap; }
.expand-all-toggle { display: block; margin: 0 0 12px; }
button:disabled { opacity: 0.5; cursor: default; }

.report { margin-top: 12px; font-size: 13px; }
.report-row { display: flex; gap: 8px; padding: 3px 0; }
.report-row .status { font-weight: 700; width: 90px; flex-shrink: 0; }
.report-row.ok .status { color: var(--ok); }
.report-row.mismatch .status { color: var(--err); }
.msg { font-size: 13px; margin-top: 10px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
/* Status is never color-only (2026-08-22 accessibility pass, item #12) —
   every .msg.ok/.msg.err gets a leading glyph too, so colorblind users (or
   anyone in a hurry) don't have to rely on red/green alone. Any i18n
   string that used to hardcode its own leading "⚠"/"✓" had it removed
   (see i18n.js) so it doesn't end up doubled with this. */
.msg.err::before { content: "⚠ "; }
.msg.ok::before { content: "✓ "; }

footer {
  margin-top: 32px;
  font-size: 12px;
  color: var(--muted);
}
code {
  background: rgba(127,127,127,0.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.floating-toggles {
  position: fixed;
  /* Vertically centered against .brand-header's own row (2026-08-22 fix —
     was top:16px, landing ~45px above the header's center once the brand
     header existed, reading as two disconnected/misaligned rows). 58px
     centers within a couple px of both the full-size header (home.html)
     and the 75% .brand-header-sub one (the 3 tool pages) — .page's own
     padding-top:56px already reserves exactly this band for the header,
     so the toggles now share it instead of floating above it. */
  top: 58px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: row-reverse;
  gap: 8px;
}

.lang-toggle, .unit-toggle, .job-toggle {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--card);
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* job.js's floating job-picker — its button sits in the shared
   #floatingToggles row like the other 3 toggles; the panel below it is
   positioned relative to a wrapper job.js creates around just that
   button (not the whole row), so it doesn't jump around as sibling
   buttons from other modules come and go. */
.job-toggle-wrap { position: relative; }
.job-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 1001;
  width: 300px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 14px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
}
.job-panel h3 { font-size: 12px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.job-panel .job-field { margin-bottom: 10px; }
.job-panel .job-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.job-panel .job-field input, .job-panel .job-field select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
.job-panel .job-list { list-style: none; margin: 0 0 10px; padding: 0; border-top: 1px solid var(--border); }
.job-panel .job-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.job-panel .job-list button.job-switch {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}
.job-panel .job-list li.active button.job-switch { color: var(--accent); font-weight: 700; }
.job-panel .job-list button.job-delete { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.job-panel .job-list button.job-delete:hover { color: #d33; }
.job-panel button.job-create {
  width: 100%;
  padding: 7px 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.app-toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.app-toast {
  max-width: 360px;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  background: var(--ok);
  color: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.app-toast.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.app-toast.app-toast-err { background: var(--err); }
/* Same "not color-only" rule as .msg above — a toast is green or red for
   a split second, easy to miss the color alone. */
.app-toast::before { content: "✓  "; }
.app-toast.app-toast-err::before { content: "⚠  "; }

/* #serverStatus's dot was a bare color-only circle (green/red) — turn it
   into a tiny glyph too. The adjacent status text already states the
   connection state in words, so this is a secondary reinforcement, not
   the only signal. */
.server-status .dot {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  line-height: 1;
}
/* color set on ::before only, not .dot itself — .dot's own "color" is what
   background: currentColor (above) reads to stay green/red; overriding it
   here too would make the glyph invisible against its own background. */
.server-status .dot::before { content: "✓"; color: white; }
.server-status.down .dot::before { content: "✕"; color: white; }

/* Consistent keyboard focus ring for every custom-styled interactive
   element (2026-08-22 accessibility pass, item #16) — browser defaults
   were never stripped, but a plain default outline can end up low-
   contrast against a pill-shaped or colored custom control. One rule
   here instead of tuning each component individually. */
.lang-toggle:focus-visible,
.unit-toggle:focus-visible,
.job-toggle:focus-visible,
.step-nav a:focus-visible,
.section-nav a:focus-visible,
.category-links a:focus-visible,
.job-panel input:focus-visible,
.job-panel select:focus-visible,
.job-panel button:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* .step-current's own background IS var(--accent) — the ring above would
   be invisible against it. Not currently a real focus target (it's a
   <span>, not a link), but kept as a safety net in case that changes. */
.step-nav .step-current:focus-visible { outline-color: #fff; }

/* Native browser up/down spinner arrows look inconsistent across
   browsers/OS and duplicate the app's own typing-first interaction for
   every L/W/H/qty/etc. field (2026-08-22 visual-consistency pass, item
   #17) — removed app-wide in favor of direct typing. */
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* .field defaults to flex:1 so it grows to fill its row — .field-auto
   sizes to content instead, for a short field that shouldn't stretch
   (e.g. a segmented toggle sitting next to nothing else in its row). */
.field-auto { flex: 0 0 auto; min-width: 0; }
/* Compact 2-option segmented toggle (index.html's p1DimInputMode,
   generate.html's dimInputMode) — both choices visible at once, no
   dropdown click needed, while staying as small as the field it sits in.
   Wired up by initSegmentedToggle() in common.js. */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: fit-content; }
.segmented-btn {
  background: var(--card); color: var(--text); border: none; border-left: 1px solid var(--border);
  font-size: 12px; font-weight: 600; padding: 7px 10px; cursor: pointer; white-space: nowrap;
}
.segmented-btn:first-child { border-left: none; }
.segmented-btn.active { background: var(--accent); color: white; }
