:root {
  --bg: #0f1216;
  --panel: #171c23;
  --panel2: #1f2630;
  --line: #2b343f;
  --text: #e8edf2;
  --muted: #8b97a6;
  --accent: #ffb020;
  --accent-ink: #1a1200;
  --ok: #3ddc84;
  --warn: #ff7a45;
  --danger: #ff4d5e;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 720px; margin: 0 auto; padding: 0 16px 96px; min-height: 100%; }
h1, h2 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
button, input, select {
  font: inherit;
  color: inherit;
}
button {
  border: 0;
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--panel2);
  color: var(--text);
  min-height: 46px;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { filter: brightness(1.15); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.danger { background: transparent; color: var(--danger); }
button.ghost { background: transparent; color: var(--muted); }
button.icon { padding: 8px 12px; min-height: 40px; }
input, select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 46px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 0 10px;
  background: linear-gradient(var(--bg) 80%, transparent);
}
.topbar .grow { flex: 1; min-width: 0; }
.topbar h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }
.row .grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
}
.card .grow { flex: 1; min-width: 0; }
.card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .count {
  background: var(--panel2); color: var(--accent);
  font-weight: 700; padding: 6px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}
.card .chev { color: var(--muted); font-size: 22px; }
.section { margin-top: 22px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 26px 16px; text-align: center; color: var(--muted);
}
.fab {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(92vw, 420px);
  display: flex; gap: 10px; z-index: 6;
}
.fab button { flex: 1; min-height: 56px; font-size: 17px; box-shadow: 0 10px 30px rgba(0,0,0,0.45); }
.login {
  min-height: 90vh; display: flex; flex-direction: column; justify-content: center; gap: 14px;
}
.login .logo { font-size: 44px; text-align: center; }
.login h1 { text-align: center; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.item .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; word-break: break-all; }
.item .meta { color: var(--muted); font-size: 12px; }
.item .qty {
  display: flex; align-items: center; gap: 4px;
}
.item .qty button { padding: 0; width: 38px; min-height: 38px; border-radius: 10px; font-size: 20px; line-height: 1; }
.item .qty span { min-width: 30px; text-align: center; font-weight: 700; }
.item .tools { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; }
.item .tools button { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.item .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.item.flash { animation: flash 900ms ease-out; }
@keyframes flash { from { background: #3a3f1a; } to { background: var(--panel); } }
#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%);
  z-index: 50; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 999px; font-weight: 600; max-width: 92vw;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#toast.ok { border-color: var(--ok); }
#toast.warn { border-color: var(--warn); }
#toast.err { border-color: var(--danger); }
.scanner {
  position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column;
}
.scanner .view { position: relative; flex: 1; overflow: hidden; background: #000; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  width: min(78vw, 360px); aspect-ratio: 1.2; border-radius: 18px;
  box-shadow: 0 0 0 200vmax rgba(0,0,0,0.42);
  border: 2px solid rgba(255,255,255,0.7); pointer-events: none;
}
.scanner .frame::after {
  content: ""; position: absolute; left: 10%; right: 10%; top: 50%; height: 2px;
  background: var(--accent); opacity: 0.85; animation: sweep 1.6s ease-in-out infinite alternate;
}
@keyframes sweep { from { transform: translateY(-40px); } to { transform: translateY(40px); } }
.scanner .head {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  display: flex; gap: 8px; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(rgba(0,0,0,0.75), transparent);
}
.scanner .head .title { flex: 1; min-width: 0; }
.scanner .head .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scanner .head .title span { font-size: 12px; color: #cfd6de; }
.scanner .foot {
  z-index: 2; background: var(--bg);
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
  border-top: 1px solid var(--line);
}
.scanner .foot select { flex: 1; }
.recent { display: flex; flex-direction: column; gap: 4px; max-height: 128px; overflow: auto; }
.recent div { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.recent .c { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .dup { color: var(--warn); }
.recent .new { color: var(--ok); }
.scanner .msg { color: #ffd28a; font-size: 13px; text-align: center; }
.toggle { flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.toggle.on { border-color: var(--accent); color: var(--accent); }
.hidden { display: none !important; }
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; width: min(92vw, 420px);
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; }
.totals {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px;
}
.totals div {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 8px; text-align: center; display: flex; flex-direction: column; gap: 2px;
}
.totals b { font-size: 24px; color: var(--accent); }
.totals span { font-size: 12px; color: var(--muted); }
dialog form.pin { text-align: center; }
dialog .lockicon { font-size: 34px; }
dialog .hint { font-size: 13px; color: var(--muted); min-height: 18px; }
.scanner .zoom { gap: 8px; }
.scanner .zoom input[type="range"] { flex: 1; min-height: 0; padding: 0; background: transparent; border: 0; accent-color: var(--accent); }
.scanner .view { cursor: pointer; }
.scanner .preset { min-width: 52px; padding: 6px 8px; font-size: 13px; }
.scanner .preset.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.scanner canvas.boxes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.chooser { background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.chooser-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chooser-head b { font-size: 14px; }
.chooser-head span { font-size: 12px; color: var(--muted); }
.chooser-list { display: flex; flex-direction: column; gap: 6px; max-height: 190px; overflow: auto; }
.cand { display: grid; grid-template-columns: 26px 1fr auto auto; gap: 8px; align-items: center; font-size: 13px; }
.cand .n { background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 999px; width: 24px; height: 24px; display: grid; place-items: center; font-size: 12px; }
.cand .c { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .f { color: var(--muted); font-size: 11px; }
.cand button { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.cand.done .n { background: var(--ok); }
.cand.done button { color: var(--ok); }
.chooser .row button { flex: 1; }
.scanner.wide .frame { width: 94vw; max-width: none; aspect-ratio: 3.4; border-radius: 10px; }
.scanner.wide .frame::after { display: none; }
.scanner .foot .toggle { font-size: 13px; padding: 8px 10px; min-height: 40px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 4px 12px; border-radius: 999px; font-size: 13px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.chip span { background: var(--panel2); color: var(--text); font-weight: 700; font-size: 12px; padding: 1px 7px; border-radius: 999px; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip.on span { background: var(--accent); color: var(--accent-ink); }
