/* === ПОИСК === */
.search {
  flex-grow: 1;
  max-width: 100%;
  margin: 0 10px;
  position: relative;
  overflow: visible;
  z-index: 1001;  
}

.search-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
}

.search input:focus {
  outline: none;
}

/* Обёртка для поиска с кнопкой */
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-input-wrapper .search-input {
  flex: 1;
  padding-right: 45px;
}

.search-submit-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: #999;
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 10%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.search-submit-btn:hover {
  background: #c73a3e;
}

/* Подсказки поиска — теперь вне потока */
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  border-radius: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  background: var(--bg-card);
  border: 1px solid #e0e0e0;
  border-color: var(--border-card);
  max-height: 280px;
  z-index: 1002;
  display: none;
  margin-top: 6px;
}

.suggestions.show {
  display: block;
}

.suggestion-item {
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid #f0f0f0;
  border-bottom-color: var(--border-card);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.suggestion-item:hover {
  background: #fef0f0;
  transform: scale(1.02);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item strong {
  color: var(--text-primary);
  font-size: 13px;
}

.suggestion-item img {
  width: auto;
  height: 50px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.suggestion-item .suggestion-info {
  flex: 1;
  min-width: 0;
}

.suggestion-item .suggestion-category {
  font-size: 11px;
  color: var(--text-secondary);
}

.suggestion-item .suggestion-price {
  font-size: 13px;
  font-weight: 700;
  color: #e44247;
  white-space: nowrap;
  flex-shrink: 0;
}

/* активный элемент */
.suggestion-item.active {
  background: #e44247;
  color: white;
}

.suggestion-item.active strong,
.suggestion-item.active .suggestion-price {
  color: #fff;
}

.suggestion-item.active .suggestion-category {
  color: rgba(255,255,255,0.7);
}

.suggestion-item.active:hover {
  background: #e44247;
  transform: scale(1);
}

/* ПК: 5 товаров */
@media (min-width: 769px) {
  .suggestions {
    max-height: 310px;              /* ≈5 товаров */
  }
}

/* Смартфоны: компактнее */
@media (max-width: 768px) {
  .suggestions {
    max-height: 260px;              /* 4-5 товаров */
    left: -10px;
    right: -10px;
    width: calc(100% + 20px);
  }

  .suggestion-item {
    padding: 8px 10px;
    gap: 8px;
  }

  .suggestion-item strong {
    font-size: 12px;
  }

  .suggestion-item .suggestion-category {
    font-size: 10px;
  }

  .suggestion-item .suggestion-price {
    font-size: 12px;
  }
}


/* === ЭФФЕКТ ВЫДЕЛЕНИЯ ТОВАРА (улучшенный) === */
.product-card.highlighted {
  animation: highlight 1.2s ease-out forwards;
  border: 2px solid #e44247;
  box-shadow: 0 0 15px rgba(228, 66, 71, 0.3);
  transform: scale(1.01);
}

@keyframes highlight {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(228, 66, 71, 0.3);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(228, 66, 71, 0.4);
  }
  100% {
    transform: scale(1.01);
    box-shadow: 0 0 15px rgba(228, 66, 71, 0.3);
  }
}

/* === Блок ФИЛЬТРОВ === */
.filters-container {
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-filter);
  border-bottom: 1px solid var(--border-card);
}

/* Основной блок фильтров */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  max-width: auto;
  margin: 0 auto;
  padding-left: 280px;
}

/* Кнопка "По умолчанию" */
#default-filter {
  background: #e44247;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

#default-filter:hover {
  background: #c0353a;
}

/* Поля ввода цены */
#min-price,
#max-price { 
  background: var(--bg-card);
  padding: 8px 12px;
  border: 1px solid var(--border-input);
  border-radius: 4px;
  color: var(--text-primary);
  width: 120px;
  font-size: 14px;
}

#min-price:focus,
#max-price:focus {
  outline: 2px solid #e44247;
  outline-offset: 0;
}

/* Сортировка цены */
.sort-controls {
  display: flex;
  gap: 10px;
  margin: 15px 0;
}

.sort-btn {
  padding: 8px 16px;
  border: 2px solid #ddd;
  background: var(--bg-sort-btn);
  border-radius: 6px;
  border-color: var(--border-input);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  transition: all 0.3s ease;
  position: relative;
  color: var(--text-primary);
}

.sort-btn:hover {
  border-color: #007bff;
  color: #007bff;
}

.sort-btn.active {
  background: #007bff;
  color: white;
  border-color: #007bff;
}

.sort-icon {
  font-weight: bold;
  font-size: 12px;
}

/* Стили для состояния загрузки */
.sort-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Кнопка применения фильтров */
#apply-filters {
  background: #28a745;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

#apply-filters:hover {
  background: #218837;
}

@media (max-width: 768px) {
  .filters-container {
    padding: 12px 16px;
  }

  .filters {
    padding-left: 0; /* Убираем отступ */
    justify-content: center; /* Центрируем элементы внутри .filters */
    width: 100%; /* Блок занимает всю ширину контейнера */
    box-sizing: border-box; /* Корректно учитываем padding и border в ширине */
  }

  /* Кнопка "По умолчанию" на мобильных */
  #default-filter {
    width: 100%;
    text-align: center;
  }

  /* Поля ввода на мобильных */
  #min-price,
  #max-price {
    width: 100%;
  }

  /* Группировка сортировки */
  .filters label {
    justify-content: center;
  }

  /* Кнопка "Применить" на мобильных */
  #apply-filters {
    width: 100%;
  }
}

/* === КАТАЛОГ === */
.catalog-layout {
  display: flex;
  gap: 30px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.categories-sidebar {
  width: 250px;
  background: var(--bg-sidebar);
  padding: 20px;
  border-radius: 15px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  position: sticky;
  top: 70px;
  align-self: flex-start;
  z-index: 100;
}

.categories-sidebar h3 {
  font-size: 18px;
  margin-bottom: 15px;
  color: var(--text-heading);
  text-align: center;
}

@media (max-width: 768px) {
  /* Сайдбар с категориями — закрепление с отступом */
  .categories-sidebar {
    width: 100%;
    padding: 0;
    position: sticky;
    top: 76px;
    background: var(--bg-sidebar);
    z-index: 100;
    border-radius: 12px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  }

  /* Контейнер для заголовка и бургер‑кнопки */
  .categories-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 3px 16px;
    background: var(--bg-sidebar);
    border-radius: 12px 12px 0 0;
    font-size: 16px;
    color: var(--text-primary);
    margin: 0;
    box-sizing: border-box;
  }

  /* Бургер‑кнопка для категорий — сделали тоньше */
  .categories-burger {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 22px;
    height: 16px;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 1001;
    margin-left: auto;
  }

  .categories-burger span {
    display: block;
    height: 2px;
    width: 100%;
    background-color: var(--burger-color);
    transition: all 0.3s ease;
  }

  /* Анимация бургер‑кнопки при активном состоянии (превращение в крестик) */
  .categories-burger.active span:nth-child(1) {
    transform: rotate(45deg) translate(3px, 3px);
  }
  .categories-burger.active span:nth-child(2) {
    opacity: 0;
  }
  .categories-burger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(3px, -3px);
  }

  /* Контейнер с содержимым категорий (скрыт по умолчанию) */
  .categories-content {
    padding: 0 16px; /* Уменьшили нижний отступ до 8px для раскрытого списка */
    max-height: ;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
  }

  /* Стиль для открытого состояния: показываем контент и меняем бургер на крестик */
  .categories-sidebar.expanded .categories-content {
    max-height: 450px;
    opacity: 1;
  }

  /* Стили для списка категорий внутри контейнера */
  .categories-content #categories-list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .categories-content #categories-list li {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
	border-bottom-color: var(--border-card);
    font-size: 14px;
  }

  /* Убираем границу у последнего элемента списка */
  .categories-content #categories-list li:last-child {
    border-bottom: none;
  }

  /* Активная категория — выделяем цветом и жирностью, но не перекрываем текст */
  .categories-content #categories-list li.active {
    color: #e44247;
    font-weight: 600;
    background-color: rgba(228, 66, 71, 0.1); /* Лёгкая заливка вместо полного закрашивания */
  }

  /* Исправление обрезки кнопки "Категории" — добавляем отступ и корректируем радиус */
  .categories-header span {
    padding-right: 30px; /* Обеспечиваем зазор до бургер-кнопки */
    box-sizing: border-box;
  }
}

#categories-list {
  list-style: none;
}

#categories-list li {
  padding: 10px 14px;
  background: var(--bg-category);
  color: var(--text-primary);
  margin-bottom: 8px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.3s ease;
  text-align: center;
}

#categories-list li:hover,
#categories-list li.active {
  background: #e44247;
  color: white;
}

.catalog-grid {
  flex: 1;
  min-width: 280px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  grid-auto-rows: 1fr;
}

.catalog-grid {
  opacity: 1;
  transition: opacity 0.3s ease;
}

.catalog-grid.loading {
  opacity: 0.5;
}

.product-card {
  width: 100%;
  max-width: 360px;
  max-height: 450px;
  background: var(--bg-card);
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  text-decoration: none;
  position: relative;
}

.product-card img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.product-info {
  padding: 16px;
  display: flex;
  flex-direction: column;
  text-align: left;
  flex-grow: 1; /* Занимает всё доступное пространство */
  justify-content: space-between; /* Фиксирует нижний блок */
}

.product-info h3 {
  font-size: 16px;
  margin-bottom: 6px;
  color: var(--text-heading);
  font-weight: 600;
}

.product-info p {
  color: var(--text-secondary);
  font-size: 14px;
}

.product-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 0px; /* Прижимает блок к низу карточки */
  padding-top: 5px; /* Фиксированный отступ сверху (от остального контента) */
  border-top: 1px solid var(--border-card); /* Необязательная разделительная линия */
}

.price {
  font-size: 20px;
  font-weight: bold;
  color: #e44247;
}

.add-to-cart {
  background: #e44247;
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.3s ease;
  margin: 15px 0 0 0;
}

.add-to-cart:hover {
  background: #c73a3e;
}

.add-to-cart.added {
  background: #4CAF50;
  cursor: default;
}

/* Кнопка удаления — крестик */
.fav-remove-btn {
  position: absolute;
  top: 15px;
  right: 5px;
  z-index: 3;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
}

.fav-remove-btn:hover {
  background: #e44247;
}

/* Адаптация под смартфоны */
@media (max-width: 768px) {
  /* Общий макет каталога */
  .catalog-layout {
    flex-direction: column; /* Сайдбар и сетка — друг под другом */
    gap: 20px; /* Уменьшаем расстояние между элементами */
  }

  /* Сайдбар с категориями */
  .categories-sidebar {
    width: 100%; /* Занимаем всю ширину экрана */
    padding: 16px; /* Уменьшаем внутренние отступы */
    border-radius: 12px; /* Немного уменьшаем скругление углов */
  }

  .categories-sidebar h3 {
    font-size: 17px; /* Уменьшаем заголовок сайдбара */
    margin-bottom: 12px; /* Сокращаем отступ под заголовком */
  }

  #categories-list li {
    padding: 9px 12px; /* Уменьшаем отступы в пунктах меню */
    font-size: 14px; /* Уменьшаем размер шрифта */
    margin-bottom: 6px; /* Сокращаем расстояние между пунктами */
  }

  /* Сетка товаров */
  .catalog-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); /* Уменьшаем минимальную ширину карточки */
    gap: 16px; /* Уменьшаем расстояние между карточками */
    min-width: auto; /* Снимаем ограничение минимальной ширины */
  }

  /* Карточка товара */
  .product-card {
    max-width: none; /* Снимаем ограничение максимальной ширины */
    width: 100%; /* Занимаем всю доступную ширину */
  }

  .product-card img {
    height: 240px; /* Уменьшаем высоту изображения */
  }

  .product-info {
    padding: 14px; /* Уменьшаем внутренние отступы */
  }

  .product-info h3 {
    font-size: 17px; /* Уменьшаем заголовок товара */
    margin-bottom: 5px; /* Сокращаем отступ под заголовком */
  }

  .product-info p {
    font-size: 13px; /* Уменьшаем описание товара */
    margin-bottom: 10px; /* Сокращаем отступ */
  }

  .product-actions {
    flex-wrap: wrap; /* Переносим элементы на новую строку при необходимости */
    gap: 8px; /* Уменьшаем расстояние между кнопками и ценой */
  }

  .price {
    font-size: 18px; /* Уменьшаем размер цены */
  }

  .add-to-cart {
    padding: 9px 12px; /* Уменьшаем отступы кнопки */
    font-size: 13px; /* Уменьшаем шрифт в кнопке */
    border-radius: 18px; /* Немного уменьшаем скругление */
  }

  /* Поиск в шапке */
  .search {
    margin: 0 5px; /* Уменьшаем внешние отступы поиска */
  }

  .search-input {
    padding: 10px 14px; /* Уменьшаем отступы в поле поиска */
    font-size: 15px; /* Уменьшаем шрифт */
  }
}

/* === БЕСКОНЕЧНАЯ ПОДГРУЗКА === */
.load-more-container {
  text-align: center;
  margin: 30px 0;
}

.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 16px;
  padding: 20px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e44247;
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.load-more-btn {
  background: #e44247;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.load-more-btn:hover {
  background: #c73a3e;
}

/* Скрываем кнопку, когда товаров больше нет */
#load-more-btn.hidden {
  display: none;
}

/* Стиль для сообщения о конце товаров */
#end-of-products {
  font-size: 16px;
  color: var(--text-secondary);
}

/* Адаптация для мобильных устройств */
@media (max-width: 768px) {
  .load-more-container {
    margin: 20px 0;
  }
  
  .loading-indicator {
    font-size: 14px;
    gap: 8px;
  }
  
  .load-more-btn {
    padding: 10px 20px;
    font-size: 15px;
  }
}

/* Плашка на карточке */
.product-card {
  position: relative;
}

/* Контейнер плашек */
.product-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
}

/* Общие стили плашек */
.product-badge {
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.badge-new {
  background: linear-gradient(135deg, #4a6cf7, #3b5de7);
}

.badge-hit {
  background: linear-gradient(135deg, #e44247, #c73a3e);
}

.badge-other {
  background: linear-gradient(135deg, #f39c12, #e67e22);
}

/* Плашка скидки */
.badge-discount {
  background: #e44247;
  color: #fff;
}

/* Старая цена */
.price-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.price-old-line {
  min-height: 16px; /* резервирует место, даже если старой цены нет */
  line-height: 1;
}

.old-price {
  font-size: 13px;
  color: #999;
  text-decoration: line-through;
  white-space: nowrap;
}

.product-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.product-actions .add-to-cart {
  flex-shrink: 0;
}

.product-actions .price {
  margin-right: 0;
}

/* ==================== АДАПТИВНОСТЬ СРАВНЕНИЯ ==================== */

@media (max-width: 768px) {
  #compare-table table {
    min-width: auto !important;
    width: 100% !important;
  }

  #compare-table td:first-child {
    width: 100px !important;
    font-size: 12px;
    padding: 8px 6px !important;
  }

  #compare-table td:not(:first-child) {
    width: auto !important;
    min-width: auto !important;
    padding: 8px 6px !important;
  }

  #compare-table td img {
    max-width: 80px !important;
  }

  #compare-table td {
    font-size: 12px;
  }

  /* Скрываем 3-й и 4-й столбцы товаров (оставляем 2) */
  #compare-table tr > td:nth-child(4),
  #compare-table tr > td:nth-child(5) {
    display: none;
  }

  /* Кнопки удаления — по 2 под таблицей */
  #compare-table .fav-buttons-like > div:nth-child(3),
  #compare-table .fav-buttons-like > div:nth-child(4) {
    display: none;
  }

  /* Кнопки навигации компактнее */
  #compare-table button {
    font-size: 13px !important;
    padding: 6px 12px !important;
  }
}

