/*
 * Pop-up (CPT `popup`, rendered by src/Popups/PopupScriptLoader.php).
 *
 * One markup tree, three layouts. Figma: miahX2u1YaWVYnLAc7CXTs
 *   6193:97133  desktop, image + content  (840x420, two columns)
 *   6194:108227 tablet, content only      (358 wide)
 *   6194:108194 mobile, content only      (358 wide)
 *   6194:108295 mobile, image + content   (140px image band on top)
 *
 * An uploaded visual shows on desktop and tablet by default; mobile opts in.
 * Both are still editor-controlled (`popup_show_image_tablet` /
 * `popup_show_image_mobile`), which the renderer turns into the --image-tablet
 * / --image-mobile modifiers. Desktop gets the 420x420 side panel; tablet and
 * mobile get the 140px band, because the card is only 358 wide there.
 *
 * Two deliberate structural choices:
 *
 * - Every rule is scoped under `.cc-popup-overlay`. This markup is injected at
 *   wp_footer into ~50 templates whose host CSS this file does not control, and
 *   a bare `.cc-popup-cta` (0,1,0) merely *ties* with a Tailwind Preflight reset
 *   like `[type="button"] { background-color: transparent }` — which then wins
 *   on source order, because the reset ships as an inline <style> later in the
 *   document than this enqueued file. The extra class buys the headroom without
 *   resorting to !important.
 *
 * - Each breakpoint owns its overrides inside an exclusive media range rather
 *   than undoing the previous one. Mixing them meant a mobile-only rule carrying
 *   two classes silently out-specified the single-class desktop rule below it.
 */

.cc-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  box-sizing: border-box;
}

/* Must beat the display:flex above — the renderer ships the overlay hidden. */
.cc-popup-overlay[hidden] {
  display: none !important;
}

.cc-popup-overlay * {
  box-sizing: border-box;
}

/*
 * The entrance is a one-shot animation keyed off the `hidden` attribute rather
 * than a class the script toggles on requestAnimationFrame. rAF does not fire
 * in a throttled tab, and a missed frame would leave the pop-up displayed,
 * scroll-locked and stuck at opacity 0. Animating from the attribute keeps the
 * resting state "visible" and makes the motion pure decoration.
 */
.cc-popup-overlay:not([hidden]) {
  animation: cc-popup-fade-in 160ms ease-out;
}

.cc-popup-overlay:not([hidden]) .cc-popup-card {
  animation: cc-popup-rise 160ms ease-out;
}

@keyframes cc-popup-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes cc-popup-rise {
  from {
    transform: translateY(8px);
  }

  to {
    transform: none;
  }
}

/* ---------- Card: content-only, 358 wide (mobile + tablet) ---------- */

.cc-popup-overlay .cc-popup-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 358px;
  max-height: calc(100vh - 32px);
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.25);
}

/* Image band above the copy; opted into per breakpoint. */
.cc-popup-overlay .cc-popup-visual {
  display: none;
  flex-shrink: 0;
  width: 100%;
  height: 140px;
  overflow: hidden;
}

.cc-popup-overlay .cc-popup-visual img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cc-popup-overlay .cc-popup-content {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  min-height: 320px;
  padding: 16px;
  overflow-y: auto;
}

/* Positioned against the card, so the same offsets hold in every variant. */
.cc-popup-overlay .cc-popup-close {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  color: #000;
  background: none;
  border: 0;
  cursor: pointer;
  appearance: none;
}

.cc-popup-overlay .cc-popup-close svg {
  display: block;
  width: 100%;
  height: 100%;
}

.cc-popup-overlay .cc-popup-logo {
  flex-shrink: 0;
  padding: 2px;
}

.cc-popup-overlay .cc-popup-logo img {
  display: block;
  width: auto;
  height: 26px;
  max-width: 100%;
}

.cc-popup-overlay .cc-popup-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: center;
}

.cc-popup-overlay .cc-popup-title {
  margin: 0;
  font-weight: 900;
  font-size: 24px;
  line-height: 32px;
  color: #333;
  overflow-wrap: break-word;
}

.cc-popup-overlay .cc-popup-copy {
  margin: 0;
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
  color: #333;
  overflow-wrap: break-word;
}

/* WYSIWYG copy arrives wrapped in <p> — the card's own gap does the spacing. */
.cc-popup-overlay .cc-popup-copy > :first-child {
  margin-top: 0;
}

.cc-popup-overlay .cc-popup-copy > :last-child {
  margin-bottom: 0;
}

.cc-popup-overlay .cc-popup-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px;
  font-family: Poppins, Roboto, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 700;
  font-size: 16px;
  line-height: 24px;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  color: var(--cc-popup-cta-color, #fff);
  background-color: var(--cc-popup-cta-bg, #000);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  appearance: none;
}

/*
 * This markup lands in ~50 templates whose resets are not ours, and both buttons
 * clear their own borders — without this a keyboard user can get no visible
 * focus at all. Scoped like everything else so a host reset cannot outrank it.
 */
.cc-popup-overlay .cc-popup-cta:focus-visible,
.cc-popup-overlay .cc-popup-close:focus-visible {
  /*
   * Fixed #333 rather than the CTA colour: --cc-popup-cta-bg is whatever the
   * content team picked, and a pale CTA — white, cream, a sale yellow — would
   * draw a near-invisible ring on the white card, which is the exact problem
   * this rule exists to solve.
   */
  outline: 2px solid #333;
  outline-offset: 2px;
}

/* ---------- Mobile only: 140px image band, off unless switched on ---------- */

@media (max-width: 639.98px) {
  .cc-popup-overlay .cc-popup-card--image-mobile .cc-popup-visual {
    display: block;
  }

  /* Sits over the band, so it follows the band's own top inset. */
  .cc-popup-overlay .cc-popup-card--image-mobile .cc-popup-close {
    top: 14px;
  }
}

/* ---------- Tablet only: 140px image band, on unless switched off ---------- */

@media (min-width: 640px) and (max-width: 1023.98px) {
  .cc-popup-overlay .cc-popup-card--image-tablet .cc-popup-visual {
    display: block;
  }

  .cc-popup-overlay .cc-popup-card--image-tablet .cc-popup-close {
    top: 14px;
  }
}

/* ---------- Desktop: two columns, 840x420 ---------- */

@media (min-width: 1024px) {
  .cc-popup-overlay .cc-popup-card {
    max-width: 420px;
    min-height: 400px;
    max-height: min(500px, calc(100vh - 32px));
  }

  .cc-popup-overlay .cc-popup-content {
    min-height: 0;
    padding: 24px;
  }

  .cc-popup-overlay .cc-popup-close {
    top: 24px;
    right: 24px;
  }

  .cc-popup-overlay .cc-popup-title {
    font-size: 32px;
    line-height: 40px;
  }

  .cc-popup-overlay .cc-popup-copy {
    font-size: 16px;
    line-height: 24px;
  }

  .cc-popup-overlay .cc-popup-cta {
    font-size: 18px;
    line-height: 26px;
  }

  .cc-popup-overlay .cc-popup-card--has-image {
    flex-direction: row;
    max-width: 840px;
  }

  /* Always shown on desktop, whatever the tablet/mobile toggles say, and
     stretched to whatever height the copy settles on (400-500px). */
  .cc-popup-overlay .cc-popup-card--has-image .cc-popup-visual {
    display: block;
    width: 420px;
    height: auto;
    align-self: stretch;
  }

  .cc-popup-overlay .cc-popup-card--has-image .cc-popup-content {
    width: 420px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cc-popup-overlay:not([hidden]),
  .cc-popup-overlay:not([hidden]) .cc-popup-card {
    animation: none;
  }
}
