/* ===================================================================
   TAIBJEE & BHALLA ADVOCATES LLP - PERFORMANCE OPTIMIZATIONS
   Fast loading indicators, optimized animations, and performance CSS
   ================================================================= */

/* ===================================================================
   LOADING STATES & ANIMATIONS
   Optimized for performance and smooth transitions
   ================================================================= */

/* Button Loading State - Optimized */
.btn.loading,
.button.loading {
  position: relative;
  pointer-events: none;
  color: transparent !important;
  will-change: color;
}

.btn.loading::after,
.button.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translate3d(-50%, -50%, 0);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  will-change: transform, border-color;
  backface-visibility: hidden;
  animation: spin-fast 0.6s linear infinite;
}

/* Optimized Pulse Loading Effect */
.loading-pulse {
  will-change: opacity;
  animation: pulse-loading 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  backface-visibility: hidden;
}

@keyframes pulse-loading {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Optimized Skeleton Loading for Content */
.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 0%,
    #e0e0e0 20%,
    #e0e0e0 40%,
    #f0f0f0 60%,
    #f0f0f0 100%
  );
  background-size: 200% 100%;
  will-change: background-position;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
  backface-visibility: hidden;
  transform: translateZ(0);
}

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

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-heading {
  height: 2rem;
  width: 60%;
  margin-bottom: 1rem;
}

.skeleton-image {
  height: 200px;
  width: 100%;
}

/* ===================================================================
   PERFORMANCE OPTIMIZATIONS
   ================================================================= */

/* Optimize Will-Change for Animations */
.will-animate {
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.will-animate-transform {
  will-change: transform;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.will-animate-opacity {
  will-change: opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
  will-change: opacity;
}

/* Remove will-change after animation completes */
.animation-complete {
  will-change: auto;
}

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

/* Optimize Image Rendering */
img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

img.smooth {
  image-rendering: auto;
}

/* Lazy Loading Placeholder */
img[loading="lazy"] {
  background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
}

/* Reduce Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .loading-spinner,
  .skeleton {
    animation: none !important;
  }
}

/* ===================================================================
   CONTENT VISIBILITY OPTIMIZATIONS
   ================================================================= */

/* Optimize rendering for off-screen content */
.optimize-rendering {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

/* ===================================================================
   SMOOTH SCROLLING OPTIMIZATION
   ================================================================= */

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Scroll Padding for Fixed Headers */
html {
  scroll-padding-top: 80px;
}

/* ===================================================================
   FONT LOADING OPTIMIZATION
   ================================================================= */

/* Prevent Flash of Invisible Text (FOIT) */
.font-loading {
  font-display: swap;
}

/* ===================================================================
   PROGRESSIVE ENHANCEMENT
   ================================================================= */

/* Hide content until JavaScript loads */
.js-only {
  display: none;
}

.js-loaded .js-only {
  display: block;
}

/* No-JS Fallback */
.no-js .js-required {
  display: none;
}

/* ===================================================================
   LOADING STATES FOR FORMS
   ================================================================= */

form.submitting {
  opacity: 0.6;
  pointer-events: none;
}

form.submitting button[type="submit"] {
  position: relative;
  color: transparent;
}

form.submitting button[type="submit"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin-fast 0.6s linear infinite;
}

/* ===================================================================
   PAGE TRANSITION OPTIMIZATION
   ================================================================= */

.page-transition {
  transition: opacity 0.3s ease;
}

.page-transition.fade-out {
  opacity: 0;
}

/* ===================================================================
   CRITICAL CSS LOADING INDICATOR
   ================================================================= */

/* Show minimal loading indicator until CSS loads */
body.show-loader::before {
  content: '';
  position: fixed;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  transform: translate(-50%, -50%);
  border: 3px solid #f3f3f3;
  border-top: 3px solid #1e3a5f;
  border-radius: 50%;
  animation: spin-fast 0.8s linear infinite;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

body.loaded::before {
  opacity: 0;
  display: none;
}

/* ===================================================================
   OPTIMIZED SEARCH LOADING
   ================================================================= */

.search-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  min-height: 200px;
}

.search-loading .loading-spinner {
  margin-bottom: 1rem;
}

.search-loading-text {
  color: #6b7280;
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* ===================================================================
   NETWORK ERROR STATES
   ================================================================= */

.error-message {
  padding: 1rem;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 0.5rem;
  color: #991b1b;
  font-size: 0.875rem;
  margin: 1rem 0;
}

.retry-button {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: #1e3a5f;
  color: white;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.2s ease;
}

.retry-button:hover {
  background: #0f1f3d;
}

/* ===================================================================
   PRINT OPTIMIZATION
   ================================================================= */

@media print {
  .loading-overlay,
  .loading-spinner,
  .skeleton {
    display: none !important;
  }
}

/* ===================================================================
   MOBILE OPTIMIZATION
   ================================================================= */

@media (max-width: 768px) {
  .loading-spinner {
    width: 32px;
    height: 32px;
    border-width: 2px;
  }
  
  .loading-text {
    font-size: 0.75rem;
  }
}
