:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #111111);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sale: #ff3b30;
  --radius: 14px;
  /* безопасные зоны: вырез/статус-бар телефона + плавающие кнопки Telegram в полноэкранном режиме */
  --safe-t: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-b: max(env(safe-area-inset-bottom, 0px), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.brandbar {
  text-align: center; font-weight: 900; font-size: 22px; letter-spacing: .04em; line-height: 1;
  text-transform: uppercase; margin: 2px 0 12px;
}
header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: calc(10px + var(--safe-t)) 12px 8px;
  transition: box-shadow .2s;
}
header.shadow { box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 6px 16px rgba(0,0,0,.04); }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border-radius: 12px; padding: 0 12px; height: 42px;
}
.search .ico { width: 18px; height: 18px; fill: var(--hint); flex: none; }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 16px;
}
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }
.qclear { width: 22px; height: 22px; border-radius: 50%; background: var(--hint); color: var(--bg); font-size: 11px; line-height: 22px; }

.suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 2px; }
.suggest .s-label { width: 100%; font-size: 12px; color: var(--hint); }
.suggest button { background: var(--bg2); border-radius: 10px; padding: 5px 10px; font-size: 13px; }

.chips {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  overflow-x: auto; scrollbar-width: none; margin-left: -12px; margin-right: -12px; padding: 0 12px;
}
.chips::-webkit-scrollbar { display: none; }
.brand-chips { display: flex; gap: 6px; }
.chip {
  flex: none; white-space: nowrap; height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--bg2); font-size: 14px; transition: background .15s, color .15s;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.chip .caret { font-size: 10px; opacity: .7; }
.sep { flex: none; width: 1px; height: 20px; background: var(--hint); opacity: .3; }

/* ---------- grid ---------- */
main { padding: 4px 10px calc(20px + var(--safe-b)); }
.info { font-size: 13px; color: var(--hint); padding: 2px 4px 8px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 10px; }
.card { display: block; text-align: left; cursor: pointer; -webkit-user-select: none; user-select: none; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 16px; }
/* фото в карточке листаются пальцем */
.card-track {
  display: flex; width: 100%; height: 100%; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; touch-action: pan-x pan-y;
}
.card-track::-webkit-scrollbar { display: none; }
.card.anim { animation: fadeIn .25s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } }
.card-img {
  position: relative; aspect-ratio: 3 / 4; border-radius: 16px; overflow: hidden;
  background: var(--bg2);
}
.card-img::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(0,0,0,.05); pointer-events: none; }
.card-img img { flex: none; width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s;
  scroll-snap-align: start; scroll-snap-stop: always; }
.card-img img.loaded { opacity: 1; }
.badge {
  position: absolute; left: 8px; top: 8px; background: var(--sale); color: #fff;
  font-size: 12px; font-weight: 600; border-radius: 8px; padding: 2px 6px;
}
.card-dots { position: absolute; bottom: 7px; left: 0; right: 0; display: flex; justify-content: center; gap: 4px; pointer-events: none; }
.card-dots i { width: 5px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.55); box-shadow: 0 0 2px rgba(0,0,0,.35); transition: width .2s, background .2s; }
.card-dots i.on { width: 12px; background: #fff; }
.card-body { padding: 9px 2px 0; }
.price { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.price s { font-weight: 400; color: var(--hint); font-size: 13px; margin-left: 4px; }
.price .sale { color: var(--sale); }
.card-title { font-size: 14px; line-height: 1.3; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-title { font-weight: 500; }
.card-sizes { display: flex; gap: 4px; margin-top: 7px; overflow: hidden; }
.card-sizes span {
  flex: none; font-size: 11px; font-weight: 600; line-height: 1; padding: 4px 7px; border-radius: 7px;
  background: var(--bg2); color: var(--text); opacity: .85;
}
.skeleton .card-img { animation: pulse 1.2s ease-in-out infinite; }
.skeleton .line { height: 12px; border-radius: 6px; background: var(--bg2); margin-top: 8px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
mark { background: none; color: inherit; font-weight: 700; text-decoration: underline; text-decoration-color: var(--accent); }

.empty { text-align: center; padding: 60px 20px; }
.empty-emoji { font-size: 48px; }
.empty-title { font-size: 18px; font-weight: 600; margin-top: 8px; }
.empty-text { color: var(--hint); margin: 6px 0 16px; }

/* ---------- buttons ---------- */
.btn-primary, .btn-secondary {
  height: 48px; border-radius: 12px; font-weight: 600; padding: 0 18px; font-size: 16px;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:disabled { opacity: .45; }
.btn-secondary { background: var(--bg2); }

/* ---------- product ---------- */
.product {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slideIn .22s ease backwards;  /* не both: иначе transform ломает position:fixed у кнопки «Заказать» */
}
@keyframes slideIn { from { transform: translateX(30%); opacity: 0; } }
.gallery-wrap { position: relative; }
.gallery {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  aspect-ratio: 3 / 4; background: var(--bg2);  /* фото из канала вертикальные 3:4 — без обрезки */
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: none; width: 100%; height: 100%; object-fit: cover; scroll-snap-align: center; scroll-snap-stop: always; }
.counter {
  position: absolute; right: 12px; bottom: 10px; background: rgba(0,0,0,.45); color: #fff;
  font-size: 12px; border-radius: 10px; padding: 3px 8px;
}
.dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.dots i { width: 6px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.55); transition: all .2s; box-shadow: 0 0 2px rgba(0,0,0,.3); }
.dots i.on { width: 16px; background: #fff; }
.close-btn {
  position: absolute; left: 12px; top: calc(12px + var(--safe-t)); width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,.45); color: #fff; font-size: 18px;
}
body.tg .close-btn { display: none; }
.product .gallery-wrap { border-radius: 0 0 22px 22px; overflow: hidden; }
.p-body { padding: 18px 16px calc(100px + var(--safe-b)); }
.p-brand { color: var(--hint); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.p-name { font-size: 24px; font-weight: 800; line-height: 1.15; letter-spacing: -.01em; margin: 6px 0 10px; }
.p-sku { color: var(--hint); font-size: 13px; margin: -4px 0 8px; }
.p-price { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.p-price s { font-size: 16px; font-weight: 400; color: var(--hint); margin-left: 8px; }
.p-price .sale { color: var(--sale); }
.p-price .off { font-size: 14px; background: var(--sale); color: #fff; border-radius: 8px; padding: 2px 6px; margin-left: 6px; vertical-align: middle; }
.p-section-title { font-weight: 700; font-size: 17px; margin: 22px 0 10px; }
.p-sizes { display: flex; flex-wrap: wrap; gap: 8px; }
.p-sizes button, .sheet-sizes button {
  min-width: 56px; height: 44px; border-radius: 12px; background: var(--bg2); font-weight: 600;
  border: 2px solid transparent; transition: all .12s;
}
.p-sizes button.on, .sheet-sizes button.on { border-color: var(--accent); background: var(--bg); }
.p-desc { white-space: pre-wrap; color: var(--text); background: var(--bg2); border-radius: 14px; padding: 12px 14px; line-height: 1.45; }
.similar { display: grid; grid-auto-flow: column; grid-auto-columns: 42%; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.similar::-webkit-scrollbar { display: none; }
.order-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; padding: 10px 16px calc(10px + var(--safe-b));
  background: var(--bg); box-shadow: 0 -1px 0 rgba(0,0,0,.06);
}
.order-bar .btn-primary { width: 100%; }
body.tg .order-bar { display: none; }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; }
.viewer-track { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.viewer-track::-webkit-scrollbar { display: none; }
.viewer-track img { flex: none; width: 100%; height: 100%; object-fit: contain; scroll-snap-align: center; scroll-snap-stop: always; }
.viewer-counter { position: absolute; top: calc(16px + var(--safe-t)); left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; }
.viewer-close { position: absolute; top: calc(10px + var(--safe-t)); right: 12px; width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--safe-b));
  max-height: calc(100vh - var(--safe-t) - 40px); overflow-y: auto; animation: up .22s ease both;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-handle { width: 36px; height: 5px; border-radius: 3px; background: var(--hint); opacity: .4; margin: 0 auto 10px; }
.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.sheet-sizes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.sheet-sizes button { min-width: 0; }
.sheet-sizes button small { display: block; font-size: 10px; font-weight: 400; color: var(--hint); }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; margin-top: 16px; }
.sort-list button { display: flex; justify-content: space-between; width: 100%; padding: 14px 4px; font-size: 16px; border-bottom: 1px solid var(--bg2); }
.sort-list button.on::after { content: "✓"; color: var(--accent); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: rgba(20,20,20,.9); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  animation: fade .2s both; max-width: 90%; text-align: center;
}

/* десктопный Telegram / широкие экраны */
header, main, .product, .sheet, .order-bar { max-width: 560px; margin-left: auto; margin-right: auto; }
.product { right: 0; left: 0; }

/* категории и бренды */
#catChips { margin-top: 8px; }
#catChips + .chips { margin-top: 6px; }
#catChips .chip { font-weight: 600; }
#chips .chip { height: 30px; font-size: 13px; }
.sheet-brands { display: flex; flex-direction: column; }
.sheet-brands button {
  display: flex; justify-content: space-between; align-items: center; padding: 13px 4px;
  font-size: 16px; border-bottom: 1px solid var(--bg2); text-align: left;
}
.sheet-brands button small { color: var(--hint); font-size: 13px; }
.sheet-brands button.on span::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.sheet-sizes button { font-size: 14px; }
.p-sizes button { padding: 0 12px; }

.chip .cnt { opacity: .55; font-weight: 500; margin-left: 2px; }
