/* ========================================
   MASTER SPLINTER - PERFORMANCE OPTIMIZATION
   CSS Performance & Loading Optimizations
   ======================================== */

/* ========================================
   CRITICAL CSS - ABOVE THE FOLD
   ======================================== */

/* Optimize font loading - fonts loaded via Google Fonts in HTML */

/* ========================================
   WILL-CHANGE OPTIMIZATION
   ======================================== */

/* Optimize animations and transitions */
.service-card,
.product-card,
.button,
.nav-link {
  will-change: transform;
}

.service-card:hover,
.product-card:hover,
.button:hover {
  will-change: auto;
}

/* ========================================
   CONTAIN PROPERTY
   ======================================== */

/* Improve rendering performance */
.service-card,
.product-card,
.testimonial-card,
.process-step {
  contain: layout style paint;
}

.service-modal,
.cart-sidebar,
.checkout-modal {
  contain: layout;
}

/* ========================================
   CONTENT-VISIBILITY
   ======================================== */

/* Lazy render off-screen content */
.section {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

.service-card,
.product-card {
  content-visibility: auto;
  contain-intrinsic-size: 0 400px;
}

/* ========================================
   HARDWARE ACCELERATION
   ======================================== */

/* Force GPU acceleration for smooth animations */
.service-card,
.product-card,
.button,
.modal,
.floating-whatsapp {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000px;
  -webkit-perspective: 1000px;
}

/* ========================================
   IMAGE OPTIMIZATION
   ======================================== */

/* Optimize image rendering */
img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: optimizeQuality;
}

/* Lazy loading hint */
img[loading="lazy"] {
  content-visibility: auto;
}

/* ========================================
   REDUCE PAINT AREAS
   ======================================== */

/* Isolate layers to reduce repaints */
.site-header,
.floating-whatsapp,
.live-chat-widget,
.modal-overlay {
  isolation: isolate;
}

/* ========================================
   OPTIMIZE SHADOWS
   ======================================== */

/* Use optimized shadows */
.service-card,
.product-card {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.3s ease;
}

.service-card:hover,
.product-card:hover {
  box-shadow: 0 8px 24px rgba(130, 207, 226, 0.3);
}

/* ========================================
   REDUCE LAYOUT SHIFTS
   ======================================== */

/* Prevent layout shifts */
.brand__logo {
  width: 50px;
  height: 50px;
  aspect-ratio: 1 / 1;
}

.service-card__icon {
  width: 60px;
  height: 60px;
  aspect-ratio: 1 / 1;
}

.product-card__image {
  aspect-ratio: 16 / 9;
  background: #f5f5f5;
}

/* ========================================
   OPTIMIZE ANIMATIONS
   ======================================== */

/* Use transform instead of position changes */
@keyframes slideIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.animate-in {
  animation: slideIn 0.5s ease-out;
}

/* ========================================
   REDUCE REFLOWS
   ======================================== */

/* Batch DOM reads and writes */
.services-grid,
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
  /* Prevent reflow on content changes */
  min-height: 400px;
}

/* ========================================
   OPTIMIZE FILTERS
   ======================================== */

/* Use efficient filters */
.modal-overlay {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Fallback for better performance */
@supports not (backdrop-filter: blur(8px)) {
  .modal-overlay {
    background: rgba(0, 0, 0, 0.85);
  }
}

/* ========================================
   REDUCE COMPOSITE LAYERS
   ======================================== */

/* Optimize composite layers */
.button,
.nav-link {
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
}

/* ========================================
   OPTIMIZE SCROLL PERFORMANCE
   ======================================== */

/* Smooth scrolling optimization */
html {
  scroll-behavior: smooth;
}

/* Optimize scroll containers */
.cart-sidebar__items,
.invoice-content,
.shop-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ========================================
   REDUCE JAVASCRIPT LAYOUT THRASHING
   ======================================== */

/* Use CSS for animations instead of JS */
.fade-in {
  animation: fadeIn 0.5s ease;
}

.slide-up {
  animation: slideUp 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ========================================
   OPTIMIZE FONT LOADING
   ======================================== */

/* Prevent FOIT (Flash of Invisible Text) */
body {
  font-display: swap;
}

/* System font stack fallback */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 
               "Helvetica Neue", Arial, "Noto Sans", sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
               "Noto Color Emoji";
}

/* ========================================
   REDUCE UNUSED CSS
   ======================================== */

/* Remove unused pseudo-elements */
.service-card::before,
.product-card::before {
  content: none;
}

/* ========================================
   OPTIMIZE MEDIA QUERIES
   ======================================== */

/* Use efficient media queries */
@media (max-width: 768px) {
  /* Reduce complexity on mobile */
  .service-card,
  .product-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  /* Disable expensive effects on mobile */
  .service-card:hover,
  .product-card:hover {
    transform: none;
  }
}

/* ========================================
   OPTIMIZE GRID LAYOUTS
   ======================================== */

/* Use efficient grid layouts */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: clamp(1rem, 3vw, 2rem);
}

/* ========================================
   REDUCE PAINT COMPLEXITY
   ======================================== */

/* Simplify gradients on mobile */
@media (max-width: 768px) {
  .hero,
  .newsletter-section {
    background: var(--color-primary);
  }
}

/* ========================================
   OPTIMIZE TRANSITIONS
   ======================================== */

/* Use efficient transition properties */
.button,
.service-card,
.product-card {
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Avoid transitioning expensive properties */
.avoid-transition {
  transition: none;
}

/* ========================================
   LOADING STATES
   ======================================== */

/* Skeleton loading states */
.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ========================================
   INTERSECTION OBSERVER OPTIMIZATION
   ======================================== */

/* Optimize visibility detection */
.lazy-load {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.lazy-load.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ========================================
   REDUCE MEMORY USAGE
   ======================================== */

/* Optimize large lists */
.virtual-scroll {
  overflow-y: auto;
  height: 500px;
}

/* ========================================
   OPTIMIZE FLEXBOX
   ======================================== */

/* Use efficient flexbox properties */
.flex-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.flex-item {
  flex: 1 1 auto;
  min-width: 0; /* Prevent flex item overflow */
}

/* ========================================
   REDUCE SPECIFICITY
   ======================================== */

/* Use low-specificity selectors */
.card { /* Instead of .section .container .card */
  background: var(--color-surface);
}

/* ========================================
   OPTIMIZE Z-INDEX
   ======================================== */

/* Use consistent z-index scale */
:root {
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-tooltip: 700;
}

.site-header {
  z-index: var(--z-sticky);
}

.modal-overlay {
  z-index: var(--z-modal-backdrop);
}

.service-modal {
  z-index: var(--z-modal);
}

/* ========================================
   PRELOAD CRITICAL RESOURCES
   ======================================== */

/* Hint browser to preload critical resources */
/* Add to HTML: <link rel="preload" as="style" href="css/styles.css"> */

/* ========================================
   REDUCE RENDER BLOCKING
   ======================================== */

/* Use CSS containment */
.independent-component {
  contain: layout style paint;
}

/* ========================================
   OPTIMIZE CUSTOM PROPERTIES
   ======================================== */

/* Cache computed values */
.cached-value {
  --computed-width: calc(100% - 2rem);
  width: var(--computed-width);
}

/* ========================================
   MOBILE-SPECIFIC OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
  /* Reduce animation complexity */
  * {
    animation-duration: 0.3s !important;
  }
  
  /* Simplify shadows */
  .service-card,
  .product-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
  
  /* Disable expensive effects */
  .backdrop-blur {
    backdrop-filter: none;
    background: rgba(0, 0, 0, 0.9);
  }
}

/* ========================================
   PERFORMANCE MONITORING
   ======================================== */

/* Performance monitoring is handled via JavaScript Performance API */
