:root {
  color-scheme: light;
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #f3f4f8; --ink: #111827; --muted: #6b7280; --line: #e7e9f0; --line-strong: #d5d9e3;
  --accent: #5b5bf0; --accent-ink: #ffffff; --accent-soft: #eeeefe;
  --red: #e5484d; --red-soft: #fdecec; --orange: #f08a1c; --orange-soft: #fef1e0; --yellow: #eab308; --yellow-soft: #fef8dc; --green: #16a34a; --green-soft: #e3f6ea; --blue-soft: #eeeefe;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 12px 32px rgba(17, 24, 39, .10);
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05);
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d12; --surface: #13161d; --surface-2: #1a1e27; --ink: #eceef4; --muted: #8f98a9; --line: #232834; --line-strong: #323847;
  --accent: #7c7cff; --accent-ink: #0b0d12; --accent-soft: #1c1f3a;
  --red: #f0646a; --red-soft: #3a1a1d; --orange-soft: #38260f; --yellow-soft: #352e0e; --green: #34c36f; --green-soft: #12301f; --blue-soft: #1c1f3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
  --shadow-sm: 0 1px 2px 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, minmax(0, 1fr)); width: 100%; gap: 2px; }
  .nav a { flex-direction: column; justify-content: center; gap: 2px; padding: 6px 2px; font-size: 11px; text-align: center; position: relative; padding-left: 0; padding-right: 0; }
  .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; } }

/* ---- Modern SaaS refinements ---- */
body { font-size: 14px; letter-spacing: -.003em; -webkit-font-smoothing: antialiased; }
.num { font-family: var(--font); font-variant-numeric: tabular-nums; font-weight: 500; }
.rail { background: var(--surface); padding: 20px 14px; border-right: 1px solid var(--line); }
.brand { font-size: 15px; padding: 2px 8px 20px; }
.mark { background: var(--ink); border-radius: 8px; padding: 5px; }
.nav a { border-radius: 10px; padding: 9px 12px; color: var(--muted); font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { background: var(--red); border-radius: 999px; }
.rail .who { border-top: 1px solid var(--line); padding: 14px 8px 4px; display: grid; gap: 8px; }
.rail .who .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.theme-btn { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px; width: 34px; height: 34px; display: inline-grid; place-items: center; color: var(--muted); }
.theme-btn:hover { color: var(--ink); background: var(--surface-2); }
.theme-btn svg { width: 17px; height: 17px; }
:root[data-theme="dark"] .theme-btn .i-moon, :root:not([data-theme="dark"]) .theme-btn .i-sun { display: none; }
main { padding: 32px 36px 110px; max-width: 1320px; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.03em; }
h2 { font-size: 15px; font-weight: 650; }
.sub { font-size: 14px; }
.btn { border-radius: 10px; font-weight: 550; box-shadow: var(--shadow-sm); transition: background .15s, filter .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn.primary { box-shadow: 0 1px 2px rgba(91, 91, 240, .35); }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select, textarea { border-radius: 10px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.seg { border-radius: 10px; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0 !important; border-radius: 8px; padding: 6px 12px; min-height: 30px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.panel, .order, .batch, .table-wrap, .ledger { border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.ledger { gap: 0; border-radius: var(--radius); }
.ledger dd { font: 650 28px/1.1 var(--font); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.ledger dt { font-weight: 500; }
th { background: var(--surface); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tbody tr:hover td { background: var(--surface-2); }
.tag { border-radius: 999px; padding: 2px 10px 2px 8px; font-weight: 550; }
.stk { border-radius: 3px; }
.notice { border-radius: 12px; }
.order header { background: var(--surface); }
.batch > summary:hover { background: var(--surface-2); }
.actionbar { background: var(--surface); color: var(--ink); border-top: 1px solid var(--line); box-shadow: 0 -8px 32px rgba(17, 24, 39, .10); }
.modal { border-radius: 18px; }
.scrim { backdrop-filter: blur(3px); }
.toast { border-radius: 12px; }
.login form { border-radius: 20px; padding: 28px; }
.login-theme { position: fixed; top: 16px; right: 16px; }
body.busy::before { background: linear-gradient(90deg, var(--accent), #a78bfa); }
@media (max-width: 860px) {
  .rail { align-items: center; }
  .nav { width: calc(100% - 46px); }
  .rail .who { display: flex; border: 0; padding: 0 2px; }
  .rail .who .row > span { display: none; }
  .rail { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); }
  main { padding: 20px 16px 110px; }
  .nav a { border-radius: 12px; color: var(--muted); }
}
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } main { padding-top: max(32px, env(safe-area-inset-top)); } }
