:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-text: #052e16;
  --danger: #ef4444;
  --border: #334155;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.1rem; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
h3 { font-size: 1rem; margin-bottom: 12px; }

.topbar {
  padding: calc(10px + var(--safe-top)) 16px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.stats { font-size: 0.85rem; color: var(--muted); }
.stats .dot { margin: 0 6px; }

main { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 12px; overflow: auto; }

.scanner {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  max-height: 45dvh;
  width: 100%;
  flex-shrink: 0;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 18% 12%;
  border: 2px solid rgba(255,255,255,.7);
  border-radius: 10px;
  pointer-events: none;
  display: none;
}
.scanner.active .scan-frame { display: block; }
.scan-frame::after {
  content: ""; position: absolute; left: 6%; right: 6%; top: 50%;
  height: 2px; background: rgba(239,68,68,.85);
}
.scanner-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 16px; text-align: center;
  background: linear-gradient(180deg, rgba(15,23,42,.85), rgba(15,23,42,.95));
}
.scanner.active .scanner-overlay { display: none; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; max-width: 32ch; }
.hint.error { color: #fca5a5; }
.scanner-toolbar {
  position: absolute; bottom: 8px; left: 8px; right: 8px;
  display: flex; gap: 8px; justify-content: flex-end;
}
.chip {
  border: none; border-radius: 999px; padding: 8px 14px;
  background: rgba(15,23,42,.75); color: #fff; font-size: 0.85rem;
  backdrop-filter: blur(4px);
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.flash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: rgba(34,197,94,.45);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.6);
  word-break: break-all; padding: 16px; text-align: center;
}
.flash.show { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

.manual { display: flex; gap: 8px; }
.manual input {
  flex: 1; min-width: 0;
  padding: 12px 14px; font-size: 1rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
}
.manual input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.list-section { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.list-header { display: flex; justify-content: space-between; align-items: baseline; }
.last-scan { font-size: 0.8rem; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border-radius: var(--radius);
  padding: 10px 12px; border: 1px solid transparent;
}
.list li.highlight { border-color: var(--accent); }
.list .code { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1rem; word-break: break-all; }
.list .qty-ctl { display: flex; align-items: center; gap: 4px; }
.list .qty-ctl button {
  width: 34px; height: 34px; border-radius: 8px; border: none;
  background: var(--panel-2); color: var(--text); font-size: 1.1rem;
}
.list .qty { min-width: 2.2ch; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.list .del { background: transparent; border: none; color: var(--muted); font-size: 1.1rem; padding: 6px; }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; font-size: 0.9rem; }

.actions {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
  position: sticky; bottom: 0;
}
.actions .btn { flex: 1; }
.actions .btn-primary { flex: 2; }

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius); padding: 12px 16px; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; touch-action: manipulation;
}
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-danger { color: #fca5a5; }
.btn-lg { padding: 16px 24px; font-size: 1.05rem; }

dialog {
  border: none; border-radius: var(--radius); background: var(--panel); color: var(--text);
  padding: 20px; width: min(92vw, 380px);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.radio small { color: var(--muted); }
.radio code { font-size: .8em; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
