:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #17263a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #17324F;
  --navy-dark: #122539;
  --gold: #C6A24C;
  --accent-soft: #eaeff5;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b42318;
  --info: #17324F;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }

/* Top bar + nav */
.topbar {
  background: var(--accent); border-bottom: 3px solid var(--gold);
  padding: 0 24px; display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.brand { font-weight: 700; padding: 12px 0; letter-spacing: -0.01em; color: #fff; display: flex; align-items: center; gap: 10px; }
.brand img { height: 34px; width: auto; background: #fff; border-radius: 6px; padding: 3px; }
.brand em { color: #b9c6d6; font-weight: 400; font-style: normal; margin-left: 2px; font-size: 13px; }
.mark { color: var(--gold); }
.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; }
.topbar nav a {
  padding: 10px 12px; border-radius: 8px; color: #c7d2df;
  font-size: 14px; font-weight: 500;
}
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.topbar nav a.on { background: var(--gold); color: var(--navy-dark); }

main { max-width: 1080px; margin: 0 auto; padding: 28px 24px 64px; }

/* Headings */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
h1 { font-size: 24px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 0 0 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

/* Cards + layout */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; margin-bottom: 18px;
}
.split { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.2fr); gap: 18px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 620px) { .kpis { grid-template-columns: repeat(2,1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi-num { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; }
.kpi-label { font-size: 13px; color: var(--muted); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sub { display: block; color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 26px; }
code, .code-block, pre { font-family: var(--mono); }
code { font-size: 13px; background: var(--bg); padding: 2px 6px; border-radius: 6px; }

/* Status */
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge.ok { background: #e7f6ec; color: var(--ok); }
.badge.warn { background: #fdf1e3; color: var(--warn); }
.badge.bad { background: #fbeae8; color: var(--bad); }
.badge.info { background: #e9f1fa; color: var(--info); }
.badge.muted { background: #eef1f5; color: var(--muted); }
.ok-text { color: var(--ok); } .bad-text { color: var(--bad); }

/* Rejection bar */
.bar { display: inline-block; width: 90px; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; vertical-align: middle; margin-right: 8px; }
.bar span { display: block; height: 100%; background: var(--gold); }
.rate { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }

/* Tabs */
.tabs, .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 7px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); border: 1px solid var(--border); }
.tab.on { background: var(--gold); color: var(--navy-dark); border-color: var(--gold); }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form.inline { flex-direction: row; align-items: stretch; }
.form.inline input { flex: 1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select { font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--ink); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
/* minmax(0,1fr), not 1fr: a bare 1fr track has min-width:auto, so a wide <select>
   or a long option label pushes the grid past the edge of its card. */
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.row3 > label, .row3 > * { min-width: 0; }
input, select, textarea { max-width: 100%; min-width: 0; }
button { font: inherit; font-weight: 600; padding: 10px 16px; border: none; border-radius: 9px; background: var(--accent); color: #fff; cursor: pointer; }
button:hover { filter: brightness(1.06); }
button.small { padding: 6px 12px; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.count { background: var(--accent); color: #fff; font-size: 12px; padding: 2px 9px; border-radius: 999px; margin-left: 6px; }

/* Buttons as links */
.btn { display: inline-block; padding: 9px 14px; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.back { display: inline-block; margin-top: 14px; color: var(--muted); }

/* Result receipts */
.result { margin-top: 16px; }
.receipt { border: 1px dashed var(--border); border-radius: 10px; padding: 6px 14px; background: var(--bg); font-family: var(--mono); }
.r-row { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.r-row:last-child { border-bottom: none; }
.r-row span { color: var(--muted); }
.ok-box .receipt { border-color: var(--ok); }
.bad-box { padding: 14px; border: 1px solid var(--bad); border-radius: 10px; background: #fbeae8; color: var(--bad); }
.info-box .receipt { border-color: var(--accent); }

/* Label sheet + packing additions */
.btn.small { padding: 5px 11px; font-size: 13px; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: 4px; }
.label-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.label-grid .label { width: auto; }

/* Print: show only the labels, hide the console chrome */
@media print {
  .topbar, nav, .no-print, .back, .hint { display: none !important; }
  main { max-width: none; padding: 0; }
  .label-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .label { border: 1px solid #000; break-inside: avoid; }
}

/* ---- Scan stations & live feedback (manpower-friendly) ---- */
.warn-text { color: var(--warn); }
button.danger { background: var(--bad); }
button.small.danger { background: var(--bad); }

.station-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 620px) { .station-row { grid-template-columns: 1fr; } }
.station-tile { display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 26px; border-radius: 16px; color: #fff; text-decoration: none; min-height: 120px; }
.station-tile.ok { background: var(--ok); }
.station-tile.warn { background: var(--warn); }
.station-tile.bad { background: var(--bad); }
.station-count { font-size: 44px; font-weight: 800; line-height: 1; }
.station-label { font-size: 15px; font-weight: 600; margin-top: 6px; letter-spacing: 0.03em; }

/* single-purpose scan card */
.station-scan { text-align: center; border-top: 6px solid transparent; }
.station-scan.ok { border-top-color: var(--ok); }
.station-scan.warn { border-top-color: var(--warn); }
.station-scan.bad { border-top-color: var(--bad); }
.station-big { font-size: 56px; font-weight: 800; line-height: 1; }
.station-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.05em; }
.station-scan .form.inline { max-width: 460px; margin: 0 auto; }
.station-scan input { font-size: 18px; padding: 14px; }

/* big result banner */
.scan-result { margin: 16px auto 0; max-width: 560px; padding: 16px 18px; border-radius: 12px;
  font-size: 18px; font-weight: 700; }
.scan-ok { background: #e7f6ec; color: var(--ok); border: 2px solid var(--ok); }
.scan-warn { background: #fdf1e3; color: var(--warn); border: 2px solid var(--warn); }
.scan-bad { background: #fbeae8; color: var(--bad); border: 2px solid var(--bad); }
/* In flight. Deliberately quiet — it must not read as a result, only as "sent".
   It is replaced by the ok/warn/bad banner as soon as the station answers. */
.scan-pending { background: var(--bg); color: var(--muted); border: 2px dashed var(--border);
  font-weight: 600; }

hr.soft { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---- Dashboard panels & inventory gauges ---- */
.kpis-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 900px) { .kpis-6 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .kpis-6 { grid-template-columns: repeat(2, 1fr); } }

.bar.wide { width: 140px; }
.bar span.fill-bad { background: var(--bad); }
.bar span.fill-warn { background: var(--warn); }

/* monthly bars */
.mbars { display: flex; gap: 12px; align-items: flex-end; height: 170px; padding-top: 6px; }
.mbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.mbar-track { width: 66%; height: 100%; display: flex; align-items: flex-end; background: var(--bg); border-radius: 6px; }
.mbar-fill { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; }
.mbar-fill.bad { background: var(--bad); }
.mbar-val { font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.mbar-lbl { font-size: 12px; color: var(--muted); }

/* in-house vs supplier split */
.split-bar { display: flex; height: 22px; border-radius: 8px; overflow: hidden; background: var(--border); }
.seg.navy { background: var(--accent); }
.seg.gold { background: var(--gold); }
.split-legend { display: flex; gap: 18px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.dot.navy { background: var(--accent); }
.dot.gold { background: var(--gold); }

/* ---------------------------------------------------------------- Auth */

/* Signed-in identity + sign-out, sitting at the right of the top bar.
   margin-left:auto keeps it hard right even when the nav wraps it to its own row. */
.userbox {
  display: flex; align-items: center; gap: 10px; margin-left: auto;
  color: #c7d2df; font-size: 13px; padding: 8px 0;
}
.userbox .who { display: flex; flex-direction: column; line-height: 1.25; text-align: right; }
.userbox .who b { color: #fff; font-weight: 600; }
.userbox .role {
  color: var(--gold); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
}
.userbox a {
  color: #c7d2df; border: 1px solid rgba(255,255,255,.22);
  padding: 6px 10px; border-radius: 8px; font-size: 13px;
}
.userbox a:hover { background: rgba(255,255,255,.10); color: #fff; }

/* Sign-in and change-password sit alone on the page, narrow and centred */
.login-card { max-width: 400px; margin: 8vh auto 0; }
.login-card h1 { margin-bottom: 6px; }
.login-card .form { margin-top: 16px; }
.login-card button { width: 100%; }

/* 403 */
.denied-roles { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }

/* Staff admin table */
.you-tag {
  background: var(--accent-soft); color: var(--accent); border-radius: 6px;
  padding: 1px 6px; font-size: 11px; font-weight: 600; margin-left: 6px;
}
.row-off { opacity: 0.55; }
.role-pick { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.temp-pass {
  font-family: var(--mono); background: var(--accent-soft); color: var(--accent);
  padding: 3px 8px; border-radius: 6px; font-weight: 600; user-select: all;
}
