/**
 * Login Mobile Optimizations
 * Stili specifici per migliorare l'esperienza su dispositivi mobili
 */

/* ===== SMOOTH SCROLLING ===== */
html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ===== TOUCH OPTIMIZATION ===== */
* {
  -webkit-tap-highlight-color: rgba(11, 179, 181, 0.1);
  -webkit-touch-callout: none;
}

/* Allow text selection only in inputs */
input,
textarea {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* ===== MOBILE VIEWPORT FIX ===== */
@media (max-width: 768px) {
  html {
    height: -webkit-fill-available;
  }
  
  body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    /* Fix per iOS con notch */
    padding-top: max(90px, calc(90px + env(safe-area-inset-top)));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  
  .app-container {
    padding-bottom: max(28px, calc(28px + env(safe-area-inset-bottom))) !important;
    min-height: auto !important;
    overflow: visible !important;
  }
  
  .card {
    margin-bottom: 16px;
    /* Assicura che il contenuto sia sempre visibile */
    max-height: none !important;
    overflow: visible !important;
  }
}

/* ===== iOS SPECIFIC FIXES ===== */
@supports (-webkit-touch-callout: none) {
  /* iPhone X and newer with notch */
  body {
    padding-top: max(90px, calc(90px + env(safe-area-inset-top)));
  }
  
  .card {
    /* Previeni che il contenuto venga tagliato */
    overflow: visible !important;
    max-height: none !important;
  }
  
  /* Fix per viewport height su iOS */
  html {
    height: -webkit-fill-available;
  }
  
  body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
}

/* ===== IMPROVED INPUT STYLES FOR MOBILE ===== */
@media (max-width: 480px) {
  /* Better touch targets */
  input,
  select,
  button,
  .oauth-btn {
    min-height: 48px;
    -webkit-appearance: none;
    appearance: none;
  }
  
  /* Prevent zoom on input focus on iOS */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="date"],
  select {
    font-size: 16px !important;
  }
  
  /* Better spacing */
  .card {
    margin-bottom: 16px;
  }
  
  /* Optimize modal for mobile */
  #registerModal,
  #businessModal {
    padding: 0;
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
  }
  
  #registerModal > div,
  #businessModal > div {
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    top: auto !important;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4) !important;
    border: 2px solid rgba(11, 179, 181, 0.3) !important;
    border-bottom: none !important;
  }
  
  /* Improve form spacing */
  form input,
  form select {
    margin-bottom: 14px;
  }
  
  /* Better button spacing */
  .oauth-btn + .oauth-btn {
    margin-top: 12px;
  }
  
  /* Optimize logo in modal */
  #footerLogo img {
    width: 200px !important;
    height: 140px !important;
  }
  
  /* Improve modal close button visibility */
  .modal-close-btn {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.8rem !important;
    background: #ffffff !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
    z-index: 10;
  }
}

/* ===== VERY SMALL SCREENS ===== */
@media (max-width: 374px) {
  .card {
    padding: 16px 12px;
    margin-bottom: 12px;
  }
  
  .card h2 {
    font-size: 1.2rem;
  }
  
  .card p {
    font-size: 0.85rem;
  }
  
  .oauth-btn {
    padding: 10px 12px !important;
    font-size: 0.85rem !important;
    min-height: 44px;
  }
  
  input,
  select {
    padding: 10px 12px;
    font-size: 15px !important;
  }
  
  #registerModal > div,
  #businessModal > div {
    padding: 20px 12px 12px 12px !important;
  }
  
  #footerLogo img {
    width: 160px !important;
    height: 110px !important;
  }
  
  .modal-close-btn {
    width: 36px !important;
    height: 36px !important;
    font-size: 1.5rem !important;
  }
}

/* ===== LANDSCAPE MODE OPTIMIZATION ===== */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding-top: 60px;
  }
  
  .app-header {
    padding: 10px 16px;
  }
  
  .app-logo {
    width: 40px;
    height: 40px;
  }
  
  .card {
    padding: 16px;
  }
  
  .card h2 {
    font-size: 1.2rem;
    margin-bottom: 8px;
  }
  
  .card p {
    margin-bottom: 12px;
  }
  
  .oauth-btn {
    padding: 10px 14px !important;
    min-height: 40px;
  }
  
  input,
  select {
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  
  .divider {
    margin: 12px 0;
  }
  
  #registerModal > div {
    max-height: 85vh;
    padding: 16px !important;
  }
  
  #footerLogo {
    display: none;
  }
}

/* ===== IMPROVED ANIMATIONS FOR MOBILE ===== */
@media (prefers-reduced-motion: no-preference) and (max-width: 768px) {
  /* Smooth transitions */
  button,
  .oauth-btn,
  input,
  .card {
    transition: all 0.2s ease-out;
  }
  
  /* Button press feedback */
  button:active,
  .oauth-btn:active {
    transform: scale(0.98);
    transition: transform 0.1s ease-out;
  }
  
  /* Modal entrance */
  #registerModal {
    transition: opacity 0.3s ease-out;
  }
  
  #registerModal[style*="display: flex"] > div {
    animation: slideUpMobile 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  }
  
  @keyframes slideUpMobile {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
}

/* ===== SAFE AREA INSETS (iOS Notch Support) ===== */
@supports (padding: max(0px)) {
  body {
    padding-top: max(90px, calc(90px + env(safe-area-inset-top)));
    padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
  }
  
  .app-header {
    padding-top: max(16px, calc(16px + env(safe-area-inset-top)));
    height: auto;
    min-height: 70px;
  }
  
  .app-container {
    padding-bottom: max(28px, calc(28px + env(safe-area-inset-bottom))) !important;
  }
  
  @media (max-width: 480px) {
    #registerModal > div {
      padding-bottom: max(16px, calc(16px + env(safe-area-inset-bottom))) !important;
      max-height: calc(90vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
  }
}

/* ===== DARK MODE SUPPORT ===== */
/* Future dark mode implementation - currently maintaining light theme */

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid #0bb3b5;
  outline-offset: 2px;
}

/* ===== LOADING STATE ===== */
.loading {
  pointer-events: none;
  opacity: 0.6;
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ===== OPTIMIZED SCROLLBAR FOR MOBILE WEBKIT ===== */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(11, 179, 181, 0.3);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(11, 179, 181, 0.5);
}
