/* ==========================================================================
   Flex Popups — Modern Clean Visitor Runtime Styles
   ========================================================================== */

.flex-popup-root[hidden] {
  display: none !important;
}

.flex-popup-root {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--flex-gap, 20px);
  box-sizing: border-box;
  pointer-events: none;
  font-family: inherit;
}

.flex-popup-root *,
.flex-popup-root *::before,
.flex-popup-root *::after {
  box-sizing: border-box;
}

/* Backdrop Overlay */
.flex-popup-overlay {
  position: absolute;
  inset: 0;
  background: var(--flex-overlay, #0f172a);
  opacity: var(--flex-overlay-opacity, 0.64);
  pointer-events: auto;
  backdrop-filter: blur(var(--flex-overlay-blur, 0px));
  -webkit-backdrop-filter: blur(var(--flex-overlay-blur, 0px));
  transition: opacity 0.2s ease;
}

.flex-overlay-gradient .flex-popup-overlay {
  background: linear-gradient(
    var(--flex-overlay-angle, 135deg),
    var(--flex-overlay, #0f172a),
    var(--flex-overlay-second, #000000)
  );
}

/* Modal Dialog Box */
.flex-popup-dialog {
  position: relative;
  pointer-events: auto;
  outline: none;
  background: var(--flex-bg, #ffffff);
  color: var(--flex-text, #0f172a);
  max-width: min(var(--flex-width, 560px), calc(100vw - 2 * var(--flex-gap, 20px)));
  width: 100%;
  max-height: min(var(--flex-max-height, 95dvh), calc(100dvh - 2 * var(--flex-gap, 20px)));
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: var(--flex-radius, 16px);
  border: var(--flex-border-width, 0px) solid var(--flex-border-color, #e2e8f0);
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  -webkit-overflow-scrolling: touch;
  will-change: transform, opacity;
}

/* Dialog Content Area */
.flex-popup-content {
  padding: var(--flex-pad, 28px);
  padding-top: max(var(--flex-pad, 28px), calc(var(--flex-close-size, 36px) + 20px));
  container-type: inline-size;
  overflow-wrap: anywhere;
}

.flex-popup-content > :first-child {
  margin-top: 0;
}

.flex-popup-content > :last-child {
  margin-bottom: 0;
}

.flex-popup-content .wp-block-button__link:not([style]):not(.has-background) {
  background: var(--flex-accent, #4f46e5);
  color: #ffffff;
}

/* Modern Close Button */
.flex-popup-close {
  position: absolute;
  z-index: 10;
  right: 12px;
  top: 12px;
  width: var(--flex-close-size, 36px);
  height: var(--flex-close-size, 36px);
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(241, 245, 249, 0.9);
  color: #475569;
  font-family: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.flex-popup-close:hover {
  background: #e2e8f0;
  color: #0f172a;
  transform: scale(1.05);
}

.flex-popup-close:active {
  transform: scale(0.95);
}

.flex-popup-close:focus-visible,
.flex-popup-dialog :focus-visible {
  outline: 2px solid var(--flex-accent, #4f46e5);
  outline-offset: 2px;
}

.flex-close-left .flex-popup-close {
  right: auto;
  left: 12px;
}

/* Positions */
.flex-pos-bottom-right {
  align-items: flex-end;
  justify-content: flex-end;
}

.flex-pos-bottom-left {
  align-items: flex-end;
  justify-content: flex-start;
}

.flex-pos-bottom-right .flex-popup-dialog,
.flex-pos-bottom-left .flex-popup-dialog {
  max-height: min(85dvh, 750px);
}

.flex-pos-fullscreen {
  padding: 0;
}

.flex-pos-fullscreen .flex-popup-dialog {
  border-radius: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100dvh;
}

/* Shadow Variations */
.flex-shadow-none .flex-popup-dialog {
  box-shadow: none;
}

.flex-shadow-soft .flex-popup-dialog {
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.08);
}

.flex-shadow-medium .flex-popup-dialog {
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

.flex-shadow-strong .flex-popup-dialog {
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

/* Preset Variations */
.flex-style-minimal .flex-popup-dialog {
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.flex-style-dark .flex-popup-dialog {
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.flex-style-dark .flex-popup-close {
  background: rgba(148, 163, 184, 0.2);
  color: var(--flex-text, #f8fafc);
}

.flex-style-glass .flex-popup-dialog {
  background: color-mix(in srgb, var(--flex-bg, #ffffff) 80%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.flex-style-brand .flex-popup-dialog {
  border-top: 5px solid var(--flex-accent, #4f46e5);
}

/* Entrance Animations */
.flex-popup-root.is-open:not(.flex-anim-none) .flex-popup-overlay {
  animation: flex-overlay-fade var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.flex-popup-root.is-open.flex-anim-zoom .flex-popup-dialog {
  animation: flex-zoom var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.flex-popup-root.is-open.flex-anim-slide .flex-popup-dialog {
  animation: flex-slide var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.flex-popup-root.is-open.flex-anim-slide-left .flex-popup-dialog {
  animation: flex-from-right var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.flex-popup-root.is-open.flex-anim-slide-right .flex-popup-dialog {
  animation: flex-from-left var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.flex-popup-root.is-open.flex-anim-bounce .flex-popup-dialog {
  animation: flex-bounce var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

.flex-popup-root.is-open.flex-anim-fade .flex-popup-dialog {
  animation: flex-fade var(--flex-motion, 260ms) var(--flex-enter-ease, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

@keyframes flex-zoom {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes flex-slide {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes flex-from-right {
  from { opacity: 0; transform: translateX(36px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes flex-from-left {
  from { opacity: 0; transform: translateX(-36px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes flex-bounce {
  0% { opacity: 0; transform: scale(0.88); }
  75% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes flex-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes flex-overlay-fade {
  from { opacity: 0; }
  to { opacity: var(--flex-overlay-opacity, 0.64); }
}

body.flex-popup-locked {
  overflow: hidden !important;
}

/* Exit Motion */
.flex-popup-root.is-closing .flex-popup-content {
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .flex-motion-preview-exit .flex-popup-dialog {
    animation: flex-preview-exit var(--flex-exit-duration) var(--flex-exit-ease) both;
  }
  .flex-motion-preview-exit .flex-popup-overlay {
    animation: flex-overlay-exit var(--flex-exit-duration) var(--flex-exit-ease) both;
  }
}

@keyframes flex-preview-exit {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: var(--flex-preview-exit-transform, none); }
}

@keyframes flex-overlay-exit {
  from { opacity: var(--flex-overlay-opacity, 0.64); }
  to { opacity: 0; }
}

/* Block Content Constraints within Popup */
.flex-popup-content img,
.flex-popup-content svg,
.flex-popup-content video,
.flex-popup-content iframe {
  max-width: 100%;
  height: auto;
}

.flex-popup-content :is(.wp-block-embed, .wp-block-image, .wp-block-gallery) {
  max-width: 100%;
}

.flex-popup-content .wp-block-columns,
.flex-popup-content .wp-block-column {
  min-width: 0;
}

@container (max-width: 500px) {
  .flex-popup-content .wp-block-columns:not(.is-not-stacked-on-mobile) {
    flex-direction: column;
  }
  .flex-popup-content .wp-block-columns:not(.is-not-stacked-on-mobile) > .wp-block-column {
    flex-basis: auto !important;
    width: 100% !important;
    flex-grow: 1 !important;
  }
}

@media (max-width: 460px) {
  .flex-popup-content .wp-block-buttons {
    flex-wrap: wrap;
  }
}

/* Mobile & Tablet Presentation */
@media (max-width: 768px) {
  .flex-popup-root {
    padding: min(var(--flex-gap, 20px), 12px);
  }

  .flex-popup-dialog {
    max-width: min(var(--flex-mobile-width, 100%), calc(100vw - 2 * min(var(--flex-gap, 20px), 12px)));
    max-height: min(var(--flex-max-height, 95dvh), calc(100dvh - 24px));
    border-radius: var(--flex-mobile-radius, 16px);
  }

  .flex-popup-content {
    padding: var(--flex-mobile-pad, 20px);
    padding-top: max(var(--flex-mobile-pad, 20px), calc(var(--flex-close-size, 36px) + 20px));
  }

  /* Bottom-Sheet Layout */
  .flex-mobile-bottom-sheet {
    align-items: flex-end;
    justify-content: center;
    padding: 0;
  }

  .flex-mobile-bottom-sheet .flex-popup-dialog {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--flex-mobile-radius, 16px) var(--flex-mobile-radius, 16px) 0 0;
  }

  /* Sleek drag affordance on bottom sheets */
  .flex-mobile-bottom-sheet .flex-popup-dialog::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.4);
    margin: 8px auto 0;
  }

  /* Mobile Fullscreen */
  .flex-mobile-fullscreen {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }

  .flex-mobile-fullscreen .flex-popup-dialog {
    max-width: 100%;
    max-height: 100dvh;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
}

/* Authorized Mobile Preview Frame Simulation */
.flex-popup-root.flex-preview-mobile {
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.flex-popup-root.flex-preview-mobile .flex-popup-dialog {
  width: 100%;
  max-width: min(390px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
}

.flex-popup-root.flex-preview-mobile.flex-mobile-bottom-sheet {
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.flex-popup-root.flex-preview-mobile.flex-mobile-bottom-sheet .flex-popup-dialog {
  max-width: min(390px, 100vw);
  max-height: 92dvh;
  border-radius: var(--flex-radius, 16px) var(--flex-radius, 16px) 0 0;
}

.flex-popup-root.flex-preview-mobile.flex-mobile-fullscreen {
  align-items: stretch;
  justify-content: center;
  padding: 0;
}

.flex-popup-root.flex-preview-mobile.flex-mobile-fullscreen .flex-popup-dialog {
  max-width: min(390px, 100vw);
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  border-radius: 0;
}

/* Reduced Motion Override */
@media (prefers-reduced-motion: reduce) {
  .flex-popup-root * {
    animation: none !important;
    transition: none !important;
  }
}

/* Built-in Lead Capture Form */
.flex-lead-form {
  display: grid;
  gap: 12px;
}

.flex-lead-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
}

.flex-lead-form input[type="email"] {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 8px;
  font-size: 14px;
  background: var(--flex-bg, #ffffff);
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.flex-lead-form input[type="email"]:focus {
  border-color: var(--flex-accent, #4f46e5);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
  outline: none;
}

.flex-lead-form button {
  justify-self: start;
  background: var(--flex-accent, #4f46e5);
  color: #ffffff;
  border: 0;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.flex-lead-form button:hover {
  filter: brightness(1.08);
}

.flex-lead-form .flex-lead-trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.flex-lead-form [data-flex-lead-status]:empty {
  display: none;
}
