/**
 * Mobile UX Enhancements
 * Advanced touch interactions and mobile-specific optimizations
 * Version: 1.0.0 - 4-Day Launch Optimization
 */

/* ===== PREVENT HORIZONTAL OVERFLOW ===== */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

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

/* ===== TOUCH INTERACTION ENHANCEMENTS (mobile only) ===== */
@media (max-width: 768px) {
  /* Enhanced touch targets */
  button,
  .btn,
  .service-option,
  .time-slot,
  .addon-item,
  [role="button"],
  input[type="submit"],
  a.interactive {
    /* Minimum 44px touch targets */
    min-height: 44px !important;
    min-width: 44px !important;

    /* Enhanced tap feedback */
    -webkit-tap-highlight-color: rgba(0, 123, 255, 0.15);
    -webkit-touch-callout: none;

    /* Smooth touch interactions */
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: manipulation;

    /* Prevent zoom on touch */
    user-select: none;
    -webkit-user-select: none;
  }

  /* Active touch states */
  button:active,
  .btn:active,
  .service-option:active,
  .time-slot:active {
    transform: scale(0.98);
    background-color: var(--primary-color, #0066cc);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  /* Enhanced form inputs for mobile */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  textarea,
  select {
    /* Prevent iOS zoom */
    font-size: 16px !important;

    /* Enhanced mobile padding */
    padding: 14px 16px !important;
    min-height: 48px !important;

    /* Better border radius for mobile */
    border-radius: 8px !important;

    /* Focus states */
    transition: all 0.2s ease;
  }
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary-color, #0066cc);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
  transform: translateY(-1px);
}

/* ===== ADVANCED MOBILE GESTURES ===== */

/* Swipe gesture zones */
.step-container {
  touch-action: pan-y;
  overflow-x: hidden;
}

/* Pull-to-refresh hint */
.pull-to-refresh-hint {
  position: fixed;
  top: env(safe-area-inset-top, 20px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.pull-to-refresh-hint.visible {
  opacity: 1;
}

/* ===== LOADING STATES ===== */

.loading-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
}

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

.progressive-enhancement {
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progressive-enhancement.loaded {
  opacity: 1;
  transform: translateY(0);
}

/* ===== ENHANCED ERROR STATES ===== */

.error-message {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
  color: #b91c1c;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: error-slide-in 0.3s ease-out;
}

.error-message::before {
  content: '⚠️';
  font-size: 20px;
  flex-shrink: 0;
}

@keyframes error-slide-in {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.retry-button {
  background: #dc2626;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.retry-button:active {
  background: #b91c1c;
}

/* ===== MOBILE-SPECIFIC LAYOUT IMPROVEMENTS ===== */

/* Safe area optimizations */
.mobile-safe-container {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Enhanced navigation for mobile */
.mobile-nav {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  z-index: 100;
}

.mobile-nav button {
  flex: 1;
  min-height: 48px;
  border-radius: 8px;
  font-weight: 500;
}

/* Progress indicator improvements */
.progress-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  margin: 16px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color, #0066cc), var(--secondary-color, #0052a3));
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: progress-shimmer 2s infinite;
}

@keyframes progress-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus visibility for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--primary-color, #0066cc);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Screen reader support */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn,
  button {
    border: 2px solid currentColor;
  }

  .error-message {
    border-width: 2px;
  }
}

/* Reduced motion support */
@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;
  }
}

/* ===== RESPONSIVE BREAKPOINT OPTIMIZATIONS ===== */

/* iPhone SE (320px) */
@media (max-width: 320px) {
  .mobile-nav {
    padding: 8px 12px;
  }

  .mobile-nav button {
    min-height: 44px;
    font-size: 14px;
  }

  input, textarea, select {
    padding: 12px 14px !important;
  }
}

/* Standard iPhone (375px) */
@media (max-width: 375px) {
  .btn {
    padding: 14px 20px;
  }
}

/* Large phones (414px+) */
@media (min-width: 414px) {
  .mobile-nav {
    padding: 16px 20px;
  }

  .mobile-nav button {
    min-height: 48px;
  }
}

/* ===== ADD-ONS STEP — MOBILE COMPACT ===== */
@media (max-width: 600px) {
  .step-content {
    padding: 16px 12px !important;
  }

  .step-content h2 {
    font-size: 1.5rem !important;
    margin-bottom: 8px !important;
  }

  .step-content h2 + p {
    font-size: 0.95rem !important;
  }

  .step-content h2 ~ div[style*="background: #fff3cd"] {
    font-size: 0.85rem !important;
    padding: 8px 14px !important;
    margin-top: 12px !important;
  }

  .step-content h3 {
    font-size: 1.1rem !important;
    margin-bottom: 12px !important;
  }

  .step-content h3 + p {
    font-size: 0.9rem !important;
    margin-bottom: 16px !important;
  }

  .step-content > div:first-child > div:first-child {
    margin-bottom: 24px !important;
  }

  .addon-card,
  .addon-card-qty {
    padding: 14px !important;
    border-radius: 10px !important;
  }

  .addon-card h4,
  .addon-card-qty h4 {
    font-size: 1rem !important;
  }

  .addon-card p,
  .addon-card-qty p {
    font-size: 13px !important;
  }

  .addon-card div[style*="font-size: 20px"],
  .addon-card-qty div[style*="font-size: 20px"] {
    font-size: 16px !important;
  }

  .addon-card .addon-select-btn {
    padding: 6px 14px !important;
    font-size: 13px !important;
  }

  .addon-card .quantity-controls,
  .addon-card-qty .quantity-controls {
    padding: 6px 8px !important;
    gap: 6px !important;
  }

  .addon-card .quantity-controls .qty-label,
  .addon-card-qty .quantity-controls .qty-label {
    display: none !important;
  }

  .addon-card .quantity-controls button,
  .addon-card-qty .quantity-controls button {
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
  }

  .addon-card .qty-display,
  .addon-card-qty .qty-display {
    min-width: 32px !important;
    height: 32px !important;
    line-height: 32px !important;
    font-size: 16px !important;
  }

  .addon-card .addon-image-container img,
  .addon-card-qty .addon-image-container img,
  .addon-card-qty img {
    height: 100px !important;
  }
}

/* ===== COMPACT SERVICE CARDS — Mobile ===== */
@media (max-width: 600px) {
  .service-card {
    padding: 16px !important;
    border-radius: 12px !important;
  }
  .service-card .service-image-container img {
    height: 120px !important;
  }
  .service-card h3 {
    font-size: 1.1rem !important;
    margin-bottom: 8px !important;
  }
  .service-card p {
    font-size: 13px !important;
    margin-bottom: 12px !important;
  }
}

/* ===== FLOATING PRICE PILL — Mobile only ===== */
.price-pill {
  display: none;
  position: sticky;
  top: 0;
  z-index: 99;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  padding: 8px 16px;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.price-pill.visible {
  display: flex;
}

.price-pill-service {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.price-pill-total {
  font-weight: 700;
  color: var(--template-primary, #007bff);
  font-size: 16px;
}

/* Only show price pill on mobile */
@media (min-width: 601px) {
  .price-pill {
    display: none !important;
  }
}

/* ===== TABLET LANDSCAPE (900–1199px) ===== */
@media (min-width: 900px) and (max-width: 1199px) {
  /* Minimum touch targets */
  button,
  .btn,
  .service-option,
  .time-slot,
  .addon-item,
  [role="button"],
  input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Service grid — responsive auto-fit */
  .service-grid,
  [class*="service"] > div[style*="grid"] {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
  }

  /* Footer nav buttons — capped width */
  #universal-back,
  #universal-next {
    max-width: 200px;
  }

  /* Step indicators — horizontal with labels */
  .step-indicators {
    max-width: 600px;
  }

  .step-label {
    display: block;
  }
}

/* Tablet portrait (768px) */
@media (min-width: 768px) and (max-width: 1024px) {
  .mobile-nav {
    position: relative;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    margin-bottom: 16px;
  }
}

/* ===== STICKY REVIEW CTA — hide inline buttons on mobile ===== */
@media (max-width: 768px) {
  .review-actions {
    display: none !important;
  }
}