/* AMPM ERP — module 1 UI
   Direction: factory control room. Steel structure, paper surface,
   safety-amber for the active/identity moments, monospace for data. */

:root {
  --paper:  #F4F5F3;
  --panel:  #FFFFFF;
  --ink:    #1B2430;
  --muted:  #5F6975;
  --line:   #DBDFE3;
  --steel:  #29323E;
  --steel-2:#394453;
  --amber:      #E89C00;
  --amber-ink:  #6E4E00;
  --amber-soft: #FDF1D7;
  --ok:      #1E7F4F;
  --ok-soft: #E3F3EA;
  --bad:     #B3362B;
  --bad-soft:#FAE8E5;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "Archivo", system-ui, "Segoe UI", Roboto, sans-serif;
  --radius: 6px;
  --shadow: 0 8px 28px rgba(27,36,48,.16);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over display:flex/grid
   rules on the same element (e.g. .guide, .toolbar). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-size: 14.5px;
  line-height: 1.45;
}

/* --------------------------------------------------- shell + side nav */

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

.sidenav {
  width: 218px; flex-shrink: 0;
  background: var(--steel); color: #E8EBEE;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid #3B4654;
}
/* The logo mark: an "A" peak with the amber crossbar. It inherits the
   text colour of wherever it sits (white on the steel nav, ink on the
   white sign-in card) — only the crossbar is always amber. */
.brand-logo {
  width: 22px; height: 22px; flex: 0 0 22px;
  border-radius: 5px; background: transparent;
}
.sidenav .brand-logo { color: #fff; }
.login-card .brand-logo, .doc .brand-logo { color: var(--steel); }
.brand-mark {
  font-weight: 700; letter-spacing: .14em; font-size: 18px; color: #fff;
}
.brand-sub {
  font-family: var(--mono); font-size: 11.5px; color: #9AA6B4;
  letter-spacing: .04em;
}
.login-card .brand-mark, .doc .brand-mark { color: var(--ink); }

/* Legal line shown under the sign-in / signup cards and on documents. */
.legal-footer {
  margin: 18px auto 0; max-width: 460px; padding: 0 14px;
  text-align: center; font-size: 11.5px; line-height: 1.65;
  color: #8A94A0;
}
.legal-footer a { color: inherit; text-decoration: underline; }
.legal-footer a:hover { color: #B9C2CC; }
.doc .legal-footer a:hover, .login-card ~ .legal-footer a:hover { color: inherit; }

.sidenav nav { display: flex; flex-direction: column; padding: 10px 0; }
.nav-item {
  appearance: none; border: 0; background: none; cursor: pointer;
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 10px 16px; text-align: left;
  color: #B9C2CC; font: 600 13.5px var(--sans); letter-spacing: .01em;
  border-left: 3px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-item:hover { color: #fff; background: var(--steel-2); }
.nav-item.is-active {
  color: #fff; background: var(--steel-2);
  border-left-color: var(--amber);
}

.sidenav-footer {
  margin-top: auto; padding: 14px 18px;
  border-top: 1px solid #3B4654;
  font: 500 11.5px var(--mono); color: #9AA6B4; letter-spacing: .04em;
}

.nav-item { position: relative; }
.nav-badge {
  margin-left: auto; background: var(--bad); color: #fff;
  font: 700 10.5px var(--mono); border-radius: 999px; padding: 1px 7px;
}
@media (min-width: 861px) and (max-width: 1280px) {
  /* icon-only nav: badge floats over the icon's corner */
  .nav-badge { position: absolute; top: 4px; right: 6px; margin: 0;
               padding: 0 5px; }
}

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: var(--steel);
  color: #E8EBEE;
  padding: 0 20px;
  min-height: 48px;
}

/* Scan box — barcode guns type into this, so it sits in the top bar
   and is always one keystroke away wherever you are in the app. */
.scanbox {
  display: flex; align-items: center; gap: 8px;
  margin-right: auto;                     /* pushes it to the left end */
}
.scanbox-icon {
  font-family: "IBM Plex Mono", monospace; letter-spacing: -2px;
  color: var(--amber); font-size: 15px;
}
.scan-input {
  min-width: 260px; height: 30px; padding: 0 10px;
  background: var(--steel-2); border: 1px solid #4A5666;
  color: #E8EBEE; font-size: 13px;
}
.scan-input::placeholder { color: #8D99A8; }
.scan-input:focus { border-color: var(--amber); outline: none; }
.scan-barcode {
  margin-top: 12px; display: flex; align-items: flex-end;
  justify-content: center; gap: 14px; flex-wrap: wrap;
}
.scan-barcode svg { max-width: 100%; height: auto; }
.scan-qr svg { width: 96px; height: 96px; }
@media (max-width: 860px) { .scan-input { min-width: 130px; } }

.actor { display: flex; align-items: center; gap: 10px; }
.actor-label { font-size: 12px; color: #9AA6B4; }
.actor-chip {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--steel-2); border: 1px solid #4A5666;
  color: #fff; border-radius: 999px; padding: 5px 6px 5px 12px;
  font: 500 13px var(--mono);
}
.actor-chip:hover { border-color: var(--amber); }

.role-chip {
  font: 500 11px var(--mono);
  background: var(--amber); color: #2A2007;
  border-radius: 999px; padding: 2px 9px; letter-spacing: .03em;
}

/* ------------------------------------------------------------- layout */

main { width: 100%; max-width: 1180px; margin: 24px auto 60px; padding: 0 22px; }

.panel { background: var(--panel); border: 1px solid var(--line);
         border-radius: var(--radius); padding: 22px 24px 26px; }

.panel-head { display: flex; justify-content: space-between;
              align-items: flex-start; gap: 16px; margin-bottom: 14px; }
h1 { font-size: 21px; font-weight: 700; margin: 0 0 2px; letter-spacing: -.01em; }
.panel-note { margin: 0; color: var(--muted); font-size: 13.5px; }

.banner {
  max-width: 1180px; margin: 18px 22px -6px; padding: 12px 16px;
  background: var(--bad-soft); color: var(--bad);
  border: 1px solid #E8C2BC; border-radius: var(--radius);
  font-weight: 500;
}

/* ------------------------------------------------------------ toolbar */

.toolbar { display: flex; align-items: end; gap: 14px; margin: 14px 0; flex-wrap: wrap; }
.count { color: var(--muted); font: 400 12.5px var(--mono); margin-left: auto; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px;
         color: var(--muted); font-weight: 500; }
.field-stack { width: 100%; }

.input {
  font: 400 14px var(--sans); color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; min-width: 0;
}
.input:focus-visible, .btn:focus-visible, .tab:focus-visible,
.actor-chip:focus-visible, .link-btn:focus-visible {
  outline: 2px solid var(--amber); outline-offset: 1px;
}
#user-search { width: 280px; }

/* ------------------------------------------------------------ buttons */

.btn {
  appearance: none; cursor: pointer;
  font: 600 13.5px var(--sans);
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 14px;
}
.btn:hover { border-color: var(--steel-2); }
.btn-primary { background: var(--steel); border-color: var(--steel); color: #fff; }
.btn-primary:hover { background: var(--steel-2); }

.link-btn {
  appearance: none; background: none; border: 0; cursor: pointer;
  color: var(--steel-2); font: 600 13px var(--sans);
  padding: 4px 6px; border-radius: 4px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--bad); }
.link-btn.ok { color: var(--ok); }

/* -------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }
/* Make the sideways scrollbar obvious when a table is wider than the
   screen — Windows hides overlay scrollbars, which made wide tables
   look cut off on the right. */
.table-wrap::-webkit-scrollbar { height: 9px; }
.table-wrap::-webkit-scrollbar-track { background: var(--paper); }
.table-wrap::-webkit-scrollbar-thumb {
  background: #B9C2CC; border-radius: 5px;
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.table-wrap { scrollbar-width: thin; scrollbar-color: #B9C2CC var(--paper); }

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font: 600 11.5px var(--mono); letter-spacing: .03em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 2px solid var(--steel);
  padding: 8px;
}
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }

/* sortable column headers — headers may wrap to two lines so long
   labels (e.g. "Purchase price") no longer force the table too wide */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable::after { content: "↕"; opacity: .35; margin-left: 5px; font-size: 10px; }
th.sortable.sort-asc::after { content: "↑"; opacity: 1; color: var(--amber-ink); }
th.sortable.sort-desc::after { content: "↓"; opacity: 1; color: var(--amber-ink); }
.table tbody tr:hover { background: #FAFBFA; }
.th-actions { text-align: right; }
.td-actions { text-align: right; white-space: nowrap; }

.cell-mono { font: 400 12.5px var(--mono); color: var(--muted); white-space: nowrap; }
.cell-strong { font-weight: 600; }

.role-tag {
  font: 500 12px var(--mono);
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 10px; white-space: nowrap;
}

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; }
.status.on  .dot { background: var(--ok); }
.status.off .dot { background: var(--bad); }
.status.off { color: var(--muted); }

/* ---------------------------------------------- audit: the ledger ---- */

.table-audit td { padding-top: 12px; padding-bottom: 12px; }
.audit-when { font: 400 12.5px var(--mono); color: var(--ink); white-space: nowrap; }
.audit-when small { display: block; color: var(--muted); }

.action-tag {
  font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase;
  border-radius: 3px; padding: 3px 8px; white-space: nowrap;
}
.action-create { background: var(--ok-soft);  color: var(--ok); }
.action-update { background: var(--amber-soft); color: var(--amber-ink); }
.action-other  { background: var(--paper); color: var(--muted); }

.entity { font: 400 12.5px var(--mono); color: var(--muted); }
.entity strong { color: var(--ink); font-weight: 500; }

/* Signature element: before -> after change chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: 400 12px var(--mono);
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 8px;
}
.chip .k { color: var(--muted); }
.chip .old { color: var(--bad); text-decoration: line-through; }
.chip .arrow { color: var(--muted); }
.chip .new { color: var(--ok); font-weight: 500; }

/* -------------------------------------------------------------- empty */

.empty { padding: 34px 10px; text-align: center; color: var(--muted); }

/* -------------------------------------------------------------- modal */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(27,36,48,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 40;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 8px; box-shadow: var(--shadow);
  padding: 22px 24px; width: 100%; max-width: 420px;
  border-top: 4px solid var(--amber);
  max-height: 92vh; overflow-y: auto;   /* long forms scroll on phones */
}
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.form-error { margin: 0; color: var(--bad); font-weight: 500; font-size: 13px; }

/* -------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--steel); color: #fff;
  font: 500 13.5px var(--sans);
  border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow);
  z-index: 50;
}

/* --------------------------------------------------------- responsive */

/* Medium windows: collapse the side nav to icons so tables get the
   width they need. Full labels return on wide screens; below 860px
   the nav becomes a top bar (next rule). Nav buttons keep a title
   tooltip (set in app.js) so icons stay identifiable. */
@media (min-width: 861px) and (max-width: 1280px) {
  .sidenav { width: 62px; }
  .sidenav .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 12px 0; }
  .nav-item svg { width: 20px; height: 20px; flex: 0 0 20px; }
  .brand { justify-content: center; padding: 14px 4px; }
  .brand-sub { display: none; }
  .brand-mark { font-size: 13px; letter-spacing: .06em; }
  .sidenav-footer { padding: 10px 4px; text-align: center; }
}

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidenav { width: 100%; height: auto; position: static; }
  .sidenav nav { flex-direction: row; overflow-x: auto; padding: 0; }
  .brand { display: none; }
  .sidenav-footer { display: none; }
  .nav-item {
    flex-direction: column; gap: 4px; padding: 10px 12px;
    font-size: 11px; white-space: nowrap;
    border-left: 0; border-bottom: 3px solid transparent;
  }
  .nav-item.is-active { border-left-color: transparent;
                        border-bottom-color: var(--amber); }
  .actor-label { display: none; }
  #user-search { width: 100%; }
  .panel { padding: 16px; }
  .field-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
  .stat .v { font-size: 17px; }
  /* dynamic line editors stack instead of squeezing */
  .line-row { flex-wrap: wrap; }
  .line-row select.input { flex: 1 1 100%; }
  .line-row input.input { flex: 1 1 40%; }
  .panel-head { flex-direction: column; }
  .panel-head .btn { align-self: flex-start; }
  .report-toolbar .btn { flex: 1 1 auto; }
  main { margin-top: 14px; }
  .funnel-row { flex-direction: column; align-items: stretch; gap: 2px; }
  .funnel-label { width: auto; text-align: left; }
  .order-acts { margin-left: 0; }
  .cr-card-meta { white-space: normal; }
}

/* Small phones — stack everything that still sits side-by-side, and
   keep touch targets comfortable. Tables keep their horizontal scroll
   (.table-wrap) so no data is ever cut off. */
@media (max-width: 560px) {
  main { padding: 0 12px; margin: 16px auto 40px; }
  .guide { margin: 10px 12px -6px; }
  .panel { padding: 12px; }
  .panel-head h1 { font-size: 18px; }

  .toolbar { gap: 8px; }
  .toolbar .field { flex: 1 1 100%; }
  .toolbar .input, .toolbar select.input { width: 100%; }
  .section-head { flex-wrap: wrap; }
  .btn { padding: 9px 14px; }

  .modal-overlay { padding: 10px; align-items: flex-start; }
  .modal { padding: 16px; }

  .cr-form { flex-direction: column; align-items: stretch; }
  .cr-form .btn { margin-bottom: 0; align-self: flex-end; }
  .cr-card-head { gap: 6px; }
  .cr-card-meta { white-space: normal; width: 100%; }
  .cr-track { flex-wrap: wrap; row-gap: 6px; }
  .cr-line { min-width: 14px; }

  .table th { padding: 7px 8px; }
  .table td { padding: 8px; }
}

@media (prefers-reduced-motion: no-preference) {
  .modal { animation: pop .14s ease-out; }
  @keyframes pop { from { transform: scale(.97); opacity: 0; } }
}

/* --------------------------------------------- module panels (2..7) --- */

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin: 26px 0 8px;
  border-bottom: 1px solid var(--line); padding-bottom: 6px;
}
.section-head:first-of-type { margin-top: 6px; }
.section-head h2 {
  margin: 0; font-size: 14px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--steel-2);
}

.empty-row {
  text-align: center; color: var(--muted); padding: 22px 10px !important;
}

/* lifecycle status badges (plans, work orders) */
.status-tag {
  font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase;
  border-radius: 3px; padding: 3px 8px; white-space: nowrap;
}
.st-draft       { background: var(--paper);      color: var(--muted);
                  border: 1px solid var(--line); }
.st-open        { background: var(--amber-soft); color: var(--amber-ink); }
.st-approved    { background: var(--amber-soft); color: var(--amber-ink); }
.st-in_progress { background: #E3EDF7;           color: #23558A; }
.st-completed   { background: var(--ok-soft);    color: var(--ok); }
.st-cancelled   { background: var(--bad-soft);   color: var(--bad); }

/* small inline badge that qualifies a status, e.g. "part received" */
.pill {
  display: inline-block; font: 600 11px var(--mono); border-radius: 3px;
  padding: 2px 7px; margin-left: 4px; white-space: nowrap;
  background: var(--paper); color: var(--muted); border: 1px solid var(--line);
}
.pill.warn { background: var(--amber-soft); color: var(--amber-ink);
             border-color: var(--amber); }

/* checkbox line inside a form */
.field-row { flex-direction: row; align-items: center; gap: 8px; }

/* a retired row: still readable, clearly not in play */
.row-off td { opacity: .55; }

/* sign-in: covers everything until there is a session */
.login-screen {
  position: fixed; inset: 0; z-index: 200;
  background: var(--steel);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.login-card {
  background: #fff; border-radius: var(--radius);
  padding: 28px 30px 22px; width: min(92vw, 380px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
.login-card .brand { display: flex; align-items: center; gap: 8px;
                     margin-bottom: 4px; padding: 0 0 10px; border-bottom: 0; }
.login-card h2 { margin: 6px 0 14px; }
.login-card code {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 3px; padding: 1px 4px; font: 11px var(--mono);
}

/* pick list: a batch already on the pallet */
.pick-done td { background: var(--ok-soft); color: var(--ok); }

/* the route a recipe is made on: machine -> machine -> machine */
.bom-route-strip {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin: 10px 0; padding: 8px 10px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px;
}
.route-step {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 8px; font-size: 13px;
}
.route-no {
  width: 18px; height: 18px; border-radius: 50%; background: var(--steel);
  color: #fff; font: 600 11px var(--mono);
  display: inline-flex; align-items: center; justify-content: center;
}
.route-arrow { color: var(--muted); }
.route-total { margin-left: auto; font: 600 12px var(--mono); color: var(--muted); }
/* routing editor rows: the two minute boxes stay narrow */
.route-row .route-setup, .route-row .route-run { flex: 0 0 110px; }

/* machine board: one card per machine, live state and OEE */
.machine-grid {
  display: grid; gap: 12px; margin-top: 12px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.machine-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; background: #fff;
}
.machine-card.is-live { border-left: 3px solid var(--ok); }
.machine-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 4px;
}
.machine-stats {
  display: flex; gap: 18px; margin: 10px 0;
}
.machine-stats div { display: flex; flex-direction: column; }
.pill.live-run { background: var(--ok-soft); color: var(--ok);
                 border-color: var(--ok); }
.pill.live-stop { background: var(--bad-soft); color: var(--bad);
                  border-color: var(--bad); }

.oee-row { display: flex; gap: 8px; }
.oee-factor {
  flex: 1; text-align: center; padding: 8px 4px; border-radius: 4px;
  background: var(--paper); border: 1px solid var(--line);
}
.oee-factor.is-good { background: var(--ok-soft); border-color: var(--ok); }
.oee-factor.is-ok   { background: var(--amber-soft); border-color: var(--amber); }
.oee-factor.is-bad  { background: var(--bad-soft); border-color: var(--bad); }
/* day / week / month / quarter / year switch */
.period-tabs { display: inline-flex; border: 1px solid var(--line);
               border-radius: 4px; overflow: hidden; }
.period-btn {
  border: 0; background: #fff; padding: 6px 14px; cursor: pointer;
  font: 500 13px var(--sans, inherit); color: var(--muted);
  border-right: 1px solid var(--line);
}
.period-btn:last-child { border-right: 0; }
.period-btn:hover { background: var(--paper); }
.period-btn.is-active { background: var(--steel); color: #fff; }

/* the trend under a machine card: one bar per sub-period */
.oee-trend {
  display: flex; align-items: flex-end; gap: 3px; height: 64px;
  margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--line);
}
.trend-bar {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: center; height: 100%; min-width: 0;
}
.trend-bar > span {
  width: 100%; border-radius: 2px 2px 0 0; background: var(--muted);
  min-height: 2px;
}
.trend-bar.is-good > span { background: var(--ok); }
.trend-bar.is-ok   > span { background: var(--amber); }
.trend-bar.is-bad  > span { background: var(--bad); }
.trend-bar.is-none > span { background: var(--line); height: 2px; }
.trend-bar em {
  font-style: normal; font-size: 9px; color: var(--muted);
  margin-top: 3px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%;
}

.oee-value { display: block; font: 600 16px var(--mono); }
.oee-label { font-size: 11px; color: var(--muted); text-transform: uppercase;
             letter-spacing: .04em; }

/* credit note lines: label, then the quantity coming off */
.cn-row { gap: 10px; }
.cn-row .cn-qty { flex: 0 0 140px; }
.cn-row .panel-note { flex: 1; margin: 0; }

/* stock alerts + signed quantities */
.row-alert td { background: #FDF6F5; }
.qty-pos { color: var(--ok); font-weight: 500; }
.qty-neg { color: var(--bad); font-weight: 500; }

/* dynamic line editors (GRN lines, BOM items) */
.line-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.line-row .input { flex: 1; min-width: 0; }
.line-row select.input { flex: 2; }
.line-remove { flex: 0 0 auto; }
.btn-small { padding: 5px 10px; font-size: 12.5px; align-self: flex-start; }

.modal-wide { max-width: 680px; }

/* BOM version blocks */
.bom-version {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 10px; background: var(--paper);
}
.bom-version.is-current { background: #fff; border-color: var(--amber); }
.bom-version-head { display: flex; align-items: center; gap: 10px; }
.bom-items { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.bom-items li { margin-bottom: 2px; }
/* ------------------------------------------------- demand notes */

.mr-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 12px 16px; margin-bottom: 12px;
}
.mr-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
           margin-bottom: 6px; }
.mr-actions { display: flex; gap: 12px; align-items: center; margin-top: 8px; }

/* ------------------------------- live plan stage tracker (in list) */

.stage-cell { min-width: 210px; }

.stage-bar { display: flex; align-items: center; gap: 3px; }
.stage {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; color: var(--muted); white-space: nowrap;
}
.stage-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--line); flex: 0 0 auto;
}
.stage.is-done { color: var(--ok); }
.stage.is-done .stage-dot { background: var(--ok); border-color: var(--ok); }
.stage.is-now { font-weight: 700; }
.stage.is-now .stage-dot {
  box-shadow: 0 0 0 3px var(--ok-soft);
  animation: stage-pulse 1.8s ease-in-out infinite;
}
.stage.is-bad { color: var(--bad); font-weight: 600; }
.stage.is-bad .stage-dot { background: var(--bad); border-color: var(--bad); }
.stage-line { flex: 1; min-width: 8px; height: 2px; background: var(--line); }
.stage-line.is-done { background: var(--ok); }

@keyframes stage-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--ok-soft); }
  50%      { box-shadow: 0 0 0 6px rgba(30,127,79,.10); }
}

.ready-note { font-size: 11px; margin-top: 3px; }
.ready-note.is-ok { color: var(--ok); }
.ready-note.is-short {
  color: var(--bad); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 260px;
}

/* actions must never be squeezed off the row */
.td-actions .link-btn { white-space: nowrap; }

/* --------------------------------- production readiness guidance */

.guidance {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; border-radius: var(--radius);
  padding: 12px 16px; margin: 4px 0 14px; border: 1px solid var(--line);
}
.guidance.is-go { background: var(--ok-soft); border-color: #BFE0CD; }
.guidance.is-wait { background: var(--bad-soft); border-color: #F0C8C2; }

/* ------------------------------------------- storage board (tanks) */

.tank-grid {
  display: grid; gap: 12px; margin: 8px 0 18px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.tank {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 10px; text-align: center;
}
.tank-body {
  position: relative; height: 96px; border-radius: 6px;
  background: repeating-linear-gradient(45deg, var(--paper), var(--paper) 6px,
              #EDEFEC 6px, #EDEFEC 12px);
  border: 1px solid var(--line); overflow: hidden; margin-bottom: 8px;
}
.tank-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--ok); transition: height .5s cubic-bezier(.2,.7,.3,1);
}
.tank.is-low .tank-fill, .tank.is-over .tank-fill { background: var(--bad); }
.tank.is-full .tank-fill { background: var(--amber); }
.tank.is-empty .tank-fill { background: var(--line); }
.tank.is-off { opacity: .55; }
.tank.is-off .tank-fill { background: var(--muted); }
.inner-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); margin: 10px 0 14px;
}
.tank-min {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 2px dashed var(--steel-2); opacity: .55;
}
.tank-pct {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font: 700 15px var(--mono); color: var(--ink);
  text-shadow: 0 1px 2px rgba(255,255,255,.85);
}
.tank-label .tank-name {
  font-size: 12.5px; font-weight: 600; margin: 2px 0 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tank-qty { font: 400 11.5px var(--mono); color: var(--muted); }
.tank-status { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tank.is-low .tank-status, .tank.is-over .tank-status { color: var(--bad); font-weight: 600; }
.tank.is-full .tank-status { color: var(--amber-ink); font-weight: 600; }

/* --------------------------------------------- warehouse racks */

.rack-grid {
  display: grid; gap: 10px; margin: 8px 0 12px;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.rack {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 9px 11px; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.rack:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(27,36,48,.12); }
.rack.is-free { background: var(--paper); border-style: dashed; }
.rack.is-used { border-color: #BFE0CD; }
.rack.is-full { border-color: var(--amber); background: var(--amber-soft); }
.rack.is-off { opacity: .5; }
.rack-code { font: 700 13px var(--mono); }
.rack-loc { font: 400 11px var(--mono); color: var(--muted); }
.rack-bar {
  height: 6px; border-radius: 3px; background: var(--line);
  overflow: hidden; margin: 6px 0 5px;
}
.rack-bar span { display: block; height: 100%; background: var(--ok);
                 transition: width .4s ease; }
.rack.is-full .rack-bar span { background: var(--amber); }
.rack-item { font-size: 12px; overflow: hidden; text-overflow: ellipsis;
             white-space: nowrap; }
.rack-cap { font: 400 11px var(--mono); color: var(--muted); }

/* ------------------------------------- serial numbers on every list */

.sr-col {
  width: 34px; text-align: right; padding-right: 10px !important;
  color: var(--muted); font: 400 12px var(--mono);
  white-space: nowrap;
}
th.sr-col { text-align: right; }

/* ----------------------------------------- goods receipt calendar */

.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  margin: 6px 0 14px;
}
.cal-head {
  font: 600 11px var(--mono); text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); text-align: center;
  padding-bottom: 2px;
}
.cal-day {
  min-height: 62px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); padding: 5px 7px; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.cal-day:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(27,36,48,.12); }
.cal-day.has-grn { background: var(--ok-soft); border-color: #BFE0CD; }
.cal-day.is-today { border-color: var(--amber); border-width: 2px; }
.cal-date { font: 600 12px var(--mono); color: var(--muted); }
.cal-count { font: 700 12.5px var(--sans); color: var(--ok); margin-top: 2px; }
.cal-lines { font-size: 11px; color: var(--muted); }

@media (max-width: 560px) {
  .cal-grid { gap: 3px; }
  .cal-day { min-height: 48px; padding: 3px 4px; }
  .cal-lines { display: none; }
}

/* --------------------------------- product photos & pricing panel */

.prod-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; font-weight: 700; letter-spacing: .02em;
  flex: 0 0 auto;
}
.prod-img { border-radius: 8px; object-fit: cover; flex: 0 0 auto;
            border: 1px solid var(--line); }
.prod-cell { display: inline-flex; align-items: center; gap: 8px; }

.bom-prodhead {
  display: flex; gap: 16px; align-items: flex-start;
  border-bottom: 1px solid var(--line); padding-bottom: 14px;
  margin-bottom: 12px;
}
.bom-prodhead .prod-photo { flex: 0 0 auto; }

.bom-pricing {
  background: var(--amber-soft); border: 1px solid #EBD9A8;
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
}
.bom-pricing:empty { display: none; }
.price-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.price-l { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
           color: var(--muted); }
.price-v { font: 700 15px var(--mono); }
.price-op { color: var(--muted); font-size: 12px; padding-bottom: 2px; }

/* ------------------------------------------- visual recipe (BOM) */

.bom-strip {
  display: flex; height: 16px; border-radius: 8px; overflow: hidden;
  margin: 12px 0 4px; border: 1px solid var(--line); background: var(--paper);
}
.bom-seg { display: block; height: 100%; transition: width .35s ease; }

.bom-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 7px; vertical-align: middle;
}

.bom-bar {
  height: 7px; border-radius: 4px; background: var(--line);
  overflow: hidden; margin-bottom: 3px; max-width: 190px;
}
.bom-bar span { display: block; height: 100%; transition: width .35s ease; }

.bom-scaler {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 10px 0 4px; font-size: 13px;
}
.bom-scaler label { display: flex; align-items: center; gap: 8px;
                    color: var(--muted); }
.bom-canmake { font: 600 12.5px var(--mono); }

.bom-allergens { margin: 8px 0 2px; font-size: 12.5px; color: var(--muted); }
.bom-allergen {
  display: inline-block; background: var(--bad-soft); color: var(--bad);
  border-radius: 999px; padding: 1px 9px; margin-left: 6px;
  font: 600 11.5px var(--sans);
}

.bom-new h3 { margin: 14px 0 10px; font-size: 14px; }
.bom-new { border-top: 2px solid var(--steel); margin-top: 14px; padding-top: 4px;
           display: flex; flex-direction: column; gap: 10px; }

/* ------------------------------------------------- dashboard + forms */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px; margin: 6px 0 10px;
}
.stat {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 15px;
}
.stat .v { font: 600 21px var(--mono); letter-spacing: -.01em; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 3px;
           font-weight: 500; }
.stat-alert { background: var(--bad-soft); border-color: #E8C2BC; }
.stat-alert .v { color: var(--bad); }

.field-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px;
}

/* ------------------------------------------------ order funnel (dash) */

.funnel { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 12px; }
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-label {
  width: 170px; flex-shrink: 0; text-align: right;
  font: 600 12.5px var(--sans); color: var(--muted);
}
.funnel-track { flex: 1; display: flex; justify-content: center; }
.funnel-bar {
  height: 36px; min-width: 92px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #fff; font: 600 13px var(--mono);
}
.funnel-bar small { font-weight: 400; opacity: .8; }

/* -------------------------------------------- order tracking (WIP) --- */

.order-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; padding: 14px 16px; margin-bottom: 14px;
}
.order-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.order-stage { font-size: 12.5px; font-weight: 600; color: var(--steel-2); }
.order-acts { margin-left: auto; white-space: nowrap; }
.progress {
  flex: 1; min-width: 110px; height: 8px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--line); overflow: hidden;
}
.progress i { display: block; height: 100%; background: var(--amber); }
.progress.p100 i { background: var(--ok); }
.est-hours { color: var(--amber-ink); background: var(--amber-soft);
             border-radius: 4px; padding: 2px 8px; font-size: 12px; }
.order-items { margin-top: 10px; }
.order-items .table td, .order-items .table th { padding: 6px 10px; }
.order-plans { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px;
               align-items: center; }

/* tasks chip in the top bar */
.tasks-chip { margin-right: 12px; }

/* ------------------------------------------ order stage timeline ----- */

.steps { display: flex; margin: 12px 0 4px; }
.step {
  flex: 1; text-align: center; position: relative;
  font: 600 11.5px var(--sans); color: var(--muted); padding-top: 2px;
}
.step .dot {
  display: block; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line);
  margin: 0 auto 5px; position: relative; z-index: 2; box-sizing: border-box;
}
.step::before {
  content: ""; position: absolute; top: 8px; left: -50%;
  width: 100%; height: 2px; background: var(--line); z-index: 1;
}
.step:first-child::before { display: none; }
.step.done { color: var(--ink); }
.step.done .dot { background: var(--ok); border-color: var(--ok); }
.step.done::before { background: var(--ok); }
.step.current { color: var(--ink); }
.step.current .dot {
  background: var(--amber); border-color: var(--amber);
  box-shadow: 0 0 0 4px var(--amber-soft);
}
.step.current::before { background: var(--ok); }
.step small { display: block; font-weight: 400; font-size: 10.5px;
              color: var(--muted); margin-top: 3px; padding: 0 6px; }

.timeline-legend {
  border: 1px dashed var(--line); border-radius: var(--radius);
  background: var(--paper); padding: 12px 16px 14px; margin-bottom: 16px;
}
.tl-title {
  font: 600 11.5px var(--mono); letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 2px;
}

/* material shortfall strip on an order card */
.mat-short {
  margin-top: 10px; padding: 8px 10px; border-radius: 4px;
  background: var(--amber-soft); border: 1px solid #EBD9A8;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.mat-short-title { font: 600 12px var(--sans); color: var(--amber-ink); }

/* ------------------------------------------------ guided instructions */

.guide {
  max-width: 1180px; margin: 14px 22px -6px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--amber-soft); border: 1px solid #EBD9A8;
  border-radius: var(--radius); padding: 9px 14px;
  font-size: 13px; color: var(--amber-ink);
}
.guide-bulb { flex-shrink: 0; }
/* text wraps inside its own flex cell, so the bulb never sits alone */
#guide-text { flex: 1 1 240px; min-width: 0; }
.guide .link-btn { color: var(--amber-ink); text-decoration: underline; }
.guide-close { margin-left: auto; text-decoration: none !important; }

/* ------------------------------------------------- sub-tabs in panels */

.subtabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 2px solid var(--steel); margin: 4px 0 16px;
}
.sub-tab {
  appearance: none; cursor: pointer;
  font: 600 13px var(--sans); color: var(--muted);
  background: var(--paper); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 6px 6px 0 0; padding: 8px 16px;
}
.sub-tab:hover { color: var(--ink); }
.sub-tab.is-active { background: var(--steel); border-color: var(--steel);
                     color: #fff; }
/* the count pill keeps its own dark text — the active tab's white would
   otherwise disappear against the pale pill */
.sub-tab .role-tag { color: var(--ink); margin-left: 6px; }

/* ------------------------------------------- vendor analytics charts */

.vchart { margin: 6px 0 14px; }
.vchart-title { font: 600 11.5px var(--mono); letter-spacing: .05em;
                text-transform: uppercase; color: var(--muted);
                margin: 10px 0 6px; }
.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
.hbar-label { width: 160px; flex-shrink: 0; text-align: right;
              font: 600 12px var(--sans); color: var(--ink);
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { flex: 1; }
.hbar { height: 26px; border-radius: 3px; min-width: 40px;
        display: flex; align-items: center; padding: 0 8px;
        color: #fff; font: 500 11.5px var(--mono); white-space: nowrap; }

/* projection strip in the plan modal */
.plan-projection {
  background: var(--amber-soft); border: 1px solid #EBD9A8;
  border-radius: 4px; padding: 8px 12px; font-size: 12.5px;
  color: var(--amber-ink);
}

/* --------------------------------------------------- change requests */

.cr-form { display: flex; gap: 12px; align-items: flex-end;
           margin-bottom: 8px; }
.cr-form textarea { resize: vertical; font-family: var(--sans); }
.cr-form .btn { flex-shrink: 0; margin-bottom: 22px; }
.release-row {
  display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper); padding: 8px 14px; margin-bottom: 6px;
  font-size: 13px;
}
.deploy-notes {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin: 10px 0;
  font-size: 13px; white-space: pre-wrap; max-height: 200px;
  overflow-y: auto;
}
.deploy-notes:empty { display: none; }

/* ----------------------------------------------------- help & training */

.help-topic {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; margin-bottom: 10px;
}
.help-topic summary {
  cursor: pointer; padding: 12px 16px;
  font: 600 14.5px var(--sans); color: var(--steel-2);
  list-style-position: inside;
}
.help-topic summary:hover { color: var(--ink); }
.help-topic[open] summary { border-bottom: 1px solid var(--line);
                            background: var(--paper); }
.help-steps { margin: 12px 0; padding: 0 20px 4px 40px; }
.help-steps li { margin-bottom: 10px; line-height: 1.55; }
.help-steps .link-btn { border: 1px solid var(--line); border-radius: 4px;
                        padding: 1px 10px; margin-left: 6px; }

/* module access grid */
.access-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
  margin: 12px 0 4px;
}
.access-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; cursor: pointer; padding: 4px 6px; border-radius: 4px;
}
.access-row:hover { background: var(--paper); }
.access-row input { accent-color: var(--amber); width: 15px; height: 15px; }

/* ------------------------------------------- change request cards */

.cr-cards { display: flex; flex-direction: column; gap: 12px; }

.cr-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.cr-card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cr-card-desc { flex: 1; min-width: 220px; }
.cr-card-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

.cr-track { display: flex; align-items: center; gap: 8px; margin: 12px 0 2px; }
.cr-step {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.cr-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--line);
}
.cr-step.is-done { color: var(--ok); }
.cr-step.is-done .cr-dot { background: var(--ok); border-color: var(--ok); }
.cr-step.is-bad { color: var(--bad); }
.cr-step.is-bad .cr-dot { background: var(--bad); border-color: var(--bad); }
.cr-line { flex: 1; height: 2px; background: var(--line); min-width: 24px; }
.cr-line.is-done { background: var(--ok); }
.cr-line.is-bad { background: var(--bad); }

.cr-dev-note { color: var(--muted); font-size: 13px; margin-top: 6px; }
.cr-card-actions { margin-top: 8px; }

/* ------------------------------------------------- lot recall trace */

.recall-box { margin-bottom: 10px; }
.recall-trace {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 12px 16px 16px; margin-top: 8px;
}
.recall-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.recall-h {
  font-size: 12.5px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--steel-2); margin: 14px 0 4px;
}

.ask-answer {
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px;
  white-space: pre-line; font-size: 14px;
}

.deploy-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  background: var(--amber-soft); border: 1px solid #EBD9A8;
  border-radius: var(--radius); padding: 12px 16px; margin: 4px 0 14px;
}
