:root {
  --bg: #0f1419;
  --bg-elev: #171e26;
  --bg-card: #1c2530;
  --line: #2a3644;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #2dd4a8;
  --accent-dim: #0f3d32;
  --warn: #f5b942;
  --danger: #f07167;
  --info: #5b9fd6;
  --ok: #2dd4a8;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2dd4a8, #1a9b7a);
  display: grid; place-items: center;
  color: #06241c;
  font-weight: 800;
}
.mode-pill {
  margin-left: auto;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid #1d6b56;
}
.mode-pill.live { background: #14304a; color: #7ec2ff; border-color: #2a5578; }
.icon-btn, .ghost-btn, .primary-btn, .danger-btn, .ok-btn {
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: 10px;
  padding: 8px 12px;
}
.icon-btn { padding: 8px 10px; }
.primary-btn { background: var(--accent); color: #06241c; border-color: transparent; font-weight: 700; }
.ok-btn { background: #1a7a5c; border-color: #249973; }
.danger-btn { background: #5a2420; border-color: #8a3a34; color: #ffd2ce; }
.ghost-btn:hover, .icon-btn:hover { border-color: #3d4d5e; }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 42vh; }
}

.sidebar {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #12181f;
}
.sidebar-tools {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
}
.chip.active { background: var(--accent-dim); color: var(--accent); border-color: #1d6b56; }

.order-list { overflow: auto; padding: 0 8px 16px; }
.order-card {
  width: 100%;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}
.order-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.order-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.order-name { font-weight: 700; }
.meta { color: var(--muted); font-size: 12px; }
.status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 999px;
}
.status.unfulfilled, .status.pending { background: #3d2a10; color: #f5b942; }
.status.partial, .status.picking { background: #14304a; color: #7ec2ff; }
.status.fulfilled, .status.packed { background: var(--accent-dim); color: var(--accent); }
.status.open { background: #3d2a10; color: #f5b942; }

.main { min-height: 0; overflow: auto; padding: 18px; }
.empty {
  max-width: 520px;
  margin: 10vh auto;
  text-align: center;
  color: var(--muted);
}
.empty h2 { color: var(--text); margin-bottom: 8px; }

.order-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.progress-wrap { width: 100%; }
.progress {
  height: 10px;
  background: #0b1015;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #1a9b7a, #2dd4a8);
  width: 0%;
  transition: width 0.25s ease;
}

.scan-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.scan-bar input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 16px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #0b1015;
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
  display: none;
}
.toast.show { display: block; }
.toast.ok { border-color: #1d6b56; }
.toast.bad { border-color: #8a3a34; }

.items { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.item.done { border-color: #1d6b56; background: #12241f; }
.item.wrong-flash { animation: shake 0.35s ease; border-color: var(--danger); }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.thumb {
  width: 64px; height: 64px;
  border-radius: 10px;
  background: #0b1015;
  object-fit: cover;
  border: 1px solid var(--line);
}
.thumb.ph {
  display: grid; place-items: center;
  color: var(--muted); font-size: 11px;
}
.item h3 { margin: 0 0 4px; font-size: 15px; }
.sku { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.qty {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.qty .n { font-size: 22px; font-weight: 700; }
.qty .n.done { color: var(--accent); }
.qty-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; align-items: center; }
.qty-actions button { width: 32px; height: 32px; padding: 0; }
.qty-actions .fulfill-line {
  width: auto;
  min-width: 76px;
  padding: 0 12px;
  height: 32px;
  font-size: 13px;
  white-space: nowrap;
}

.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}
.modal-bg.open { display: flex; }
.modal {
  width: min(560px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow: auto;
}
.modal h2 { margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.help { font-size: 13px; color: var(--muted); line-height: 1.45; }
.help ol { padding-left: 18px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

#reader { width: 100%; min-height: 240px; border-radius: 12px; overflow: hidden; background: #000; }

.barcode-preview { margin-top: 6px; }
.barcode-preview svg { max-width: 100%; height: 40px; }

.stats {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}
.stat b { color: var(--text); display: block; font-size: 16px; }

.carton {
  margin-top: 18px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.carton h3 { margin: 0 0 6px; }
.carton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.carton-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #d5e2ee;
}
.carton-grid input, .carton-grid select,
input, select, textarea {
  background: #0b1015;
  border: 1px solid #4a5d70;
  border-radius: 10px;
  padding: 10px 12px;
  color: #f4f8fb;
  caret-color: #f4f8fb;
  color-scheme: dark;
}
.carton-grid input:focus, .carton-grid select:focus,
input:focus, select:focus {
  outline: 2px solid #2dd4a8;
  border-color: #2dd4a8;
}
.carton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.rate-box { margin-top: 12px; }
.rate-list { display: flex; flex-direction: column; gap: 6px; }
.rate-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: #0b1015;
  border: 1px solid #4a5d70;
  color: #f4f8fb;
  border-radius: 10px;
  padding: 8px 12px;
}
.rate-row:hover { border-color: #2dd4a8; }
.rate-row b { color: #2dd4a8; }
.svc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin: 0 0 14px;
}
.svc-grid label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: #d5e2ee;
}
#labelFrame {
  position: fixed !important;
  width: 0 !important;
  height: 0 !important;
  border: 0 !important;
  opacity: 0;
  pointer-events: none;
}
a.primary-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .topbar, .sidebar, .scan-bar, .no-print { display: none !important; }
  .layout { display: block; }
  .print-only { display: block; }
  .item { border-color: #ccc; background: #fff; }
}
