/* Pete Pharma × FabRx Formula Library
   Palette: clinical light surface, Pete Pharma blue brand, status colors reserved
   for status meaning only (same colors as the workbook's status cells).
   Type: IBM Plex Sans; Plex Mono for row IDs. */

:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --ink: #15312c;
  --muted: #5d716c;
  --line: #dbe4e1;
  --brand: #1172b1;
  --brand-deep: #06425f;
  --brand-wash: #e4f1f7;
  --accent: #62c3d2;

  /* status colors = the workbook's conditional formatting */
  --ok-bg: #c6efce;   --ok-ink: #006100;
  --warn-bg: #ffeb9c; --warn-ink: #9c6500;
  --bad-bg: #ffc7ce;  --bad-ink: #9c0006;
  --idle-bg: #f2f2f2; --idle-ink: #808080;
  --na-bg: #ffffff;   --na-ink: #bfbfbf;
  --row-alt: #f7fafb;
  --link: #06425f;
  --doc-teal-bg: #dff4f6; --doc-teal-ink: #0b5e6b;
  --doc-violet-bg: #ece8f8; --doc-violet-ink: #4a3a86;
  --doc-amber-bg: #fff1d6; --doc-amber-ink: #7a4e00;

  --hover: #f8fbfa; --flash: #fff3b0;
  --alert-bg: #fdf4f3;
  --alert-border: #f0b9b4;
  --banner-bg: #fcf0cc;
  --banner-ink: #6b4a00;
  --banner-border: #efd9a0;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(21, 49, 44, 0.07), 0 4px 16px rgba(21, 49, 44, 0.06);
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111917; --surface: #19231f; --ink: #e3ece9; --muted: #96a7a2;
    --line: #2b3934; --brand: #3ba0dd; --brand-deep: #06425f; --brand-wash: #15303e; --accent: #62c3d2;
    --row-alt: #151f1c; --link: #8fd0f5; --doc-teal-bg: #11363b; --doc-teal-ink: #8fd9e3; --doc-violet-bg: #2a2544; --doc-violet-ink: #c3b6f0;
    --doc-amber-bg: #3b2d0f; --doc-amber-ink: #f0c87a;
    --ok-bg: #1d3b29; --ok-ink: #93daab; --warn-bg: #3e3113; --warn-ink: #eec76e;
    --bad-bg: #44211a; --bad-ink: #f29b90; --idle-bg: #232d2a; --idle-ink: #8b9a95;
    --na-bg: #19231f; --na-ink: #5a6964;
    --hover: #1e2a26; --alert-bg: #2b1c19; --alert-border: #5c2f28; --flash: #4a3f10; --flash: #4a3f10;
    --banner-bg: #332a10; --banner-ink: #ecc56a; --banner-border: #4a3d17;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #111917; --surface: #19231f; --ink: #e3ece9; --muted: #96a7a2;
  --line: #2b3934; --brand: #3ba0dd; --brand-deep: #06425f; --brand-wash: #15303e; --accent: #62c3d2;
  --row-alt: #151f1c; --link: #8fd0f5; --doc-teal-bg: #11363b; --doc-teal-ink: #8fd9e3; --doc-violet-bg: #2a2544; --doc-violet-ink: #c3b6f0;
  --doc-amber-bg: #3b2d0f; --doc-amber-ink: #f0c87a;
  --ok-bg: #1d3b29; --ok-ink: #93daab; --warn-bg: #3e3113; --warn-ink: #eec76e;
  --bad-bg: #44211a; --bad-ink: #f29b90; --idle-bg: #232d2a; --idle-ink: #8b9a95;
  --na-bg: #19231f; --na-ink: #5a6964;
  --hover: #1e2a26; --alert-bg: #2b1c19; --alert-border: #5c2f28; --flash: #4a3f10;
  --banner-bg: #332a10; --banner-ink: #ecc56a; --banner-border: #4a3d17;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- top bar ---------- */
.topbar { background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: min(1720px, 96vw); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { display: block; width: auto; }
.logo-pete { height: 38px; }
.logo-fabrx { height: 24px; }
.logo-div { width: 1px; height: 28px; background: var(--line); flex: none; }
.logo-plate { display: flex; align-items: center; gap: 14px; }
.gate-logos { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 14px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-plate,
  :root:not([data-theme="light"]) .gate-logos {
    background: #fff; border-radius: 10px; padding: 6px 14px;
  }
}
:root[data-theme="dark"] .logo-plate,
:root[data-theme="dark"] .gate-logos {
  background: #fff; border-radius: 10px; padding: 6px 14px;
}
.brand h1 { font-size: 1rem; font-weight: 600; margin: 0; letter-spacing: .01em; }
.brand p { margin: 0; font-size: .78rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync { font-size: .75rem; color: var(--muted); }
.sync.live::before { content: "●  "; color: #7fe3a9; }
.sync.demo::before { content: "●  "; color: #ffd36b; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-weight: 500; font-size: .875rem; background: none;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-deep); }
.btn.ghost { color: var(--brand); border-color: var(--line); }
.btn.ghost:hover { background: var(--brand-wash); }
.btn.quiet { color: var(--brand); border-color: var(--line); background: var(--surface); }
.btn.quiet:hover { background: var(--brand-wash); }
.btn.danger { color: var(--bad-ink); border-color: var(--line); background: var(--surface); }
.btn:disabled { opacity: .55; cursor: default; }

.demo-banner {
  background: var(--banner-bg); color: var(--banner-ink); text-align: center;
  padding: 8px 16px; font-size: .85rem; border-bottom: 1px solid var(--banner-border);
}

/* ---------- layout ---------- */
.shell { max-width: min(1800px, 97vw); margin: 0 auto; padding: 14px 20px 20px; }

.summary { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; margin: 0 0 10px 2px; }
.stat { display: inline-flex; gap: 6px; align-items: baseline; font-size: .8rem; color: var(--muted); }
.stat b { font-size: 1rem; font-weight: 600; color: var(--ink); }
.stat.alert b { color: var(--bad-ink); }

.toolbar {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px; align-items: center;
}
.views { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.view-btn {
  border: 0; background: none; padding: 6px 14px; border-radius: 7px;
  cursor: pointer; font-size: .875rem; color: var(--muted); font-weight: 500;
}
.view-btn.active { background: var(--brand); color: #fff; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type="search"], .filters select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  background: var(--surface); font-size: .875rem; min-width: 160px;
}

/* ---------- project cards ---------- */
.project-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.project-head {
  padding: 14px 16px 10px; display: flex; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; align-items: baseline;
}
.project-head h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.project-meta { font-size: .8rem; color: var(--muted); }
.sku-row {
  display: block; padding: 10px 16px 12px;
  border-top: 1px solid var(--line); cursor: pointer;
  background: none; width: 100%; text-align: left; border-left: 0; border-right: 0; border-bottom: 0;
}
.sku-top { display: flex; align-items: center; gap: 14px; }
.sku-row:hover { background: var(--hover); }
.row-id {
  font-family: "IBM Plex Mono", monospace; font-size: .75rem; color: var(--muted);
  flex: none; width: 44px;
}
.sku-name { flex: 1 1 180px; font-size: .875rem; font-weight: 500; min-width: 140px; }
.sku-sub { display: block; font-weight: 400; color: var(--muted); font-size: .78rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; }

/* ---------- the stage rail ---------- */
.rail { display: flex; gap: 3px; flex: none; }
.seg {
  width: 36px; height: 26px; border-radius: 6px; display: grid; place-items: center;
  font-size: .62rem; font-weight: 600; letter-spacing: .02em; position: relative;
  border: 1px solid transparent;
}
.seg[data-s="Completed"]   { background: var(--ok-bg);   color: var(--ok-ink); }
.seg[data-s="In Progress"] { background: var(--warn-bg); color: var(--warn-ink); }
.seg[data-s="Blocked"]     { background: var(--bad-bg);  color: var(--bad-ink); }
.seg[data-s="Not Started"] { background: var(--idle-bg); color: var(--idle-ink); }
.seg[data-s="N/A"]         { background: var(--na-bg);   color: var(--na-ink); border-color: var(--line); }
.seg[data-s="Blocked"]::after {
  content: ""; position: absolute; top: -3px; right: -3px; width: 8px; height: 8px;
  border-radius: 50%; background: #d23c30; border: 1.5px solid #fff;
}
.rail.mini .seg { width: 26px; height: 20px; font-size: .55rem; border-radius: 5px; }
.progress-pct { font-size: .78rem; color: var(--muted); width: 38px; text-align: right; flex: none; }

/* ---------- table view ---------- */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); font-size: .85rem; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top; }
.data-table th { background: var(--brand-wash); color: var(--brand-deep); font-weight: 600;
  font-size: .72rem; position: sticky; top: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--hover); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.chip { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.chip[data-s="Completed"]   { background: var(--ok-bg);   color: var(--ok-ink); }
.chip[data-s="In Progress"] { background: var(--warn-bg); color: var(--warn-ink); }
.chip[data-s="Blocked"]     { background: var(--bad-bg);  color: var(--bad-ink); }
.chip[data-s="Not Started"] { background: var(--idle-bg); color: var(--idle-ink); }
.chip[data-s="N/A"]         { background: var(--na-bg);   color: var(--na-ink); box-shadow: inset 0 0 0 1px var(--line); }


/* ---------- library grid (spreadsheet-style default view) ---------- */
.grid-wrap {
  overflow: auto; max-height: calc(100vh - 205px); min-height: 320px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.grid { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: .78rem; }
.grid th, .grid td {
  padding: 3px 8px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  text-align: left; vertical-align: middle; white-space: nowrap; line-height: 1.25; height: 31px;
  background: var(--surface); overflow: hidden; text-overflow: ellipsis;
}
.grid th {
  position: sticky; top: 0; z-index: 3; background: var(--brand-deep); color: #fff; font-weight: 600;
  font-size: .68rem; letter-spacing: .02em; cursor: pointer; user-select: none; border-right-color: rgba(255,255,255,.14);
  vertical-align: bottom; padding-bottom: 5px;
}
.grid th:hover { background: #0a5578; }
.grid th .sort { opacity: .85; margin-left: 4px; font-size: .58rem; }
.grid th.c-stage { white-space: normal; width: 126px; min-width: 126px; max-width: 126px; line-height: 1.15; }
.grid td.sticky-1, .grid th.sticky-1 { position: sticky; left: 0; z-index: 2; }
.grid td.sticky-2, .grid th.sticky-2 { position: sticky; left: 60px; z-index: 2; box-shadow: 3px 0 0 -1px var(--line); }
.grid th.sticky-1, .grid th.sticky-2 { z-index: 4; }
.grid tbody tr:nth-child(even) td { background: var(--row-alt); }
.grid tbody tr:hover td { background: var(--hover); }
.grid .c-id { width: 60px; min-width: 60px; max-width: 60px; }
.grid .c-formula { width: 300px; min-width: 300px; max-width: 300px; }
.grid .c-formula .cell-link { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid .c-sku { min-width: 90px; max-width: 170px; font-weight: 500; }
.grid .c-field { max-width: 220px; }
.grid .c-lead { max-width: 150px; }
.grid td.c-stage, .grid td.c-section { padding: 2px 5px; }
.grid .c-docs { min-width: 250px; max-width: 460px; }
.grid .c-notes { width: 56px; text-align: center; }
.grid .c-updated { min-width: 118px; }
.cell-link { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; text-align: left; font: inherit; font-weight: 500; }
.cell-link.mono { font-family: "IBM Plex Mono", monospace; font-size: .72rem; font-weight: 500; color: var(--muted); }
.cell-link:hover { text-decoration: underline; color: var(--brand); }
.cell-muted { color: var(--muted); font-size: .74rem; }
.cell-date { display: block; font-size: .64rem; color: var(--muted); padding-left: 2px; line-height: 1.1; }
.cell-select {
  appearance: none; -webkit-appearance: none; border: 1px solid transparent; border-radius: 5px;
  padding: 2px 20px 2px 7px; font-size: .71rem; font-weight: 600; cursor: pointer; width: 100%; min-width: 108px;
  background-repeat: no-repeat; background-position: right 7px center; background-color: var(--surface);
}
.cell-select:hover { filter: brightness(.97); }
.cell-select.sel-stage[data-s="Completed"]   { background-color: var(--ok-bg);   color: var(--ok-ink); }
.cell-select.sel-stage[data-s="In Progress"] { background-color: var(--warn-bg); color: var(--warn-ink); }
.cell-select.sel-stage[data-s="Blocked"]     { background-color: var(--bad-bg);  color: var(--bad-ink); }
.cell-select.sel-stage[data-s="Not Started"] { background-color: var(--idle-bg); color: var(--idle-ink); }
.cell-select.sel-stage[data-s="N/A"]         { background-color: var(--na-bg);   color: var(--na-ink); border-color: var(--line); }
.cell-select.sel-section { min-width: 128px; }
.cell-select.sel-section[data-s="In Testing"]     { background-color: var(--brand-wash); color: var(--brand-deep); }
.cell-select.sel-section[data-s="Validated"]      { background-color: var(--ok-bg); color: var(--ok-ink); }
.cell-select.sel-section[data-s="Not Yet Tested"] { background-color: var(--idle-bg); color: var(--idle-ink); }
.cell-select.sel-section[data-s="Backlog"]        { background-color: var(--na-bg); color: var(--muted); border-color: var(--line); }
.cell-select.sel-section[data-s="On Hold"]        { background-color: var(--warn-bg); color: var(--warn-ink); }
.cell-select.sel-section[data-s="Not Feasible"]   { background-color: var(--bad-bg); color: var(--bad-ink); }
td.saving .cell-select { opacity: .6; }
.doc-chip {
  display: inline-block; margin: 0 4px 0 0; padding: 1px 8px; border-radius: 999px; font-size: .68rem; font-weight: 600;
  text-decoration: none; color: var(--link); background: var(--brand-wash); border: 1px solid transparent; vertical-align: middle;
}
.doc-chip:hover { text-decoration: underline; }
.doc-chip[data-t="Dissolution report"] { background: var(--doc-teal-bg); color: var(--doc-teal-ink); }
.doc-chip[data-t="Printing spec"] { background: var(--doc-violet-bg); color: var(--doc-violet-ink); }
.doc-chip[data-t="SOP"], .doc-chip[data-t="Other"] { background: var(--doc-amber-bg); color: var(--doc-amber-ink); }
.doc-add {
  border: 1px dashed var(--line); background: none; color: var(--muted); border-radius: 999px;
  width: 20px; height: 20px; font-size: .8rem; cursor: pointer; line-height: 1; vertical-align: middle; padding: 0;
}
.doc-add:hover { color: var(--brand); border-color: var(--brand); }
.grid-foot { font-size: .75rem; color: var(--muted); margin: 8px 2px 0; }

/* section bands: one header row per section, rows move between bands when their section changes */
.grid tr.sec-head td {
  position: sticky; left: 0; z-index: 1; height: 34px; padding: 0 8px; border-right: 0;
  background: var(--brand-wash); color: var(--brand-deep); border-top: 2px solid var(--brand); border-bottom: 1px solid var(--line);
}
.grid tr.sec-head:hover td { background: var(--brand-wash); }
.grid tr.sec-head[data-s="Validated"] td      { background: var(--ok-bg); color: var(--ok-ink); border-top-color: var(--ok-ink); }
.grid tr.sec-head[data-s="Not Yet Tested"] td { background: var(--idle-bg); color: var(--idle-ink); border-top-color: #9aa5a1; }
.grid tr.sec-head[data-s="Backlog"] td        { background: var(--na-bg); color: var(--muted); border-top-color: #b8c2be; }
.grid tr.sec-head[data-s="On Hold"] td        { background: var(--warn-bg); color: var(--warn-ink); border-top-color: var(--warn-ink); }
.grid tr.sec-head[data-s="Not Feasible"] td   { background: var(--bad-bg); color: var(--bad-ink); border-top-color: var(--bad-ink); }
.sec-toggle {
  position: sticky; left: 8px; display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; color: inherit;
  font: inherit; font-size: .8rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; cursor: pointer; padding: 0;
}
.sec-caret { width: 10px; font-size: .8rem; }
.sec-count { font-weight: 500; text-transform: none; letter-spacing: 0; opacity: .8; }
@keyframes moved-flash { from { background: var(--flash); } to { background: var(--surface); } }
.grid tr.moved td { animation: moved-flash 2.2s ease-out; }
.api-search { position: relative; display: inline-block; }
.api-search::before {
  content: "API"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%); font-size: .62rem; font-weight: 700;
  letter-spacing: .06em; color: var(--brand); pointer-events: none;
}
.api-search input { padding-left: 38px !important; }
.group-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); padding: 0 4px; white-space: nowrap; }
.group-toggle input { accent-color: var(--brand); }

/* ---------- notes view ---------- */
.note-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 10px;
}
.note-head { display: flex; gap: 10px; font-size: .78rem; color: var(--muted); margin-bottom: 4px; flex-wrap: wrap; }
.note-head b { color: var(--ink); font-weight: 600; }
.note-body { font-size: .9rem; white-space: pre-wrap; }

/* ---------- project detail popup (built on .modal / .modal-backdrop) ---------- */
body.modal-open { overflow: hidden; }
.modal.detail-modal {
  width: min(680px, 94vw); max-height: 90vh; padding: 0; overflow: hidden;
  display: flex; flex-direction: column; outline: none;
}
.detail-head { padding: 16px 20px; border-bottom: 1px solid var(--line); flex: none;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.detail-head h2 { margin: 0 0 2px; font-size: 1rem; }
.detail-head .row-id { width: auto; }
.detail-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px 20px; }
.detail-close { border: 0; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; }
.detail-close:disabled { opacity: .35; cursor: not-allowed; }
.detail-modal h3 { font-size: .8rem; color: var(--muted); font-weight: 600; margin: 18px 0 8px; }
.detail-modal h3:first-child { margin-top: 0; }
@media (max-width: 600px) {
  .modal-backdrop:has(> .detail-modal) { padding: 0; }
  .modal.detail-modal { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
}
.fact { font-size: .875rem; margin: 0 0 4px; }
.fact b { font-weight: 600; }

.stage-list { display: flex; flex-direction: column; gap: 6px; }
.stage-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
}
.stage-item .seg { flex: none; }
.stage-item label { flex: 1; font-size: .85rem; font-weight: 500; }
.stage-item select {
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
  font-size: .8rem; background: var(--surface);
}
.stage-item.saving select { opacity: .5; }

.note-form textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
  min-height: 72px; resize: vertical; font-size: .875rem;
}
.note-form .note-controls { display: flex; gap: 8px; margin-top: 8px; }
.note-form input {
  flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: .85rem;
}
.detail-modal .note-card { padding: 10px 12px; }

/* ---------- modal (intake) ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(13,36,32,.45); z-index: 60;
  display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal {
  background: var(--surface); border-radius: 14px; width: min(640px, 100%);
  max-height: 92vh; overflow-y: auto; padding: 22px 24px; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 4px; font-size: 1.1rem; }
.modal .hint { color: var(--muted); font-size: .85rem; margin: 0 0 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .875rem;
}
.sku-block { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; position: relative; }
.sku-block .remove-sku { position: absolute; top: 8px; right: 8px; border: 0; background: none;
  color: var(--muted); cursor: pointer; font-size: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 540px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- gate ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; background:
  linear-gradient(160deg, #06425f, #1172b1 62%, #62c3d2); padding: 16px; }
.gate-card {
  background: var(--surface); border-radius: 16px; padding: 34px 32px; width: min(380px, 100%);
  text-align: center; box-shadow: 0 24px 60px rgba(4, 30, 27, .35);
}
.gate-card h1 { font-size: 1.15rem; margin: 0 0 4px; }
.gate-card p { color: var(--muted); font-size: .875rem; margin: 0 0 18px; }
.gate-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px;
  margin-bottom: 10px; font-size: .95rem; text-align: center;
}
.gate-card .btn { width: 100%; padding: 10px; }
.gate-card .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.gate-error { color: var(--bad-ink) !important; margin-top: 10px !important; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #0d2420; color: #fff; border-radius: 9px; padding: 10px 18px;
  font-size: .875rem; z-index: 80; box-shadow: var(--shadow);
}
.toast.error { background: #7c1f17; }

.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: .9rem; }

@media (max-width: 760px) {
  .sku-row { gap: 8px; }
  .rail .seg { width: 28px; }
  .progress-pct { display: none; }
  .shell { padding: 14px; }
}


/* ---------- milestone timeline ---------- */
.timeline { display: flex; width: 100%; margin-top: 8px; }
.tl-stage {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  position: relative; min-width: 0;
}
.tl-stage::before, .tl-stage::after {
  content: ""; position: absolute; top: 7px; height: 2px; background: var(--line);
}
.tl-stage::before { left: 0; right: calc(50% + 10px); }
.tl-stage::after { left: calc(50% + 10px); right: 0; }
.tl-stage:first-child::before, .tl-stage:last-child::after { display: none; }
.tl-stage.li-fill::before { background: var(--brand); }
.tl-stage.lo-fill::after { background: var(--brand); }
.tl-node {
  width: 14px; height: 14px; border-radius: 50%; z-index: 1; flex: none;
  background: var(--surface); border: 2px solid var(--line); box-sizing: border-box;
}
.tl-node[data-s="Completed"] { background: var(--brand); border-color: var(--brand); }
.tl-node[data-s="In Progress"] { background: var(--warn-bg); border-color: var(--warn-ink); }
.tl-node[data-s="Blocked"] { background: var(--bad-bg); border-color: var(--bad-ink); }
.tl-node[data-s="N/A"] { border-style: dashed; opacity: .55; }
.tl-node[data-cur="true"] {
  box-shadow: 0 0 0 4px var(--brand-wash); width: 16px; height: 16px; margin-top: -1px;
}
.tl-node[data-cur="true"][data-s="Blocked"] { box-shadow: 0 0 0 4px var(--bad-bg); }
.tl-label {
  font-size: .66rem; line-height: 1.15; font-weight: 600; color: var(--muted); margin-top: 5px;
  text-align: center; max-width: min(150px, 100%); min-height: 2.3em; padding: 0 2px;
  overflow-wrap: break-word; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.tl-label.cur { color: var(--ink); }
.tl-date { font-size: .58rem; color: var(--muted); opacity: .85; min-height: .8em; }
.tl-short { display: none; }
@media (max-width: 600px) {
  .tl-date { display: none; }
  .tl-full { display: none; }
  .tl-short { display: inline; }
  .tl-label { min-height: 0; }
}

/* ---------- board sections ---------- */
.section {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  margin-bottom: 16px; overflow: hidden;
}
/* --brand-deep is the same in light and dark themes, so white text works in both. */
.section-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: var(--brand-deep); color: #fff;
  font-size: .85rem; font-weight: 600; letter-spacing: .01em;
}
.section-body { padding: 14px 14px 0; }
.section-body .empty { padding: 16px 0 30px; }
.section-count {
  background: #fff; color: var(--brand-deep); border-radius: 999px;
  padding: 1px 9px; font-size: .72rem; font-weight: 700;
}

/* ---------- detail popup extras ---------- */
.stage-date { display: block; font-weight: 400; font-size: .7rem; color: var(--muted); }
.section-row select {
  border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px;
  font-size: .82rem; background: var(--surface); margin-left: 4px;
}
.rework-btn { margin-top: 10px; width: 100%; }

/* ---------- formula documents ---------- */
.fact.muted { color: var(--muted); }
.formula-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.formula-item { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.formula-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.formula-meta { font-size: .82rem; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.formula-meta b { color: var(--ink); font-weight: 600; }
.formula-name { color: var(--ink); font-weight: 500; }
.formula-actions { display: inline-flex; gap: 10px; align-items: baseline; flex: none; }
.formula-dl { font-size: .8rem; font-weight: 500; color: var(--brand); flex: none; text-decoration: none; }
.formula-dl:hover { text-decoration: underline; }
.formula-del { font: inherit; font-size: .74rem; color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; }
.formula-del:hover { color: var(--bad-ink); text-decoration: underline; }
.formula-del:disabled { opacity: .5; cursor: default; }
.danger-zone .muted { color: var(--muted); }
.danger-zone { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 28px; padding-top: 14px; border-top: 1px dashed var(--line); font-size: .8rem; }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-ink); }
.confirm-modal { max-width: 520px; }
.confirm-modal .field { margin: 10px 0; }
.confirm-modal .field input { width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .9rem; background: var(--surface); color: var(--ink); }
.confirm-controls { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.formula-notes { font-size: .8rem; color: var(--ink); margin-top: 3px; white-space: pre-wrap; }
.formula-form { display: flex; flex-direction: column; gap: 8px; }
.formula-form input[type="file"] { font-size: .8rem; color: var(--muted); }
.formula-form textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  resize: vertical; font-size: .85rem; background: var(--surface);
}
.formula-form .note-controls { display: flex; justify-content: flex-end; margin-top: 0; }
.formula-form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.formula-version { display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.formula-version input {
  width: 90px; border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
  font-size: .85rem; background: var(--surface); color: var(--ink);
}
.formula-form :disabled { opacity: .6; cursor: not-allowed; }
.formula-current {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px;
  background: var(--ok-bg); color: var(--ok-ink); font-size: .7rem; font-weight: 600;
  vertical-align: 1px;
}
.formula-type {
  display: inline-block; margin-right: 6px; padding: 0 7px; border-radius: 999px;
  background: var(--brand-wash); color: var(--brand); font-size: .7rem; font-weight: 600;
  vertical-align: 1px;
}
.formula-version select {
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
  font-size: .85rem; background: var(--surface); color: var(--ink);
}
.section-hint { display: block; font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* ---------- filters, intake, excipient equivalence ---------- */
.field-filters { display: contents; }
.field-filters select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  background: var(--surface); font-size: .875rem; min-width: 160px;
}
.item-field { position: relative; }
.item-field .remove-sku { position: absolute; top: 0; right: 0; border: 0; background: none;
  color: var(--muted); cursor: pointer; font-size: 1rem; }
.modal.equiv-modal { width: min(560px, 100%); }
.equiv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.equiv-table { box-shadow: none; }
.equiv-table tbody tr { cursor: default; }
.equiv-table td.muted { color: var(--muted); text-align: center; }

/* ---------- FabRx API stock view ---------- */
.stock-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 4px 0 12px; }
.stock-title { margin: 0 0 4px; font-size: 1.05rem; }
.stock-head .hint { margin: 0; color: var(--muted); font-size: .85rem; max-width: 720px; }
.stock-stats { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.stock-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.stock-add input, .stock-add select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); color: var(--ink); font-size: .875rem; }
.stock-add input { min-width: 280px; }
.stock-table tbody tr { cursor: default; }
.stock-table td { vertical-align: middle; }
.stock-table .stock-api { font-weight: 600; white-space: nowrap; }
.stock-table .stock-uses { white-space: nowrap; }
.stock-notes { width: 100%; min-width: 220px; border: 1px solid transparent; border-radius: 6px; padding: 4px 6px; background: transparent; color: var(--ink); font-size: .82rem; }
.stock-notes:hover, .stock-notes:focus { border-color: var(--line); background: var(--surface); }
.cell-select.sel-stock { min-width: 160px; width: auto; }
.cell-select.sel-stock[data-s="Yes"] { background-color: var(--ok-bg); color: var(--ok-ink); }
.cell-select.sel-stock[data-s="No"]  { background-color: var(--bad-bg); color: var(--bad-ink); }
.cell-select.sel-stock[data-s=""]    { background-color: var(--idle-bg); color: var(--idle-ink); }
body.view-stock .api-search, body.view-stock #filter-section, body.view-stock #field-filters, body.view-stock #filter-status, body.view-stock .group-toggle { display: none; }
