/**
 * Enhanced Mobile Optimizations CSS
 * This file contains improved mobile-specific optimizations to address PageSpeed Insights issues:
 * - Prevent layout shifts by setting explicit dimensions
 * - Optimize for mobile-first approach
 * - Reduce animation complexity
 * - Optimize image display
 * - Fix Cumulative Layout Shift (CLS) issues
 */

/* Set explicit dimensions for images to prevent layout shifts */
img {
  max-width: 100%;
  height: auto;
  display: block; /* Prevent inline image spacing issues */
}

/* Add default aspect ratios for common image types */
.app-screenshot {
  aspect-ratio: 9 / 16;
  width: 100%;
  height: auto;
  object-fit: cover;
  display: block;
  max-width: 100%;
  z-index: 1;
  position: relative;
}

.portfolio-item img {
  aspect-ratio: 9 / 16;
  display: block;
  max-width: 100%;
}

.iphone-frame {
  aspect-ratio: 9 / 19.5;
  position: relative;
  overflow: hidden;
}

/* Fix for the hero section layout shifts */
.hero {
  min-height: 600px; /* Reserve space for content */
  contain: layout paint; /* Improve rendering performance */
}

.hero-content {
  min-height: 350px; /* Reserve space for content */
  contain: layout paint;
}

/* Fix for the AppSolutions logo/text with gradient-border (LCP element) */
.navbar-logo {
  height: 40px; /* Set explicit height */
  contain: layout paint;
}

.navbar-logo span.gradient-border {
  font-size: 1.5rem;
  font-weight: bold;
  will-change: transform; /* Optimize for compositing */
  transform: translateZ(0); /* Force GPU acceleration */
}

/* Optimize hero section for mobile */
@media (max-width: 768px) {
  .hero {
    padding: 6rem 0 3rem;
    background: var(--primary-color) !important; /* Simplified background */
    min-height: 500px; /* Adjusted for mobile */
  }
  
  .hero h1 {
    font-size: 2.2rem !important;
    line-height: 1.3;
    margin-bottom: 1rem;
  }
  
  .hero p {
    font-size: 1.1rem !important;
    margin-bottom: 1.5rem;
  }
  
  .hero-content {
    min-height: 300px; /* Adjusted for mobile */
  }
  
  /* Optimize CTA buttons for mobile */
  .cta-buttons {
    flex-direction: column;
    gap: 1rem;
  }
  
  .cta-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
  }
  
  /* Disable complex animations on mobile */
  .loading-animation,
  .floating,
  .pulse-animation,
  [class*="animate-"] {
    animation: none !important;
    transform: none !important;
    transition: none !important;
  }
  
  /* Optimize navbar for mobile */
  .navbar-container {
    padding: 10px 1rem;
    height: 60px; /* Set explicit height */
  }
  
  .navbar-logo span {
    font-size: 1.3rem;
  }
  
  /* Hide hamburger menu on mobile */
  .hamburger {
    display: none !important;
  }
  
  /* Hide the nav menu completely on mobile since we have bottom navigation */
  .nav-menu {
    display: none !important;
  }
  
  /* Optimize service cards for mobile */
  .service-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 0 0.5rem;
  }
  
  .service-card {
    padding: 1.8rem 1.5rem;
    transform: none !important;
    height: auto; /* Allow natural height */
    min-height: 200px; /* But set minimum to prevent shifts */
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    border-left: 4px solid var(--primary-color);
    transition: box-shadow 0.3s ease;
  }
  
  .service-card:hover {
    transform: none !important;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  }
  
  .service-card h3 {
    font-size: 1.3rem;
    margin-bottom: 0.8rem;
    color: #333;
  }
  
  .service-card p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #555;
    margin-bottom: 1rem;
  }
  
  /* Service card tags */
  .service-card-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: auto;
  }
  
  .service-tag {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    background-color: rgba(44, 107, 237, 0.1);
    color: var(--primary-color);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
  }
  
  .service-icon {
    margin-bottom: 1.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #5a8eff);
    box-shadow: 0 4px 10px rgba(44, 107, 237, 0.25);
  }
  
  .service-icon i {
    font-size: 1.5rem;
    color: white;
  }
  
  /* Optimize portfolio section for mobile */
  .portfolio {
    padding: 4rem 0 5rem;
    background: linear-gradient(to bottom, #f9f9f9, #ffffff);
  }
  
  .portfolio-slider-container {
    padding: 0;
    height: 550px; /* Set explicit height */
    position: relative;
    margin: 2rem auto 3rem;
    overflow: hidden;
  }
  
  .portfolio-item.mobile-app {
    height: 480px;
    width: 240px;
    margin: 0 auto;
    position: relative;
    transform: perspective(1000px) rotateY(0deg) rotateX(5deg) !important;
    transition: transform 0.5s ease !important;
    will-change: transform;
  }
  
  /* Enhanced iPhone frame for mobile */
  .iphone-frame {
    border-radius: 36px;
    background: linear-gradient(to bottom, #1a1a1a, #2c2c2c);
    box-shadow: 
      0 0 0 2px #444, 
      0 10px 20px rgba(0, 0, 0, 0.2),
      inset 0 0 10px rgba(0, 0, 0, 0.2);
    padding: 10px 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  /* Add side button to iPhone frame */
  .iphone-frame::before {
    content: "";
    position: absolute;
    right: -3px;
    top: 100px;
    width: 3px;
    height: 30px;
    background-color: #444;
    border-radius: 3px 0 0 3px;
  }
  
  /* Improved iPhone notch */
  .iphone-notch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 50%;
    height: 25px;
    background-color: #1a1a1a;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
    z-index: 10;
    box-shadow: inset 0 -2px 5px rgba(0, 0, 0, 0.2);
  }
  
  /* Add camera dot in notch */
  .iphone-notch::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 30%;
    width: 8px;
    height: 8px;
    background-color: #333;
    border-radius: 50%;
    box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.5);
  }
  
  /* Improved home indicator */
  .iphone-home-indicator {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    height: 5px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 3px;
    z-index: 10;
  }
  
  /* Optimize testimonials for mobile */
  .testimonial-card {
    padding: 1.5rem;
    height: auto;
    min-height: 200px; /* Set minimum height */
  }
  
  /* Optimize FAQ section for mobile */
  .faq-grid {
    grid-template-columns: 1fr;
  }
  
  .faq-item {
    margin-bottom: 1rem;
  }
  
  .faq-question {
    padding: 1rem;
  }
  
  /* Optimize footer for mobile */
  .footer-content {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
}

/* Optimize for smaller mobile devices */
@media (max-width: 480px) {
  .hero {
    min-height: 450px; /* Adjusted for small mobile */
  }
  
  .hero-content {
    min-height: 250px; /* Adjusted for small mobile */
  }
  
  .hero h1 {
    font-size: 1.8rem !important;
  }
  
  .hero p {
    font-size: 1rem !important;
  }
  
  .section-title h2 {
    font-size: 1.6rem !important;
  }
  
  /* Further optimize portfolio for small screens */
  .portfolio-item.mobile-app {
    height: 420px;
    width: 210px;
    transform: perspective(1000px) rotateY(0deg) rotateX(3deg) !important;
  }
  
  /* Improved portfolio navigation for small screens */
  .portfolio-nav {
    padding: 0 10px;
  }
  
  .portfolio-nav button {
    width: 44px;
    height: 44px;
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    opacity: 0.9;
    -webkit-tap-highlight-color: transparent;
  }
  
  .portfolio-nav button:active {
    transform: scale(0.95);
    opacity: 1;
  }
  
  /* Improved portfolio dots for mobile */
  .portfolio-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 1.5rem;
  }
  
  .portfolio-dot {
    width: 10px;
    height: 10px;
    background-color: rgba(44, 107, 237, 0.3);
    border-radius: 50%;
    transition: all 0.3s ease;
    border: none;
    position: relative;
  }
  
  .portfolio-dot.active {
    background-color: var(--primary-color);
    transform: scale(1.3);
  }
  
  /* Add touch area around dots */
  .portfolio-dot::before {
    content: "";
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
  }
  
  /* Optimize process timeline for small screens */
  .timeline-step {
    padding-left: 2rem;
  }
  
  .timeline-number {
    width: 30px;
    height: 30px;
    font-size: 1rem;
  }
}

/* Fix for layout shifts in portfolio slider */
.portfolio-slider {
  display: flex;
  transition: transform 0.4s cubic-bezier(0.215, 0.610, 0.355, 1.000);
  width: 100%;
  height: 550px;
  position: relative;
}

.portfolio-slide {
  flex: 0 0 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 100%;
  height: 100%;
  position: relative;
}

/* Enhanced portfolio overlay for mobile */
@media (max-width: 768px) {
  .portfolio-overlay {
    transform: translateY(60%) !important;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.7) 60%, rgba(0, 0, 0, 0) 100%);
    padding: 1.5rem 1.2rem 1.2rem;
    border-radius: 0 0 28px 28px;
  }
  
  /* Show part of the overlay by default on mobile */
  .portfolio-overlay h3 {
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
  
  /* Add subtle tap hint for mobile */
  .portfolio-item::after {
    content: "";
    position: absolute;
    bottom: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    background-color: rgba(44, 107, 237, 0.9);
    border-radius: 50%;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    opacity: 0.9;
    animation: pulse 1.5s infinite;
    transition: opacity 0.3s ease;
  }
  
  /* Hide tap hint when overlay is visible */
  .portfolio-item.overlay-visible::after {
    opacity: 0;
  }
  
  /* Mobile-specific app features styling */
  .app-features {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.8rem;
  }
  
  .app-features span {
    background-color: rgba(58, 123, 219, 0.8);
    color: white;
    padding: 0.3rem 0.7rem;
    border-radius: 20px;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
  }
  
  .portfolio-item.overlay-visible .app-features span {
    opacity: 1;
    transform: translateY(0);
  }
  
  .portfolio-item.overlay-visible .app-features span:nth-child(1) {
    transition-delay: 0.1s;
  }
  
  .portfolio-item.overlay-visible .app-features span:nth-child(2) {
    transition-delay: 0.2s;
  }
  
  .portfolio-item.overlay-visible .app-features span:nth-child(3) {
    transition-delay: 0.3s;
  }
  
  /* Subtle swipe hint animation */
  .portfolio-slider-container::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 15%;
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translateY(-50%);
    opacity: 0;
    animation: swipeHint 3s ease-in-out 1s;
    pointer-events: none;
  }
  
  @keyframes swipeHint {
    0%, 100% { opacity: 0; right: 15%; }
    20%, 80% { opacity: 0.7; }
    90% { right: 5%; opacity: 0; }
  }
}

/* Prevent content jumping when scrollbar appears */
html {
  scrollbar-gutter: stable;
}

/* Optimize font loading */
body {
  font-display: swap;
}

/* Reduce motion for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Add content-visibility for offscreen content to improve rendering performance */
.tech-stack,
.process-section,
.portfolio,
.testimonials,
.faq-section,
.cta,
footer {
  content-visibility: auto;
  contain-intrinsic-size: 1px 1000px; /* Approximate size to prevent layout shifts */
}

/* Ensure services section is always rendered */
.services {
  content-visibility: visible;
  contain-intrinsic-size: auto;
}

/* Enhanced services section for mobile */
@media (max-width: 768px) {
  .services {
    padding: 4rem 0;
    position: relative;
    overflow: hidden;
  }
  
  .services-bg-hue {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(44, 107, 237, 0.05) 0%, rgba(90, 142, 255, 0.05) 100%);
    z-index: -1;
  }
  
  .services .section-title h2 {
    margin-bottom: 0.5rem;
    font-size: 1.8rem !important;
  }
  
  .services .section-subtitle {
    font-size: 0.9rem;
    letter-spacing: 1px;
  }
  
  .services .section-description {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 2rem;
    padding: 0 1rem;
    color: #555;
  }
  
  /* Touch-friendly design for service cards */
  .service-card {
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
  }
  
  .service-card::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
  }
  
  .service-card:active::after {
    opacity: 1;
  }
}

/* Further optimize for smaller screens */
@media (max-width: 480px) {
  .services {
    padding: 3rem 0;
  }
  
  .service-grid {
    gap: 1.2rem;
  }
  
  .service-card {
    padding: 1.5rem 1.2rem;
    min-height: 180px;
  }
  
  .service-icon {
    width: 50px;
    height: 50px;
    margin-bottom: 1rem;
  }
  
  .service-icon i {
    font-size: 1.3rem;
  }
  
  .service-card h3 {
    font-size: 1.2rem;
    margin-bottom: 0.6rem;
  }
  
  .service-card p {
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 0.8rem;
  }
  
  .service-tag {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
  }
  
  .service-card-footer {
    gap: 0.4rem;
  }
}

/* Fix for non-composited animations by using transform and opacity */
.loading-bar,
.progress-bar,
.floating,
.pulse {
  will-change: transform;
  transform: translateZ(0);
}

/* Optimize animations to use composited properties */
@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes float {
  0% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

/* Fix for loading animations to use composited properties */
@keyframes loader {
  0% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(2);
  }
  100% {
    transform: scaleY(1);
  }
}

/* Optimize images with loading attribute */
img:not([loading]) {
  loading: lazy;
}

/* Fix for the floating elements in hero section */
.floating-element {
  position: absolute;
  pointer-events: none;
  will-change: transform;
  transform: translateZ(0);
}

/* Preload critical fonts to prevent layout shifts */
@font-face {
  font-family: 'FontAwesome';
  font-display: swap;
  src: url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.woff2') format('woff2');
  font-weight: 900;
  font-style: normal;
}

/* Service card animations and effects for mobile */
@media (max-width: 768px) {
  /* Ripple effect for service cards */
  .service-card {
    position: relative;
    overflow: hidden;
  }
  
  .ripple-effect {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.7);
    width: 100px;
    height: 100px;
    margin-top: -50px;
    margin-left: -50px;
    animation: ripple 0.6s linear;
    transform: scale(0);
    opacity: 1;
    pointer-events: none;
  }
  
  @keyframes ripple {
    to {
      transform: scale(4);
      opacity: 0;
    }
  }
  
  /* Smooth entrance animation for service cards */
  .service-card {
    opacity: 0.6;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease, box-shadow 0.3s ease;
  }
  
  .service-card.in-view {
    opacity: 1;
    transform: translateY(0);
  }
  
  /* Staggered animation for service tags */
  .service-tag {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
  }
  
  .service-card.in-view .service-tag {
    opacity: 1;
    transform: translateY(0);
  }
  
  .service-card.in-view .service-tag:nth-child(1) {
    transition-delay: 0.1s;
  }
  
  .service-card.in-view .service-tag:nth-child(2) {
    transition-delay: 0.2s;
  }
  
  .service-card.in-view .service-tag:nth-child(3) {
    transition-delay: 0.3s;
  }
}
