/* ── Shell ──────────────────────────────────────────────────────────────── */

.ep-popup {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  box-sizing: border-box;

  /* Isolated stacking context: prevents z-index fights with page builders */
  isolation: isolate;

  /* Prevent background scroll on touch devices */
  touch-action: none;
  overscroll-behavior: none;

  /* Safe area insets for iOS notch / home indicator */
  padding: max(0.75rem, env(safe-area-inset-top, 0px))
           max(0.75rem, env(safe-area-inset-right, 0px))
           max(0.75rem, env(safe-area-inset-bottom, 0px))
           max(0.75rem, env(safe-area-inset-left, 0px));

  /* Full viewport height including browser chrome on mobile */
  max-height: 100vh;
  max-height: 100dvh;
  max-height: -webkit-fill-available;
}

.ep-popup.ep-is-open {
  display: flex;
}

/* ── Body scroll lock class (applied by JS) ─────────────────────────────── */
/* JS uses position:fixed + top:-scrollY for iOS. This adds the bounce guard. */

body.ep-modal-open {
  overscroll-behavior: none;
}

/* ── Overlay ────────────────────────────────────────────────────────────── */

.ep-popup__overlay {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

/* ── Container ──────────────────────────────────────────────────────────── */

.ep-popup__container {
  position: relative;
  background: #fff;
  max-height: 90vh;
  max-height: 90dvh;
  max-width: calc(100vw - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* momentum scroll on iOS */
  overscroll-behavior: contain;      /* prevent scroll chaining to background */
  border-radius: 4px;
  z-index: 1;
}

/* ── Sizes ──────────────────────────────────────────────────────────────── */

.ep-popup--small    .ep-popup__container { width: 400px; }
.ep-popup--medium   .ep-popup__container { width: 600px; }
.ep-popup--large    .ep-popup__container { width: 800px; }
.ep-popup--fullscreen .ep-popup__container {
  width: 100%;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  border-radius: 0;
}

/* ── Close button ───────────────────────────────────────────────────────── */

.ep-popup__close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 4px;
  z-index: 2;
  /* Minimum tap target size for mobile */
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.ep-popup__close:hover { color: #000; }

.ep-popup__close:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Body ───────────────────────────────────────────────────────────────── */

.ep-popup__body {
  padding: 40px 32px 32px;
}

/* ── Screen-reader only utility ─────────────────────────────────────────── */
/* Own implementation: WP core .screen-reader-text is overridden by many themes */

.ep-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── Animations ─────────────────────────────────────────────────────────── */

/* Fade */
.ep-popup--fade {
  opacity: 0;
  transition: opacity 0.25s ease;
}
.ep-popup--fade.ep-is-open {
  opacity: 1;
}
.ep-popup--fade .ep-popup__container {
  transform: scale(0.97);
  transition: transform 0.25s ease;
}
.ep-popup--fade.ep-is-open .ep-popup__container {
  transform: scale(1);
}

/* Slide */
.ep-popup--slide {
  opacity: 0;
  transition: opacity 0.25s ease;
}
.ep-popup--slide.ep-is-open {
  opacity: 1;
}
.ep-popup--slide .ep-popup__container {
  transform: translateY(-24px);
  transition: transform 0.3s ease;
}
.ep-popup--slide.ep-is-open .ep-popup__container {
  transform: translateY(0);
}

/* Respect prefers-reduced-motion: skip animation, show immediately */
@media (prefers-reduced-motion: reduce) {
  .ep-popup--fade,
  .ep-popup--slide {
    transition: none;
    opacity: 1;
  }
  .ep-popup--fade .ep-popup__container,
  .ep-popup--slide .ep-popup__container {
    transition: none;
    transform: none;
  }
}

/* ── Encapsulated mode ──────────────────────────────────────────────────── */

.ep-popup--encapsulated .ep-popup__body,
.ep-popup--encapsulated .ep-popup__body * {
  box-sizing: border-box;
}

.ep-popup--encapsulated .ep-popup__body input,
.ep-popup--encapsulated .ep-popup__body textarea,
.ep-popup--encapsulated .ep-popup__body select,
.ep-popup--encapsulated .ep-popup__body button {
  font-family: inherit;
  font-size: inherit;
}
