/**
 * TokTix Modal Checkout Styles
 * White-label modal checkout experience for WordPress
 *
 * @package TokTix
 * @version 1.4.0
 */

/* ==========================================================================
   Modal Container & Backdrop
   ========================================================================== */

.toktix-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999999; /* Above WordPress admin bar (999999) */
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.toktix-modal.active {
  opacity: 1;
  visibility: visible;
}

.toktix-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ==========================================================================
   Modal Content
   ========================================================================== */

.toktix-modal-content {
  position: relative;
  width: 90%;
  max-width: 500px;  /* Match ticket form width */
  max-height: 90vh;
  /* Background set via JS inline style to match custom header color */
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  /* min-height removed - modal now resizes dynamically based on content */
}

.toktix-modal.active .toktix-modal-content {
  transform: scale(1);
}

/* ==========================================================================
   Modal Header
   ========================================================================== */

.toktix-modal-header {
  background: #1E1E21; /* blackBackground - set as fallback, overridden by inline style */
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.toktix-modal-title {
  color: #ffffff;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ==========================================================================
   Modal Body
   ========================================================================== */

.toktix-modal-body {
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  /* Removed display: flex to prevent layout issues with tall content */
  max-height: calc(90vh - 80px); /* 90vh minus approximate header height */
  /* Background set via JS inline style to match custom header color */
  /* SCROLLING FIX: When iframe content exceeds max-height, this container scrolls */
}

/* ==========================================================================
   Close Button
   ========================================================================== */

.toktix-modal-close {
  width: 36px;
  height: 36px;
  /* Background set via JS inline style to match custom settings */
  border: 1px solid #999999; /* grayMuted from TokTix color scheme */
  border-radius: 50%;
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
  padding: 0;
  flex-shrink: 0;
}

.toktix-modal-close:hover {
  /* Background set via JS inline style on hover */
  transform: scale(1.1);
}

.toktix-modal-close:focus {
  outline: 2px solid #8b5cf6;
  outline-offset: 2px;
}

.toktix-modal-close:active {
  transform: scale(0.95);
}

/* ==========================================================================
   Iframe Container
   ========================================================================== */

.toktix-modal-iframe {
  width: 100%;
  border: none;
  display: block;
  background: transparent;
  min-height: 300px; /* Minimum height while loading */
  /* SCROLLING FIX: Prevent flex shrinking, allow modal-body to scroll */
  flex-shrink: 0;
  /* Fade in once revealed (starts at opacity:0 via inline style). #1897 */
  transition: opacity 0.25s ease;
}

/* ==========================================================================
   Loading State (#1897 mobile polish)
   The modal appears instantly with this spinner while the embed-session token
   is minted and the iframe loads; revealIframe() dismisses it once the embed
   signals it has rendered, hiding the embed page's own loader flash.
   ========================================================================== */

/* Give the body room for the spinner before the iframe exists. Removed on
   reveal so desktop modals resume sizing to content. */
.toktix-modal.is-loading .toktix-modal-body {
  min-height: 50vh;
}

.toktix-modal-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  background: inherit; /* matches the modal body's inline background color */
  transition: opacity 0.25s ease;
}

.toktix-modal-loading--hidden {
  opacity: 0;
  pointer-events: none;
}

.toktix-modal-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #B3E053; /* greenPrimary */
  border-radius: 50%;
  animation: toktix-spin 0.8s linear infinite;
}

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

.toktix-modal-error {
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding: 24px;
  text-align: center;
}

/* ==========================================================================
   Success Message
   ========================================================================== */

.toktix-modal-success {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  z-index: 15;
  padding: 40px;
  text-align: center;
  animation: toktix-fadeIn 0.4s ease;
}

@keyframes toktix-fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toktix-success-icon {
  margin-bottom: 24px;
  animation: toktix-scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes toktix-scaleIn {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

.toktix-modal-success h2 {
  margin: 0 0 12px 0;
  color: #111827;
  font-size: 28px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.toktix-modal-success p {
  margin: 0;
  color: #6b7280;
  font-size: 16px;
  line-height: 1.6;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */

@media (max-width: 768px) {
  .toktix-modal-content {
    width: 95%;
    max-width: none;
    max-height: 95vh;
    border-radius: 12px;
  }

  .toktix-modal-header {
    padding: 16px 20px;
  }

  .toktix-modal-title {
    font-size: 18px;
  }

  .toktix-modal-close {
    width: 32px;
    height: 32px;
    font-size: 20px;
  }

  .toktix-modal-success {
    padding: 24px;
  }

  .toktix-modal-success h2 {
    font-size: 24px;
  }

  .toktix-modal-success p {
    font-size: 14px;
  }

  .toktix-success-icon svg {
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 480px) {
  .toktix-modal-content {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  /* Full-screen mobile (#1897 mobile fix).
     The body fills the space under the header and the iframe fills the body.
     The `!important` height overrides the inline pixel height set by
     resizeIframe() — on the multi-step checkout the embed reports a stale/short
     body.scrollHeight, which left the modal occupying only ~half the screen
     with dead backdrop below. Letting the iframe fill the viewport and scroll
     its own content is robust regardless of which checkout step is showing. */
  .toktix-modal-body {
    flex: 1 1 auto;
    max-height: none;
    -webkit-overflow-scrolling: touch;
  }

  .toktix-modal-iframe {
    height: 100% !important;
    min-height: 100%;
  }
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
  .toktix-modal-backdrop {
    background: rgba(0, 0, 0, 0.9);
  }

  .toktix-modal-close {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #ffffff;
  }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .toktix-modal,
  .toktix-modal-content,
  .toktix-modal-close,
  .toktix-modal-iframe,
  .toktix-modal-success,
  .toktix-success-icon,
  .toktix-modal-loading,
  .toktix-modal-spinner {
    animation: none !important;
    transition: none !important;
  }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
  .toktix-modal {
    display: none !important;
  }
}
