/* Каталог. Цвета - из темы Telegram (светлая/темная), акцент - из brand.css. */
:root {
  --fb-bg: #ffffff;
  --fb-bg2: #f4f2ef;
  --fb-text: #1c1a19;
  --fb-hint: #8d8782;
  --fb-danger: #d64541;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #1b1a19;
    --fb-bg2: #111010;
    --fb-text: #f3f1ee;
    --fb-hint: #9b958f;
    --fb-danger: #ff6b61;
  }
}
:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --accent: var(--brand, var(--tg-theme-button-color, #2481cc));
  --accent-text: var(--brand-text, var(--tg-theme-button-text-color, #fff));
  --line: rgba(128, 128, 128, 0.2);
  --soft: rgba(128, 128, 128, 0.1);
  --radius: 14px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
img, video { display: block; max-width: 100%; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; flex: none; }

/* ---------- шапка и поиск ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 6px;
}
.brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.logo {
  display: none; height: 34px; width: 140px;
  background: var(--logo) left center / contain no-repeat;
}
.has-logo .logo { display: block; }
.has-logo .shop-title { display: none; }
.shop-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  position: relative; width: 42px; height: 42px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .count {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
.icon-btn .dot {
  position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.searchbar { display: flex; gap: 8px; padding: 8px 16px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  height: 42px; border-radius: 12px; background: var(--bg); color: var(--hint);
}
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text);
  font-size: 16px; /* меньше 16px - айфон приближает страницу при вводе */
}
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { color: var(--hint); display: inline-flex; }

/* ---------- категории и фильтры ---------- */
.cats {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.cats::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 20px; white-space: nowrap;
  background: var(--bg); color: var(--text); border: 1px solid transparent;
  font-size: 14px; transition: background .15s, color .15s;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.product .chip, .sheet .chip { border-color: var(--line); background: var(--bg); }
.product .chip.on, .sheet .chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.chip.muted { opacity: .45; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 16px;
  background: var(--soft); font-size: 13px;
}
.tag svg { width: 14px; height: 14px; }
.tag.reset { background: none; color: var(--accent); }

/* ---------- сетка товаров ---------- */
.grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  padding: 0 12px calc(24px + var(--safe-bottom));
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.has-cartbar .grid { padding-bottom: calc(96px + var(--safe-bottom)); }
.card {
  display: block; text-align: left; background: var(--bg); border-radius: var(--radius);
  overflow: hidden; cursor: pointer;
}
.card:active { transform: scale(.985); }
.card-img { position: relative; aspect-ratio: 3 / 4; background: var(--soft); }
.card-img img, .card-img video { width: 100%; height: 100%; object-fit: cover; }
.badge-video {
  position: absolute; left: 8px; bottom: 8px; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.badge-video svg { width: 12px; height: 12px; }
.card-body { padding: 8px 10px 12px; }
.card-title { font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-price { margin-top: 4px; font-weight: 700; font-size: 15px; }
.card-meta { margin-top: 2px; color: var(--hint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--hint); }
.noimg svg { width: 36px; height: 36px; opacity: .5; }
.skeleton .card-img, .skeleton .line {
  background: linear-gradient(90deg, var(--soft) 25%, var(--line) 37%, var(--soft) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}
.skeleton .line { height: 12px; border-radius: 6px; margin: 10px 10px 0; }
.skeleton .line.short { width: 50%; margin-bottom: 12px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.empty {
  grid-column: 1 / -1; text-align: center; color: var(--hint); padding: 48px 24px;
}
.empty svg { width: 44px; height: 44px; margin: 0 auto 12px; display: block; opacity: .6; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 20px; border-radius: 14px; font-weight: 600; font-size: 16px;
  background: var(--accent); color: var(--accent-text); width: 100%;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.secondary { background: var(--soft); color: var(--text); }
.btn.ghost { background: none; color: var(--accent); }
.btn svg { width: 20px; height: 20px; }
.link { color: var(--accent); display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.link svg { width: 16px; height: 16px; }

/* ---------- панель корзины на главной ---------- */
.cartbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom)); z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 0 18px; height: 56px;
  border-radius: 16px; background: var(--accent); color: var(--accent-text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); font-weight: 600;
}
.cartbar .grow { flex: 1; text-align: left; }
.cartbar small { display: block; font-weight: 400; opacity: .85; font-size: 12px; }

/* ---------- экраны поверх каталога ---------- */
.screen { min-height: 100vh; min-height: var(--tg-viewport-stable-height, 100vh); background: var(--bg); }
.screen-head {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.screen-head h2 { margin: 0; font-size: 18px; flex: 1; }
.tg .screen-head .back { display: none; }
.floating-back {
  position: absolute; top: 12px; left: 12px; z-index: 4; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .4); color: #fff;
}
.tg .floating-back { display: none; }

/* ---------- товар ---------- */
.product { padding-bottom: calc(96px + var(--safe-bottom)); position: relative; }
.gallery { position: relative; background: var(--soft); }
.slides {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.slides::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: center; aspect-ratio: 3 / 4; max-height: 78vh; }
.slide img, .slide video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.slide img { background: none; }
.gallery.empty { aspect-ratio: 4 / 3; }
.dots { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; justify-content: center; gap: 6px; pointer-events: none; }
.dots i { width: 6px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .55); transition: width .2s; }
.dots i.on { width: 16px; background: #fff; }
.info { padding: 16px; }
.info h1 { margin: 0; font-size: 21px; line-height: 1.25; letter-spacing: -0.01em; }
.price { margin-top: 6px; font-size: 22px; font-weight: 700; }
.opt { margin-top: 20px; }
.opt-title { display: flex; align-items: baseline; gap: 6px; margin-bottom: 10px; color: var(--hint); font-size: 14px; }
.opt-title b { color: var(--text); font-weight: 600; }
.opt-title .link { margin-left: auto; }
.opt.attention .opt-title { color: var(--danger); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.desc { margin-top: 20px; white-space: pre-line; line-height: 1.5; }
.article { margin-top: 14px; color: var(--hint); font-size: 13px; }
.chart-link { margin-top: 18px; }
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 10px; padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.actions .btn.secondary { flex: 0 0 auto; width: auto; padding: 0 16px; }
.in-cart { margin-top: 12px; color: var(--hint); font-size: 14px; display: flex; gap: 6px; align-items: center; }
.in-cart svg { width: 16px; height: 16px; color: var(--accent); }

/* ---------- корзина ---------- */
.cart { padding: 8px 16px calc(24px + var(--safe-bottom)); }
.line-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.line-item .thumb { width: 72px; height: 96px; border-radius: 10px; overflow: hidden; background: var(--soft); flex: none; }
.line-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.line-item .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.line-item .title { font-weight: 600; }
.line-item .opts { color: var(--hint); font-size: 13px; margin-top: 2px; }
.line-item .sum { margin-top: auto; font-weight: 700; }
.line-item.gone { opacity: .55; }
.line-item.gone .sum { color: var(--danger); font-weight: 600; font-size: 13px; }
.line-item .side { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; }
.remove { color: var(--hint); padding: 2px; }
.qty { display: flex; align-items: center; gap: 2px; background: var(--soft); border-radius: 10px; }
.qty button { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.qty button svg { width: 16px; height: 16px; }
.qty span { min-width: 20px; text-align: center; font-weight: 600; }
.total { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 0 6px; font-size: 18px; font-weight: 700; }
.note { color: var(--hint); font-size: 13px; line-height: 1.45; margin: 8px 0 18px; }
.note.warn { color: var(--danger); }

/* ---------- заказ передан ---------- */
.done { padding: 48px 24px calc(24px + var(--safe-bottom)); text-align: center; }
.done .big { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-text); }
.done .big svg { width: 32px; height: 32px; }
.done h2 { margin: 0 0 8px; font-size: 21px; }
.done p { color: var(--hint); margin: 0 0 24px; line-height: 1.5; }
.done .btn + .btn { margin-top: 10px; }
.order-preview { text-align: left; background: var(--soft); border-radius: 12px; padding: 12px 14px; margin: 0 0 24px; white-space: pre-line; font-size: 14px; }

/* ---------- нижние панели: фильтры, размерная сетка ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--safe-bottom));
  animation: up .22s ease-out; overscroll-behavior: contain;
}
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 4px 0 14px; font-size: 18px; }
.sheet h4 { margin: 18px 0 10px; font-size: 14px; color: var(--hint); font-weight: 500; }
.sheet .row { display: flex; gap: 10px; margin-top: 22px; }
.sheet .row .btn.secondary { flex: 0 0 38%; }
.sheet img { border-radius: 10px; margin-bottom: 12px; width: 100%; }
.radio { display: flex; flex-direction: column; gap: 4px; }
.radio button { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; text-align: left; }
.radio button svg { color: var(--accent); visibility: hidden; }
.radio button.on svg { visibility: visible; }
.size-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.size-table th, .size-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.size-table th { color: var(--hint); font-weight: 500; }
.pre { white-space: pre-wrap; line-height: 1.55; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- фото на весь экран ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; display: flex; align-items: center; justify-content: center;
  animation: fade .15s;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .close { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .15); color: #fff; display: flex; align-items: center; justify-content: center; }

/* ---------- уведомление ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(92px + var(--safe-bottom)); z-index: 60;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 14px;
  /* цвета наоборот к теме - уведомление видно и на светлой, и на темной */
  background: var(--text); color: var(--bg); font-size: 14px; animation: up-small .2s ease-out;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast span { flex: 1; }
.toast button { color: inherit; font-weight: 600; text-decoration: underline; }
@keyframes up-small { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

.error-box { padding: 64px 24px; text-align: center; color: var(--hint); }
.error-box b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.error-box .btn { margin-top: 18px; max-width: 260px; }
