/* ============================================================
   Smart Popup Manager — popup.css
   Mobile-first, Forminator-safe, elegant
   ============================================================ */

:root {
  --spm-accent:         #6c63ff;
  --spm-z:              99999;
  --spm-radius:         20px;
  --spm-shadow:         0 24px 80px rgba(0,0,0,.22), 0 4px 16px rgba(0,0,0,.1);
  --spm-bg:             #ffffff;
  --spm-overlay-bg:     rgba(10,10,20,.65);
  --spm-text:           #1a1a2e;
  --spm-muted:          #6b7280;
  --spm-border:         rgba(0,0,0,.07);
  --spm-duration:       320ms;
  --spm-ease:           cubic-bezier(.4,0,.2,1);
  --spm-max-w:          560px;
}

/* ── Overlay ─────────────────────────────────────────────── */
.spm-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--spm-z);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--spm-overlay-bg);
  box-sizing: border-box;

  /* hidden state */
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--spm-duration) var(--spm-ease),
    visibility 0s var(--spm-duration);
}

.spm-overlay.spm-blur {
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.spm-overlay.spm-active {
  opacity: 1;
  visibility: visible;
  transition:
    opacity var(--spm-duration) var(--spm-ease),
    visibility 0s 0s;
}

/* ── Modal ───────────────────────────────────────────────── */
.spm-modal {
  position: relative;
  width: 100%;
  max-width: var(--spm-max-w);
  max-height: calc(100dvh - 32px);
  max-height: calc(var(--spm-vh, 100vh) - 32px);
  background: var(--spm-bg);
  border-radius: var(--spm-radius);
  box-shadow: var(--spm-shadow);
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;

  /* hidden state — scale */
  transform: scale(.88) translateY(12px);
  transition: transform var(--spm-duration) var(--spm-ease);
}

/* Animation variants */
:root[style*="--spm-anim:slide-up"] .spm-modal,
.spm-anim-slide-up .spm-modal {
  transform: translateY(32px);
}
:root[style*="--spm-anim:fade"] .spm-modal,
.spm-anim-fade .spm-modal {
  transform: none;
}

.spm-overlay.spm-active .spm-modal {
  transform: scale(1) translateY(0);
}

/* ── Inner scroll area ───────────────────────────────────── */
.spm-modal-inner {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 40px 36px 36px;
  box-sizing: border-box;
  flex: 1;
}

/* ── Header ──────────────────────────────────────────────── */
.spm-header {
  margin-bottom: 24px;
}

.spm-title {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 700;
  line-height: 1.2;
  color: var(--spm-text);
  margin: 0 0 8px;
  padding: 0;
  letter-spacing: -.02em;
}

.spm-description {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--spm-muted);
  margin: 0;
  padding: 0;
}

/* ── Body ────────────────────────────────────────────────── */
.spm-body {
  width: 100%;
  box-sizing: border-box;
}

/* ── Close button ────────────────────────────────────────── */
.spm-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.05);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--spm-muted);
  padding: 0;
  transition: background var(--spm-duration) var(--spm-ease),
              color var(--spm-duration) var(--spm-ease),
              transform var(--spm-duration) var(--spm-ease);
  touch-action: manipulation;
}

.spm-close svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.spm-close:hover {
  background: var(--spm-accent);
  color: #fff;
  transform: rotate(90deg);
}

.spm-close:focus-visible {
  outline: 3px solid var(--spm-accent);
  outline-offset: 2px;
}

/* ── Trigger button (shortcode helper) ───────────────────── */
.spm-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 50px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s var(--spm-ease);
  touch-action: manipulation;
  min-height: 48px;
  border: 2px solid transparent;
  box-sizing: border-box;
  white-space: nowrap;
}

.spm-trigger.spm-btn-default,
.spm-trigger:not([class*="spm-btn"]) {
  background: var(--spm-accent);
  color: #fff;
}
.spm-trigger.spm-btn-default:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.spm-trigger.spm-btn-ghost {
  background: transparent;
  color: var(--spm-accent);
  border-color: var(--spm-accent);
}
.spm-trigger.spm-btn-ghost:hover {
  background: var(--spm-accent);
  color: #fff;
}

.spm-trigger.spm-btn-link {
  background: transparent;
  color: var(--spm-accent);
  padding: 4px 0;
  border-radius: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Forminator label & field size overrides ─────────────── */
.spm-body .forminator-label,
.spm-body .forminator-field label,
.spm-body label.forminator-label,
.spm-body .forminator-field--label label {
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1.4 !important;
  margin-bottom: 5px !important;
}

.spm-body .forminator-input,
.spm-body .forminator-input-text,
.spm-body input[type="text"],
.spm-body input[type="email"],
.spm-body input[type="tel"],
.spm-body input[type="number"],
.spm-body input[type="url"],
.spm-body select,
.spm-body textarea {
  font-size: 14px !important;
  padding: 8px 12px !important;
  height: auto !important;
  line-height: 1.5 !important;
}

.spm-body .forminator-row {
  margin-bottom: 14px !important;
}

.spm-body .forminator-field {
  margin-bottom: 0 !important;
}

/* Submit button */
.spm-body .forminator-button-submit,
.spm-body button[type="submit"] {
  font-size: 14px !important;
  padding: 10px 24px !important;
}

/* Consent / checkbox label */
.spm-body .forminator-checkbox label,
.spm-body .forminator-field-checkbox label {
  font-size: 13px !important;
  font-weight: 400 !important;
}

/* ── Forminator compatibility ────────────────────────────── */
/* Prevent Forminator's styles from breaking inside the modal */
.spm-body .forminator-ui {
  padding: 0 !important;
}

.spm-body .forminator-custom-form {
  margin: 0 !important;
}

/* Make all form elements fit */
.spm-body input[type="text"],
.spm-body input[type="email"],
.spm-body input[type="tel"],
.spm-body input[type="url"],
.spm-body input[type="number"],
.spm-body input[type="password"],
.spm-body input[type="date"],
.spm-body input[type="search"],
.spm-body select,
.spm-body textarea {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.spm-body .forminator-row {
  max-width: 100% !important;
}

/* File upload zone */
.spm-body .forminator-drag-drop-wrap {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Buttons inside forms */
.spm-body .forminator-button,
.spm-body button[type="submit"] {
  min-height: 44px;
  touch-action: manipulation;
}

/* ── Body scroll lock (added via JS) ────────────────────── */
body.spm-open {
  overflow: hidden;
  position: relative;
}

/* iOS bounce prevention */
html.spm-open {
  overflow: hidden;
}

/* ── Decorative gradient header accent ───────────────────── */
.spm-modal::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--spm-accent), #a78bfa, #60a5fa);
  border-radius: var(--spm-radius) var(--spm-radius) 0 0;
  z-index: 1;
  pointer-events: none;
}

/* ── Reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .spm-overlay,
  .spm-modal,
  .spm-close,
  .spm-trigger {
    transition-duration: 1ms !important;
  }
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .spm-overlay {
    align-items: flex-end;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .spm-modal {
    width: 100%;
    max-width: 100%;
    max-height: 90dvh;
    max-height: calc(var(--spm-vh, 90vh) * 0.9);
    border-radius: 24px 24px 0 0;
    transform: translateY(48px) !important;
  }

  .spm-overlay.spm-active .spm-modal {
    transform: translateY(0) !important;
  }

  .spm-modal-inner {
    padding: 32px 20px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .spm-title {
    font-size: 22px;
  }

  .spm-close {
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
  }

  .spm-close svg {
    width: 18px;
    height: 18px;
  }
}

/* ── Very small screens ──────────────────────────────────── */
@media (max-width: 360px) {
  .spm-modal-inner {
    padding: 28px 16px 16px;
  }
}

/* ── Landscape + keyboard open ───────────────────────────── */
@media (max-height: 500px) {
  .spm-overlay {
    align-items: flex-start;
    padding-top: 8px;
  }

  .spm-modal {
    max-height: calc(100dvh - 16px);
    border-radius: var(--spm-radius);
  }
}
