/* IBM Carbon design language, applied 2026-08-15 — see
   docs/research/TEMPLATE-CARBON.md for the verified token extraction and every
   deviation. Density still beats whitespace (docs/DESIGN-UI.md); no color-only
   signal anywhere.

   Every color is a token and ONLY the tokens flip in the dark block --
   that invariant is what web/tests/test_e2e_ui.py and the a11y suite hold:
   body contrast >= 4.5:1 in both schemes, dark != light, 3px ring on every
   focus stop, zero external hosts (fonts are VENDORED, never fetched). */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/IBMPlexSans-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/IBMPlexSans-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

/* Carbon "White" theme (values from @carbon/themes, extracted 2026-08-15). */
:root {
  --fg: #161616; /* text-primary */
  --page: #ffffff; /* background */
  --bg: #f4f4f4; /* layer-01: cards, panels */
  --field: #ffffff; /* field-02: inputs on a layer */
  --line: #e0e0e0; /* border-subtle-00 */
  --line-strong: #c6c6c6; /* border-subtle-01 */
  --muted: #525252; /* text-secondary */
  --accent: #0f62fe; /* link-primary / blue-60 */
  --accent-strong: #0043ce; /* blue-70 */
  --good: #198038; /* green-60: Carbon's #24a148 is 3.9:1 on white -- below our AA gate */
  --bad: #da1e28; /* support-error */
  --warn: #f1c21b; /* support-warning -- borders only, never text */
  --focus: #0f62fe;
  --surface: #e0e0e0; /* layer-accent: table headers */
  --surface-2: #ffffff; /* quiet button face on a layer */
  --hover: #e8e8e8; /* layer-hover-01 */
  --selected: #edf5ff; /* chosen review candidate (blue-10) */
  --highlight: #fcf4d6; /* yellow-10: the review-queue count */
  --input-line: #8d8d8d; /* gray-50: the Carbon field bottom border */
  --on-accent: #ffffff;
  --btn-primary: #0f62fe; /* Carbon button-primary is blue-60 in BOTH themes */
  /* Carbon UI Shell: the header is gray-100 in both schemes -- deliberately
     not flipped below. Its own focus ring is white for contrast on gray-100. */
  --shell-bg: #161616;
  --shell-fg: #f4f4f4;
  --shell-muted: #c6c6c6;
  --shell-hover: #353535;
  --shell-focus: #ffffff;
  --shadow-pop: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Carbon "Gray 100" theme. Only tokens flip -- every rule stays scheme-agnostic. */
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f4f4f4;
    --page: #161616;
    --bg: #262626; /* layer-01 */
    --field: #393939; /* field-02 */
    --line: #393939;
    --line-strong: #525252;
    --muted: #c6c6c6;
    --accent: #78a9ff; /* blue-40 */
    --accent-strong: #a6c8ff; /* blue-30 */
    --good: #42be65;
    --bad: #ff8389; /* text-error (red-40): red-50 #fa4d56 is 4.4:1 on layer-01 */
    --warn: #f1c21b;
    --focus: #ffffff; /* Carbon g100 focus is white */
    --surface: #393939; /* layer-accent-01 */
    --surface-2: #393939;
    --hover: #333333; /* layer-hover-01 */
    --selected: #1d3458; /* selection on g100 */
    --highlight: #302400; /* yellow-90 */
    --input-line: #8d8d8d;
    --on-accent: #ffffff;
    --btn-primary: #0f62fe;
    --shadow-pop: 0 2px 6px rgba(0, 0, 0, 0.8);
  }
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 0.875rem; /* Carbon body-01: 14px */
  color: var(--fg);
  background: var(--page);
  line-height: 1.43;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-strong);
}

/* Visible focus everywhere -- non-negotiable (docs/DESIGN-UI.md
   Accessibility). 3px is ours (UI-SPEC), wider than Carbon's 2px. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* --- Header: the Carbon UI Shell, gray-100 in BOTH schemes ----------------- */

header.site {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 1rem;
  min-height: 3rem; /* Carbon shell is a fixed 48px band */
  background: var(--shell-bg);
  color: var(--shell-fg);
  border-bottom: 1px solid #393939;
  flex-wrap: wrap;
}

header.site .brand {
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-right: 1.25rem;
  color: var(--shell-fg);
}

header.site nav {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  align-self: stretch;
}

/* Nav links are the only routinely-tapped controls; give them a real hit area
   rather than the 20px a bare inline <a> reports. */
header.site nav a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 0.75rem;
  align-self: stretch;
  text-decoration: none;
  font-weight: 400;
  color: var(--shell-fg);
  border-top: 2px solid transparent;
  border-bottom: 2px solid transparent;
  transition: background-color 110ms cubic-bezier(0.2, 0, 0.38, 0.9);
}

header.site nav a:hover {
  background: var(--shell-hover);
  color: #ffffff;
}

/* Carbon marks the current shell item with a top rule + a lifted surface.
   Driven by aria-current, so the visual state and the state assistive tech
   announces can never drift apart -- and it is not colour-only: the border
   is a second, non-chromatic cue. */
header.site nav a[aria-current="page"] {
  background: var(--shell-hover);
  border-top-color: var(--accent);
  color: #ffffff;
}

@media (pointer: coarse) {
  header.site nav a {
    min-height: 44px;
  }
}

header.site .spacer {
  flex: 1;
}

/* Everything focusable inside the shell rings white -- the scheme token can
   be blue-on-near-black, which fails the >=3:1 ring check the a11y suite runs. */
header.site a:focus-visible,
header.site button:focus-visible {
  outline-color: var(--shell-focus);
}

/* The one button living in the shell (Log out) dresses as a shell item. */
header.site button {
  background: transparent;
  color: var(--shell-fg);
  border: 1px solid var(--shell-muted);
}

header.site button:hover {
  background: var(--shell-hover);
  border-color: var(--shell-fg);
  color: #ffffff;
}

main {
  padding: 1.5rem 1rem 3rem;
  max-width: 1200px;
  margin: 0 auto;
}

h1 {
  font-size: 1.25rem; /* Carbon heading-03: 20px */
  font-weight: 400; /* Carbon headings are regular-weight */
  letter-spacing: 0;
  margin: 0.25rem 0 1rem;
}

h2 {
  font-size: 1rem; /* Carbon heading-02 */
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

/* --- Tables: Carbon data table -------------------------------------------- */

table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1rem;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

th,
td {
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0.4375rem 1rem; /* Carbon compact rows */
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface);
  font-size: 0.75rem; /* Carbon label-01 */
  font-weight: 600;
  letter-spacing: 0.32px;
  text-transform: uppercase;
}

tbody tr:hover > td {
  background: var(--hover);
}

/* --- Flash messages: Carbon inline notification ---------------------------- */

.messages {
  list-style: none;
  margin: 0.5rem 0 1rem;
  padding: 0;
}

.messages li {
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
}

.messages .success {
  border-left-color: var(--good);
  background: color-mix(in srgb, var(--good) 8%, var(--bg));
}

.messages .error {
  border-left-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 8%, var(--bg));
}

.messages .info,
.messages .warning {
  border-left-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, var(--bg));
}

/* --- Dashboard stat tiles: Carbon layer tiles ------------------------------- */

.stat-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--bg);
  border: 1px solid transparent; /* flat Carbon tile; border appears on hover */
  padding: 1rem;
  min-width: 12rem;
  transition: border-color 110ms cubic-bezier(0.2, 0, 0.38, 0.9);
}

.stat:hover {
  border-color: var(--line-strong);
}

.stat .n {
  font-size: 2rem;
  font-weight: 400; /* Carbon displays numbers light, not heavy */
  letter-spacing: 0;
  display: block;
  font-variant-numeric: tabular-nums;
}

.stat.queue-count {
  border: 1px solid var(--warn);
  border-left-width: 3px;
  background: var(--highlight);
}

.stat.queue-count .n {
  font-size: 2.625rem;
}

fieldset {
  border: 1px solid var(--line);
  background: var(--bg);
  margin-bottom: 1rem;
}

/* Sign-in card. The only screen with no navigation, so it centres rather than
   sitting top-left where it read as an unstyled fragment. */
.signin {
  max-width: 24rem;
  margin: 4rem auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-top: 3px solid var(--btn-primary);
  padding: 2rem;
}

.signin h1 {
  margin-top: 0;
}

.signin input[type="text"],
.signin input[type="password"] {
  width: 100%;
}

.signin button {
  width: 100%;
}

.error-list {
  color: var(--bad);
}

/* --- Review queue ------------------------------------------------------------- */

.shortcut-legend {
  border: 1px solid var(--line);
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.32px;
  background: var(--bg);
  color: var(--fg);
}

.shortcut-legend kbd {
  display: inline-block;
  border: 1px solid var(--input-line);
  padding: 0 0.375rem;
  background: var(--field);
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  font-size: 0.85em;
}

.candidate {
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  /* Deliberately NO transition: the highlight is the confirmation of which
     product Enter will buy, so it must snap, not fade -- and the regression
     test reads the computed background the instant after the keypress. */
}

/* The chosen candidate. `:has()` rather than a JS-toggled class so the
   highlight follows the radio itself -- mouse click, keyboard 1-9, and
   browser-restored state all light up the same row with no JS to keep in
   sync. `.selected` is retained for any server-rendered pre-selection.

   Found live 2026-08-14: this rule previously matched only `.candidate.selected`,
   and nothing anywhere added that class, so pressing 1-9 moved the radio with
   no row highlight at all. On a screen whose whole job is "confirm you are
   buying THIS one", the operator was choosing against native radio dots only. */
.candidate:has(input[type="radio"]:checked),
.candidate.selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background: var(--selected);
}

.candidate .idx {
  font-weight: 600;
  min-width: 1.5rem;
  height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-size: 0.8125rem;
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}

.candidate:has(input[type="radio"]:checked) .idx {
  background: var(--btn-primary);
  color: var(--on-accent);
}

.candidate .confidence {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.evidence {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8125rem;
  color: var(--muted);
}

.line-panel {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 1rem;
  margin-bottom: 1rem;
}

.line-panel > div {
  flex: 1;
  min-width: 18rem;
}

.nav-lines {
  display: flex;
  gap: 1rem;
  margin: 0.75rem 0;
}

.below-minimum {
  color: var(--bad);
  font-weight: 600;
}

/* --- Drafts ------------------------------------------------------------------- */

.draft-card {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 1rem;
  margin-bottom: 1rem;
}

.draft-card summary {
  cursor: pointer;
}

/* An 8-column line table does not fit 375px. Scroll the table, never the
   page -- horizontal body scroll is what the viewport suite forbids.
   A scroller is a focus stop (Chromium focuses one implicitly), so it needs
   the app's ring like every other stop. */
.table-scroll {
  overflow-x: auto;
}

.table-scroll:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* --- Buttons and inputs: Carbon field + button language --------------------- */

button,
input[type="submit"] {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.4375rem 1rem;
  border: 1px solid var(--input-line);
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
  transition:
    background-color 110ms cubic-bezier(0.2, 0, 0.38, 0.9),
    border-color 110ms cubic-bezier(0.2, 0, 0.38, 0.9);
}

button:hover,
input[type="submit"]:hover {
  background: var(--hover);
  border-color: var(--fg);
}

button.primary {
  background: var(--btn-primary);
  color: var(--on-accent);
  border-color: var(--btn-primary);
}

button.primary:hover {
  background: #0353e9; /* Carbon button-primary-hover, both themes */
  border-color: #0353e9;
}

button.danger {
  background: transparent;
  color: var(--bad);
  border-color: var(--bad);
}

button.danger:hover {
  background: color-mix(in srgb, var(--bad) 10%, var(--bg));
}

label {
  display: block;
  font-size: 0.75rem; /* Carbon label-01 captions */
  letter-spacing: 0.32px;
  color: var(--muted);
  margin: 0.5rem 0 0.25rem;
}

/* Carbon text input: filled field, bottom border only. */
/* `password` was missing here until 2026-08-15 -- the login field rendered as
   a raw UA input next to a styled username box, which is exactly the kind of
   detail that makes a real page look broken. */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="file"],
select,
textarea {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.4375rem 0.75rem;
  border: 1px solid transparent;
  border-bottom: 1px solid var(--input-line);
  background: var(--field);
  color: var(--fg);
  transition: border-color 110ms cubic-bezier(0.2, 0, 0.38, 0.9);
}

input[type="text"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="search"]:hover,
select:hover,
textarea:hover {
  border-bottom-color: var(--fg);
}

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

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

/* --- Allocation ------------------------------------------------------------------ */

.group-allocation {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.group-allocation summary {
  cursor: pointer;
}

.group-allocation .strains-body {
  margin-top: 0.75rem;
}

/* --- Inventory browser: filter form + multi-select dropdowns ---------------
   Ported in structure from repricing-dashboard's `.dd` widget, restated in
   this project's tokens. Every color here is a token: a literal hex would
   survive the light scheme and break dark, which is the exact defect the
   2026-08-11 UI review found. */

.filters .field-group {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 1rem;
  margin-bottom: 1rem;
}

.filters .field-group h2 {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}

/* The one control the screen exists for: full width, and visibly larger than
   every other field so it reads as the entry point, not one filter among 15. */
.search-group {
  border-left: 3px solid var(--btn-primary);
}

.search-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg);
}

.search-input {
  width: 100%;
  font-size: 1rem;
  padding: 0.625rem 0.75rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.75rem;
}

/* `> label`, not `label`: the descendant form also matched the option labels
   inside the dropdown panels -- and beat `.dd-option` on specificity -- so the
   values the operator picks from rendered in --muted instead of --fg. This
   rule is about the cell's own caption, nothing nested. */
.filter-cell > label,
.filter-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.32px;
  text-transform: none;
  color: var(--muted);
  margin: 0 0 0.25rem;
}

.filter-cell input,
.filter-cell select {
  width: 100%;
}

.filter-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Native <details> popover, no JS library and no <select multiple> -- Enter and
   Space open it, Tab walks the checkboxes, Escape closes it (base.html). */
.dd {
  position: relative;
}

.dd summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0.4375rem 0.75rem;
  border: 1px solid transparent;
  border-bottom: 1px solid var(--input-line);
  background: var(--field);
  color: var(--fg);
  transition: border-color 110ms cubic-bezier(0.2, 0, 0.38, 0.9);
}

.dd summary:hover {
  border-bottom-color: var(--fg);
}

.dd summary::-webkit-details-marker {
  display: none;
}

.dd summary::after {
  content: "\25BE";
  color: var(--muted);
  flex-shrink: 0;
}

.dd[open] summary {
  border-color: var(--focus);
}

.dd-count {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dd-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--field);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.dd-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--fg);
  cursor: pointer;
}

.dd-option:hover {
  background: var(--hover);
}

.dd-option input {
  width: auto;
  margin: 0;
}

.dd-empty {
  margin: 0;
  padding: 0.375rem 0.75rem;
  color: var(--muted);
  font-size: 0.875rem;
}

/* The narrowing/widening feedback -- kept immediately above the table so the
   number the operator is steering by never scrolls out of view. */
.count-line {
  margin: 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.room {
  display: block;
  white-space: nowrap;
}

.pagination {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Every transition above is decorative. When the OS says reduce motion,
   all of it goes -- the a11y suite asserts zero surviving transition or
   animation under prefers-reduced-motion. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
