/* ============================================
   CLEAN STAR - Mobile UX Enhancements
   Premium Mobile Experience
   ============================================ */

/* ========================================
   TOUCH-FRIENDLY INTERFACE
   ======================================== */

/* Minimum touch target size: 48x48px (Apple HIG & Material Design) */
*[role="button"],
button,
a,
input,
label,
select,
textarea {
  min-height: 44px; /* iOS minimum for comfort */
  min-width: 44px;
}

/* Enhanced tap targets for mobile */
@media (max-width: 768px) {
  .btn {
    min-height: 56px; /* Larger for easier tapping */
    padding: 1rem 1.5rem;
    font-size: 1.0625rem;
  }

  .btn-lg {
    min-height: 64px;
    padding: 1.375rem 2rem;
    font-size: 1.125rem;
  }

  .btn-sm {
    min-height: 48px;
    padding: 0.875rem 1.5rem;
  }

  /* Navigation links */
  .mobile-menu-link {
    min-height: 60px;
    padding: 1.25rem;
    font-size: 1.0625rem;
  }

  /* Header phone button */
  .header-phone {
    min-height: 52px;
    padding: 1rem 1.75rem;
  }
}

/* ========================================
   TOUCH FEEDBACK & HAPTIC-LIKE EFFECTS
   ======================================== */

/* Active state for touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn:active,
  .card:active,
  .mobile-menu-link:active,
  a:active {
    transform: scale(0.97);
    opacity: 0.9;
    transition: transform 0.1s ease, opacity 0.1s ease;
  }

  .whatsapp-sticky:active {
    transform: scale(0.92);
  }
}

/* Ripple effect for touch feedback */
.touch-ripple {
  position: relative;
  overflow: hidden;
}

.touch-ripple::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s, opacity 0.6s;
  opacity: 0;
  pointer-events: none;
}

.touch-ripple:active::after {
  width: 300px;
  height: 300px;
  opacity: 1;
}

/* ========================================
   MOBILE NAVIGATION ENHANCEMENTS
   ======================================== */

/* Smooth mobile menu with backdrop blur */
@media (max-width: 1023px) {
  .mobile-menu {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mobile-menu.active {
    transform: translateX(0);
  }

  /* Slide-in animation for menu items */
  .mobile-menu.active .mobile-menu-link {
    animation: slideInRight 0.5s ease-out backwards;
  }

  .mobile-menu.active .mobile-menu-link:nth-child(1) { animation-delay: 0.05s; }
  .mobile-menu.active .mobile-menu-link:nth-child(2) { animation-delay: 0.1s; }
  .mobile-menu.active .mobile-menu-link:nth-child(3) { animation-delay: 0.15s; }
  .mobile-menu.active .mobile-menu-link:nth-child(4) { animation-delay: 0.2s; }
  .mobile-menu.active .mobile-menu-link:nth-child(5) { animation-delay: 0.25s; }
  .mobile-menu.active .mobile-menu-link:nth-child(6) { animation-delay: 0.3s; }
  .mobile-menu.active .mobile-menu-link:nth-child(7) { animation-delay: 0.35s; }

  @keyframes slideInRight {
    from {
      opacity: 0;
      transform: translateX(30px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  /* Menu backdrop overlay */
  .mobile-menu::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: -1;
  }

  .mobile-menu.active::before {
    opacity: 1;
  }
}

/* ========================================
   SWIPE GESTURE INDICATORS
   ======================================== */

/* Swipeable cards - visual hint */
.swipe-hint {
  position: relative;
}

.swipe-hint::after {
  content: '← Swipe →';
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  opacity: 0.6;
  animation: fadeInOut 3s ease-in-out infinite;
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

/* ========================================
   MOBILE VIEWPORT OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
  /* Prevent text size adjustment on orientation change */
  html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Optimize tap highlight color */
  * {
    -webkit-tap-highlight-color: rgba(0, 102, 204, 0.1);
  }

  /* Remove default touch callout */
  a, button, img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Allow text selection in paragraphs */
  p, span, li {
    -webkit-user-select: text;
    user-select: text;
  }

  /* Optimize scrolling performance */
  body {
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile Header Optimizations */
  .header {
    padding: 0;
  }

  .header-content {
    padding: 0.75rem 0;
    min-height: 60px;
    gap: 0.75rem;
  }

  .header-logo {
    font-size: 1.25rem;
  }

  .mobile-menu-toggle {
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
  }

  /* Reduce hero section height for small screens */
  .hero {
    min-height: 500px;
    padding: var(--space-xl) 0;
  }

  /* Stack hero CTAs vertically with better spacing */
  .hero-cta {
    flex-direction: column;
    gap: 1rem;
    width: 100%;
  }

  .hero-cta .btn {
    width: 100%;
    max-width: 400px;
  }

  /* Mobile-optimized typography */
  h1 {
    font-size: clamp(1.875rem, 8vw, 2.75rem);
    line-height: 1.2;
  }

  h2 {
    font-size: clamp(1.5rem, 6vw, 2rem);
  }

  .hero-subtitle {
    font-size: 1rem;
    line-height: 1.6;
  }

  /* Reduce section padding on mobile */
  .section {
    padding: var(--space-lg) 0;
  }

  .section-lg {
    padding: var(--space-xl) 0;
  }

  /* Optimize card spacing */
  .card {
    padding: var(--space-md);
  }

  .service-grid {
    gap: 1.25rem;
  }
}

/* ========================================
   MOBILE KEYBOARD HANDLING
   ======================================== */

/* Prevent viewport zoom on input focus (iOS) */
input,
select,
textarea {
  font-size: 16px !important; /* Prevents iOS zoom */
}

/* Input focus enhancements for mobile */
@media (max-width: 768px) {
  input:focus,
  textarea:focus,
  select:focus {
    outline: 3px solid rgba(0, 102, 204, 0.4);
    outline-offset: 2px;
    border-color: var(--color-primary);
    background: var(--color-bg);
    transform: scale(1.01);
    transition: all 0.2s ease;
  }

  /* Sticky keyboard fix */
  .form-container {
    position: relative;
    margin-bottom: 200px; /* Space for keyboard */
  }
}

/* ========================================
   MOBILE WHATSAPP BUTTON OPTIMIZATION
   ======================================== */

@media (max-width: 768px) {
  .whatsapp-sticky {
    bottom: 16px;
    right: 16px;
    padding: 1rem 1.25rem;
    min-width: 60px;
    min-height: 60px;
    border-radius: 30px;
    box-shadow: 0 8px 24px rgba(37, 211, 102, 0.5);
  }

  .whatsapp-sticky svg {
    width: 28px;
    height: 28px;
  }

  .whatsapp-text {
    display: none; /* Icon only on mobile */
  }

  /* Floating label on hover/long-press */
  .whatsapp-sticky::before {
    content: 'WhatsApp';
    position: absolute;
    right: calc(100% + 12px);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .whatsapp-sticky:active::before {
    opacity: 1;
  }

  /* Arrow pointer */
  .whatsapp-sticky::after {
    content: '';
    position: absolute;
    right: calc(100% + 4px);
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-left-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .whatsapp-sticky:active::after {
    opacity: 1;
  }
}

/* ========================================
   MOBILE SCROLL ENHANCEMENTS
   ======================================== */

/* Smooth scroll behavior */
@media (max-width: 768px) {
  html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px; /* Account for sticky header */
  }

  /* Scroll snap for sections (optional - can be enabled) */
  .snap-container {
    scroll-snap-type: y proximity;
  }

  .snap-section {
    scroll-snap-align: start;
  }

  /* Hide scrollbar on mobile for cleaner look */
  .custom-scrollbar::-webkit-scrollbar {
    width: 4px;
  }

  .custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
  }

  .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(0, 102, 204, 0.3);
    border-radius: 2px;
  }
}

/* ========================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
  /* Reduce animations on low-end devices */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* Optimize transforms for mobile GPU */
  .card,
  .btn,
  .mobile-menu,
  .whatsapp-sticky {
    will-change: transform;
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }

  /* Reduce box-shadows on mobile for better performance */
  @media (max-device-width: 480px) {
    .card {
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .card:hover {
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    }
  }
}

/* ========================================
   LANDSCAPE MODE OPTIMIZATIONS
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .hero {
    min-height: 400px;
    padding: var(--space-lg) 0;
  }

  .hero h1 {
    font-size: 2rem;
    margin-bottom: var(--space-sm);
  }

  .hero-subtitle {
    font-size: 0.9375rem;
    margin-bottom: var(--space-md);
  }

  .mobile-menu {
    padding: var(--space-md);
  }

  .mobile-menu-link {
    min-height: 48px;
    padding: 0.875rem;
  }
}

/* ========================================
   SAFE AREA INSETS (iPhone X+)
   ======================================== */

@supports (padding: env(safe-area-inset-bottom)) {
  .header {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .footer {
    padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
  }

  .whatsapp-sticky {
    bottom: calc(16px + env(safe-area-inset-bottom));
    right: calc(16px + env(safe-area-inset-right));
  }

  .mobile-menu {
    padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
  }
}

/* ========================================
   PULL-TO-REFRESH VISUAL INDICATOR
   ======================================== */

.pull-to-refresh {
  position: fixed;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  background: var(--gradient-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: top 0.3s ease;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

.pull-to-refresh.active {
  top: 80px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: translateX(-50%) rotate(0deg); }
  to { transform: translateX(-50%) rotate(360deg); }
}

/* ========================================
   MOBILE ACCESSIBILITY IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
  /* Focus visible for keyboard navigation */
  :focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
  }

  /* Skip to content link */
  .skip-to-content {
    position: absolute;
    top: -100px;
    left: 16px;
    background: var(--color-primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    text-decoration: none;
    z-index: 10000;
    transition: top 0.3s ease;
  }

  .skip-to-content:focus {
    top: 16px;
  }

  /* Larger touch targets for links in text */
  p a,
  li a {
    padding: 0.25rem 0.5rem;
    margin: -0.25rem -0.5rem;
    border-radius: 4px;
    display: inline-block;
  }
}

/* ========================================
   MOBILE-SPECIFIC ANIMATIONS
   ======================================== */

@media (max-width: 768px) {
  /* Slide-up cards animation */
  @keyframes mobileSlideUp {
    from {
      opacity: 0;
      transform: translateY(40px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .scroll-reveal.revealed {
    animation: mobileSlideUp 0.6s ease-out;
  }

  /* Mobile floating animation - slower for battery */
  .float {
    animation: float 4s ease-in-out infinite;
  }

  /* Reduce pulse intensity on mobile */
  @keyframes mobilePulse {
    0%, 100% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.03);
    }
  }

  .pulse {
    animation: mobilePulse 2.5s ease-in-out infinite;
  }
}

/* ========================================
   MOBILE DARK MODE SUPPORT
   ======================================== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
  .mobile-menu {
    background: rgba(26, 26, 46, 0.98);
    color: white;
  }

  .mobile-menu-link {
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .mobile-menu-link:hover,
  .mobile-menu-link:active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
  }
}
