/* Сканер ШК — оформление.
   Белый / серый / чёрный, системный шрифт, акцент #007AFF.
   Тач-зоны крупные: на складе работают в перчатках. */

:root {
  --accent: #007AFF;
  --ink: #000;
  --ink-2: #3c3c43;
  --ink-3: #8a8a8e;
  --bg: #fff;
  --bg-2: #f2f2f7;
  --warn: #ff9500;
  --err: #ff3b30;
  --tap: 56px;               /* минимальная высота кнопки — работают в перчатках */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.screen[hidden] { display: none; }

.top {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--safe-t) + 8px) 8px 8px;
  min-height: 52px;
  flex: none;
}
.top h1 { font-size: 28px; font-weight: 700; margin: 0 0 0 12px; letter-spacing: -0.5px; }
.top-title { font-size: 17px; font-weight: 600; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 0; background: none; color: var(--accent);
  cursor: pointer; padding: 0;
  flex: none;
}
.icon-btn:active { opacity: .4; }
.top h1 + .icon-btn { margin-left: auto; }

/* --- главный экран ----------------------------------------------------- */

.home-body { flex: 1; overflow-y: auto; padding: 0 20px; -webkit-overflow-scrolling: touch; }

.db-state { padding: 28px 0 8px; }
.db-count { font-size: 44px; font-weight: 700; letter-spacing: -1.5px; line-height: 1.1; }
.db-label { font-size: 15px; color: var(--ink-3); margin-top: 2px; }
.db-label.is-stale { color: var(--warn); }

.recent { margin-top: 36px; }
.recent-title {
  font-size: 13px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .6px; margin-bottom: 8px;
}
.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li { padding: 0; }
.recent-list button {
  width: 100%; min-height: var(--tap);
  display: block; text-align: left;
  padding: 12px 0; border: 0; background: none;
  font: inherit; color: var(--ink); cursor: pointer;
}
.recent-list button:active { opacity: .4; }
.recent-name {
  display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.recent-meta { display: block; font-size: 14px; color: var(--ink-3); margin-top: 2px; }

.link-btn {
  min-height: var(--tap);
  border: 0; background: none; padding: 0;
  font: inherit; color: var(--accent); cursor: pointer;
}
.link-btn:active { opacity: .4; }

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

.home-actions {
  flex: none;
  padding: 12px 20px calc(var(--safe-b) + 20px);
  display: flex; flex-direction: column; gap: 8px;
}

.btn-primary {
  min-height: 62px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 14px;
  background: var(--accent); color: #fff;
  font: 600 19px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}
.btn-primary:active { opacity: .75; }
.btn-primary[disabled] { background: var(--bg-2); color: var(--ink-3); }

.btn-secondary {
  min-height: var(--tap);
  border: 0; border-radius: 14px;
  background: var(--bg-2); color: var(--accent);
  font: 500 17px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
}
.btn-secondary:active { opacity: .55; }

/* --- экран камеры ------------------------------------------------------ */

.screen-scanner { background: #000; }
#video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}

.scan-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.scan-frame {
  position: relative;
  width: min(78vw, 340px);
  aspect-ratio: 1 / .62;
}
/* Уголки прицела — четыре span'а по углам, без сплошной рамки */
.scan-frame span {
  position: absolute; width: 34px; height: 34px;
  border: 3px solid #fff; border-radius: 3px;
}
.scan-frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scan-frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scan-frame span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scan-frame span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.scan-hint {
  margin: 24px 0 0;
  color: #fff; font-size: 16px;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.scan-frame.is-hit span { border-color: #34c759; }

.scan-controls {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--safe-b) + 24px);
  display: flex; justify-content: center; gap: 28px;
}
.round-btn {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; background: rgba(255,255,255,.22); color: #fff;
  cursor: pointer; backdrop-filter: blur(8px);
}
.round-btn:active { background: rgba(255,255,255,.4); }
.round-btn.is-on { background: #fff; color: #000; }

/* --- карточка товара --------------------------------------------------- */

.card-body { flex: 1; overflow-y: auto; padding: 4px 20px 20px; -webkit-overflow-scrolling: touch; }

.card-name {
  font-size: 26px; font-weight: 700; line-height: 1.22;
  letter-spacing: -0.4px;
  margin: 8px 0 0;
}

.card-qty { margin: 28px 0 0; }
.card-qty-value {
  font-size: 76px; font-weight: 700; line-height: 1;
  letter-spacing: -3px;
}
.card-qty-label { font-size: 15px; color: var(--ink-3); margin-top: 4px; }
.card-qty-src { font-size: 13px; color: var(--warn); margin-top: 2px; }

.card-fields { margin: 32px 0 0; display: flex; flex-direction: column; gap: 18px; }
.card-field-label {
  font-size: 13px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .6px;
}
/* Моноширинный — чтобы не путать 0 и O, 1 и I */
.card-field-value {
  font: 500 20px/1.3 ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  margin-top: 3px;
  word-break: break-all;
}

/* --- сообщения (не найдено / конфликт) --------------------------------- */

.msg-body { flex: 1; overflow-y: auto; padding: 12px 20px 20px; -webkit-overflow-scrolling: touch; }
.msg-body-tight { padding-top: 4px; }

.msg-icon {
  width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 32px; font-weight: 700;
  margin-bottom: 20px;
}
.msg-icon-warn { background: var(--bg-2); color: var(--ink-3); }

.msg-title { font-size: 24px; font-weight: 700; line-height: 1.25; margin: 0 0 12px; letter-spacing: -0.4px; }
.msg-text { font-size: 16px; color: var(--ink-2); line-height: 1.45; margin: 0 0 20px; }
.msg-note { font-size: 14px; color: var(--ink-3); margin: 14px 0 0; }

.big-code {
  font: 700 32px/1.2 ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  letter-spacing: 1px;
  background: var(--bg-2);
  border-radius: 14px;
  padding: 18px 16px;
  text-align: center;
  word-break: break-all;
  user-select: all;
}

/* --- списки выбора ----------------------------------------------------- */

.pick-list { list-style: none; margin: 20px 0 0; padding: 0; }
.pick-list button {
  width: 100%; min-height: var(--tap);
  display: block; text-align: left;
  padding: 14px 0; border: 0; background: none;
  font: inherit; color: var(--ink); cursor: pointer;
}
.pick-list button:active { opacity: .4; }
.pick-name { display: block; line-height: 1.3; }
.pick-meta {
  display: block; margin-top: 4px;
  font: 400 14px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink-3);
}

/* --- ручной ввод ------------------------------------------------------- */

.manual-body, .list-body {
  flex: 1; overflow-y: auto;
  padding: 8px 20px calc(var(--safe-b) + 20px);
  -webkit-overflow-scrolling: touch;
}
.manual-input {
  width: 100%; min-height: 62px;
  border: 0; border-radius: 14px;
  background: var(--bg-2);
  padding: 0 16px;
  font: 500 24px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
}
.manual-input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.manual-empty { color: var(--ink-3); font-size: 16px; margin-top: 28px; }

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

.info-list { margin: 8px 0 28px; }
.info-list div { padding: 12px 0; }
.info-list dt { font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .6px; }
.info-list dd { margin: 3px 0 0; font-size: 17px; }
.info-list dd.is-off { color: var(--ink-3); }
.info-list dd.is-on { color: #34c759; }

.update-note { font-size: 14px; color: var(--ink-3); margin: 12px 0 0; min-height: 20px; }
.version-note { font-size: 13px; color: var(--ink-3); margin-top: 32px; }

/* --- всплывающая плашка ------------------------------------------------ */

.toast {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(var(--safe-b) + 16px);
  z-index: 100;
  background: rgba(0,0,0,.88); color: #fff;
  border-radius: 12px; padding: 14px 16px;
  font-size: 15px; line-height: 1.35;
  backdrop-filter: blur(8px);
}
.toast[hidden] { display: none; }

/* Тёмная тема — на складе бывает темно, и телефон часто в тёмной теме */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #fff; --ink-2: #ebebf5; --ink-3: #8e8e93;
    --bg: #000; --bg-2: #1c1c1e;
  }
  body { background: #000; }
  .toast { background: rgba(60,60,67,.95); }
}
