:root {
  --bg: #eef0f3; --surface: #ffffff; --surface-2: #f6f7f9; --ink: #14161a; --muted: #5b6472; --line: #dce0e6; --line-strong: #c3c9d2;
  --accent: #2a62d9; --accent-ink: #ffffff; --accent-soft: #e4ecfc;
  --red: #d93a2f; --red-soft: #fde9e7; --orange: #f08a1c; --orange-soft: #fdf0de; --yellow: #f2c230; --yellow-soft: #fdf5d8; --green: #1f9d55; --green-soft: #e0f4e8; --blue-soft: #e4ecfc;
  --shadow: 0 1px 2px rgba(20, 22, 26, .06), 0 8px 24px rgba(20, 22, 26, .08);
  --radius: 8px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013; --surface: #171a1f; --surface-2: #1d2128; --ink: #e8eaee; --muted: #9aa3b1; --line: #2a2f38; --line-strong: #3a414d;
    --accent: #5b8cf0; --accent-ink: #0b1020; --accent-soft: #1b2540;
    --red-soft: #3a1c1a; --orange-soft: #3a2a15; --yellow-soft: #3a3213; --green-soft: #15301f; --blue-soft: #1b2540;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.right { text-align: right; }
.hide { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Layout */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; letter-spacing: -.01em; }
.mark { display: grid; grid-template-columns: repeat(3, 7px); gap: 2px; padding: 4px; background: #14161a; border-radius: 6px; }
.mark i { width: 7px; height: 7px; border-radius: 1.5px; display: block; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { font: 500 12px var(--mono); background: var(--red); color: #fff; border-radius: 10px; padding: 1px 7px; }
.rail .spacer { flex: 1; }
.rail .who { font-size: 12px; color: var(--muted); padding: 8px 10px; border-top: 1px solid var(--line); }
main { padding: 24px 28px 96px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; line-height: 1.15; }
h2 { margin: 0 0 10px; font-size: 15px; letter-spacing: -.005em; }
.sub { color: var(--muted); margin-top: 4px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }

/* Controls */
.btn { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; padding: 7px 12px; font-weight: 600; min-height: 34px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 9px; min-height: 28px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select, textarea {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; padding: 7px 10px; min-height: 34px; width: 100%;
}
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
input[type=number] { font-family: var(--mono); text-align: right; }
td input[type=number] { width: 84px; min-height: 30px; padding: 4px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 12px; font-weight: 600; color: var(--muted); border-right: 1px solid var(--line); min-height: 34px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg .n { font: 500 12px var(--mono); margin-left: 6px; opacity: .8; }
label.field { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
label.field span.hint { font-weight: 400; color: var(--muted); }

/* Surfaces */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > .panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel > .panel-head h2 { margin: 0; }
.panel-body { padding: 4px 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.ledger { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.ledger > div { padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.ledger dt { color: var(--muted); font-size: 12.5px; margin: 0; display: flex; align-items: center; gap: 6px; }
.ledger dd { margin: 4px 0 0; font: 500 26px/1.1 var(--mono); letter-spacing: -.02em; }
.ledger dd small { font: 400 12px var(--font); color: var(--muted); letter-spacing: 0; }
.notice { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; border: 1px solid var(--line-strong); background: var(--yellow-soft); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.notice.info { background: var(--blue-soft); }
.notice.bad { background: var(--red-soft); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* Cube stickers: the status vocabulary */
.stk { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; background: var(--muted); }
.stk.red { background: var(--red); } .stk.orange { background: var(--orange); } .stk.yellow { background: var(--yellow); } .stk.green { background: var(--green); } .stk.blue { background: var(--accent); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; padding: 2px 8px 2px 7px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.tag.red { background: var(--red-soft); } .tag.green { background: var(--green-soft); } .tag.yellow { background: var(--yellow-soft); } .tag.blue { background: var(--blue-soft); } .tag.orange { background: var(--orange-soft); }

/* Tables */
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 230px); }
.panel .table-wrap { border: 0; border-radius: 0; max-height: none; }
table { border-collapse: collapse; width: 100%; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
th.right, td.right { text-align: right; }
td.item { min-width: 240px; }
.item .t { font-weight: 600; }
.item .v { color: var(--muted); font-size: 13px; }
.item .sku { font: 400 11.5px var(--mono); color: var(--muted); }
.neg { color: var(--red); font-weight: 600; }
.pos { color: var(--green); font-weight: 600; }
tr.sel td { background: var(--accent-soft); }

/* Orders */
.orders { display: grid; gap: 10px; }
.order { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; break-inside: avoid; }
.order header { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.order header .name { font: 600 15px var(--mono); }
.order ul { list-style: none; margin: 0; padding: 4px 0; }
.order li { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; padding: 6px 14px; align-items: baseline; }
.order li .q { font: 600 14px var(--mono); }
.order li.svc { color: var(--muted); }
.order .note { padding: 6px 14px 10px; color: var(--muted); font-size: 13px; }

/* Batches */
.batch { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.batch > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; }
.batch > summary::-webkit-details-marker { display: none; }
.batch > summary .name { font-weight: 700; font-size: 15px; }
.batch .body { border-top: 1px solid var(--line); }
.batch .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }

/* Sticky action bar */
.actionbar { position: fixed; left: 216px; right: 0; bottom: 0; z-index: 20; display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 12px 28px; background: var(--ink); color: var(--bg); box-shadow: 0 -6px 24px rgba(0,0,0,.18); }
.actionbar .btn { border-color: transparent; }

/* Modal */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide { width: min(940px, 100%); }
.modal header { padding: 16px 20px 0; display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.modal header h2 { font-size: 18px; margin: 0; }
.modal .content { padding: 14px 20px 6px; display: grid; gap: 14px; }
.modal footer { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.picker { position: relative; }
.picker .results { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
.picker .results button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.picker .results button:hover { background: var(--surface-2); }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 76px; display: grid; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--red); color: #fff; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login .brand { padding: 0; }

/* Phone */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; z-index: 30; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); }
  .rail .brand, .rail .spacer, .rail .who { display: none; }
  .nav { display: grid; grid-template-columns: repeat(6, 1fr); width: 100%; gap: 2px; }
  .nav a { flex-direction: column; justify-content: center; gap: 2px; padding: 6px 2px; font-size: 11.5px; text-align: center; position: relative; }
  .nav .count { position: absolute; top: 0; right: 6px; font-size: 10px; padding: 0 5px; }
  main { padding: 16px 16px 96px; }
  h1 { font-size: 22px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .actionbar { left: 0; bottom: 56px; padding: 10px 16px; }
  .table-wrap { max-height: none; }
  .ledger dd { font-size: 22px; }
  #toasts { bottom: 130px; right: 8px; left: 8px; }
}

/* Print: the pick list */
@media print {
  body { background: #fff; color: #000; }
  .rail, .toolbar, .actionbar, #toasts, .page-head .btn, .no-print, .notice { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .order { border-color: #999; }
  .order header { background: #f1f1f1 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Thin progress bar while data is refreshing */
body.busy::before { content: ""; position: fixed; z-index: 90; top: 0; left: 0; height: 3px; width: 100%; background: var(--accent); transform-origin: left; animation: busy 1.4s ease-in-out infinite; }
@keyframes busy { 0% { transform: scaleX(.05); } 60% { transform: scaleX(.85); } 100% { transform: scaleX(1); opacity: .2; } }
