@import url('https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;600;700&display=swap');

:root {
  --black: #000;
  --brick: #A02010; --navy: #083040; --gold: #C8A868;
  --bg: #F3F4F6; --surface: #fff; --surface-2: #F8F9FA;
  --text: #24282D; --text-2: #565C64; --text-3: #6B7178;
  --line: #DADDE1; --line-2: #E8EAED;
  --primary: #24282D; --primary-hover: #000;
  --focus: #2B6CB0;
  /* status pairs: text on tint, all >= 4.5:1 (SYS-17) */
  --ok-fg: #17603A; --ok-bg: #E2F2E8; --ok-bd: #A9D6BA;
  --warn-fg: #7A4300; --warn-bg: #FDF0D2; --warn-bd: #EFCB80;
  --bad-fg: #9A1B1B; --bad-bg: #FBE3E3; --bad-bd: #EBA9A9;
  --info-fg: #1B4C8C; --info-bg: #E1EBF8; --info-bd: #A8C3E8;
  --none-fg: #474C52; --none-bg: #ECEDEF; --none-bd: #CDD0D4;
  --r: 6px;
  --fs-1: 12px; --fs-2: 14px; --fs-3: 16px; --fs-4: 20px; --fs-5: 26px;
  --nav-w: 224px;
  --header-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: var(--fs-2); line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: var(--fs-5); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-4); }
h3 { font-size: var(--fs-3); }
p { margin: 0 0 .75em; }
a { color: var(--info-fg); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-1); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App header (brand only here) ---------- */
.app-header { position: sticky; top: 0; z-index: 30; height: var(--header-h); background: var(--black); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 16px; }
.app-header::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--brick) 0 33.3%, var(--navy) 33.3% 66.6%, var(--gold) 66.6%); }
.brand { display: flex; align-items: baseline; gap: 8px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand b { font-size: 19px; font-weight: 700; letter-spacing: .02em; }
.brand span { font-size: var(--fs-1); color: var(--gold); }
.menu-btn { display: none; background: none; border: 0; color: #fff; padding: 8px; cursor: pointer; }
.search { flex: 1; max-width: 520px; position: relative; }
.search input { width: 100%; height: 36px; border-radius: var(--r); border: 1px solid #3a3d42; background: #16181b; color: #fff; padding: 0 12px; }
.search input::placeholder { color: #9aa0a6; }
.search-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 420px; overflow: auto; }
.search-results a { display: block; padding: 8px 12px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line-2); }
.search-results a:hover, .search-results a:focus { background: var(--surface-2); }
.search-results .t { font-weight: 600; } .search-results .k { color: var(--text-3); font-size: var(--fs-1); margin-left: 6px; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.bell { position: relative; background: none; border: 1px solid #3a3d42; color: #fff; border-radius: var(--r); height: 36px; padding: 0 10px; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.bell .count { background: var(--gold); color: #000; border-radius: 10px; padding: 0 7px; font-size: var(--fs-1); font-weight: 700; }
.user-btn { background: none; border: 0; color: #fff; cursor: pointer; text-align: right; line-height: 1.2; padding: 4px 6px; }
.user-btn small { display: block; color: #b8bdc3; font-size: 11px; }
.popover { position: absolute; right: 12px; top: 52px; width: 380px; max-width: calc(100vw - 24px); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 40; }
.popover header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.popover .list { max-height: 420px; overflow: auto; }
.popover .item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--text); }
.popover .item.unread { background: var(--info-bg); }
.popover .item small { display: block; color: var(--text-3); }

/* ---------- Role switch (System Administrator testing aid) ---------- */
.role-switch { display: flex; align-items: center; gap: 8px; color: #c3c7cc; font-size: var(--fs-1); white-space: nowrap; }
.role-switch select { width: auto; min-height: 36px; height: 36px; padding: 0 28px 0 10px; background-color: #16181b; color: #fff; border: 1px solid #3a3d42; border-radius: var(--r); }
.role-switch.on select { border-color: var(--gold); color: var(--gold); font-weight: 600; }
.role-switch select option { color: var(--text); background: #fff; }
.nav-switch { padding: 0 10px; }
.acting-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 8px 24px; background: var(--warn-bg); color: var(--warn-fg); border-bottom: 1px solid var(--warn-bd); }
.content { min-width: 0; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: calc(100vh - var(--header-h)); }
.nav { background: var(--surface); border-right: 1px solid var(--line); padding: 12px 8px 24px; position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow: auto; }
.nav .group { margin: 14px 10px 4px; font-size: var(--fs-1); color: var(--text-3); font-weight: 600; }
.nav a { display: block; padding: 7px 10px; border-radius: var(--r); color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--none-bg); font-weight: 600; box-shadow: inset 3px 0 0 var(--text); }
main { padding: 20px 24px 64px; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head .grow { flex: 1; }

/* ---------- Buttons and forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #b6bbc1; background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--bad-fg); border-color: var(--bad-bd); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: var(--fs-1); }
.btn.big { min-height: 52px; font-size: var(--fs-3); padding: 0 22px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-weight: 600; font-size: var(--fs-2); }
.field label .req { color: var(--bad-fg); margin-left: 2px; }
.field .help { font-size: var(--fs-1); color: var(--text-3); }
.field .err { font-size: var(--fs-1); color: var(--bad-fg); font-weight: 600; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--bad-fg); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=time], select, textarea {
  width: 100%; min-height: 36px; border: 1px solid #c4c8cd; border-radius: var(--r); padding: 6px 10px; background: #fff; }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.grid2 > *, .grid3 > * { min-width: 0; }
.totals { display: grid; grid-template-columns: auto auto; gap: 4px 24px; justify-content: end; padding: 12px 16px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.totals .g { font-weight: 700; font-size: var(--fs-3); }
.totals div:nth-child(even) { text-align: right; }

/* ---------- Status badge (always text, SYS-17) ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 4px; font-size: var(--fs-1); font-weight: 600; border: 1px solid; white-space: nowrap; line-height: 20px; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.t-ok { color: var(--ok-fg); background: var(--ok-bg); border-color: var(--ok-bd); }
.t-warn { color: var(--warn-fg); background: var(--warn-bg); border-color: var(--warn-bd); }
.t-bad { color: var(--bad-fg); background: var(--bad-bg); border-color: var(--bad-bd); }
.t-info { color: var(--info-fg); background: var(--info-bg); border-color: var(--info-bd); }
.t-none { color: var(--none-fg); background: var(--none-bg); border-color: var(--none-bd); }

/* ---------- Panels, tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 16px; }
.panel > header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel > header h2, .panel > header h3 { flex: 1; font-size: var(--fs-3); }
.panel > .body { padding: 16px; }
.panel > .body.flush { padding: 0; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
table.data td b { white-space: nowrap; }
table.data th { font-size: var(--fs-1); font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
table.data th button { all: unset; cursor: pointer; }
table.data th button:focus-visible { outline: 2px solid var(--focus); }
table.data tbody tr.link { cursor: pointer; }
table.data tbody tr.link:hover { background: #F7F9FB; }
table.data td a.rowlink { font-weight: 600; color: var(--text); text-decoration: none; }
table.data td a.rowlink:hover { text-decoration: underline; }
table.data tfoot td { font-weight: 600; background: var(--surface-2); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; min-width: 140px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 16px; color: var(--text-2); }
.empty { padding: 28px 16px; text-align: center; color: var(--text-2); }
.colmenu { position: relative; }
.colmenu .menu { position: absolute; right: 0; top: 40px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 10; min-width: 200px; }

/* ---------- Workspace ---------- */
.workspace { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.workspace .panel { margin: 0; }
.wrow { display: flex; gap: 10px; align-items: flex-start; padding: 10px 16px; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--text); }
.wrow:hover { background: var(--surface-2); }
.wrow .main { flex: 1; min-width: 0; }
.wrow .main b { display: block; }
.wrow .main span { display: block; color: var(--text-2); font-size: var(--fs-1); overflow: hidden; text-overflow: ellipsis; }
.count-pill { font-size: var(--fs-1); color: var(--text-2); background: var(--none-bg); border-radius: 10px; padding: 0 8px; font-weight: 600; }

/* ---------- Record header and tabs ---------- */
.record-head { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 20px; margin-bottom: 16px; }
.record-head .top { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.record-head .top h1 { margin-right: 4px; }
.record-head .facts { display: flex; flex-wrap: wrap; gap: 6px 28px; margin-top: 10px; color: var(--text-2); }
.record-head .facts b { color: var(--text); font-weight: 600; }
.next-action { margin-top: 12px; padding: 10px 14px; border-left: 4px solid var(--text); background: var(--surface-2); border-radius: 0 var(--r) var(--r) 0; }
.next-action.blocked { border-color: var(--bad-fg); background: var(--bad-bg); color: var(--bad-fg); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; border-bottom: 3px solid transparent; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--text-2); }
dl.kv dd { margin: 0; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.stat { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.stat .l { font-size: var(--fs-1); color: var(--text-2); }
.stat .v { font-size: var(--fs-4); font-weight: 600; font-variant-numeric: tabular-nums; }
.callout { padding: 10px 14px; border: 1px solid; border-radius: var(--r); margin-bottom: 12px; }
.callout ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Process rail: the flow chart of an Order Line (ORD-27) ---------- */
.line-card { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin-bottom: 14px; }
.line-card > .lc-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.line-card > .lc-head b { font-size: var(--fs-3); }
.rail { display: flex; overflow-x: auto; padding: 22px 16px 14px; gap: 0; scrollbar-width: thin; }
.station { position: relative; flex: 0 0 auto; width: 118px; text-align: center; padding: 0 6px; }
.station::before { content: ''; position: absolute; top: 9px; left: -50%; width: 100%; height: 3px; background: var(--line); z-index: 0; }
.station:first-child::before { display: none; }
.station.done::before, .station.current::before { background: var(--text); }
.station .dot { position: relative; z-index: 1; width: 21px; height: 21px; margin: 0 auto 8px; border-radius: 50%; border: 3px solid var(--line); background: var(--surface); }
.station.decision .dot { border-radius: 4px; transform: rotate(45deg) scale(.86); }
.station.done .dot { background: var(--text); border-color: var(--text); }
.station.current .dot { border-color: var(--text); background: var(--gold); box-shadow: 0 0 0 5px rgba(200,168,104,.35); }
.station .nm { font-size: var(--fs-1); font-weight: 600; line-height: 1.3; }
.station.todo .nm { color: var(--text-3); font-weight: 500; }
.station .rl { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.station .passes { display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 700; color: var(--warn-fg); background: var(--warn-bg); border: 1px solid var(--warn-bd); border-radius: 8px; padding: 0 6px; }
.moves { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 var(--r) var(--r); }
.move { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.gate-note { font-size: var(--fs-1); color: var(--bad-fg); max-width: 360px; }

/* ---------- Dialogs and toasts ---------- */
dialog { border: 0; border-radius: 8px; padding: 0; width: min(640px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.wide { width: min(920px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(15,17,20,.5); }
dialog header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
dialog header h2 { flex: 1; font-size: var(--fs-4); }
dialog .dbody { padding: 18px 20px; max-height: 70vh; overflow: auto; }
dialog footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; line-height: 1; padding: 4px 8px; color: var(--text-2); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { min-width: 260px; max-width: 420px; padding: 12px 16px; border-radius: var(--r); background: var(--text); color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad-fg); }
.combo { position: relative; }
.combo .opts { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); max-height: 240px; overflow: auto; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.combo .opts button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.combo .opts button:hover, .combo .opts button:focus { background: var(--surface-2); }

/* ---------- Sign in (brand allowed) ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr minmax(320px, 460px); }
.auth .side { background: var(--black); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth .side::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: linear-gradient(90deg, var(--brick) 0 33.3%, var(--navy) 33.3% 66.6%, var(--gold) 66.6%); }
.auth .side .mark { font-size: 46px; font-weight: 700; letter-spacing: .01em; line-height: 1; }
.auth .side .mark small { display: block; font-size: var(--fs-3); font-weight: 500; color: var(--gold); margin-top: 10px; letter-spacing: 0; }
.auth .side p { color: #c3c7cc; max-width: 46ch; font-size: var(--fs-3); }
.auth .form { background: var(--surface); padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; }
.auth .form h1 { margin-bottom: 6px; }
.auth .form .lead { color: var(--text-2); margin-bottom: 22px; }

/* ---------- Tablet work views (picking): next action at the bottom ---------- */
.work-list .work-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.work-row .qty input { width: 110px; min-height: 48px; font-size: var(--fs-4); text-align: right; }
.sticky-action { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; justify-content: flex-end; z-index: 5; }

/* ---------- Responsive (SYS-13: 360, 768, 1280 without sideways page scroll) ---------- */
@media (max-width: 1180px) { .role-switch .lbl { display: none; } }
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .nav { position: fixed; z-index: 25; left: 0; top: var(--header-h); width: 260px; transform: translateX(-100%); transition: transform .18s ease; visibility: hidden; }
  .nav.open { transform: none; visibility: visible; box-shadow: 4px 0 18px rgba(0,0,0,.15); }
  .menu-btn { display: block; }
  main { padding: 16px; }
}
@media (max-width: 700px) {
  .brand span, .user-btn small, .bell .lbl, .role-switch { display: none; }
  .acting-bar { padding: 8px 16px; }
  .app-header { gap: 8px; padding: 0 8px; }
  .search { max-width: none; min-width: 0; }
  .user-btn { display: none; }
  .header-right { margin-left: 0; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth .side { padding: 28px 24px 34px; min-height: 0; }
  .auth .side p { display: none; }
  .auth .form { padding: 28px 20px; }
  .workspace { grid-template-columns: 1fr; }
  .record-head { padding: 14px; }
  h1 { font-size: var(--fs-4); }
  .user-btn .nm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .app-header, .nav, .btn, .tabs { display: none !important; } .layout { display: block; } }
