/* =====================================================================
   TOPLOFT · семейства товаров (компонент) — по образцу toploft.shop/catalog/aksesuaryi:
   3 колонки (параметр — 4), на телефоне 1 (параметр — 2); фото квадратом со скруглением 16, кружок «10%» слева внизу;
   под фото: «в Наличии», название, цена + жёлтая цена, справа — корзина и тёмная кнопка «Подробнее»;
   ниже — квадраты-схемы размеров (74 px) или лента фото товара (60 px).
   Отступ сверху, поля и заголовок — общие классы лейаута .tl-section и .tl-title.
   ===================================================================== */

.tl-fam { --fam-r: 16px; font-family: var(--tl-font, "Montserrat", system-ui, sans-serif); color: var(--tl-c-text, #212529); }
.tl-fam *, .tl-fam *::before, .tl-fam *::after { box-sizing: border-box; }
.tl-fam :where(h3, p) { margin: 0; }
.tl-fam :where(a) { color: inherit; text-decoration: none; }
.tl-fam :where(button) { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.tl-fam :where(a, button):focus { outline: none; }

.tl-fam__title { margin-bottom: var(--tl-space, 40px); }
.tl-fam__title:not(:has(span:not(:empty))) { display: none; }

/* сетка видна, когда скрипт собрал семейства и подставил фото (is-shown) — без мелькания всех товаров и чужих фото.
   Если скрипт не сработал — сетка всё равно проявится через 3 с (товары не прячутся навсегда). */
.tl-fam__grid { opacity: 0; animation: tl-fam-show .2s ease 3s forwards; }
.tl-fam.is-shown .tl-fam__grid { opacity: 1; animation: none; transition: opacity .2s ease; }
/* фото «Вид сверху» ещё не пришло — серая подложка вместо превью (запасной показ превью через 4 с) */
.tl-fam__card.is-pending .tl-fam__img { opacity: 0; animation: tl-fam-show .2s ease 4s forwards; }
.tl-fam__img { transition: opacity .2s ease; }
@keyframes tl-fam-show { to { opacity: 1; } }

.tl-fam__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.tl-fam--c4 .tl-fam__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tl-fam__family { min-width: 0; }
.tl-fam__card { min-width: 0; }
.tl-fam__card.is-off { display: none; }

/* фото */
.tl-fam__media { position: relative; display: block; overflow: hidden; aspect-ratio: 1; border-radius: var(--fam-r); background: #f1f1f1; }
.tl-fam__img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tl-fam__promo {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  color: #111;
  background: var(--tl-c-accent, #fffd00);
  box-shadow: 0 1px 6px rgb(0 0 0 / 20%);
}
.tl-fam__promo:empty { display: none; }

/* под фото */
.tl-fam__body { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.tl-fam__info { display: flex; flex-direction: column; min-width: 0; }
.tl-fam__stock { font-size: 12px; font-weight: 500; color: #198754; }
.tl-fam__stock--out { color: #8a8a8a; }
.tl-fam__name { margin: 2px 0 4px; font-size: 14px; font-weight: 600; line-height: 1.3; }
.tl-fam__price { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 14px; }
.tl-fam__price b { font-weight: 700; }
.tl-fam__price s { color: #9a9a9a; }
.tl-fam__yellow { padding: 2px 8px; border-radius: 6px; font-weight: 600; background: var(--tl-c-accent, #fffd00); }
.tl-fam__yellow:empty { display: none; }
.tl-fam__actions { display: flex; flex: 0 0 auto; align-items: center; gap: 6px; }
.tl-fam__cart { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; opacity: .75; transition: opacity .2s, background-color .2s; }
.tl-fam__cart:hover { opacity: 1; }
.tl-fam__cart[vz-state="in-cart"] { opacity: 1; background: var(--tl-c-accent, #fffd00); }
.tl-fam__more {
  display: inline-flex;
  align-items: center;
  height: 35px;
  padding: 0 16px;
  border-radius: 2rem;
  font-size: 14px;
  white-space: nowrap;
  color: #fff !important;
  background: #212529;
  transition: background-color .2s;
}
.tl-fam__more:hover { background: #424649; }

/* переключатель размеров: квадраты-схемы */
.tl-fam__sizes { display: grid; grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.tl-fam__size {
  display: grid;
  place-items: center;
  aspect-ratio: 1;             /* квадраты тянутся на всю ширину строки, промежутки ровные */
  padding: 4px;
  overflow: hidden;
  border: 1px solid #adb5bd;
  border-radius: var(--fam-r);   /* как у фото карточки */
  background: #fff;
  transition: border-color .2s;
}
.tl-fam__size img { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: calc(var(--fam-r) - 5px); }
.tl-fam__size span { font-size: 14px; font-weight: 600; }
.tl-fam__size:hover { border-color: #6c757d; }
.tl-fam__size.is-active { border: 3px solid #6c757d; padding: 2px; }

/* фото, которые листаются (mode=gallery) */
.tl-fam__track { display: flex; width: 100%; height: 100%; overflow-x: auto; overscroll-behavior-x: contain; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; scroll-snap-type: x mandatory; scrollbar-width: none; cursor: grab; }
.tl-fam__track::-webkit-scrollbar { display: none; }
.tl-fam__track.is-drag, .tl-fam__thumbs.is-drag { scroll-snap-type: none; cursor: grabbing; }
.tl-fam__thumbs.is-drag .tl-fam__thumb { pointer-events: none; }
.tl-fam__thumbs { cursor: grab; }
.tl-fam__slide { flex: 0 0 100%; width: 100%; height: 100%; object-fit: cover; scroll-snap-align: start; user-select: none; -webkit-user-drag: none; }

/* стрелки: на фото и у ленты миниатюр — появляются при наведении (как в галерее карточки товара) */
.tl-fam__rail { position: relative; }
.tl-fam__arr {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  margin-top: -18px;
  opacity: 0;
  transition: opacity .2s;
}
.tl-fam__arr[hidden] { display: none; }
.tl-fam__arr-dot {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #111;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 2px 10px rgb(0 0 0 / 18%);
  transition: background-color .2s;
}
.tl-fam__arr:hover .tl-fam__arr-dot { background: #fff; }
.tl-fam__arr--prev { left: 8px; }
.tl-fam__arr--next { right: 8px; }
/* на фото стрелка — это вся полоса 20 % ширины с края: попасть легко, центр фото по-прежнему открывает товар */
.tl-fam__arr--photo { top: 0; bottom: 0; width: 20%; margin: 0; cursor: pointer; }
.tl-fam__arr--photo.tl-fam__arr--prev { left: 0; justify-items: start; padding-left: 12px; }
.tl-fam__arr--photo.tl-fam__arr--next { right: 0; justify-items: end; padding-right: 12px; }
.tl-fam__rail .tl-fam__arr { margin-top: -15px; }
.tl-fam__rail .tl-fam__arr-dot { width: 30px; height: 30px; }
.tl-fam__rail .tl-fam__arr--prev { left: -6px; }
.tl-fam__rail .tl-fam__arr--next { right: -6px; }
.tl-fam__rail:hover .tl-fam__arr, .tl-fam__media:hover .tl-fam__arr { opacity: 1; }
/* телефон и касание — без стрелок, листание пальцем (и в узком окне компьютера тоже) */
@media (hover: none), (max-width: 767.98px) { .tl-fam__arr { display: none !important; } }

/* лента фото товара */
/* миниатюры: 6 в ряд на компьютере, 5 на телефоне, ровные промежутки; больше — листаются вбок */
.tl-fam__thumbs { --per: 6; --g: 10px; display: flex; gap: var(--g); margin-top: 12px; overflow-x: auto; touch-action: pan-x pan-y; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none; }
.tl-fam__thumbs::-webkit-scrollbar { display: none; }
.tl-fam__thumb { flex: 0 0 calc((100% - (var(--per) - 1) * var(--g)) / var(--per)); aspect-ratio: 1; overflow: hidden; border: 2px solid transparent; border-radius: var(--fam-r); scroll-snap-align: start; }
.tl-fam__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tl-fam__thumb.is-active { border-color: #2ea3d8; }

@media (max-width: 1023.98px) {
  .tl-fam__grid, .tl-fam--c4 .tl-fam__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767.98px) {
  .tl-fam__grid { gap: 28px 12px; }
  .tl-fam--m1 .tl-fam__grid { grid-template-columns: minmax(0, 1fr); }
  .tl-fam--m2 .tl-fam__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tl-fam__name { font-size: 12px; }
  .tl-fam--m2 .tl-fam__body { flex-direction: column; align-items: flex-start; }
  .tl-fam--m2 .tl-fam__cart { display: none; }
  .tl-fam__sizes { gap: 10px; }
  .tl-fam__thumbs { --per: 5; --g: 8px; }
}
