/* ====================================
   Performance Optimization
   CSS-based Performance Improvements
   ==================================== */

/* ====================
   Font Optimization
   ==================== */

/* Use system font stack for faster loading */
:root {
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  --font-mono: 'Monaco', 'Courier New', monospace;
}

/* Font-display: swap for faster text rendering */
@font-face {
  font-family: 'Inter';
  font-display: swap;
  src: local('Inter'), url('/public/fonts/inter.woff2') format('woff2');
}

/* ====================
   Image Optimization
   ==================== */

/* Lazy loading images */
img[loading="lazy"] {
  background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: imageSkeleton 1.5s infinite;
}

@keyframes imageSkeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Responsive images */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Image container aspect ratio */
.image-container {
  position: relative;
  overflow: hidden;
  background-color: #1a1a1a;
}

.image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ====================
   CSS Containment
   ==================== */

/* Contain layout calculations for better performance */
.card, [class*="card"] {
  contain: layout style paint;
}

/* Video containers */
.video-player, video {
  contain: layout style paint;
}

/* Feed items */
.feed-item, [class*="item"] {
  contain: layout style paint;
}

/* ====================
   Will-Change Property
   ==================== */

/* Use sparingly for animated elements */
.animated-button {
  will-change: transform, opacity;
}

.page-transition {
  will-change: opacity;
}

/* Clear will-change after animation */
.animated-button:not(:hover),
.page-transition {
  will-change: auto;
}

/* ====================
   Transform Performance
   ==================== */

/* Use transform instead of top/left for animations */
.slide-element {
  transform: translateX(0);
}

.fade-element {
  opacity: 1;
}

/* GPU acceleration */
.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* ====================
   CSS Grid & Flexbox Optimization
   ==================== */

/* Auto-fit for better rendering */
.grid-responsive {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

/* CSS Grid containers */
.products-grid, .feed-grid, .dashboard-grid {
  contain: layout;
}

/* ====================
   Color Optimization
   ==================== */

/* Use CSS variables for efficient color changes */
:root {
  --primary: #6366f1;
  --secondary: #ec4899;
  --background: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
}

/* Efficient color transitions */
a, button, .interactive {
  color: var(--primary);
  transition: color 150ms ease-out;
}

/* ====================
   Shadow Optimization
   ==================== */

/* Use simpler, optimized shadows */
:root {
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* Apply shadows efficiently */
.card {
  box-shadow: var(--shadow-sm);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

/* ====================
   Animation Performance
   ==================== */

/* Use shorter animations on mobile */
@media (max-width: 768px) {
  :root {
    --transition-duration: 150ms;
  }
  
  * {
    animation-duration: 150ms !important;
  }
}

/* Disable animations for low-power devices */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ====================
   Scroll Performance
   ==================== */

/* Optimize scroll performance */
.scroll-container {
  will-change: scroll-position;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Passive scroll listeners */
.scrollable {
  touch-action: pan-y;
}

/* ====================
   Paint Area Optimization
   ==================== */

/* Reduce paint areas */
.static-background {
  background-attachment: fixed;
  will-change: auto;
}

/* Optimize gradients */
:root {
  --gradient-primary: linear-gradient(135deg, var(--primary), var(--secondary));
  --gradient-background: linear-gradient(180deg, var(--background), transparent);
}

/* ====================
   Display Optimization
   ==================== */

/* Use display:none for hidden elements */
.hidden {
  display: none !important;
}

/* Use visibility:hidden for space-preserving hidden */
.invisible {
  visibility: hidden;
}

/* Efficient visibility toggle */
.page {
  display: none;
}

.page.active {
  display: block;
}

/* ====================
   CSS Efficiency
   ==================== */

/* Reusable utility classes */
.flex {
  display: flex;
}

.grid {
  display: grid;
}

.block {
  display: block;
}

.inline {
  display: inline;
}

/* ====================
   Memory Optimization
   ==================== */

/* Efficient borders */
.border {
  border: 1px solid var(--border);
}

/* Efficient padding/margin */
.p-4 { padding: 1rem; }
.m-4 { margin: 1rem; }
.gap-4 { gap: 1rem; }

/* ====================
   Z-Index Optimization
   ==================== */

:root {
  --z-dropdown: 100;
  --z-modal: 1000;
  --z-notification: 1001;
  --z-tooltip: 1002;
}

.dropdown { z-index: var(--z-dropdown); }
.modal { z-index: var(--z-modal); }
.notification { z-index: var(--z-notification); }
.tooltip { z-index: var(--z-tooltip); }

/* ====================
   Content Visibility
   ==================== */

/* Progressive rendering */
@supports (content-visibility: auto) {
  .card, .item, [class*="card"] {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
  }
}

/* ====================
   Layout Shift Prevention
   ==================== */

/* Reserve space for dynamic content */
.video-player {
  aspect-ratio: 16 / 9;
}

.image-container {
  aspect-ratio: auto;
}

/* Minimum size to prevent layout shift */
.button {
  min-height: 44px;
  min-width: 44px;
}

/* ====================
   Resource Hints
   ==================== */

/* Preload critical resources */
/* Added in HTML: <link rel="preload" as="style" href="..." /> */

/* Prefetch non-critical resources */
/* Added in HTML: <link rel="prefetch" href="..." /> */

/* DNS prefetch */
/* Added in HTML: <link rel="dns-prefetch" href="..." /> */

/* ====================
   Rendering Optimization
   ==================== */

/* Force hardware acceleration */
.hardware-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Optimize text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ====================
   CSS Compression Tips
   ==================== */

/* Short utility classes */
.w-100 { width: 100%; }
.h-100 { height: 100%; }
.mx-auto { margin-left: auto; margin-right: auto; }
.text-center { text-align: center; }
.rounded { border-radius: 4px; }

/* ====================
   Dark Mode Optimization
   ==================== */

/* Efficient dark mode without media query overhead */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
  
  body {
    background-color: var(--background);
    color: #ffffff;
  }
}

/* ====================
   Network Optimization
   ==================== */

/* Reduce CSS file size with selectors */
:is(h1, h2, h3, h4, h5, h6) {
  margin: 0;
  font-weight: 700;
}

:is(button, input, select, textarea) {
  font-family: inherit;
  font-size: 1rem;
}

/* ====================
   Critical CSS
   ==================== */

/* Inline critical CSS above the fold */
/* Note: This should be generated at build time */

/* Above-the-fold content */
.hero, .header, .feed-header {
  will-change: auto;
  contain: layout;
}

/* ====================
   Performance Metrics
   ====================

   Optimization targets:
   - First Contentful Paint (FCP): < 1.8s
   - Largest Contentful Paint (LCP): < 2.5s
   - Cumulative Layout Shift (CLS): < 0.1
   - First Input Delay (FID): < 100ms
   - Time to Interactive (TTI): < 3.8s

   Measured with Google Lighthouse
*/

/* ====================
   File Size Reduction
   ==================== */

/* Remove unused CSS at build time */
/* Use PurgeCSS or similar tools */

/* Minify CSS in production */
/* Use cssnano or equivalent */

/* ====================
   Testing Classes
   ==================== */

/* Performance testing classes */
.perf-test {
  /* Minimal styling for performance testing */
}

/* Enable profiling */
.performance-monitor {
  display: grid;
  font-size: 12px;
  font-family: monospace;
  position: fixed;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  color: #00ff00;
  padding: 10px;
  z-index: 10000;
  max-width: 300px;
  max-height: 200px;
  overflow: auto;
}
