/**
 * crm-popup.css
 *
 * CRM Popup Lead Capture Forms
 * 4 templates: classic | minimal | dark | vibrant
 * 3 positions:  center | bottom_right | top_bar
 *
 * Uses CSS custom properties set per-popup by PopupRenderer:
 *   --popup-accent        accent / primary brand colour
 *   --popup-bg            card background colour
 *   --popup-text          body text colour
 *   --popup-btn           submit button background
 *   --popup-btn-text      submit button text colour
 *   --popup-radius        card border radius (e.g. 24px)
 *   --popup-overlay-opacity  backdrop opacity (0–1)
 */

/* =========================================================================
   1. RESET / BASE SHELL
   ========================================================================= */

.crm-popup-shell {
  --popup-accent: #0284c7;
  --popup-bg: #ffffff;
  --popup-text: #0f172a;
  --popup-btn: #0284c7;
  --popup-btn-text: #ffffff;
  --popup-radius: 24px;
  --popup-overlay-opacity: 0.5;
  display: none;
  z-index: 9000;
}

.crm-popup-shell[style] {
  /* The hidden attribute is removed by JS on open */
}

/* Screen-reader-only utility */
.crm-popup-shell .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* =========================================================================
   2. POSITIONS
   ========================================================================= */

/* ---- Center ---- */
.crm-popup-pos--center {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crm-popup-pos--center .crm-popup-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, var(--popup-overlay-opacity));
  cursor: pointer;
}

.crm-popup-pos--center .crm-popup-wrapper {
  position: relative;
  width: min(90vw, 520px);
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
}

/* ---- Bottom-right slide-in ---- */
.crm-popup-pos--bottom-right {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: block;
  z-index: 9000;
}

.crm-popup-pos--bottom-right .crm-popup-overlay {
  display: none;
}

.crm-popup-pos--bottom-right .crm-popup-wrapper {
  width: min(92vw, 420px);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  animation: crmPopupSlideUp 300ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes crmPopupSlideUp {
  from { transform: translateY(32px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ---- Top bar ---- */
.crm-popup-pos--top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: block;
  z-index: 9000;
}

.crm-popup-pos--top-bar .crm-popup-overlay {
  display: none;
}

.crm-popup-pos--top-bar .crm-popup-wrapper {
  width: 100%;
  border-radius: 0 !important;
  padding: 12px 24px;
}

.crm-popup-pos--top-bar .crm-popup-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 24px;
}

.crm-popup-pos--top-bar .crm-popup-form-area {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

/* In top-bar mode, compress the form to a single-line feel */
.crm-popup-pos--top-bar .crm-form-embed .grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.crm-popup-pos--top-bar .crm-form-embed .t-input-wrap {
  flex: 1 1 180px;
}

/* =========================================================================
   3. COMMON WRAPPER ELEMENTS
   ========================================================================= */

.crm-popup-wrapper {
  position: relative;
  background: var(--popup-bg);
  color: var(--popup-text);
  border-radius: var(--popup-radius);
  padding: 40px;
  box-sizing: border-box;
}

/* Close button — top-right corner */
.crm-popup-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--popup-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  opacity: 0.55;
  transition: opacity 150ms, background 150ms;
  z-index: 2;
}

.crm-popup-close:hover,
.crm-popup-close:focus-visible {
  opacity: 1;
  background: rgba(15, 23, 42, 0.08);
  outline: 2px solid var(--popup-accent);
  outline-offset: 2px;
}

/* Headline */
.crm-popup-headline {
  margin: 0 0 8px;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--popup-text);
}

/* Body copy */
.crm-popup-body-copy {
  margin: 0 0 20px;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--popup-text);
  opacity: 0.8;
}

/* Preview-only status so an admin cannot mistake the isolated form for a live one. */
.crm-popup-preview-note {
  margin: 0 0 18px;
  padding: 8px 12px;
  border: 1px solid var(--popup-accent);
  border-radius: 10px;
  background: rgba(2, 132, 199, 0.08);
  color: var(--popup-text);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
}

/* "No thanks" link */
.crm-popup-nothanks {
  display: block;
  margin: 16px auto 0;
  background: none;
  border: none;
  color: var(--popup-text);
  font-size: 0.8125rem;
  text-decoration: underline;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 150ms;
  padding: 4px 8px;
}

.crm-popup-nothanks:hover,
.crm-popup-nothanks:focus-visible {
  opacity: 0.9;
  outline: 2px solid var(--popup-accent);
  outline-offset: 2px;
}

/* Privacy note */
.crm-popup-privacy {
  margin: 12px 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--popup-text);
  opacity: 0.5;
}

/* Success state */
.crm-popup-success {
  padding: 20px 0;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--popup-accent);
}

.crm-popup-success.hidden {
  display: none;
}

/* Override CRM form submit button colours with popup config */
.crm-popup-wrapper form[data-crm-form] button[type="submit"] {
  background-color: var(--popup-btn) !important;
  color: var(--popup-btn-text) !important;
}

.crm-popup-wrapper form[data-crm-form] button[type="submit"]:hover {
  filter: brightness(0.9);
}

/* =========================================================================
   4. TEMPLATE: classic
   ========================================================================= */

.crm-popup-tpl--classic .crm-popup-header {
  background: var(--popup-accent);
  margin: -40px -40px 28px;
  padding: 32px 40px 28px;
  border-radius: var(--popup-radius) var(--popup-radius) 0 0;
}

.crm-popup-tpl--classic .crm-popup-headline {
  color: #ffffff;
  font-size: 1.5rem;
}

.crm-popup-tpl--classic .crm-popup-body-copy {
  color: rgba(255, 255, 255, 0.85);
  opacity: 1;
}

.crm-popup-tpl--classic .crm-popup-close {
  color: #ffffff;
  opacity: 0.7;
}

.crm-popup-tpl--classic .crm-popup-close:hover,
.crm-popup-tpl--classic .crm-popup-close:focus-visible {
  background: rgba(255, 255, 255, 0.15);
  opacity: 1;
}

/* =========================================================================
   5. TEMPLATE: minimal
   ========================================================================= */

.crm-popup-tpl--minimal {
  border: 1px solid rgba(15, 23, 42, 0.12);
  padding: 52px 48px;
}

.crm-popup-tpl--minimal .crm-popup-header {
  margin-bottom: 24px;
}

.crm-popup-tpl--minimal .crm-popup-headline {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* =========================================================================
   6. TEMPLATE: dark
   ========================================================================= */

.crm-popup-tpl--dark {
  background: #0f172a;
  color: #f1f5f9;
}

.crm-popup-tpl--dark .crm-popup-headline {
  color: #f1f5f9;
}

.crm-popup-tpl--dark .crm-popup-body-copy {
  color: #94a3b8;
  opacity: 1;
}

.crm-popup-tpl--dark .crm-popup-close {
  color: #94a3b8;
}

.crm-popup-tpl--dark .crm-popup-close:hover,
.crm-popup-tpl--dark .crm-popup-close:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

.crm-popup-tpl--dark .crm-form-embed .t-input {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  color: #f1f5f9;
}

.crm-popup-tpl--dark .crm-form-embed label {
  color: #cbd5e1;
}

.crm-popup-tpl--dark form[data-crm-form] button[type="submit"] {
  background-color: #f1f5f9 !important;
  color: #0f172a !important;
}

.crm-popup-tpl--dark form[data-crm-form] button[type="submit"]:hover {
  background-color: #e2e8f0 !important;
}

.crm-popup-tpl--dark .crm-popup-nothanks {
  color: #64748b;
}

.crm-popup-tpl--dark .crm-popup-privacy {
  color: #475569;
  opacity: 1;
}

/* =========================================================================
   7. TEMPLATE: vibrant
   ========================================================================= */

.crm-popup-tpl--vibrant .crm-popup-header {
  background: linear-gradient(135deg, var(--popup-accent) 0%, color-mix(in srgb, var(--popup-accent) 60%, #ffffff) 100%);
  margin: -40px -40px 28px;
  padding: 36px 40px 32px;
  border-radius: var(--popup-radius) var(--popup-radius) 0 0;
}

.crm-popup-tpl--vibrant .crm-popup-headline {
  color: #ffffff;
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.crm-popup-tpl--vibrant .crm-popup-body-copy {
  color: rgba(255, 255, 255, 0.88);
  opacity: 1;
  font-size: 1rem;
}

.crm-popup-tpl--vibrant .crm-popup-close {
  color: #ffffff;
  opacity: 0.7;
}

.crm-popup-tpl--vibrant .crm-popup-close:hover,
.crm-popup-tpl--vibrant .crm-popup-close:focus-visible {
  background: rgba(255, 255, 255, 0.2);
  opacity: 1;
}

.crm-popup-tpl--vibrant form[data-crm-form] button[type="submit"] {
  border-radius: 9999px !important;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* =========================================================================
   8. FOCUS / ANIMATION
   ========================================================================= */

.crm-popup-wrapper:focus {
  outline: none;
}

/* Accessible animation: respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .crm-popup-pos--bottom-right .crm-popup-wrapper {
    animation: none;
  }
}

/* Mobile: full-width bottom sheet for center modals */
@media (max-width: 480px) {
  .crm-popup-pos--center .crm-popup-wrapper {
    width: 100%;
    max-height: 95vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
  }

  .crm-popup-pos--center {
    align-items: flex-end;
  }

  .crm-popup-pos--bottom-right {
    bottom: 0;
    right: 0;
    left: 0;
  }

  .crm-popup-pos--bottom-right .crm-popup-wrapper {
    width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .crm-popup-tpl--classic .crm-popup-header,
  .crm-popup-tpl--vibrant .crm-popup-header {
    margin-left: -24px;
    margin-right: -24px;
    padding-left: 24px;
    padding-right: 24px;
  }

  .crm-popup-wrapper {
    padding: 32px 24px;
  }
}
