/* Цвета берутся из темы Telegram (переменные задаёт telegram-web-app.js), фолбэк — светлая тема */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f80ed);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { padding-bottom: 80px; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }

.loader {
  width: 32px; height: 32px; margin: 40vh auto 0;
  border: 3px solid var(--hint); border-top-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- шапка ---------- */
.header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--bg);
}
.header h1 { flex: 1; margin: 0; font-size: 20px; }
.icon-btn {
  position: relative; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px; background: var(--bg2); font-size: 18px;
}
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-text);
  font-size: 11px; font-weight: 600; line-height: 18px; text-align: center;
}
.back { color: var(--link); font-size: 15px; }

/* ---------- категории ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px;
  background: var(--bg); scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 18px; background: var(--bg2); white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip small { opacity: .7; margin-left: 4px; }

/* ---------- сетка товаров ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; }
.card { overflow: hidden; border-radius: var(--radius); background: var(--bg); text-align: left; }
.card img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--bg2); }
.card .info { padding: 8px 10px 10px; }
.card .title { overflow: hidden; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
.card .price { margin-top: 2px; font-weight: 700; }
.empty { padding: 60px 24px; color: var(--hint); text-align: center; }

/* ---------- карточка товара ---------- */
.gallery {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; background: var(--bg); scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img, .gallery video {
  flex: none; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; scroll-snap-align: center; background: #000;
}
.dots span.video { border-radius: 1px; }
.dots { display: flex; justify-content: center; gap: 5px; padding: 8px 0 0; background: var(--bg); }
.dots span { width: 6px; height: 6px; border-radius: 3px; background: var(--hint); opacity: .4; transition: .2s; }
.dots span.on { width: 16px; opacity: 1; background: var(--accent); }

.section { margin-bottom: 10px; padding: 14px 16px; background: var(--bg); }
.p-title { margin: 0 0 4px; font-size: 20px; }
.p-price { font-size: 24px; font-weight: 800; }
.label { margin-bottom: 8px; color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.sizes { display: flex; flex-wrap: wrap; gap: 8px; }
.size {
  min-width: 52px; padding: 9px 12px; border: 1.5px solid var(--bg2); border-radius: 10px;
  background: var(--bg2); font-weight: 600;
}
.size.active { border-color: var(--accent); background: var(--bg); color: var(--accent); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.desc { white-space: pre-line; }
.link-btn { color: var(--link); font-weight: 500; }

/* ---------- корзина ---------- */
.cart-item { display: flex; gap: 12px; padding: 12px 16px; background: var(--bg); }
.cart-item + .cart-item { border-top: 1px solid var(--bg2); }
.cart-item img { flex: none; width: 64px; height: 84px; border-radius: 10px; object-fit: cover; }
.cart-item .ci-body { flex: 1; min-width: 0; }
.cart-item .ci-title { font-weight: 600; }
.cart-item .ci-sub { color: var(--hint); font-size: 13px; }
.qty { display: inline-flex; align-items: center; gap: 12px; margin-top: 8px; }
.qty button {
  width: 30px; height: 30px; border-radius: 9px; background: var(--bg2); font-size: 18px; line-height: 1;
}
.row { display: flex; justify-content: space-between; padding: 4px 0; }
.row.total { padding-top: 8px; font-size: 18px; font-weight: 700; }

/* ---------- прочее ---------- */
.order { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--bg); }
.order + .order { border-top: 1px solid var(--bg2); }
.order .o-sub { color: var(--hint); font-size: 13px; }
.success { padding: 60px 24px; text-align: center; }
.success .big { font-size: 64px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; z-index: 20;
  padding: 10px 16px; border-radius: 12px; background: rgba(0, 0, 0, .8); color: #fff;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.fallback-main {
  position: fixed; right: 12px; bottom: 12px; left: 12px; z-index: 10;
  padding: 15px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.fallback-main:disabled { opacity: .6; }

/* значок «есть видео» на карточке каталога */
.card { position: relative; }
.vbadge {
  position: absolute; top: 8px; left: 8px;
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; padding-left: 2px;
}
