/* ===================================
   WAITLIST MODAL STYLES
   Enhanced Design - Fully Responsive
   =================================== */

/* Modal Overlay - Dark Background */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: 1rem;
}

.modal-overlay.active,
.modal-overlay[aria-hidden='false'] {
  opacity: 1;
  visibility: visible;
}

/* Modal Container - White Box */
.modal-container {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  height: auto;
  max-height: 90vh;
  position: relative;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal-container,
.modal-overlay[aria-hidden='false'] .modal-container {
  transform: scale(1);
}

/* Close Button - Circular, Top Right */
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  background: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: rotate(90deg);
}

.modal-close svg {
  width: 24px;
  height: 24px;
}

/* Modal Content Container */
.modal-content {
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  position: relative;
}

/* Modal Header */
.modal-header {
  padding: 1.5rem 2rem 0.25rem 2rem;
  text-align: left;
}

.modal-badge {
  display: inline-block;
  background: #d1fe17;
  color: #000000;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: 100px;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-header h2,
#waitlist-modal-title {
  font-size: 1.75rem !important;
  font-weight: 700;
  margin: 0 0 0.25rem 0 !important;
  color: #000000;
  line-height: 1.2;
  text-align: left;
}

.modal-header p {
  font-size: 0.9375rem;
  line-height: 1.5;
  color: rgba(0, 0, 0, 0.7);
  margin: 0 0 0.25rem 0;
}

/* Iframe Container */
.modal-content iframe {
  width: 100%;
  height: auto;
  min-height: 550px;
  border: none;
  display: block;
  margin-top: -1.5rem;
}

/* Mobile Responsive (≤768px) */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 1.5rem 0 0 0; /* Add top padding for better spacing */
    align-items: flex-start; /* Position modal starting from top */
  }

  .modal-container {
    border-radius: 20px; /* Rounded all corners for floating effect */
    width: calc(100% - 1rem); /* Add horizontal margins */
    max-width: calc(100% - 1rem);
    height: auto;
    max-height: calc(100vh - 3rem - env(safe-area-inset-top, 0));
    max-height: calc(100dvh - 3rem - env(safe-area-inset-top, 0)); /* Dynamic viewport with spacing */
    transform: translateY(-100%); /* Slide in from top */
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    margin: 0 auto; /* Center horizontally */
    margin-top: env(safe-area-inset-top, 0); /* Respect iPhone notch/status bar */
  }

  .modal-overlay.active .modal-container,
  .modal-overlay[aria-hidden='false'] .modal-container {
    transform: translateY(0);
  }

  .modal-close {
    top: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.8);
  }

  .modal-close svg {
    width: 22px;
    height: 22px;
  }

  .modal-content {
    max-height: calc(100vh - 3rem - env(safe-area-inset-top, 0));
    max-height: calc(100dvh - 3rem - env(safe-area-inset-top, 0));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-header {
    padding: 1.25rem 1.5rem 0.5rem 1.5rem;
    padding-right: 4rem; /* Space for close button */
    padding-top: calc(1.25rem + env(safe-area-inset-top, 0)); /* Respect notch area */
  }

  .modal-badge {
    font-size: 0.6875rem;
    padding: 0.3125rem 0.75rem;
    margin-bottom: 0.75rem;
  }

  .modal-header h2,
  #waitlist-modal-title {
    font-size: 1.375rem !important;
    margin-bottom: 0.25rem !important;
    line-height: 1.3;
    text-align: left;
  }

  .modal-header p {
    font-size: 0.9375rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
  }

  .modal-content iframe {
    min-height: 500px;
    margin-top: -1rem;
    padding-bottom: env(safe-area-inset-bottom, 16px); /* Space for bottom of form */
  }
}

/* Medium Mobile (≤640px) - iPhone 14 Pro, etc */
@media (max-width: 640px) {
  .modal-overlay {
    padding: 1rem 0 0 0; /* Slightly less top padding on smaller screens */
  }

  .modal-container {
    max-height: calc(100vh - 2rem - env(safe-area-inset-top, 0));
    max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0));
    width: calc(100% - 1rem);
    max-width: calc(100% - 1rem);
  }

  .modal-content {
    max-height: calc(100vh - 2rem - env(safe-area-inset-top, 0));
    max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0));
  }

  .modal-header {
    padding: 1rem 1.25rem 0.5rem 1.25rem;
    padding-right: 4rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0));
  }

  .modal-badge {
    font-size: 0.625rem;
    padding: 0.25rem 0.625rem;
    margin-bottom: 0.625rem;
  }

  .modal-header h2,
  #waitlist-modal-title {
    font-size: 1.25rem !important;
    margin-bottom: 0.25rem !important;
    text-align: left;
    line-height: 1.25;
  }

  .modal-header p {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
  }

  .modal-content iframe {
    min-height: 480px;
    margin-top: -0.75rem;
  }
}

/* Extra Small Mobile (≤480px) - Smaller iPhones */
@media (max-width: 480px) {
  .modal-overlay {
    padding: 0.75rem 0 0 0; /* Minimal top padding on very small screens */
  }

  .modal-container {
    max-height: calc(100vh - 1.5rem - env(safe-area-inset-top, 0));
    max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top, 0));
    border-radius: 16px; /* All corners rounded */
    width: calc(100% - 0.75rem);
    max-width: calc(100% - 0.75rem);
  }

  .modal-content {
    max-height: calc(100vh - 1.5rem - env(safe-area-inset-top, 0));
    max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top, 0));
  }

  .modal-close {
    width: 40px;
    height: 40px;
    top: 0.875rem;
    right: 0.875rem;
  }

  .modal-close svg {
    width: 20px;
    height: 20px;
  }

  .modal-header {
    padding: 0.875rem 1.125rem 0.5rem 1.125rem;
    padding-right: 3.5rem;
    padding-top: calc(0.875rem + env(safe-area-inset-top, 0));
  }

  .modal-badge {
    font-size: 0.5625rem;
    padding: 0.1875rem 0.5rem;
    margin-bottom: 0.5rem;
  }

  .modal-header h2,
  #waitlist-modal-title {
    font-size: 1.125rem !important;
    margin-bottom: 0.25rem !important;
    text-align: left;
    line-height: 1.25;
  }

  .modal-header p {
    font-size: 0.8125rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
  }

  .modal-content iframe {
    min-height: 460px;
    margin-top: -0.5rem;
  }
}

/* Prevent Body Scroll When Modal Open */
body.waitlist-modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* iOS-specific fixes for iPhone 14 and similar devices */
@supports (-webkit-touch-callout: none) {
  /* iPhone 14 Pro, Pro Max with notch - Optimal top positioning */
  @media (max-width: 430px) and (max-height: 932px) {
    .modal-overlay {
      padding-top: 1rem;
    }

    .modal-container {
      max-height: calc(100vh - 2rem - env(safe-area-inset-top, 0));
      max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0));
      margin-top: env(safe-area-inset-top, 0);
    }

    .modal-content {
      max-height: calc(100vh - 2rem - env(safe-area-inset-top, 0));
      max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0));
    }
    
    .modal-header {
      padding-top: calc(1rem + env(safe-area-inset-top, 20px));
    }
  }

  /* Ensure smooth scrolling on iOS */
  .modal-content {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
  }

  /* Fix for iOS Safari address bar */
  body.waitlist-modal-open {
    position: fixed;
    overflow: hidden;
    width: 100%;
    height: 100vh;
    height: 100dvh;
  }
}
