/* ================================================
   MOBILE OPTIMIZATIONS - PERFECT iOS EXPERIENCE
   Mobile-first, iOS Safari optimized, zero issues
   Version: 2.0 - Complete Rewrite
   ================================================ */

/* ========================================
   iOS SAFE AREA & VIEWPORT FIX
   ======================================== */

:root {
  /* Mobile Variables */
  --mobile-padding: clamp(16px, 5vw, 24px);
  --mobile-margin: 12px;
  --tap-target: 44px;
  --header-height: 64px;

  /* iOS Safe Area Support */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);

  /* Mobile Typography */
  --mobile-font-base: 16px;
  --mobile-h1: clamp(32px, 10vw, 48px);
  --mobile-h2: clamp(24px, 7vw, 36px);
  --mobile-h3: clamp(20px, 5vw, 28px);

  /* Touch-optimized */
  --touch-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --bounce-ease: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* iOS Viewport Height Fix */
html {
  min-height: -webkit-fill-available;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* ========================================
   PREVENT HORIZONTAL SCROLL - ABSOLUTE
   ======================================== */

html,
body {
  overflow-x: hidden;
  max-width: 100vw;
}

*,
*::before,
*::after {
  max-width: 100%;
}

img,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

/* ========================================
   MOBILE HEADER - FIXED & COMPACT
   ======================================== */

@media (max-width: 768px) {
  .header {
    padding: max(12px, var(--safe-top)) var(--mobile-padding) 12px !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: var(--header-height);
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
  }

  .header-content {
    gap: 12px !important;
    height: 40px;
    align-items: center !important;
    justify-content: space-between !important;
  }

  /* Logo - Compact */
  .logo {
    font-size: 18px !important;
    flex-shrink: 0;
  }

  .logo svg,
  .logo img {
    height: 32px !important;
    width: auto !important;
  }

  /* Hide desktop navigation */
  .nav {
    display: none !important;
  }

  /* Header Actions Group */
  .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* Language Switcher Mobile */
  .language-switcher {
    position: relative;
    z-index: 1002;
  }

  .lang-btn {
    min-width: 60px !important;
    min-height: var(--tap-target) !important;
    padding: 8px 12px !important;
    font-size: 14px !important;
    border-radius: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255, 233, 0, 0.2);
  }

  .lang-dropdown {
    position: fixed !important;
    top: calc(var(--header-height) + 8px);
    right: max(16px, var(--safe-right));
    left: auto !important;
    min-width: 180px;
    max-width: calc(100vw - 32px);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .lang-option {
    min-height: var(--tap-target) !important;
    padding: 14px 16px !important;
    font-size: 16px !important;
    touch-action: manipulation;
  }

  /* Space for fixed header - CORRECT OFFSET */
  main,
  .hero,
  .services-hero {
    padding-top: var(--header-height) !important;
    margin-top: 0 !important;
  }

  /* First section after header needs extra space */
  .services-hero {
    padding-top: calc(var(--header-height) + 40px) !important;
  }
}

/* ========================================
   HAMBURGER MENU - SMOOTH ANIMATION
   ======================================== */

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: var(--tap-target);
  height: var(--tap-target);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  position: relative;
  z-index: 1001;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hamburger-line {
  width: 24px;
  height: 2px;
  background: var(--cyan, #00E5FF);
  border-radius: 2px;
  transition: all 0.5s ease-in-out;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.hamburger-line:nth-child(1) {
  top: calc(50% - 8px);
}

.hamburger-line:nth-child(2) {
  top: 50%;
  transform: translate(-50%, -50%);
}

.hamburger-line:nth-child(3) {
  top: calc(50% + 8px);
}

/* Active State - Perfect X */
.hamburger.active .hamburger-line:nth-child(1) {
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
}

.hamburger.active .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: translate(-50%, -50%) scaleX(0);
}

.hamburger.active .hamburger-line:nth-child(3) {
  top: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
}

@media (max-width: 768px) {
  .hamburger {
    display: flex;
  }
}

/* ========================================
   MOBILE NAV OVERLAY - FULL SCREEN
   ======================================== */

.mobile-nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw; /* Dynamic viewport */
  height: 100vh;
  height: 100dvh;
  background: linear-gradient(
    135deg,
    rgba(10, 1, 24, 0.98) 0%,
    rgba(30, 32, 38, 0.98) 100%
  );
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  z-index: 999;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: max(80px, var(--safe-top)) max(24px, var(--safe-left)) max(40px, var(--safe-bottom)) max(24px, var(--safe-right));

  opacity: 0;
  visibility: hidden;
  transform: translateY(-20px);
  transition: opacity 0.5s ease-in-out,
              visibility 0.5s ease-in-out,
              transform 0.5s ease-in-out;

  /* Prevent scroll on body when menu open */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-nav-overlay.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Mobile Nav Content Container */
.mobile-nav-content {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

/* Mobile Nav Links */
.mobile-nav-overlay .nav-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  list-style: none;
  width: 100%;
}

.mobile-nav-overlay .nav-item {
  width: 100%;
}

.mobile-nav-overlay .nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap-target);
  padding: 14px 24px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--text-primary, #FFFFFF);
  border-radius: 12px;
  transition: all 0.5s ease-in-out;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.mobile-nav-overlay .nav-link:hover,
.mobile-nav-overlay .nav-link:focus,
.mobile-nav-overlay .nav-link:active {
  background: rgba(255, 233, 0, 0.15);
  border-color: rgba(255, 233, 0, 0.4);
  transform: translateX(4px) scale(1.02);
}

.mobile-nav-overlay .nav-link.active {
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.2), rgba(59, 130, 246, 0.2));
  border-color: var(--cosmic-purple, #9333ea);
}

/* Mobile CTA Button */
.mobile-nav-overlay .btn-primary,
.mobile-nav-overlay .mobile-cta {
  margin-top: 16px;
  min-height: 52px;
  padding: 16px 32px;
  font-size: 18px;
  font-weight: 700;
  width: 100%;
  max-width: 300px;
  border-radius: 12px;
  touch-action: manipulation;
  transition: all 0.5s ease-in-out;
}

.mobile-nav-overlay .btn-primary:active,
.mobile-nav-overlay .mobile-cta:active {
  transform: scale(0.95);
}

/* Mobile Language Switcher in Overlay */
.mobile-nav-overlay .language-switcher,
.mobile-nav-overlay .mobile-lang-switcher {
  width: 100%;
  max-width: 300px;
  position: relative;
  z-index: 10;
}

.mobile-nav-overlay .lang-btn {
  width: 100%;
  justify-content: center;
  background: rgba(147, 51, 234, 0.2) !important;
  border: 1px solid rgba(147, 51, 234, 0.4) !important;
  min-height: 52px !important;
}

.mobile-nav-overlay .lang-dropdown {
  position: relative !important;
  top: 8px !important;
  right: auto !important;
  left: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
}

/* ========================================
   MOBILE TYPOGRAPHY - PERFECT SCALE
   ======================================== */

@media (max-width: 768px) {
  body {
    font-size: var(--mobile-font-base);
    line-height: 1.6;
  }

  h1,
  .hero-title {
    font-size: var(--mobile-h1) !important;
    line-height: 1.15 !important;
    margin-bottom: 16px;
  }

  h2,
  .section-title {
    font-size: var(--mobile-h2) !important;
    line-height: 1.25 !important;
    margin-bottom: 14px;
  }

  h3 {
    font-size: var(--mobile-h3) !important;
    line-height: 1.3 !important;
    margin-bottom: 12px;
  }

  h4 {
    font-size: clamp(18px, 4vw, 22px) !important;
    line-height: 1.35 !important;
  }

  p,
  li,
  span {
    font-size: 16px;
    line-height: 1.6;
  }

  .hero-description,
  .section-description {
    font-size: 16px !important;
    line-height: 1.65 !important;
  }
}

/* Extra Small - iPhone SE */
@media (max-width: 375px) {
  h1,
  .hero-title {
    font-size: clamp(28px, 9vw, 36px) !important;
  }

  h2,
  .section-title {
    font-size: clamp(22px, 6vw, 28px) !important;
  }
}

/* ========================================
   MOBILE SPACING & CONTAINERS
   ======================================== */

@media (max-width: 768px) {
  .container {
    padding-left: max(var(--mobile-padding), var(--safe-left)) !important;
    padding-right: max(var(--mobile-padding), var(--safe-right)) !important;
    max-width: 100%;
  }

  .section {
    padding: 48px 0 !important;
  }

  /* Reduce spacing on small screens */
  @media (max-width: 375px) {
    .section {
      padding: 40px 0 !important;
    }
  }

  /* Hero sections */
  .hero,
  .services-hero {
    padding: calc(var(--header-height) + 40px) 0 40px !important;
    min-height: auto !important;
  }
}

/* ========================================
   TOUCH-OPTIMIZED BUTTONS
   ======================================== */

@media (max-width: 768px) {
  /* All interactive elements */
  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-outline,
  button,
  a[role="button"],
  .services-tab,
  .lang-option {
    min-height: var(--tap-target) !important;
    min-width: var(--tap-target) !important;
    padding: 12px 24px !important;
    font-size: 16px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Button sizing variants */
  .btn-sm {
    min-height: 40px !important;
    padding: 10px 20px !important;
    font-size: 15px !important;
  }

  .btn-lg {
    min-height: 52px !important;
    padding: 16px 32px !important;
    font-size: 18px !important;
  }

  /* Full width buttons */
  .service-actions .btn,
  .cta-buttons .btn,
  .mobile-full-width {
    width: 100% !important;
  }

  /* Service tabs - scrollable on mobile */
  .services-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    gap: 8px;
    padding: 12px var(--mobile-padding);
    margin: 0 calc(var(--mobile-padding) * -1);
  }

  .services-tab {
    flex: 0 0 auto;
    min-width: 140px;
    scroll-snap-align: start;
  }

  /* Hide scrollbar but keep functionality */
  .services-tabs::-webkit-scrollbar {
    display: none;
  }
}

/* ========================================
   MOBILE GRIDS - RESPONSIVE STACKING
   ======================================== */

@media (max-width: 768px) {
  /* Hero Stats - 2 columns */
  .hero-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
    padding: 20px 16px !important;
  }

  .stat-value {
    font-size: clamp(28px, 8vw, 36px) !important;
  }

  .stat-label {
    font-size: 13px !important;
  }

  /* Single column layouts */
  .featured-services-grid,
  .advantages-grid,
  .service-pricing-grid,
  .footer-content {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  /* Cards padding */
  .glass-card,
  .service-card,
  .service-featured-card {
    padding: 20px !important;
  }
}

/* Extra Small - Single column stats */
@media (max-width: 375px) {
  .hero-stats {
    grid-template-columns: 1fr !important;
  }

  .glass-card,
  .service-card {
    padding: 16px !important;
  }
}

/* ========================================
   MOBILE SERVICE CARDS - OPTIMIZED
   ======================================== */

@media (max-width: 768px) {
  .service-card,
  .service-featured-card {
    text-align: left;
  }

  .service-icon {
    font-size: 40px !important;
    margin-bottom: 16px;
  }

  .service-title {
    font-size: 22px !important;
    margin-bottom: 12px;
  }

  .service-description {
    font-size: 15px !important;
    margin-bottom: 16px;
    line-height: 1.6;
  }

  .service-highlights {
    text-align: left;
    margin-bottom: 20px;
  }

  .service-highlights li {
    font-size: 15px !important;
    padding: 6px 0;
  }

  .service-actions {
    flex-direction: column;
    gap: 12px;
  }

  /* Price tiers */
  .price-tier {
    padding: 16px !important;
  }

  .tier-price {
    font-size: clamp(24px, 6vw, 32px) !important;
  }

  .tier-features li {
    font-size: 14px !important;
  }
}

/* ========================================
   MOBILE FORMS - PREVENT ZOOM ON FOCUS
   ======================================== */

@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important; /* Critical: prevents iOS zoom */
    min-height: var(--tap-target);
    padding: 12px 16px;
    border-radius: 8px;
    width: 100%;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
  }

  textarea {
    min-height: 120px;
    resize: vertical;
  }

  .form-group {
    margin-bottom: 20px;
  }

  label {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
  }
}

/* ========================================
   MOBILE CTA SECTIONS
   ======================================== */

@media (max-width: 768px) {
  .cta-card-large {
    padding: 32px var(--mobile-padding) !important;
    text-align: center;
  }

  .cta-title {
    font-size: var(--mobile-h2) !important;
    margin-bottom: 16px;
  }

  .cta-description {
    font-size: 16px !important;
    line-height: 1.6;
    margin-bottom: 24px;
  }

  .cta-buttons {
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }

  .cta-trust-line {
    font-size: 14px !important;
  }
}

/* ========================================
   MOBILE FOOTER
   ======================================== */

@media (max-width: 768px) {
  .footer {
    padding: 48px 0 max(32px, var(--safe-bottom)) !important;
  }

  .footer-content {
    text-align: center;
  }

  .footer-section {
    margin-bottom: 32px;
  }

  .footer-section h4 {
    font-size: 18px;
    margin-bottom: 16px;
  }

  .footer-link,
  .footer-section p {
    font-size: 15px;
    line-height: 1.6;
  }

  .footer-bottom {
    font-size: 14px;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
}

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

@media (max-width: 768px) {
  /* Cap transition durations to keep interactions snappy on mobile.
     We do NOT override animation-duration globally — that breaks infinite
     loops and intentional slow pulses. Only transitions are capped. */
  *:not(.hamburger-line):not(.mobile-nav-overlay):not(.nav-link) {
    transition-duration: 0.3s !important;
  }

  /* Hide heavy decorative elements */
  .gradient-orb,
  .particles,
  .geometric-shapes,
  .hero-background::before {
    display: none !important;
  }

  /* Simplify backdrop blur */
  .glass-card,
  .header,
  .lang-dropdown,
  .mobile-nav-overlay {
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
  }

  /* Hardware acceleration */
  .hamburger,
  .mobile-nav-overlay,
  .header {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
  }
}

/* ========================================
   MOBILE ACCESSIBILITY
   ======================================== */

@media (max-width: 768px) {
  /* Larger focus outlines */
  *:focus-visible {
    outline: 3px solid var(--cyan, #00E5FF);
    outline-offset: 2px;
    border-radius: 4px;
  }

  /* Better contrast */
  .text-secondary {
    color: #B7BDC6;
  }

  /* Readable spacing */
  p,
  li {
    padding-left: 2px;
    padding-right: 2px;
  }

  /* Skip to content - mobile friendly */
  .skip-to-main {
    padding: 14px 24px;
    font-size: 16px;
  }
}

/* ========================================
   LANDSCAPE MODE - MOBILE
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
  .mobile-nav-overlay {
    justify-content: flex-start;
    padding-top: max(20px, var(--safe-top));
    overflow-y: auto;
  }

  .mobile-nav-content {
    padding: 20px 0;
  }

  .mobile-nav-overlay .nav-list {
    gap: 4px;
  }

  .mobile-nav-overlay .nav-link {
    min-height: 40px;
    padding: 10px 20px;
    font-size: 16px;
  }

  .hero,
  .services-hero {
    min-height: auto !important;
    padding: calc(var(--header-height) + 20px) 0 30px !important;
  }

  .hero-stats {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* ========================================
   iOS SAFARI SPECIFIC FIXES
   ======================================== */

/* iOS momentum scrolling */
body {
  -webkit-overflow-scrolling: touch;
}

/* Fix input styling on iOS */
input,
textarea,
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
}

/* Prevent tap delay */
a,
button,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* iOS: mobile-nav-overlay height fix */
@supports (-webkit-touch-callout: none) {
  .mobile-nav-overlay {
    position: fixed;
    height: -webkit-fill-available;
  }
}

/* ========================================
   TWITTER AUTOMATION PAGE - MOBILE
   ======================================== */

@media (max-width: 768px) {
  .twitter-icon {
    font-size: 3rem !important;
  }

  .pricing-table {
    grid-template-columns: 1fr !important;
    gap: 20px;
  }

  .pricing-card {
    padding: 24px !important;
  }

  .pricing-card.featured {
    transform: scale(1) !important;
  }

  .plan-price {
    font-size: clamp(2rem, 8vw, 2.5rem) !important;
  }

  .plan-features li {
    font-size: 15px !important;
  }

  .results-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px;
  }

  .result-number {
    font-size: clamp(2rem, 7vw, 2.5rem) !important;
  }

  .timeline-item {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .timeline-number {
    width: 44px;
    height: 44px;
    font-size: 1.125rem;
  }
}

@media (max-width: 375px) {
  .results-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ========================================
   UTILITY CLASSES - MOBILE
   ======================================== */

@media (max-width: 768px) {
  .mobile-hide {
    display: none !important;
  }

  .mobile-show {
    display: block !important;
  }

  .mobile-center {
    text-align: center !important;
  }

  .mobile-full-width {
    width: 100% !important;
  }

  .mobile-stack {
    flex-direction: column !important;
  }
}

/* ========================================
   DEBUG MODE - REMOVE IN PRODUCTION
   ======================================== */

/* Uncomment to show layout boundaries
@media (max-width: 768px) {
  .container { outline: 2px solid red; }
  .section { outline: 2px solid blue; }
  .grid { outline: 2px solid green; }
}
*/
