/*
 * Цвета берём из темы Telegram: у продавца светлая или тёмная — Mini App выглядит
 * как сам Telegram. Запасные значения — на случай открытия вне Telegram.
 */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f5);
  --text: var(--tg-theme-text-color, #1f2933);
  --hint: var(--tg-theme-hint-color, #7b8794);
  --link: var(--tg-theme-link-color, #2a78d6);
  --btn: var(--tg-theme-button-color, #1a7f5a);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d64545;
  --warn-bg: rgba(237, 161, 0, .14);
  --ok: #1a9c6a;
  --line: rgba(128, 128, 128, .22);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body { font: 15px/1.4 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; padding-bottom: 260px; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.dim { color: var(--hint); }
.small { font-size: 12px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); padding: 10px 12px 0; }
.who { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.who .dim { font-size: 12px; }
.tabs { display: flex; margin-top: 8px; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px 0; border-bottom: 2px solid transparent; color: var(--hint); font-weight: 600; }
.tabs button.on { color: var(--text); border-bottom-color: var(--btn); }

main { padding: 10px 12px; }
#search {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: var(--bg); margin-bottom: 10px; outline: none;
}

/* ---------- каталог ---------- */
.products { display: flex; flex-direction: column; gap: 8px; }
.prod { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.prod.chosen { box-shadow: inset 0 0 0 2px var(--btn); }
.prod-row { display: flex; align-items: center; gap: 10px; }
.prod-info { flex: 1; min-width: 0; }
.prod-name { font-weight: 600; }
.prod-price { font-size: 13px; color: var(--hint); }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button {
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: var(--bg2); font-size: 20px; font-weight: 700; line-height: 1;
}
.qty button.plus { background: var(--btn); color: var(--btn-text); }
.qty input {
  width: 58px; height: 38px; text-align: center; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); font-weight: 700; outline: none;
}
.stock { margin-top: 6px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.stock .neg { color: var(--danger); font-weight: 600; }
.short-note { margin-top: 6px; background: var(--warn-bg); border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.why { font-size: 12px; color: var(--hint); text-align: center; }

/* ---------- итог ---------- */
.checkout {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 -6px 18px rgba(0, 0, 0, .08);
  max-height: 72vh; overflow-y: auto;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--hint); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--bg); outline: none; width: 100%;
}
/* подсказки — обычным блоком под полем: над панелью их обрезала бы её прокрутка */
.cp-list {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  max-height: 180px; overflow-y: auto;
}
.cp-item { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.cp-item:last-child { border-bottom: 0; }
.cp-item.new { color: var(--link); font-weight: 600; }
.cp-picked { font-size: 12px; color: var(--ok); }
.total-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 16px; }
.total-row b { font-size: 20px; }
.paid { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.paid input { width: 20px; height: 20px; accent-color: var(--btn); }
.pay { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pay .small { grid-column: 1 / -1; }
.error { color: var(--danger); font-size: 13px; }
.primary {
  border: 0; border-radius: 12px; padding: 13px; font-weight: 700; font-size: 16px;
  background: var(--btn); color: var(--btn-text);
}
.primary:disabled { opacity: .45; }

/* ---------- мои продажи ---------- */
.sales { display: flex; flex-direction: column; gap: 8px; }
.sale { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.sale-top { display: flex; justify-content: space-between; gap: 8px; }
.sale-sub { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--hint); margin-top: 2px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--bg2); }
.badge.posted { background: rgba(26, 156, 106, .15); color: var(--ok); }
.badge.pending { background: var(--warn-bg); }
.badge.deleted { background: rgba(214, 69, 69, .12); color: var(--danger); }
.reason { font-size: 12px; color: var(--danger); margin-top: 4px; }

.note { text-align: center; color: var(--hint); padding: 30px 10px; }

/* ---------- кончающийся товар ---------- */
.rule { margin: 0 2px 10px; }
.ls-group { background: var(--bg); border-radius: 12px; padding: 2px 12px; margin-bottom: 10px; overflow: hidden; }
.ls-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.ls-head span { font-size: 13px; }
.ls-head .neg { color: var(--danger); font-weight: 600; }
.ls-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ls-row:last-child { border-bottom: 0; }
/* кончающееся — вся строка красной полосой, видно не вчитываясь */
.ls-row.low { color: var(--danger); font-weight: 600; background: rgba(214, 69, 69, .1); margin: 0 -12px; padding: 8px 12px; }

/* ---------- карточка продажи ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; }
.sheet-box { background: var(--bg); width: 100%; max-height: 85vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 17px; }
.icon { border: 0; background: var(--bg2); width: 34px; height: 34px; border-radius: 50%; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv span:first-child { color: var(--hint); }
.line { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

.toast {
  position: fixed; left: 12px; right: 12px; top: 12px; z-index: 30;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px; font-weight: 600; text-align: center;
}
.toast.bad { background: var(--danger); color: #fff; }

.blocked { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; }
.blocked .big { font-size: 48px; }
