/* Сканер: коробочный картон, белые наклейки, красный луч как у ручного сканера */
:root {
  --kraft: #a97f52;
  --kraft-deep: #8a6540;
  --label: #ffffff;
  --ink: #000000;
  --ink-soft: #5b5b5b;
  --laser: #ff2d2d;
  --hit: #22c55e;
  --ok: #158a4a;
  --wait: #b5b5b5;
  --warn: #d97706;
  --bad: #c81e3a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: 'Golos Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--kraft);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* Камера */
.cam {
  position: relative;
  flex: 0 0 auto;
  height: 50vh;
  height: 50dvh;
  background: #000;
  overflow: hidden;
}
/* кадр целиком, как в обычной камере телефона (cover обрезал края и выглядел как зум) */
.cam video { width: 100%; height: 100%; object-fit: contain; display: block; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.laser {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  height: 2px;
  background: var(--laser);
  box-shadow: 0 0 8px 1px rgba(255, 45, 45, .7);
  opacity: .75;
  transition: background-color .12s, box-shadow .12s;
}
.laser.hit { background: var(--hit); box-shadow: 0 0 14px 3px rgba(34, 197, 94, .8); opacity: 1; }
.cam-info {
  position: absolute;
  left: 10px;
  top: calc(8px + var(--safe-top));
  max-width: 70%;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-line;
}
.cam-info:empty { display: none; }
.cam-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
}
.cam-btn[aria-pressed="true"] { background: #fff; color: #000; }
.cam-settings { position: absolute; right: 10px; top: calc(8px + var(--safe-top)); }
.cam-tools { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 10px; }

/* Полоса партии */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--kraft-deep);
  color: #fff;
}
.bar-batch {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
  padding: 6px 0;
  border: 0;
  background: none;
  text-align: left;
  font-weight: 500;
  font-size: 16px;
}
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-batch svg { flex: none; width: 18px; height: 18px; }
.bar-count {
  flex: none;
  min-width: 44px;
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--label);
  color: var(--ink);
  font-weight: 700;
  font-size: 22px;
  text-align: center;
}
.bar-net { flex: none; font-size: 13px; max-width: 34%; text-align: right; line-height: 1.2; }
.bar-net::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--wait);
  vertical-align: 1px;
}
.bar-net[data-state="ok"]::before { background: #4ade80; }
.bar-net[data-state="queue"]::before { background: #fbbf24; }
.bar-net[data-state="error"]::before { background: #f87171; }

/* Список: наклейки на картоне */
.list {
  flex: 1 1 auto;
  margin: 0;
  padding: 10px 10px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  list-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.row {
  display: grid;
  grid-template-columns: 2.4em 1fr auto 14px;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--label);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .28);
}
.row-n { color: var(--ink-soft); font-size: 13px; }
.code { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.code-head { font-size: 15px; font-weight: 500; letter-spacing: .02em; }
.code-tail { font-size: 26px; font-weight: 700; line-height: 1; letter-spacing: .01em; }
.row-time { color: var(--ink-soft); font-size: 13px; }
.row-meta { display: grid; justify-items: end; line-height: 1.2; }
.row-src { color: var(--ink); font-size: 11px; font-weight: 500; }
.row-src:empty { display: none; }
.row-state { width: 12px; height: 12px; border-radius: 50%; background: var(--wait); }
.row[data-state="ok"] .row-state { background: var(--ok); }
.row[data-state="dup"] .row-state { background: var(--warn); }
.row[data-state="bad"] .row-state { background: var(--bad); }
.row.fresh { animation: drop .5s ease-out; }
.row.again { animation: again .6s ease-out; }
@keyframes drop { from { background: #d9f99d; } to { background: var(--label); } }
@keyframes again { 0%, 60% { background: #fde68a; } 100% { background: var(--label); } }

.empty {
  position: absolute;
  left: 24px;
  right: 24px;
  top: calc(50dvh + 90px);
  margin: 0;
  color: #fff;
  font-size: 16px;
  line-height: 1.45;
  text-align: center;
}
.empty[hidden] { display: none; }

/* Полноэкранные состояния */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px 24px calc(24px + var(--safe-bottom));
  background: var(--kraft);
  color: #fff;
}
.screen[hidden] { display: none; }
.screen-inner { width: 100%; max-width: 380px; text-align: center; }
.screen-title { margin: 0 0 12px; font-size: 26px; font-weight: 700; }
.screen-batch { margin: 0 0 18px; font-size: 18px; font-weight: 500; }
.screen-note { margin: 16px 0 0; font-size: 16px; line-height: 1.45; }
.screen-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--label);
  color: var(--bad);
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
}
.big {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 14px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}
.big:active { transform: translateY(1px); }
.big-wide { margin: 4px 0 14px; }
.link {
  margin-top: 14px;
  padding: 10px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 16px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
a.link { display: inline-block; }
.link-block { display: block; margin: 0 0 8px; padding: 8px 0; color: var(--ink); }
.pair-note { margin: 0 0 16px !important; }
.pair-or { margin: 22px 0 10px; font-size: 15px; opacity: .9; }
.pair-login { display: grid; gap: 10px; }
.pair-login input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--label);
  color: var(--ink);
  font-size: 18px;
}
.pw { position: relative; display: block; }
.pw input { padding-right: 54px; }
.eye {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 44px;
  height: 44px;
  transform: translateY(-50%);
  border: 0;
  background: var(--ink-soft);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / 24px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / 24px no-repeat;
}
.eye[aria-pressed="true"] {
  background: var(--ink);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M3 3l18 18'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M3 3l18 18'/%3E%3C/svg%3E");
}
.big-light { background: var(--label); color: var(--ink); }
.pair-done { display: grid; justify-items: center; gap: 10px; padding: 12px 0; }
.pair-done[hidden] { display: none; }
.pair-done p { margin: 0; font-size: 19px; font-weight: 500; }
.check {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--hit);
  color: #fff;
  font-size: 34px;
  font-weight: 700;
}
.who-line { margin: 14px 0 0; color: var(--ink-soft); font-size: 14px; }
.who-line:empty { display: none; }
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 30;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
}
.toast[hidden] { display: none; }
.screen-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 6px; margin-top: 4px; }
.screen-links .link { margin-top: 6px; }
.screen-foot { margin-top: 26px; font-size: 15px; opacity: .85; }
.kind-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 10px; }
.kind-row .big { min-height: 72px; padding: 10px 8px; font-size: 17px; line-height: 1.2; }
.kind-row .big small { display: block; margin-top: 3px; font-size: 13px; font-weight: 500; opacity: .8; }
.big-out { background: #5b21b6; }
.sheet-note { margin: 0 0 6px; color: var(--ink-soft); font-size: 14px; }
.sheet-note:empty { display: none; }
.batch-list .bl-name { display: grid; gap: 2px; }
.batch-list .bl-sub { color: var(--ink-soft); font-size: 13px; font-weight: 400; }
.batch-list .remote .bl-sub { color: #5b21b6; font-weight: 500; }

/* Нижние листы */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, .45);
}
.sheet[hidden] { display: none; }
.sheet-panel {
  width: 100%;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  border-radius: 14px 14px 0 0;
  background: var(--label);
  color: var(--ink);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet-close { width: 44px; height: 44px; border: 0; background: none; font-size: 20px; }
.sheet .link { color: var(--ink); }
.batch-list { margin: 0; padding: 0; list-style: none; }
.batch-list li + li { border-top: 1px solid #e5e5e5; }
.batch-list button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 4px;
  border: 0;
  background: none;
  text-align: left;
  font-size: 17px;
}
.batch-list button[aria-current="true"] { font-weight: 700; }
.batch-list small { color: var(--ink-soft); font-size: 15px; white-space: nowrap; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; padding: 0; border: 0; }
.seg legend { width: 100%; margin-bottom: 6px; padding: 0; color: var(--ink-soft); font-size: 14px; }
.seg label {
  flex: 1 1 0;
  min-width: 90px;
  padding: 10px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  font-size: 15px;
  text-align: center;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--ink); color: #fff; }
.seg label:has(input:disabled) { opacity: .35; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--kraft); outline-offset: 2px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 6px 0 4px; font-size: 14px; }
.info dt { color: var(--ink-soft); }
.info dd { margin: 0; word-break: break-word; }
.info .warn { color: var(--warn); font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  .row.fresh, .row.again { animation: none; }
  .laser { transition: none; }
}
