/*
 * Оформление мини-приложения. Цвета — из темы Telegram (переменные
 * --tg-theme-*, их ставит telegram-web-app.js): светлая и тёмная тема
 * работают сами. Запасные значения — для открытия в обычном браузере.
 */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111317);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2d7fe0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2d7fe0);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --ok: #2fa84f;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
svg { display: block; }

/* --- шапка с поиском ---------------------------------------------------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: 10px 16px 8px;
  background: var(--bg2);
}
.search {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px;
  background: var(--section); border-radius: 12px;
}
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--hint); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: none; color: var(--text); font: inherit;
}
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }

main { padding: 4px 16px 0; }

/* --- заголовки и секции -------------------------------------------------- */
.title { margin: 10px 4px 12px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.crumbs { margin: 6px 4px -6px; color: var(--hint); font-size: 13px; }
.label { margin: 18px 4px 8px; color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.note { margin: 6px 4px 12px; color: var(--hint); font-size: 13px; }

.list { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 48px; padding: 10px 14px; text-align: left;
}
.row + .row { border-top: 1px solid var(--sep); }
.row:active { background: color-mix(in srgb, var(--hint) 12%, transparent); }
.row .emoji { width: 26px; font-size: 20px; text-align: center; flex: none; }
.row .name { flex: 1; min-width: 0; font-weight: 500; }
.row .count { color: var(--hint); font-size: 14px; }
.row .chev { width: 8px; height: 14px; fill: none; stroke: var(--hint); stroke-width: 2; flex: none; }

/* Новинки и SALE — плитками вверху главной. */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.tile {
  display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 14px; border-radius: var(--radius); background: var(--section); text-align: left;
}
.tile b { font-size: 16px; }
.tile span { color: var(--hint); font-size: 13px; }
.tile:active { opacity: 0.8; }

/* --- фильтр «в наличии» -------------------------------------------------- */
.filter { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 10px; color: var(--hint); font-size: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.switch i { width: 38px; height: 22px; border-radius: 11px; background: var(--sep); position: relative; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch[aria-checked="true"] i { background: var(--accent); }
.switch[aria-checked="true"] i::after { transform: translateX(16px); }

/* --- товар --------------------------------------------------------------- */
.product { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.product + .product { border-top: 1px solid var(--sep); }
.product .info { flex: 1; min-width: 0; }
.product .pname { font-weight: 500; overflow-wrap: anywhere; }
.product .meta { margin-top: 4px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 14px; }
.product .rub { font-weight: 700; }
.product .usd, .product .sku { color: var(--hint); }
.product .sku { font-size: 12px; margin-top: 2px; }
.stock { font-size: 12px; font-weight: 600; }
.stock.in { color: var(--ok); }
.stock.out { color: var(--hint); }
.product.out .pname { color: color-mix(in srgb, var(--text) 70%, var(--hint)); }

/* Круглая «+» справа — узкая, название занимает всё остальное место. */
.add {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
}
.add svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; fill: none; }
.add:active { transform: scale(0.92); }
.na { flex: none; font-size: 12px; color: var(--hint); width: 44px; text-align: center; }

/* Счётчик «− 2 +» */
.stepper {
  display: flex; align-items: center; flex: none;
  height: 36px; border-radius: 18px; background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.stepper button { width: 34px; height: 36px; display: grid; place-items: center; color: var(--accent); }
.stepper button svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; fill: none; }
.stepper input {
  width: 38px; height: 36px; border: 0; outline: 0; background: none; text-align: center;
  color: var(--text); font: inherit; font-weight: 700; -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Мусорка — в цвет текста, жирной линией: в тёмной теме белая. */
.trash { width: 36px; height: 36px; display: grid; place-items: center; flex: none; color: var(--text); }
.trash svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; fill: none; }

/* --- корзина ------------------------------------------------------------- */
.cart-item { padding: 12px 14px; }
.cart-item + .cart-item { border-top: 1px solid var(--sep); }
.cart-item .head { display: flex; gap: 10px; align-items: flex-start; }
.cart-item .num { color: var(--hint); font-weight: 600; min-width: 18px; }
.cart-item .pname { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.cart-item .foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-left: 28px; }
.cart-item .sum { flex: 1; min-width: 0; font-size: 14px; }
/* Сумма сверху, расчёт «цена × шт» под ней — без переноса посреди числа. */
.cart-item .sum b { display: block; font-size: 15px; white-space: nowrap; }
.cart-item .sum span { display: block; color: var(--hint); font-size: 13px; white-space: nowrap; }
.cart-item.gone .pname { color: var(--danger); }
.gone-note { color: var(--danger); font-size: 13px; margin-top: 4px; }

.totals { margin-top: 12px; padding: 14px; background: var(--section); border-radius: var(--radius); }
.totals .line { display: flex; justify-content: space-between; gap: 12px; }
.totals .line + .line { margin-top: 4px; }
.totals .big { font-size: 18px; font-weight: 700; }
.totals .muted { color: var(--hint); }

.btn {
  display: block; width: 100%; margin-top: 12px; padding: 13px;
  border-radius: 12px; text-align: center; font-weight: 600;
  background: var(--section); color: var(--link);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }

/* --- состояния ----------------------------------------------------------- */
.state { padding: 64px 24px; text-align: center; color: var(--hint); }
.state h2 { color: var(--text); font-size: 18px; margin: 12px 0 6px; }
.state .big-emoji { font-size: 44px; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--sep); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.info-text { padding: 14px; background: var(--section); border-radius: var(--radius); white-space: pre-line; }
.info-text a { color: var(--link); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg); font-size: 14px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0s !important; }
}
