:root {
  /* Grok dark tokens (from grok.com / Jess SoT) */
  --bg: #1e1d1d;
  --surface: #282726;
  --surface2: #322f2e;
  --border: rgba(230, 229, 227, 0.12);
  --text: #e6e5e3;
  --muted: #a3a29e;
  --accent: #1084fe;
  --accent-soft: rgba(16, 132, 254, 0.18);
  --ok: #34d399;
  --ok-bg: rgba(52, 211, 153, 0.12);
  --short: #fbbf24;
  --short-bg: rgba(251, 191, 36, 0.12);
  --over: #38bdf8;
  --over-bg: rgba(56, 189, 248, 0.12);
  --unexpected: #f87171;
  --unexpected-bg: rgba(248, 113, 113, 0.12);
  --tap: 48px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding: 0 0 40px;
}

.banner {
  margin: 0 0 14px;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.25);
  color: #a7f3d0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.banner.staging-banner {
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.35);
  color: #fde68a;
}
.banner b { color: #fff; }

.shell { max-width: 1180px; margin: 0 auto; padding: 16px 20px 0; }

.menubar-wrap{
  margin:0 0 16px;background:rgba(30,29,29,.94);border-bottom:1px solid var(--border);
  backdrop-filter:saturate(1.2) blur(10px);
}
.menubar{
  max-width:1180px;margin:0 auto;display:flex;align-items:center;justify-content:space-between;gap:16px;
  min-height:56px;padding:0 20px;background:transparent;border:0;border-radius:0;
}
.menubar-brand{display:flex;align-items:center;gap:10px;min-width:0}
.menubar-brand img{height:26px;width:auto;display:block}
.menubar-right{display:flex;align-items:center;gap:12px;flex-shrink:0}
.menubar-app{font-size:.85rem;font-weight:600;color:var(--text);letter-spacing:-.01em}
.menubar-env{
  font-size:.7rem;font-weight:600;padding:4px 10px;border-radius:999px;
  background:rgba(251,191,36,.12);color:#fde68a;border:1px solid rgba(251,191,36,.35);
}

.header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2; /* was inheriting body 1.45 — optical center drifts vs 42px input */
  flex-shrink: 0;
}

.shipment {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

/* MUST override global label — this is the actual misalignment bug */
.shipment label {
  display: inline;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}

.shipment input {
  flex: 1;
  min-width: 0; /* prevent flex overflow shove */
  height: 42px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.chip {
  background: var(--ok-bg);
  color: var(--ok);
  font-weight: 700;
  font-size: 0.75rem;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(52, 211, 153, 0.25);
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip.empty {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-color: var(--border);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat span {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.stat.ok b { color: var(--ok); }
.stat.short b { color: var(--short); }
.stat.over b { color: var(--over); }
.stat.bad b { color: var(--unexpected); }

.main {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .status-strip { grid-template-columns: repeat(3, 1fr); }
  .scan-col { position: static; }
}

.scan-col { position: sticky; top: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card.scan {
  border: 1px solid rgba(16, 132, 254, 0.4);
  box-shadow: none;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.card.scan h2 { color: #93c5fd; }

.collapsed {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  margin-bottom: 10px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.collapsed.loaded {
  background: var(--ok-bg);
  border-color: rgba(52, 211, 153, 0.22);
}
.collapsed strong { color: var(--muted); font-size: 0.9rem; }
.collapsed.loaded strong { color: var(--ok); }
.collapsed span { color: var(--muted); font-size: 0.8rem; }

.import-panel {
  display: none;
  margin-bottom: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.import-panel.open { display: block; }
.import-panel input[type="file"] {
  width: 100%;
  color: var(--muted);
  font-size: 0.85rem;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--muted);
}
.optional-tag { color: var(--muted); font-weight: 400; }

.field { margin-bottom: 12px; }
.field input,
.modal input {
  width: 100%;
  height: var(--tap);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.3;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.field input:focus,
.modal input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.flash {
  display: none;
  margin: 8px 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-align: center;
  border: 1px solid transparent;
}
.flash.show { display: block; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.flash.err { background: var(--unexpected-bg); color: var(--unexpected); border-color: rgba(248, 113, 113, 0.3); }
.flash.info { background: var(--over-bg); color: var(--over); border-color: rgba(56, 189, 248, 0.3); }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: transparent; color: var(--unexpected); border-color: rgba(248, 113, 113, 0.35); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.hint { margin: 10px 0 0; color: var(--muted); font-size: 0.78rem; }

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.results-head h2 { margin: 0; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr.short { background: var(--short-bg); }
tr.bad { background: var(--unexpected-bg); }
tr.over { background: var(--over-bg); }
td.empty { color: var(--muted); text-align: center; padding: 28px 14px; }

.shipment input,
.scan-fields input,
.modal input,
.pn,
.counted,
.num,
.modal-meta,
.log {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.pn, .counted { font-weight: 700; }
th, td { vertical-align: middle; }

.status {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.short { background: var(--short-bg); color: var(--short); }
.status.bad, .status.unexpected { background: var(--unexpected-bg); color: var(--unexpected); }
.status.over { background: var(--over-bg); color: var(--over); }

td.actions { width: 40px; text-align: right; padding-right: 10px; }
.row-menu { position: relative; display: inline-block; }
.menu-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}
.menu-btn:hover,
.menu-btn.open {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}
.menu-pop {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  bottom: auto;
  z-index: 50;
  min-width: 176px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 6px;
}
.menu-pop.show { display: block; }
.menu-pop.up {
  top: auto;
  bottom: calc(100% + 6px);
}
.menu-pop button {
  display: flex;
  width: 100%;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}
.menu-pop button:hover { background: rgba(255, 255, 255, 0.05); }
.menu-pop button.danger { color: var(--unexpected); }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}
.footer .right { display: flex; gap: 8px; flex-wrap: wrap; }

.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.modal-card.danger {
  background: #1c1416;
  border: 1px solid rgba(248, 113, 113, 0.45);
}
.modal-card h3 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 700; }
.modal-card.danger h3 { color: #fecaca; }
.modal-card p { margin: 0 0 8px; color: var(--muted); }
.modal-card.danger p { color: #fecaca; font-weight: 600; }
.modal-meta {
  color: var(--muted);
  margin-bottom: 16px;
}
.modal-card.danger .modal-meta { color: #fca5a5; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}
.modal-card.danger .modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
}
.btn.reject {
  background: transparent;
  border: 1px solid rgba(252, 165, 165, 0.5);
  color: #fecaca;
}
.btn.accept {
  background: #ef4444;
  border-color: transparent;
  color: #fff;
}

body.locked .scan-fields input,
body.locked #btnRecord {
  opacity: 0.45;
  pointer-events: none;
}

.complete-banner {
  display: none;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--ok-bg);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: var(--ok);
  font-weight: 700;
}
.complete-banner.show { display: block; }

.log {
  margin-top: 12px;
  max-height: 120px;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
