/******************************************************************
  Final Optimizations for Professional E-commerce Presentation
  Ensuring Perfect Consistency and Performance
******************************************************************/

/*----------------------------------------
  Global Optimizations
----------------------------------------*/
* {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
  scroll-behavior: smooth;
}

/* Ensure consistent font loading */
@font-face {
  font-family: 'Cairo';
  font-display: swap;
  src: url('https://fonts.googleapis.com/css2?family=Cairo:wght@200;300;400;600;700;900&display=swap');
}

/*----------------------------------------
  Enhanced Loading States
----------------------------------------*/
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.loading-overlay.show {
  opacity: 1;
  visibility: visible;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/*----------------------------------------
  Enhanced Button States
----------------------------------------*/
.btn-modern {
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.btn-modern:active {
  transform: scale(0.95);
}

.btn-modern.loading {
  pointer-events: none;
  opacity: 0.7;
}

.btn-modern.loading:before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/*----------------------------------------
  Enhanced Form Controls
----------------------------------------*/
.form-control, .form-select {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 15px;
  font-size: 0.95rem;
  transition: all 0.3s ease;
  background: var(--background-white);
}

.form-control:focus, .form-select:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
  outline: none;
}

.form-control::placeholder {
  color: var(--text-light);
  opacity: 0.7;
}

/*----------------------------------------
  Enhanced Card Hover Effects
----------------------------------------*/
.product-card, .categories__item, .latest-product__item {
  transform: translateZ(0);
  backface-visibility: hidden;
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.product-card:hover, .categories__item:hover, .latest-product__item:hover {
  transform: translateY(-8px) scale(1.02);
}

/*----------------------------------------
  Enhanced Image Loading
----------------------------------------*/
img {
  loading: lazy;
  transition: opacity 0.3s ease;
}

img:not([src]) {
  opacity: 0;
}

img[src] {
  opacity: 1;
}

/*----------------------------------------
  Enhanced Accessibility
----------------------------------------*/
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus indicators */
a:focus, button:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/*----------------------------------------
  Enhanced Performance
----------------------------------------*/
/* GPU acceleration for smooth animations */
.hero-section, .product-card, .categories__item, .cart-table {
  transform: translateZ(0);
  will-change: transform;
}

/*----------------------------------------
  Enhanced Print Styles
----------------------------------------*/
@media print {
  .header, .footer, .hero-section, .btn-modern {
    display: none !important;
  }
  
  .product-card, .cart-table {
    break-inside: avoid;
    box-shadow: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.4;
  }
}

/*----------------------------------------
  Enhanced Dark Mode Support
----------------------------------------*/
@media (prefers-color-scheme: dark) {
  :root {
    --background-light: #1a1a1a;
    --background-white: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #404040;
  }
}

/*----------------------------------------
  Enhanced Reduced Motion
----------------------------------------*/
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/*----------------------------------------
  Enhanced High Contrast
----------------------------------------*/
@media (prefers-contrast: high) {
  :root {
    --accent-color: #0066cc;
    --primary-color: #000000;
    --text-secondary: #333333;
  }
  
  .btn-modern {
    border: 2px solid currentColor;
  }
}

/*----------------------------------------
  Cross-browser Compatibility
----------------------------------------*/
/* Firefox specific fixes */
@-moz-document url-prefix() {
  .product-card {
    scrollbar-width: thin;
  }
}

/* Safari specific fixes */
@supports (-webkit-appearance: none) {
  .quantity-selector input {
    -webkit-appearance: textfield;
  }
  
  .quantity-selector input::-webkit-inner-spin-button,
  .quantity-selector input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}

/* Edge specific fixes */
@supports (-ms-ime-align: auto) {
  .hero-section {
    -ms-overflow-style: scrollbar;
  }
}

/*----------------------------------------
  Enhanced Mobile Optimizations
----------------------------------------*/
/* Touch-friendly targets */
@media (hover: none) and (pointer: coarse) {
  .btn-modern, .product-card__action-btn, .quantity-selector button {
    min-height: 44px;
    min-width: 44px;
  }
  
  .header__menu ul li a {
    padding: 15px 0;
  }
}

/*----------------------------------------
  Enhanced SEO & Meta
----------------------------------------*/
/* Structured data hints */
.product-card, .categories__item {
  itemtype: "https://schema.org/Product";
}

.product-card__title {
  itemprop: "name";
}

.product-card__price {
  itemprop: "offers";
  itemtype: "https://schema.org/Offer";
}

/*----------------------------------------
  Enhanced Error States
----------------------------------------*/
.error-message {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
  padding: 15px 20px;
  border-radius: 8px;
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.error-message:before {
  content: '⚠️';
  font-size: 1.2rem;
}

.success-message {
  background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
  color: white;
  padding: 15px 20px;
  border-radius: 8px;
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.success-message:before {
  content: '✅';
  font-size: 1.2rem;
}

/*----------------------------------------
  Enhanced Micro-interactions
----------------------------------------*/
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  transform: scale(0);
  animation: ripple 0.6s ease-out;
  pointer-events: none;
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/*----------------------------------------
  Enhanced Performance Monitoring
----------------------------------------*/
.performance-indicator {
  position: fixed;
  bottom: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: monospace;
  z-index: 10000;
  display: none; /* Hidden in production */
}

/*----------------------------------------
  Final Polish
----------------------------------------*/
/* Ensure smooth scrolling on all browsers */
html {
  scroll-behavior: smooth;
}

/* Better text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Better image rendering */
img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* Prevent text selection on interactive elements */
.btn-modern, .product-card__action-btn {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--background-light);
}

::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dark);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--accent-color) var(--background-light);
}