:root {
  --accent: #5b3a8e;
  --accent-dark: #472d70;
  --danger: #c0392b;
  --ok: #1e8449;
  --bg: #f4f2f8;
  --card: #ffffff;
  --text: #221c2e;
  --muted: #7a738c;
  --border: #e2ddee;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior: none;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.hidden { display: none !important; }
.screen { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

h1 { font-size: 22px; text-align: center; color: var(--accent); margin-bottom: 16px; }
h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 20px 0 8px; }

/* вход */
.login-box { max-width: 320px; margin: 8vh auto 0; }
.pin-display {
  height: 34px; font-size: 26px; letter-spacing: .4em; text-align: center;
  margin-bottom: 12px; font-variant-numeric: tabular-nums;
}
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-pad button {
  font-size: 26px; padding: 16px 0; border: none; border-radius: 14px;
  background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12);
  touch-action: manipulation; user-select: none;
}
.pin-pad button:active { background: var(--border); }
.pin-pad button.fn { color: var(--accent); font-size: 18px; }

/* верхняя панель */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.user { font-weight: 600; }
.sync-status { font-size: 12px; color: var(--muted); }
.sync-status.ok { color: var(--ok); }
.sync-status.bad { color: var(--danger); }
.count-title { flex: 1; text-align: center; min-width: 0; }
.count-title div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* карточки */
.card-list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.card:active { background: #faf8fd; }
.card .name { font-weight: 600; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card .badge {
  font-size: 12px; padding: 3px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--border); color: var(--text);
}
.badge.created { background: #d5f5e3; color: var(--ok); }
.badge.submitted, .badge.creating { background: #fef9e7; color: #9a7d0a; }
.badge.error { background: #fadbd8; color: var(--danger); }
.badge.draft { background: var(--border); color: var(--muted); }

/* кнопки */
.btn {
  border: none; border-radius: 10px; background: var(--accent); color: #fff;
  padding: 10px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn:active { background: var(--accent-dark); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.big { font-size: 26px; padding: 10px 22px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn.ghost:active { background: var(--border); }
.btn.danger { color: var(--danger); }
.btn.icon { font-size: 20px; padding: 9px 13px; }
.btn:disabled { opacity: .5; }

/* экран пересчёта */
.scan-row { display: flex; gap: 8px; margin: 10px 0; }
.scan-row input {
  flex: 1; font-size: 17px; padding: 12px; border: 2px solid var(--accent);
  border-radius: 10px; outline: none;
}
#camera { width: 100%; border-radius: 10px; margin-bottom: 8px; background: #000; }
.error { color: var(--danger); font-size: 13px; margin: 6px 0; min-height: 1em; }

.count-summary { font-size: 13px; color: var(--muted); margin: 6px 0; }

.lines { display: flex; flex-direction: column; gap: 6px; }
.line {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px;
}
.line .info { flex: 1; min-width: 0; }
.line .name { font-weight: 600; font-size: 15px; }
.line .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.line .qty { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.line .qty .stock { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.line.mismatch .qty { color: var(--danger); }

/* модалка количества */
.modal { position: fixed; inset: 0; background: rgba(20,12,35,.5); display: flex; align-items: flex-end; z-index: 10; }
.modal-box {
  background: var(--card); width: 100%; max-width: 560px; margin: 0 auto;
  border-radius: 18px 18px 0 0; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.modal-name { font-weight: 600; font-size: 16px; margin-bottom: 4px; }
.modal-stock { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.qty-row { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.qty-row input {
  flex: 1; font-size: 28px; text-align: center; padding: 10px;
  border: 2px solid var(--accent); border-radius: 10px; outline: none;
  font-variant-numeric: tabular-nums;
}
.modal-actions { display: flex; justify-content: space-between; gap: 10px; }

.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }
