/* ==========================================
   CARDS.CSS — Сетка и карточки товаров Handmade.ru
   ========================================== */

/* Сетка каталога */
.products-grid, #productsGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
  align-items: stretch;
}

.products-grid.view-3 {
  grid-template-columns: repeat(3, 1fr);
}

.products-grid.view-list {
  grid-template-columns: 1fr;
}

/* Карточка товара */
.product-card {
  background: var(--bg-white, #ffffff);
  border: 1px solid var(--border-light, #e9ecef);
  border-radius: var(--radius-md, 12px);
  overflow: hidden;
  box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,0.04));
  transition: all 0.25s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  animation: cardFadeIn 0.3s ease backwards;
}

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover, 0 8px 20px rgba(0,0,0,0.08));
  border-color: var(--border, #dee2e6);
}

/* Изображение товара (Квадрат 1:1) */
.product-card__image {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--bg-gray, #f8f9fa);
  flex-shrink: 0;
}

.product-card__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
  display: block;
}

.product-card:hover .product-card__image img {
  transform: scale(1.05);
}

/* Кнопка "В избранное" (Сердечко) */
.product-card__fav {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--text-light, #95a5a6);
  z-index: 2;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.product-card__fav:hover, .product-card__fav.active {
  color: var(--primary, #e74c3c);
  background: #ffffff;
  transform: scale(1.1);
}

.product-card__fav.active i {
  animation: heartPop 0.3s ease;
}

@keyframes heartPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* Бейджи (Новинка, Скидка, Хит) */
.product-card__badges {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 2;
}

.badge-tag {
  padding: 3px 8px;
  border-radius: var(--radius-full, 12px);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-tag.new { background: var(--success, #27ae60); color: #fff; }
.badge-tag.sale { background: var(--primary, #e74c3c); color: #fff; }
.badge-tag.hit { background: var(--warning, #f39c12); color: #fff; }

/* Тело карточки */
.product-card__body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  justify-content: space-between;
  background: #ffffff;
  box-sizing: border-box;
}

/* Магазин */
.product-card__shop {
  font-size: 11px;
  color: var(--text-muted, #7f8c8d);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.product-card__shop i {
  color: var(--success, #27ae60);
  font-size: 10px;
}

/* Название товара */
.product-card__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #2c3e50);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 36px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: color 0.15s;
}

.product-card__title:hover {
  color: var(--primary, #e74c3c);
}

/* Рейтинг */
.product-card__rating {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.product-card__rating .stars {
  color: var(--warning, #f39c12);
  font-size: 12px;
  letter-spacing: 1px;
}

.product-card__rating .reviews {
  color: var(--text-light, #95a5a6);
  font-size: 12px;
}

/* Цена */
.product-card__price {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: auto;
  margin-bottom: 12px;
}

.product-card__price .current {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary, #2c3e50);
}

.product-card__price .old {
  font-size: 12px;
  color: var(--text-light, #95a5a6);
  text-decoration: line-through;
}

.product-card__price .discount {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary, #e74c3c);
  background: rgba(231, 76, 60, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: auto;
}

/* Кнопка "В корзину" */
.product-card__cart-btn {
  width: 100%;
  padding: 10px;
  background: var(--primary, #e74c3c);
  color: #ffffff;
  border-radius: var(--radius-sm, 8px);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.product-card__cart-btn:hover {
  background: var(--primary-dark, #c0392b);
  transform: translateY(-1px);
}

/* Вид списком */
.products-grid.view-list .product-card {
  flex-direction: row;
}

.products-grid.view-list .product-card__image {
  width: 200px;
  min-width: 200px;
  aspect-ratio: auto;
  height: 200px;
}

.products-grid.view-list .product-card__body {
  flex: 1;
  justify-content: center;
  padding: 20px;
}

/* ==========================================
   ИСПРАВЛЕНИЕ МОБИЛЬНОЙ ВЕРСТКИ (Добавить в конец cards.css)
   ========================================== */

@media (max-width: 1024px) {
  .products-grid { 
    grid-template-columns: repeat(3, 1fr); 
  }
}

@media (max-width: 768px) {
  /* Принудительно держим ровно 2 колонки на планшетах и смартфонах */
  .products-grid, #productsGrid { 
    grid-template-columns: repeat(2, 1fr) !important; 
    gap: 10px !important;
  }
  
  .product-card__body { 
    padding: 10px; 
  }
  
  .product-card__title { 
    font-size: 12px; 
    min-height: 32px; 
  }
  
  .product-card__price .current { 
    font-size: 14px; 
  }

  .view-switcher {
    display: none !important;
  }
}

@media (max-width: 400px) {
  /* Даже на самых маленьких экранах сохраняем 2 колонки, но делаем отступы чуть компактнее */
  .products-grid, #productsGrid { 
    grid-template-columns: repeat(2, 1fr) !important; 
    gap: 8px !important;
  }
  
  .product-card__body { 
    padding: 8px; 
  }
  
  .product-card__cart-btn {
    padding: 8px 4px;
    font-size: 11px;
  }

  .view-switcher {
    display: none !important;
  }
}

/* Бесконечный скролл */
.infinite-scroll-loader, .infinite-scroll-end {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px 0;
  color: var(--text-muted, #7f8c8d);
  font-size: 14px;
  font-weight: 600;
}