/* Стили для ленивой загрузки товаров и изображений */

/* Плейсхолдеры для изображений */
.image-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  color: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 1;
  text-align: center;
  padding: 16px;
}

.image-placeholder:not(.permanent)::after {
  content: ". . .";
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: pre-line;
  display: none;
}

.image-placeholder .loading-spinner {
  display: none;
}

.image-placeholder.permanent {
  position: relative;
  height: 200px;
  background: #f8f9fa;
  border: 2px dashed #dee2e6;
}

.image-placeholder span {
  color: #6c757d;
  font-size: 14px;
  text-align: center;
  padding: 0 16px;
}

/* Спиннер загрузки */
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

body.page-loaded .loading-spinner {
  width: 48px;
  height: 48px;
  border-width: 3px;
  border-color: rgba(25, 25, 35, 0.1);
  border-top-color: rgba(25, 25, 35, 0.4);
  border-left-color: rgba(25, 25, 35, 0.05);
  background: transparent;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  pointer-events: none;
  display: none;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Ленивые изображения */
.lazy-image {
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  position: relative;
  z-index: 2;
}

.lazy-image.loaded {
  opacity: 1;
  width: 100%;
  height: 100%;
}

.lazy-image.error {
  opacity: 0.7;
  filter: grayscale(100%);
}

/* Индикатор загрузки товаров */
.lazy-loading-indicator {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  gap: 16px;
  grid-column: 1 / -1;
  color: #6c757d;
  font-size: 14px;
}

.lazy-loading-indicator .loading-spinner {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

/* Сентинел для отслеживания прокрутки */
.lazy-sentinel {
  opacity: 0;
  pointer-events: none;
}

/* Оптимизация для мобильных устройств */
@media (max-width: 768px) {
  .image-placeholder {
    border-radius: 6px;
  }
  
  .loading-spinner {
    width: 20px;
    height: 20px;
    border-width: 2px;
  }

  body.page-loaded .loading-spinner {
    width: 40px;
    height: 40px;
    border-width: 2.5px;
  }
  
  .lazy-loading-indicator {
    padding: 24px 16px;
  }
  
  .lazy-loading-indicator .loading-spinner {
    width: 28px;
    height: 28px;
  }
}

/* Анимация появления товаров */
.lazy-item {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.4s ease-out forwards;
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Задержка анимации для плавного появления */
.lazy-item:nth-child(1) { animation-delay: 0.05s; }
.lazy-item:nth-child(2) { animation-delay: 0.1s; }
.lazy-item:nth-child(3) { animation-delay: 0.15s; }
.lazy-item:nth-child(4) { animation-delay: 0.2s; }
.lazy-item:nth-child(5) { animation-delay: 0.25s; }
.lazy-item:nth-child(6) { animation-delay: 0.3s; }

/* Улучшенные стили для слайдера изображений */
.product-image-slider {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  touch-action: pan-y pinch-zoom;
}

.slider-track {
  display: flex;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.slider-item {
  flex: 0 0 100%;
  position: relative;
  min-height: 200px;
}

.slider-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
}

.slider-indicators {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 3;
  display: none;
}

.slider-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background: rgba(25, 25, 35, 0.4);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
  scale: 0.8;
}

.slider-dot.active {
  background: rgba(35, 35, 50, 0.85);
  scale: 1;
}

.slider-dot:hover {
  background: rgba(35, 35, 50, 0.65);
}

/* Состояния загрузки для разных типов подключения */
@media (prefers-reduced-data: reduce) {
  .lazy-image {
    transition: none;
  }
  

.low-end .lazy-item {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}

.low-end .slider-track {
  transition: none !important;
}
  
  .lazy-item {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* Высокая плотность пикселей */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .loading-spinner {
    border-width: 1px;
  }

  body.page-loaded .loading-spinner {
    border-width: 2px;
  }
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
  .image-placeholder {
    background: white;
  }
  
  .image-placeholder.permanent {
    background: #2d3748;
    border-color: #4a5568;
  }
  
  .image-placeholder span {
    color: #a0aec0;
  }
  
  .loading-spinner {
    border-color: #4a5568;
    border-top-color: #63b3ed;
  }

  body.page-loaded .loading-spinner {
    border-color: rgba(160, 174, 192, 0.15);
    border-top-color: rgba(99, 179, 237, 0.6);
    border-left-color: rgba(99, 179, 237, 0.15);
  }
  
  .lazy-loading-indicator {
    color: #a0aec0;
  }
}
