/* Popup donation forms — markup is built by assets/js/popup.js. Loaded site-wide, so keep it small. */

html.tzd-popup-open {
  overflow: hidden;
}
html.tzd-popup-open body {
  /* Stops the page shifting sideways when the scrollbar disappears. */
  padding-right: var(--tzd-popup-scrollbar, 0);
}

.tzd-popup {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}
.tzd-popup[hidden] {
  display: none;
}

.tzd-popup__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  opacity: 0;
  transition: opacity 0.2s ease;
}

/*
 * The dialog is only a transparent frame: the form's own card is what the donor sees. popup.js
 * pins its width to the form's measured width (fit()), so dialog, body and form are always the
 * same size — widen the form in the builder and the popup widens with it.
 */
.tzd-popup__dialog {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: auto 0;
  background: transparent;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease;
  outline: none;
}

.tzd-popup.is-open .tzd-popup__backdrop { opacity: 1; }
.tzd-popup.is-open .tzd-popup__dialog { opacity: 1; transform: none; }

/* The popup is blocking: a click outside it only bounces the dialog (see nudge() in popup.js). */
.tzd-popup__dialog.is-nudged { animation: tzd-popup-nudge 0.35s ease; }
@keyframes tzd-popup-nudge {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.02); }
  70% { transform: scale(0.995); }
}
.tzd-popup__dialog.is-nudged .tzd-popup__close {
  box-shadow: 0 0 0 3px var(--tzd-brand-alpha-30, rgba(237, 25, 58, 0.3));
}

/* Body = form: no padding, no extra chrome, nothing below the active step. */
.tzd-popup__body {
  padding: 0;
  margin: 0;
}
/* Three-class selectors so they outrank both styles.css and the builder's per-form CSS. */
.tzd-popup .tzd-popup__body .tzd-form-wrap {
  margin: 0;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  box-sizing: border-box;
}
/*
 * A builder form whose Form Width was cleared is width:100% (form-builder-frontend.css), which
 * in a popup would mean the whole screen. Fall back to the plugin's standard 550px instead.
 * :where() keeps this at (0,2,0) — the same weight as the builder's own per-form width rule,
 * which is printed later and so still wins whenever a width is set.
 */
:where(.tzd-popup__body) .tzd-fb-form.tzd-form-wrap {
  width: var(--tzd-container-width, 550px);
}
.tzd-popup .tzd-popup__body .tzd-step-panel {
  position: relative;
  margin-bottom: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* × — lives in each step's header bar, mirroring the Back button on the left. */
.tzd-popup .tzd-popup__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--tzd-border-color, #e0e4ee);
  border-radius: 999px;
  background: var(--tzd-card-bg, #fff);
  color: var(--tzd-text, #1f2937);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  line-height: 1;
  z-index: 2;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tzd-popup .tzd-popup__close:hover {
  background: var(--tzd-brand, #ED193A);
  border-color: var(--tzd-brand, #ED193A);
  color: #fff;
}
.tzd-popup .tzd-popup__close:focus-visible {
  outline: 2px solid var(--tzd-brand, #ED193A);
  outline-offset: 2px;
}
.tzd-popup .tzd-popup__close--header {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
}
/* Keep a long step title clear of the × (the Back button already reserves the left side). */
.tzd-popup .tzd-step-panel__header--popup {
  padding-right: 64px;
  padding-left: 64px;
}
.tzd-popup .tzd-popup__close--panel {
  position: absolute;
  top: 12px;
  right: 12px;
}
.tzd-popup .tzd-popup__close--status {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* Loading / error placeholder — a card of its own until the form arrives. */
.tzd-popup__status {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 560px;
  min-height: 220px;
  margin: 0 auto;
  padding: 32px 56px;
  box-sizing: border-box;
  background: var(--tzd-card-bg, #fff);
  border-radius: var(--tzd-radius-card, 20px);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
  color: #475569;
  font-size: 15px;
  text-align: center;
}
.tzd-popup__status--error { color: #b91c1c; }

.tzd-popup__spinner {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 3px solid rgba(15, 23, 42, 0.12);
  border-top-color: var(--tzd-brand, #ED193A);
  border-radius: 50%;
  animation: tzd-popup-spin 0.8s linear infinite;
}
@keyframes tzd-popup-spin { to { transform: rotate(360deg); } }

/* Phones: a full-screen sheet — the form fills it edge to edge. */
@media (max-width: 640px) {
  .tzd-popup { padding: 0; align-items: stretch; }
  .tzd-popup__dialog {
    min-height: 100%;
    margin: 0;
    background: var(--tzd-card-bg, #fff);
    transform: translateY(24px);
  }
  .tzd-popup .tzd-popup__body .tzd-form-wrap {
    width: 100%;
  }
  .tzd-popup .tzd-popup__body .tzd-step-panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
  .tzd-popup .tzd-step-panel__header--popup {
    padding-left: 56px;
    padding-right: 56px;
    text-align: center;
  }
  .tzd-popup .tzd-popup__close--header { right: 12px; }
  .tzd-popup__status { max-width: none; min-height: 100vh; border-radius: 0; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tzd-popup__backdrop,
  .tzd-popup__dialog { transition: none; }
  .tzd-popup__spinner { animation-duration: 2s; }
  .tzd-popup__dialog.is-nudged { animation: none; }
}

/* [tzd_donate_button] */
.tzd-popup-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 999px;
  background: var(--tzd-brand, #2563eb);
  color: #fff !important;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none !important;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.tzd-popup-button:hover,
.tzd-popup-button:focus-visible {
  background: var(--tzd-brand-hover, #1d4ed8);
  transform: translateY(-1px);
}
.tzd-popup-button:focus-visible {
  outline: 2px solid var(--tzd-brand, #2563eb);
  outline-offset: 3px;
}
.tzd-popup-button--error {
  background: #fef2f2;
  color: #b91c1c !important;
  cursor: default;
}
