:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16202b;
  --muted: #6b7a8c;
  --line: #e2e7ee;
  --brand: #1d2b3a;
  --accent: #2f6fed;
  --ok: #1c8b5a;
  --warn: #b8710d;
  --bad: #c8352b;
  --warn-bg: #fff5e5;
  --bad-bg: #fdeceb;
  --ok-bg: #e8f6ee;
  --radius: 14px;
  --tab-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --card: #1a212a; --ink: #e8edf3; --muted: #94a3b4;
    --line: #2a3441; --brand: #0f151b; --accent: #6b9bff;
    --ok: #4cc38a; --warn: #e0a02c; --bad: #f06a5f;
    --warn-bg: #33270f; --bad-bg: #33191a; --ok-bg: #14291f;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

/* ---------- вхід ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 22px; width: 100%; max-width: 360px; box-shadow: 0 8px 30px rgba(0,0,0,.06);
}
.logo { font-size: 28px; font-weight: 700; letter-spacing: -.4px; }
.login-card .muted { margin: 2px 0 20px; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--brand); color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar .chip { background: rgba(255,255,255,.14); color: #fff; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.3); }

main { padding: 14px; max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; text-decoration: none; color: var(--muted);
}
.tabbar a .ic { font-size: 19px; line-height: 1; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.scan-tab .ic { font-size: 24px; }

/* ---------- елементи ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; min-height: 42px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger  { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok      { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.ghost   { background: transparent; }
.btn.big     { width: 100%; min-height: 50px; font-size: 17px; margin-top: 8px; }
.btn.small   { min-height: 32px; padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.grow { flex: 1; min-width: 0; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 70px; }

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); font-size: 12px; white-space: nowrap;
}
.chip.bad  { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }
.chip.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.chip.ok   { background: var(--ok-bg);   border-color: var(--ok);   color: var(--ok); }
.chip.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.error { color: var(--bad); background: var(--bad-bg); border: 1px solid var(--bad);
  border-radius: 10px; padding: 9px 11px; font-size: 14px; margin-bottom: 10px; }
.notice { color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn);
  border-radius: 10px; padding: 9px 11px; font-size: 14px; margin-bottom: 10px; }

/* ---------- статистика ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; text-align: left; cursor: pointer;
}
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.bad b  { color: var(--bad); }
.stat.warn b { color: var(--warn); }

/* ---------- список товарів ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 7px; cursor: pointer;
}
.list li.dim { opacity: .58; }
.list .name { flex: 1; min-width: 0; }
.list .name b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .name .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.qty { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; min-width: 44px; text-align: right; }
.qty.zero { color: var(--muted); font-weight: 500; }

.group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 2px 7px; text-transform: uppercase; letter-spacing: .4px; }

/* ---------- сканер ---------- */
.scanbox { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4/3; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox .reticle {
  position: absolute; inset: 22% 8%; border: 2px solid rgba(255,255,255,.85);
  border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.28);
}
.scanbox .hintline {
  position: absolute; left: 0; right: 0; bottom: 8px; text-align: center;
  color: #fff; font-size: 13px; text-shadow: 0 1px 3px #000;
}
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.mode-switch button { min-height: 48px; font-weight: 600; }
.mode-switch button[aria-pressed="true"].in  { background: var(--ok);  border-color: var(--ok);  color: #fff; }
.mode-switch button[aria-pressed="true"].out { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ---------- модалка ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-sheet {
  position: relative; background: var(--card); width: 100%; max-width: 620px;
  border-radius: 18px 18px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(14px); opacity: .6 } to { transform: none; opacity: 1 } }
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.modal-head strong { flex: 1; font-size: 16px; }
.modal-body { padding: 14px; overflow: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: 18px; }
}

/* ---------- партії ---------- */
.batch {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 11px; margin-bottom: 7px; background: var(--bg);
}
.batch.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,111,237,.18); }
.batch .exp { flex: 1; min-width: 0; }
.batch .exp b { display: block; font-weight: 600; }
.batch input[type=number] { width: 82px; text-align: center; }

/* ---------- журнал ---------- */
.logline {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px;
  margin-bottom: 6px; background: var(--card); font-size: 14px;
}
.logline .ts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.logline .delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.logline .delta.plus { color: var(--ok); }
.logline .delta.minus { color: var(--bad); }
.logline .meta { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--brand); color: #fff; padding: 11px 16px; border-radius: 12px;
  max-width: 88vw; box-shadow: 0 6px 22px rgba(0,0,0,.25); font-size: 14px;
}
.toast.bad { background: var(--bad); }
.toast.ok  { background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 34px 12px; }

/* Прогресс подтверждения кода поверх видоискателя */
.scanprogress {
  position: absolute; left: 0; right: 0; top: 8px; text-align: center;
  color: #fff; font-size: 13px; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px #000; pointer-events: none; min-height: 18px;
}
