/* ================================================================
   Склад — оформление в стиле iOS
   Светлая и тёмная тема переключаются вместе с системой.
   ================================================================ */
:root {
  --bg: #f2f2f7;               /* systemGroupedBackground */
  --card: #ffffff;             /* secondarySystemGroupedBackground */
  --fill: rgba(118,118,128,.12);
  --fill-2: rgba(118,118,128,.2);
  --line: rgba(60,60,67,.18);  /* separator */
  --text: #000000;
  --muted: rgba(60,60,67,.6);  /* secondaryLabel */
  --accent: #007aff;           /* systemBlue */
  --accent-soft: rgba(0,122,255,.12);
  --green: #34c759;
  --green-soft: rgba(52,199,89,.15);
  --danger: #ff3b30;
  --danger-soft: rgba(255,59,48,.12);
  --warn: #ff9500;
  --warn-soft: rgba(255,149,0,.15);
  --bar: rgba(249,249,249,.82);
  --shadow: 0 1px 2px rgba(0,0,0,.04);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --fill: rgba(118,118,128,.24);
    --fill-2: rgba(118,118,128,.32);
    --line: rgba(84,84,88,.6);
    --text: #ffffff;
    --muted: rgba(235,235,245,.6);
    --accent: #0a84ff;
    --accent-soft: rgba(10,132,255,.2);
    --green: #30d158;
    --green-soft: rgba(48,209,88,.2);
    --danger: #ff453a;
    --danger-soft: rgba(255,69,58,.2);
    --warn: #ff9f0a;
    --warn-soft: rgba(255,159,10,.2);
    --bar: rgba(22,22,24,.82);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.35 var(--font); letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { -webkit-user-select: none; user-select: none; }
.boot { padding: 40vh 20px 0; text-align: center; color: var(--muted); }

/* ---------- Верхняя панель и большой заголовок ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-bar { max-width: 760px; margin: 0 auto; height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.role { font-weight: 400; color: var(--muted); }
.sync { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.sync.off { background: var(--danger); }
.link { border: 0; background: none; color: var(--accent); font-size: 17px; cursor: pointer; padding: 6px 0; }

main { max-width: 760px; margin: 0 auto; padding: 0 16px calc(100px + env(safe-area-inset-bottom)); }
.large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .01em; margin: 10px 4px 14px; }
h2 { font-size: 20px; font-weight: 600; margin: 0 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .02em; margin: 22px 16px 7px; color: var(--muted); font-weight: 400; }

/* ---------- Нижняя панель вкладок ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 150px; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; color: #999; font-size: 10px; font-weight: 500; letter-spacing: .01em;
}
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button.on { color: var(--accent); }
.tabbar button.on svg { stroke-width: 2.2; }

/* ---------- Карточки — «сгруппированные списки» iOS ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; box-shadow: var(--shadow); }

/* Поле сканирования — как поиск в iOS */
.scan { display: flex; gap: 8px; align-items: center; }
.scan input { flex: 1; }
.card > .scan input { font-size: 17px; padding: 11px 14px 11px 38px; background: var(--fill) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center; border: 0; }
.scan-hint { font-size: 13px; color: var(--muted); margin: 8px 2px 0; }

input[type=text], input[type=number], input[type=password], input[type=search], input[type=date], select {
  width: 100%; border: 0; background: var(--fill); border-radius: 10px; padding: 11px 13px; outline: none;
  font-size: 17px; -webkit-appearance: none; appearance: none; min-height: 44px;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { box-shadow: 0 0 0 2px var(--accent) inset; }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* Кнопки */
.btn {
  border: 0; background: var(--accent); color: #fff; padding: 11px 18px; border-radius: 12px;
  cursor: pointer; font-weight: 600; font-size: 17px; white-space: nowrap; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn.light { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: var(--fill); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.big { width: 100%; padding: 15px; border-radius: 14px; }
.btn.icon { padding: 0; width: 44px; font-size: 20px; flex: none; }
.btn svg { width: 22px; height: 22px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > label { flex: 1; min-width: 130px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 180px; }

/* ---------- Таблицы как списки iOS ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 400; padding: 4px 8px 8px; border-bottom: .5px solid var(--line); }
td { padding: 11px 8px; border-bottom: .5px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:active td { background: var(--fill); }
@media (hover: hover) { tr.click:hover td { background: var(--fill); } }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 14px; }
.low { color: var(--danger); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; font-size: 15px; }

/* ---------- Корзина ---------- */
.cart-line { display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: .5px solid var(--line); }
.cart-line:last-child { border-bottom: 0; }
.cart-line .name { font-weight: 500; }
.qty { display: flex; align-items: center; background: var(--fill); border-radius: 10px; overflow: hidden; }
.qty button { width: 36px; height: 34px; border: 0; background: none; cursor: pointer; font-size: 20px; color: var(--accent); }
.qty button:active { background: var(--fill-2); }
.qty input { width: 52px; text-align: center; padding: 4px; min-height: 34px; background: none; border-radius: 0; border-left: .5px solid var(--line); border-right: .5px solid var(--line); }
.x { border: 0; background: none; color: var(--muted); font-size: 17px; cursor: pointer; padding: 6px 8px; }
.x.close { width: 30px; height: 30px; padding: 0; border-radius: 50%; background: var(--fill); font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 28px; font-weight: 700; margin: 16px 0 14px; letter-spacing: -0.02em; }

.suggest { background: var(--card); border-radius: 12px; margin-top: 8px; overflow: hidden; box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.suggest button { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; border: 0; border-bottom: .5px solid var(--line); background: none; padding: 12px 14px; cursor: pointer; }
.suggest button:last-child { border-bottom: 0; }
.suggest button:active { background: var(--fill); }

/* ---------- Отчёты ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin-top: 2px; }
.stat.good .value { color: var(--green); }

/* Переключатели периодов и категорий — «таблетки» */
.periods { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.periods button { border: 0; background: var(--card); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 15px; box-shadow: var(--shadow); }
.periods button.on { background: var(--accent); color: #fff; }
.cats { overflow-x: auto; flex-wrap: nowrap; margin: 0 -16px 6px; padding: 2px 16px 6px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats button { white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--fill); color: var(--muted); }

/* ---------- Окна — шторка снизу, как в iOS ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
.modal {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 14px 14px 0 0;
  padding: 8px 16px 20px; max-height: 94vh; overflow-y: auto;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  animation: up .32s cubic-bezier(.2,.9,.3,1);
}
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 0 auto 10px; }
.modal h2 { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 20px; margin-bottom: 14px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.modal input[type=text], .modal input[type=password], .modal select { background: var(--card); }
.modal .scan input { background: var(--card); }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 16px; animation: pop .25s cubic-bezier(.2,.9,.3,1); }
  .grabber { display: none; }
  @keyframes pop { from { transform: scale(.94); opacity: 0; } }
}

.camera { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 4/3; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera .frame { position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%; border: 2.5px solid rgba(255,255,255,.9); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.4); }
#cam-lib { width: 100%; border-radius: 14px; overflow: hidden; }

/* Уведомление — «пилюля» сверху, как в iOS */
.toast {
  position: fixed; left: 50%; top: calc(54px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 100;
  background: var(--card); color: var(--text); padding: 12px 20px; border-radius: 999px; max-width: 92vw;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); font-size: 15px; font-weight: 500; text-align: center;
  animation: drop .3s cubic-bezier(.2,.9,.3,1);
}
.toast.err { color: var(--danger); }
.toast.ok::before { content: "✓ "; color: var(--green); font-weight: 700; }
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

/* Вход */
.login { max-width: 380px; margin: 12vh auto 0; padding: 26px 20px; display: flex; flex-direction: column; gap: 14px; }
.login-icon { display: flex; justify-content: center; }
.login-icon img { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.login .brand { font-size: 28px; font-weight: 700; text-align: center; }

/* Найдено по штрих-коду */
.found { display: flex; gap: 12px; align-items: flex-start; background: var(--green-soft); border-radius: 12px; padding: 12px 14px; font-size: 15px; }
.found .btn { margin-top: 8px; min-height: 34px; padding: 6px 12px; font-size: 15px; }
.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--fill-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Фото товаров ---------- */
.thumb { display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; object-fit: cover; background: #fff; flex: none; vertical-align: middle; }
.thumb.none { background: var(--fill); font-size: 20px; }
.with-thumb { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.pcard { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pcard-img { background: #fff; border-radius: 16px; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.pcard-img img { width: 100%; height: 100%; object-fit: contain; }
.pcard-img span { font-size: 64px; }
.pcard-info { background: var(--card); border-radius: 16px; padding: 14px 16px; }
.pcard-price { font-size: 32px; font-weight: 700; margin: 10px 0 6px; letter-spacing: -0.02em; }
.pf-photo { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: 14px; padding: 12px; }
.pf-img { width: 96px; height: 96px; border-radius: 12px; background: var(--fill); display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; font-size: 34px; }
.pf-img .ph svg { width: 36px; height: 36px; color: var(--muted); }
.pf-img img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.pf-photo-btns { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pf-photo-btns .btn { min-height: 36px; padding: 7px 14px; font-size: 15px; }
.hide-d { display: none; }

@media (max-width: 600px) {
  .hide-m { display: none; }
  .cart-line { grid-template-columns: auto 1fr auto; row-gap: 10px; }
  .cart-line > :first-child { grid-column: 1 / -1; }
  .cart-line .sum { font-weight: 600; font-size: 17px; }
  .pcard { grid-template-columns: 1fr; }
  .pcard-img { aspect-ratio: auto; height: 280px; }
  .hide-d { display: block; }
  .large-title { font-size: 32px; }
}

/* Проверка «Честный знак» */
.verdict { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 12px; margin-bottom: 10px; }
.verdict .vmark { width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; color: #fff; flex: none; }
.verdict.ok { background: var(--green-soft); } .verdict.ok .vmark { background: var(--green); }
.verdict.warn { background: var(--warn-soft); } .verdict.warn .vmark { background: var(--warn); }
.verdict.bad { background: var(--danger-soft); } .verdict.bad .vmark { background: var(--danger); }
.verdict.unknown { background: var(--fill); } .verdict.unknown .vmark { background: #8e8e93; }
.raw { margin-top: 10px; font-size: 13px; }
.raw summary { color: var(--accent); cursor: pointer; }
.raw pre { white-space: pre-wrap; word-break: break-all; background: var(--fill); padding: 10px; border-radius: 10px; max-height: 260px; overflow: auto; font-size: 12px; }
.tabbar button span { white-space: nowrap; }
.check .btn { white-space: normal; text-align: left; width: 100%; justify-content: flex-start; }
.check td.muted { white-space: nowrap; width: 1%; padding-right: 14px; }
