/*
 * PopupZen — Frontend Styles
 * All popup layout, overlay, animation, and responsive rules.
 * Custom per-popup colors are injected as inline <style> by PHP.
 *
 * @package PopupZen
 */

/* ── Reset & Scope ─────────────────────────────────────── */
.pz-popup-wrap *,
.pz-popup-wrap *::before,
.pz-popup-wrap *::after {
  box-sizing: border-box;
}

/* ── Wrapper ───────────────────────────────────────────── */
.pz-popup-wrap {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.pz-popup-wrap.pz-hidden {
  display: none;
}

/* ── Overlay ───────────────────────────────────────────── */
.pz-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0.6;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

/* ── Inner popup box ───────────────────────────────────── */
.pz-popup-inner {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 8px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.08);
  padding: 40px;
  -webkit-overflow-scrolling: touch;
}

/* ── Close button ──────────────────────────────────────── */
.pz-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  transition: background 0.2s ease, transform 0.15s ease;
  padding: 0;
  line-height: 1;
}

.pz-close-btn:hover {
  background: rgba(0, 0, 0, 0.15);
  transform: scale(1.1);
}

.pz-close-btn:focus-visible {
  outline: 2px solid #0073aa;
  outline-offset: 2px;
}

/* ── Content area ──────────────────────────────────────── */
.pz-popup-content {
  margin-top: 8px;
}

.pz-popup-content img {
  max-width: 100%;
  height: auto;
}

.pz-popup-content a {
  color: inherit;
}

/* ── ========================================================
   ANIMATIONS
   Each animation has: initial state (pre-open), active state
   (open), and exit state handled by JS removing the class.
   ======================================================== */

/* --- Fade --- */
@keyframes pz-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

.pz-popup-wrap[data-animation="fade"].pz-animating-in .pz-popup-inner {
  animation: pz-fade-in 0.35s ease both;
}
.pz-popup-wrap[data-animation="fade"].pz-animating-out .pz-popup-inner {
  animation: pz-fade-out 0.25s ease both;
}

/* --- Slide Down --- */
@keyframes pz-slide-down-in {
  from { opacity: 0; transform: translateY(-40px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pz-slide-down-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-40px); }
}

.pz-popup-wrap[data-animation="slide-down"].pz-animating-in .pz-popup-inner {
  animation: pz-slide-down-in 0.4s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}
.pz-popup-wrap[data-animation="slide-down"].pz-animating-out .pz-popup-inner {
  animation: pz-slide-down-out 0.25s ease both;
}

/* --- Slide Up --- */
@keyframes pz-slide-up-in {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pz-slide-up-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(40px); }
}

.pz-popup-wrap[data-animation="slide-up"].pz-animating-in .pz-popup-inner {
  animation: pz-slide-up-in 0.4s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}
.pz-popup-wrap[data-animation="slide-up"].pz-animating-out .pz-popup-inner {
  animation: pz-slide-up-out 0.25s ease both;
}

/* --- Zoom --- */
@keyframes pz-zoom-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes pz-zoom-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.85); }
}

.pz-popup-wrap[data-animation="zoom"].pz-animating-in .pz-popup-inner {
  animation: pz-zoom-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.pz-popup-wrap[data-animation="zoom"].pz-animating-out .pz-popup-inner {
  animation: pz-zoom-out 0.2s ease both;
}

/* --- Bounce --- */
@keyframes pz-bounce-in {
  0%   { opacity: 0; transform: scale(0.3); }
  55%  { opacity: 1; transform: scale(1.06); }
  75%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}

.pz-popup-wrap[data-animation="bounce"].pz-animating-in .pz-popup-inner {
  animation: pz-bounce-in 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
.pz-popup-wrap[data-animation="bounce"].pz-animating-out .pz-popup-inner {
  animation: pz-zoom-out 0.2s ease both;
}

/* --- Flip --- */
@keyframes pz-flip-in {
  from { opacity: 0; transform: perspective(600px) rotateX(-20deg) scale(0.9); }
  to   { opacity: 1; transform: perspective(600px) rotateX(0deg) scale(1); }
}

.pz-popup-wrap[data-animation="flip"].pz-animating-in .pz-popup-inner {
  animation: pz-flip-in 0.45s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}
.pz-popup-wrap[data-animation="flip"].pz-animating-out .pz-popup-inner {
  animation: pz-fade-out 0.2s ease both;
}

/* Overlay animation (always fade) */
.pz-popup-wrap.pz-animating-in .pz-overlay {
  animation: pz-fade-in 0.3s ease both;
}
.pz-popup-wrap.pz-animating-out .pz-overlay {
  animation: pz-fade-out 0.25s ease both;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 600px) {
  .pz-popup-inner {
    padding: 24px 20px;
    border-radius: 12px;
    max-height: 85vh;
  }
}

/* ── Device visibility ─────────────────────────────────── */
/* Server-side pre-filters, but CSS acts as safety net */
@media (min-width: 769px) {
  .pz-popup-wrap.pz-device-mobile {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .pz-popup-wrap.pz-device-desktop {
    display: none !important;
  }
}

/* ── Accessibility: respect motion preference ──────────── */
@media (prefers-reduced-motion: reduce) {
  .pz-popup-wrap[data-animation] .pz-popup-inner,
  .pz-overlay {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
