/**
 * Mobile UX Fixes - ACT-27
 * Critical improvements for mobile engagement
 */

/* ===== 1. TOUCH TARGETS (minimum 44x44px) ===== */
:is(#signup-page, #login-page, .mobile-ux-wizard) .btn,
:is(#signup-page, #login-page, .mobile-ux-wizard) button,
:is(#signup-page, #login-page, .mobile-ux-wizard) [type="button"],
:is(#signup-page, #login-page, .mobile-ux-wizard) [type="submit"],
:is(#signup-page, #login-page, .mobile-ux-wizard) [type="reset"],
#hero-landing a.tw-bg-brand-blue,
#hero-landing a.tw-border-2,
#hero-landing-v2 a.tw-bg-brand-blue,
#hero-landing-v2 a.tw-border-2 {
  min-height: 44px;
  min-width: 44px;
}

/* Form inputs need comfortable touch targets */
:is(#signup-page, #login-page, .mobile-ux-wizard) .input-lg,
:is(#signup-page, #login-page, .mobile-ux-wizard) input[type="text"],
:is(#signup-page, #login-page, .mobile-ux-wizard) input[type="email"],
:is(#signup-page, #login-page, .mobile-ux-wizard) input[type="password"],
:is(#signup-page, #login-page, .mobile-ux-wizard) input[type="tel"],
:is(#signup-page, #login-page, .mobile-ux-wizard) input[type="number"],
:is(#signup-page, #login-page, .mobile-ux-wizard) textarea,
:is(#signup-page, #login-page, .mobile-ux-wizard) select {
  min-height: 48px; /* Slightly larger for better mobile UX */
  font-size: 16px !important; /* Prevents iOS zoom on focus */
}

/* Social login buttons */
:is(#signup-page, #login-page) .btn-google,
:is(#signup-page, #login-page) .btn-microsoft,
:is(#signup-page, #login-page) .omniauth-social-buttons a {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== 2. MOBILE VIEWPORT OPTIMIZATIONS ===== */
@supports (-webkit-touch-callout: none) {
  /* iOS specific fixes */
  body {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(59, 150, 210, 0.3);
  }

  :is(#signup-page, #login-page, .mobile-ux-wizard) input,
  :is(#signup-page, #login-page, .mobile-ux-wizard) textarea,
  :is(#signup-page, #login-page, .mobile-ux-wizard) select {
    font-size: 16px !important; /* Prevents zoom on iOS */
  }
}

/* ===== 3. RESPONSIVE BREAKPOINT FIXES ===== */
/* Extra small devices (320px+) */
@media (max-width: 374px) {
  :is(#hero-landing, #hero-landing-v2) .tw-text-3xl { font-size: 1.5rem !important; line-height: 1.2 !important; }
  :is(#hero-landing, #hero-landing-v2) .tw-text-4xl { font-size: 1.75rem !important; line-height: 1.2 !important; }
  :is(#hero-landing, #hero-landing-v2) .tw-text-5xl { font-size: 2rem !important; line-height: 1.2 !important; }

  /* Hero section compact */
  #hero-landing .tw-pt-16 { padding-top: 1rem !important; }
  #hero-landing .tw-pb-12 { padding-bottom: 1.5rem !important; }

  /* Reduce container padding */
  :is(#hero-landing, #hero-landing-v2) .tw-px-4 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }

  /* Stack CTAs with proper spacing */
  #hero-landing .tw-flex.tw-flex-col.sm\\:tw-flex-row {
    gap: 0.75rem !important;
  }

  /* Trust indicators in column */
  #hero-landing .tw-flex.tw-flex-col.sm\\:tw-flex-row.tw-items-center {
    flex-direction: column !important;
    gap: 0.5rem !important;
  }
}

/* Small devices (375px - 413px) */
@media (min-width: 375px) and (max-width: 413px) {
  :is(#hero-landing, #hero-landing-v2) .tw-text-3xl { font-size: 1.625rem !important; }
  :is(#hero-landing, #hero-landing-v2) .tw-text-4xl { font-size: 1.875rem !important; }
  :is(#hero-landing, #hero-landing-v2) .tw-text-5xl { font-size: 2.25rem !important; }
}

/* Medium phones (414px - 767px) */
@media (min-width: 414px) and (max-width: 767px) {
  :is(#hero-landing, #hero-landing-v2) .tw-text-3xl { font-size: 1.75rem !important; }
  :is(#hero-landing, #hero-landing-v2) .tw-text-4xl { font-size: 2.25rem !important; }
  :is(#hero-landing, #hero-landing-v2) .tw-text-5xl { font-size: 2.5rem !important; }
}

/* ===== 4. FORM IMPROVEMENTS FOR MOBILE ===== */
@media (max-width: 767px) {
  /* Registration form container */
  #signup-page .container,
  #login-page .container {
    padding-left: 16px !important;
    padding-right: 16px !important;
    max-width: 100% !important;
  }

  /* Form wrapper adjustments */
  #signup-page .form-wrapper,
  #login-page .form-wrapper {
    padding: 0 !important;
  }

  #signup-page .form-data,
  #login-page .form-data {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* Social buttons full width on mobile */
  .omniauth-social-buttons a,
  .signup-divider + div a,
  .tw-mt-6 a.btn {
    width: 100% !important;
    margin-bottom: 0.5rem;
  }

  /* Form card full width */
  #signup-page .tw-bg-white.tw-rounded-xl.tw-shadow-lg.tw-p-6,
  #login-page .tw-bg-white.tw-rounded-xl.tw-shadow-lg.tw-p-6 {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    border-radius: 0.75rem;
  }

  /* Input spacing */
  #signup-page .tw-space-y-4 > * + *,
  #login-page .tw-space-y-4 > * + *,
  .mobile-ux-wizard .tw-space-y-4 > * + * {
    margin-top: 0.75rem !important;
  }

  /* Submit button prominent */
  .signup-submit,
  .signin-submit {
    font-size: 1.125rem !important;
    padding: 1rem !important;
    min-height: 52px;
  }
}

/* ===== 5. NAVIGATION - HAMBURGER MENU ===== */
.mobile-menu-container {
  position: relative;
  z-index: 50;
}

.mobile-menu-button {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
}

.mobile-menu-button:focus {
  outline: 2px solid #3b96d2;
  outline-offset: 2px;
}

.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.mobile-menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

.mobile-menu-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 320px;
  background: white;
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.3s ease-out;
  overflow-y: auto;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
}

.mobile-menu-panel.active {
  transform: translateX(0);
}

.mobile-menu-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
}

.mobile-menu-link {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  color: #323232;
  text-decoration: none;
  font-weight: 500;
  min-height: 56px;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.2s;
}

.mobile-menu-link:active {
  background-color: #f3f4f6;
}

.mobile-menu-cta {
  background: #3b96d2;
  color: white !important;
  margin: 1rem;
  border-radius: 0.75rem;
  justify-content: center;
  font-weight: 600;
}

/* ===== 6. IMAGE OPTIMIZATIONS ===== */
/* Hero image responsive */
#hero-landing img,
[data-section="hero"] img {
  max-width: 100%;
  height: auto;
}

@media (max-width: 767px) {
  #hero-landing img {
    margin-top: 1.5rem;
  }
}

/* Lazy loading fade-in */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s;
}

img[loading="lazy"].loaded,
img[loading="lazy"][data-loaded="true"] {
  opacity: 1;
}

/* ===== 7. ACCESSIBILITY IMPROVEMENTS ===== */
/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #3b96d2;
  outline-offset: 2px;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #3b96d2;
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== 8. LOADING STATES ===== */
.btn-loading {
  position: relative;
  color: transparent !important;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin-top: -10px;
  margin-left: -10px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== 9. SOCIAL LOGIN PROMINENT ===== */
.social-login-section {
  margin: 1.5rem 0;
}

.social-login-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1rem 0;
  color: #606060;
  font-size: 0.875rem;
}

.social-login-divider::before,
.social-login-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #e5e7eb;
}

.social-login-divider span {
  padding: 0 1rem;
}

.social-login-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.social-login-buttons .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.2s;
}

.social-login-buttons .btn-google {
  background: white;
  border: 1px solid #dadce0;
  color: #3c4043;
}

.social-login-buttons .btn-google:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.social-login-buttons .btn-microsoft {
  background: #2f2f2f;
  color: white;
  border: none;
}

.social-login-buttons .btn-microsoft:hover {
  background: #1f1f1f;
}

/* ===== 10. INLINE VALIDATION ===== */
.field-with-error input,
.field-with-error select,
.field-with-error textarea {
  border-color: #c7254e;
  background-color: #fef2f2;
}

.field-error-message {
  color: #c7254e;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.field-success input,
.field-success select {
  border-color: #57af17;
  background-color: #f0fdf4;
}

/* Password strength indicator */
.password-strength {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  margin-top: 0.5rem;
  overflow: hidden;
}

.password-strength-bar {
  height: 100%;
  transition: width 0.3s, background-color 0.3s;
}

.password-strength-bar.weak { background: #ef4444; width: 33%; }
.password-strength-bar.medium { background: #f59e0b; width: 66%; }
.password-strength-bar.strong { background: #57af17; width: 100%; }
