/* Catalog template cards only (landing, home trends, /templates uses generation_templates.css) */
.templates-grid {
  margin-top: 20px;
}

/* Каталог шаблонов: колонки как у AiHere (CSS column-count, без JS) */
.templates-grid--masonry {
  display: block;
  width: 100%;
  box-sizing: border-box;
  column-count: 4;
  column-gap: 8px;
}

@media (max-width: 1100px) {
  .templates-grid--masonry {
    column-count: 3;
  }
}

@media (max-width: 600px) {
  .templates-grid--masonry {
    column-count: 2;
    column-gap: 10px;
  }
}

@media (max-width: 550px) {
  .templates-grid--masonry {
    column-count: 2;
    column-gap: 6px;
  }
}

/* Узкий WebView (Telegram): одна колонка читабельнее */
@media (max-width: 320px) {
  .templates-grid--masonry {
    column-count: 1;
    column-gap: 8px;
  }
}

.templates-grid--masonry > .template-card-wrap[hidden],
.templates-grid--masonry > .template-card-link[hidden] {
  display: none !important;
}

.templates-grid--masonry > .template-card-wrap,
.templates-grid--masonry > .template-card-link {
  display: block;
  width: 100%;
  box-sizing: border-box;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 8px;
  position: relative;
  z-index: 0;
  transition: transform 0.22s ease;
  content-visibility: auto;
  contain-intrinsic-size: auto 320px;
}

.templates-grid--masonry > .template-card-wrap:hover,
.templates-grid--masonry > .template-card-link:hover {
  z-index: 3;
  transform: scale(1.02);
}

.templates-grid--masonry > .template-card-wrap:hover .template-card,
.templates-grid--masonry > .template-card-link:hover .template-card {
  transform: none;
  border-color: rgba(172, 75, 255, 0.95);
  box-shadow:
    0 0 0 1px rgba(172, 75, 255, 0.35),
    0 14px 36px rgba(0, 0, 0, 0.38);
}
.templates-grid--masonry .template-card {
  height: auto;
  min-height: 0;
  aspect-ratio: auto;
  display: block;
  position: relative;
  transition:
    transform 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease;
}

.templates-grid--masonry .template-preview {
  position: relative;
  inset: auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
}

.templates-grid--masonry .template-preview img,
.templates-grid--masonry .template-preview video,
.templates-grid--masonry .template-preview .template-preview-video-wrap .template-preview-video {
  display: block;
  width: 100%;
  height: auto;
  /* Компромисс: выше старых 280px для 9:16, но без почти полного экрана */
  max-height: min(60dvh, 620px);
  object-fit: contain;
  object-position: center;
}

/* В masonry превью задаёт высоту контент в потоке; absolute-wrap схлопывал карточку */
.templates-grid--masonry .template-preview .template-preview-video-wrap {
  position: relative;
  inset: auto;
  width: 100%;
  height: auto;
  display: block;
}

.templates-grid--masonry .template-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    to top,
    rgba(5, 8, 20, 0.92) 0%,
    rgba(5, 8, 20, 0.55) 32%,
    rgba(5, 8, 20, 0.18) 58%,
    rgba(5, 8, 20, 0) 82%
  );
}

.templates-grid--masonry .template-card-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin-top: 0;
  padding: 8px 10px 10px;
  background: transparent;
  border-top: none;
  z-index: 2;
}

.templates-grid--masonry .template-card-title-row h3 {
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.65);
}

.templates-grid--masonry .template-price-inline {
  filter: drop-shadow(0 1px 6px rgba(0, 0, 0, 0.55));
}

.templates-grid--masonry .template-preview-placeholder {
  height: auto;
  min-height: 120px;
}
.template-card-link {
  color: inherit;
  text-decoration: none;
  display: block;
  -webkit-tap-highlight-color: transparent;
}

.template-card-link:hover {
  color: inherit;
  text-decoration: none;
}

.template-card-link[hidden] {
  display: none !important;
}

.template-card {
  background: rgba(10, 11, 29, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
  height: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.template-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    to top,
    rgba(5, 8, 20, 0.82) 0%,
    rgba(5, 8, 20, 0.58) 26%,
    rgba(5, 8, 20, 0.22) 48%,
    rgba(5, 8, 20, 0.0) 72%
  );
}

.template-card-link:hover .template-card {
  transform: translateY(-2px);
  border-color: rgba(172, 75, 255, 0.8);
}

.template-preview {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.template-preview-top-badges {
  --template-preview-badge-size: clamp(22px, 2vw, 24px);
  --template-preview-badge-icon-size: 16px;
  --template-preview-badge-radius: 6px;
  position: absolute;
  top: 15px;
  left: clamp(10px, 2vw, 15px);
  z-index: 3;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

/* >800 и 451–600: в ряд; 601–800 и ≤450: колонкой */
@media (max-width: 800px) and (min-width: 601px) {
  .template-preview-top-badges {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 450px) {
  .template-preview-top-badges {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (min-width: 451px) and (max-width: 600px) {
  .template-preview-top-badges {
    flex-direction: row;
    align-items: center;
  }
}

/* Плашки каталога: один размер с template-input-badge (перекрывает .template-like-btn ниже) */
.template-preview-top-badges .template-input-badge,
.template-preview-top-badges .template-like-badge.template-like-btn {
  flex-shrink: 0;
  box-sizing: border-box;
  width: var(--template-preview-badge-size);
  height: var(--template-preview-badge-size);
  min-width: var(--template-preview-badge-size);
  min-height: var(--template-preview-badge-size);
  max-height: var(--template-preview-badge-size);
  padding: 0;
  margin: 0;
  border-radius: var(--template-preview-badge-radius);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.template-preview-top-badges .template-input-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.template-preview-top-badges .template-like-badge.template-like-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 3px;
  appearance: none;
  -webkit-appearance: none;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.template-preview-top-badges .template-like-badge.template-like-btn.has-count {
  width: auto;
  min-width: var(--template-preview-badge-size);
  padding: 0 5px 0 4px;
}

.template-preview-top-badges .template-input-badge img,
.template-preview-top-badges .template-like-badge__icon {
  flex-shrink: 0;
  display: block;
  width: var(--template-preview-badge-icon-size);
  height: var(--template-preview-badge-icon-size);
  max-width: var(--template-preview-badge-icon-size);
  max-height: var(--template-preview-badge-icon-size);
  opacity: 0.92;
}

.template-preview-top-badges .template-input-badge img {
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.template-preview-top-badges .template-like-badge__count {
  flex-shrink: 0;
  min-width: var(--template-preview-badge-icon-size);
  height: var(--template-preview-badge-icon-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: rgba(255, 255, 255, 0.92);
  pointer-events: none;
  white-space: nowrap;
}

.template-preview-top-badges .template-like-badge__count[hidden] {
  display: none;
}

.template-preview-top-badges .template-like-badge.template-like-btn:hover {
  border-color: rgba(255, 120, 160, 0.65);
  color: #fff;
}

.template-preview-top-badges .template-like-badge.template-like-btn.is-liked {
  border-color: rgba(255, 90, 130, 0.85);
  background: rgba(180, 40, 90, 0.55);
  color: #fff;
}

.template-preview-top-badges .template-like-badge.template-like-btn.is-liked .template-stat__icon--heart path {
  fill: rgba(255, 120, 160, 0.35);
}

.template-preview-top-badges .template-like-badge.template-like-btn[data-loading="1"] {
  opacity: 0.65;
  pointer-events: none;
}

.template-category-badge {
  position: absolute;
  top: 15px;
  right: clamp(10px, 2vw, 15px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: clamp(22px, 2.5vw, 24px);
  max-width: calc(100% - 52px);
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: clamp(9px, 2vw, 11px);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.template-preview img,
.template-preview video,
.template-preview .template-preview-video-wrap .template-preview-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.template-preview-video-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.template-preview-video-controls {
  position: absolute;
  right: clamp(8px, 2vw, 12px);
  bottom: clamp(8px, 2vw, 12px);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.template-preview-video-controls > .template-preview-video-play,
.template-preview-video-controls > .template-preview-video-sound {
  pointer-events: auto;
}

/* На карточках каталога — выше градиента ::after и блока с заголовком */
.template-card > .template-preview-video-controls--card {
  z-index: 4;
  bottom: clamp(44px, 11vw, 58px);
}

.templates-grid--masonry .template-card > .template-preview-video-controls--card {
  bottom: clamp(38px, 9vw, 50px);
}
.template-preview-video-play,
.template-preview-video-sound {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(12, 8, 24, 0.72);
  color: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.template-preview-video-play:hover,
.template-preview-video-sound:hover {
  background: rgba(24, 14, 40, 0.88);
  border-color: rgba(186, 95, 255, 0.55);
}

.template-preview-video-play:active,
.template-preview-video-sound:active {
  transform: scale(0.96);
}

.template-preview-video-play__icon,
.template-preview-video-sound__icon {
  width: 18px;
  height: 18px;
  display: block;
}

.template-preview-video-play__icon--pause {
  display: none;
}

.template-preview-video-play.is-playing .template-preview-video-play__icon--play {
  display: none;
}

.template-preview-video-play.is-playing .template-preview-video-play__icon--pause {
  display: block;
}

.template-preview-video-sound__icon--on {
  display: none;
}

.template-preview-video-sound.is-unmuted .template-preview-video-sound__icon--off {
  display: none;
}

.template-preview-video-sound.is-unmuted .template-preview-video-sound__icon--on {
  display: block;
}
.template-preview-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
}

.template-card-body {
  position: relative;
  z-index: 2;
  padding: 14px;
}

.template-card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.template-card-title-row h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: clamp(10px, 2.5vw, 14px);
  font-weight: 400;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.92);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.template-card-link:hover .template-card-title-row h3 {
  color: rgba(255, 255, 255, 0.92);
}

/* Статистика шаблона (детальная страница и общие элементы) */
.template-card-wrap {
  position: relative;
}
.template-card-link:hover .template-price-value {
  color: rgba(255, 255, 255, 0.92);
}

.template-price-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin-top: 1px;
}

.template-price-value {
  font-size: clamp(11px, 2.5vw, 14px);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
}

.template-neuron-icon {
  width: clamp(15px, 3.6vw, 18px);
  height: clamp(15px, 3.6vw, 18px);
  object-fit: contain;
  opacity: 0.9;
  flex-shrink: 0;
}
