/**
 * Products Component Styles
 * Product grid, cards, featured section, filters, and related components
 */

/* ============================================================================
   FEATURED SECTION
   ============================================================================ */

.featured-section {
  padding: var(--spacing-lg) 0;
  margin-bottom: var(--spacing-md);
}

.featured-section .section-title {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

.featured-section .section-title::before {
  content: '⭐';
  font-size: var(--font-size-xl);
}

.featured-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

@media (max-width: 768px) {
  .featured-items-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   ATTRIBUTES LEGEND
   ============================================================================ */

.attributes-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  padding: var(--spacing-lg);
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  margin-bottom: var(--spacing-lg);
}

.attributes-legend-title {
  width: 100%;
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.attributes-legend-title .material-icons {
  font-size: 20px;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-md);
  background: var(--background-color);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
}

.legend-item .material-icons {
  font-size: 18px;
}

.legend-item.vegetarian .material-icons {
  color: #4caf50;
}

.legend-item.vegan .material-icons {
  color: #8bc34a;
}

.legend-item.gluten-free .material-icons {
  color: #ff9800;
}

.legend-item.spicy .material-icons {
  color: #f44336;
}

.legend-item.seafood .material-icons {
  color: #2196f3;
}

/* ============================================================================
   FILTERS
   ============================================================================ */

.filters-section {
  padding: var(--spacing-md) 0;
}

.filters-container {
  display: flex;
  gap: var(--spacing-sm);
  overflow-x: auto;
  padding: var(--spacing-xs) 0;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  min-height: 44px;
  border: 1px solid var(--divider-color);
  border-radius: var(--radius-xl);
  background: var(--surface-color);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.filter-chip:hover {
  border-color: var(--primary-color);
  background: var(--primary-alpha-10);
}

.filter-chip.selected {
  background: var(--primary-color);
  color: var(--primary-contrast);
  border-color: var(--primary-color);
}

.filter-chip .material-icons {
  font-size: 18px;
}

/* ============================================================================
   EMPTY STATES (UX Improvement)
   ============================================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xxl) var(--spacing-lg);
  text-align: center;
  min-height: 300px;
}

.empty-state .material-icons {
  font-size: 72px;
  color: var(--text-disabled);
  margin-bottom: var(--spacing-lg);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
}

.empty-state-message {
  font-size: var(--font-size-base);
  color: var(--text-secondary);
  max-width: 400px;
  margin-bottom: var(--spacing-lg);
  line-height: 1.6;
}

.empty-state .btn {
  margin-top: var(--spacing-md);
}

/* ============================================================================
   SKELETON LOADERS (UX Improvement)
   ============================================================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--divider-color) 0%,
    #f0f0f0 50%,
    var(--divider-color) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-product-card {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  animation: fadeIn 0.3s ease-in;
}

.skeleton-product-image {
  width: 100%;
  height: 200px;
  background: var(--divider-color);
}

.skeleton-product-content {
  padding: var(--spacing-md);
}

.skeleton-text {
  height: 16px;
  margin-bottom: var(--spacing-sm);
  border-radius: var(--radius-sm);
}

.skeleton-text.title {
  width: 80%;
  height: 20px;
  margin-bottom: var(--spacing-md);
}

.skeleton-text.subtitle {
  width: 60%;
}

.skeleton-text.price {
  width: 40%;
  height: 18px;
  margin-top: var(--spacing-md);
}

/* ============================================================================
   SECTIONS
   ============================================================================ */

.section {
  padding: var(--spacing-xl) 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
}

.section-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.view-toggle {
  display: flex;
  gap: var(--spacing-xs);
}

.view-button {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  border: 1px solid var(--divider-color);
}

.view-button:hover {
  background: var(--primary-alpha-10);
  border-color: var(--primary-color);
}

.view-button.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.view-button.active .material-icons {
  color: var(--primary-contrast);
}

.view-button .material-icons {
  font-size: 20px;
  color: var(--text-secondary);
}

/* ============================================================================
   PRODUCTS GRID & CARDS
   ============================================================================ */

.products-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-lg);
}

@media (min-width: 640px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .products-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.product-card {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
  animation: fadeInUp 0.4s ease-out;
  display: flex;
  flex-direction: column;
}

/* Staggered animation for cards (set via JS or nth-child) */
.product-card:nth-child(1) { animation-delay: 0.05s; }
.product-card:nth-child(2) { animation-delay: 0.1s; }
.product-card:nth-child(3) { animation-delay: 0.15s; }
.product-card:nth-child(4) { animation-delay: 0.2s; }
.product-card:nth-child(5) { animation-delay: 0.25s; }
.product-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.product-card:hover {
  box-shadow: var(--shadow-4);
  transform: translateY(-6px);
}

.product-card:active {
  transform: translateY(-3px);
  box-shadow: var(--shadow-3);
}

/* Featured indicator */
.product-card.featured::before {
  content: '⭐';
  position: absolute;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  z-index: 2;
  font-size: 24px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  animation: featured-pulse 2s ease-in-out infinite;
}

@keyframes featured-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Out of stock overlay */
.product-card.out-of-stock::after {
  content: attr(data-unavailable-text);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: var(--font-size-lg);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  z-index: 2;
}

.product-card.out-of-stock {
  opacity: 0.7;
  cursor: not-allowed;
}

.product-card.out-of-stock:hover {
  transform: none;
  box-shadow: var(--shadow-1);
}

/* Image container with overlay gradient */
.product-image-container {
  position: relative;
  width: 100%;
  height: 200px;
  overflow: hidden;
  background: var(--divider-color);
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}

/* Gradient overlay for better text readability on badges */
.product-image-container::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.4), transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.product-card:hover .product-image-container::after {
  opacity: 1;
}

.product-card:hover .product-image {
  transform: scale(1.08);
}

/* Lazy loading image style */
.product-image[data-src] {
  opacity: 0.5;
  filter: blur(10px);
}

.product-image.loaded {
  opacity: 1;
  filter: blur(0);
  transition: opacity var(--transition-slow), filter var(--transition-slow);
}

.product-body {
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  flex: 1;
}

.product-name {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
  color: var(--text-primary);
  line-height: 1.3;
}

.product-description {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  margin-bottom: var(--spacing-md);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  margin-top: auto;
}

.product-price {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--primary-color);
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--primary-alpha-10);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.product-card:hover .product-price {
  background: var(--primary-alpha-20);
  transform: scale(1.05);
}

/* Dietary badges on image (positioned at top left) */
.dietary-badges {
  position: absolute;
  top: var(--spacing-sm);
  left: var(--spacing-sm);
  display: flex;
  gap: var(--spacing-xs);
  flex-wrap: wrap;
  z-index: 2;
  max-width: calc(100% - var(--spacing-xl));
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(4px);
  transition: transform var(--transition-fast);
}

.badge:hover {
  transform: scale(1.1);
}

.badge .material-icons {
  font-size: 14px;
}

.badge.vegan {
  background: rgba(200, 230, 201, 0.95);
  color: #2e7d32;
  border: 1px solid #4caf50;
}

.badge.vegetarian {
  background: rgba(255, 249, 196, 0.95);
  color: #f57f17;
  border: 1px solid #fbc02d;
}

.badge.gluten-free {
  background: rgba(255, 204, 188, 0.95);
  color: #d84315;
  border: 1px solid #ff7043;
}

.badge.spicy {
  background: rgba(255, 204, 188, 0.95);
  color: #d32f2f;
  border: 1px solid #f44336;
}

/* Dark theme badge adjustments */
.dark-theme .badge {
  background: rgba(30, 30, 30, 0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.dark-theme .badge.vegan {
  background: rgba(46, 125, 50, 0.9);
  color: #c8e6c9;
}

.dark-theme .badge.vegetarian {
  background: rgba(245, 127, 23, 0.9);
  color: #fff9c4;
}

.dark-theme .badge.gluten-free {
  background: rgba(216, 67, 21, 0.9);
  color: #ffccbc;
}

.dark-theme .badge.spicy {
  background: rgba(211, 47, 47, 0.9);
  color: #ffccbc;
}

/* List view */
.products-grid.list-view {
  grid-template-columns: 1fr;
}

.products-grid.list-view .product-card {
  flex-direction: row;
}

.products-grid.list-view .product-image-container {
  width: 200px;
  height: 150px;
  flex-shrink: 0;
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 767px) {
  .section-title {
    font-size: var(--font-size-xl);
  }

  .product-name {
    font-size: var(--font-size-base);
  }

  .product-price {
    font-size: var(--font-size-xl);
  }
}

/* ============================================================================
   DARK THEME ADJUSTMENTS
   ============================================================================ */

.dark-theme .skeleton {
  background: linear-gradient(
    90deg,
    #2a2a2a 0%,
    #333333 50%,
    #2a2a2a 100%
  );
  background-size: 200% 100%;
}

.dark-theme .filter-chip:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ============================================================================
   RTL SUPPORT
   ============================================================================ */

[dir="rtl"] .filter-chip {
  flex-direction: row-reverse;
}

/* Quick Add Button */
.quick-add-btn {
  transition: all var(--transition-normal);
}

.quick-add-btn:hover {
  transform: scale(1.1);
  background: var(--primary-dark) !important;
}

.quick-add-btn:active {
  transform: scale(0.95);
}

.quick-add-btn.success {
  background: var(--success-color) !important;
  transform: scale(1.1);
}

/* ============================================================================
   FORCED COLORS (Windows High Contrast Mode)
   ============================================================================ */

@media (forced-colors: active) {
  .product-card {
    border: 1px solid ButtonText;
  }

  .badge {
    border: 1px solid ButtonText;
    background: ButtonFace;
    color: ButtonText;
    forced-color-adjust: none;
  }

  .filter-chip {
    border: 1px solid ButtonText;
  }

  .filter-chip.selected {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }

  .product-card.out-of-stock::after {
    background: Canvas;
    color: GrayText;
    border: 2px solid GrayText;
  }

  .view-button.active {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }
}
