:root {
  --bg: #101418;
  --panel: #191f26;
  --panel-2: #212932;
  --line: #2c3542;
  --text: #e8edf2;
  --muted: #8b98a8;
  --accent: #3da9fc;
  --green: #2ecc71;
  --red: #ff4d4f;
  --amber: #ffb020;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 19px; }
h2 { font-size: 15px; margin-bottom: 12px; color: var(--accent); }

.pad {
  padding: 14px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

/* ---------- кнопки ---------- */

.btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #04121e;
  font-weight: 650;
  font-size: 15px;
  padding: 11px 16px;
  border-radius: 11px;
  cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.big { width: 100%; padding: 15px; font-size: 16px; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { color: var(--red); border-color: #4a2226; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.45);
  color: var(--text);
  font-size: 19px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.on { background: var(--accent); color: #04121e; }

/* ---------- верхняя панель ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar .btn { margin-left: auto; }
.topbar .icon-btn { margin-left: auto; }
.topbar .icon-btn ~ * { margin-left: 0; }

/* ---------- карточки настройки ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

input, select, .search {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  padding: 11px 12px;
  border-radius: 11px;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.hint.ok { color: var(--green); }
.hint.err { color: var(--red); }

.tables { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.tables button {
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.tables button small { display: block; color: var(--muted); }

.danger-zone { background: transparent; border-color: transparent; }

/* ---------- сканер ---------- */

#view-scan { position: relative; background: #000; }

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#reticle {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 26%;
  height: 30%;
  pointer-events: none;
}
#reticle span {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 3px solid rgba(255,255,255,.85);
}
#reticle span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
#reticle span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
#reticle span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
#reticle span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }

#flash {
  position: absolute;
  inset: 0;
  background: var(--green);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease-out;
}
#flash.bad { background: var(--red); }
#flash.show { opacity: .55; transition: none; }

.scan-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(#000000cc, transparent);
}

.scan-stats { display: flex; gap: 14px; margin: 0 auto; }
.stat { text-align: center; line-height: 1.1; }
.stat b { display: block; font-size: 17px; }
.stat i { font-style: normal; font-size: 10px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.stat b.pending { color: var(--amber); }
.stat b.bad { color: var(--red); }

.last-card {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(118px + env(safe-area-inset-bottom));
  background: rgba(12,16,20,.92);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.last-card.ok { border-left-color: var(--green); }
.last-card.bad { border-left-color: var(--red); }
.last-card .lc-name { font-weight: 650; font-size: 16px; }
.last-card .lc-meta { color: var(--muted); font-size: 13px; }
.last-card .lc-meta.ok { color: var(--green); }
.last-card .lc-meta.bad { color: var(--red); }

.scan-bottom {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, #000000dd 30%);
}

.progress { height: 5px; background: #ffffff26; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .25s; }
.progress.big { height: 9px; }

.manual { display: flex; gap: 8px; margin-top: 12px; }
.manual input { flex: 1; }
.manual .btn { flex: none; }

/* ---------- список ---------- */

.summary { margin-bottom: 14px; }
.summary-main { margin-bottom: 8px; }
.summary-main b { font-size: 19px; }

.filters { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }

.chip {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #04121e; }

.search { margin-bottom: 12px; }

.items { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
}
.item .qty {
  min-width: 42px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  border-radius: 9px;
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.item .body { flex: 1; min-width: 0; }
.item .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .cd { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.item .minus {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 17px;
  cursor: pointer;
}

/* позиций, которых нет на складе — красные */
.item.missing {
  background: #2a1315;
  border-color: #61262a;
  color: #ffb3b5;
}
.item.missing .qty { background: #611d20; color: #ffd7d8; }
.item.missing .cd { color: #c07a7c; }

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

/* ---------- всплывашка ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.err { border-color: var(--red); color: #ffb3b5; }
.toast.ok { border-color: var(--green); color: #b6f0cd; }