/* =====================================================================
 *  components/popup.css — پاپ‌آپ قابل مدیریت از پنل ادمین
 *  ---------------------------------------------------------------------
 *  کامپوننت ۱۰ در ORDER (build_css_bundle.js) ⇒ در همهٔ صفحات عمومی از
 *  bundle بارگذاری می‌شود. اختصاصی‌بودن CSS در اینجا یعنی امکان نگه‌داشتن
 *  پاپ‌آپ در همهٔ صفحات بدون هزینهٔ یک <link> جداگانه؛ خودِ HTML به شرط
 *  فعال بودن پاپ‌آپ محدود است (قرارداد صفر بایت در includes/popup.php).
 *
 *  قراردادهای بین‌فایلی که نباید تغییر کنند:
 *    • .pp .............. includes/popup.php — ریشه، aria-hidden="true" در
 *                         حالت بسته و .is-open برای باز شدن (popup.js)
 *    • .pp__close ....... دکمهٔ بستن؛ focus اول روی این می‌رود، نه CTA،
 *                         تا کاربر با Enter چیزی را سفارش ندهد.
 *    • [data-popup-copy] . دکمهٔ کپی کوپن (popup.js متن دکمه را عوض می‌کند)
 *    • [data-popup-live] . اعلان صفحه‌خوان برای نتیجهٔ کپی.
 *
 *  قواعد سخت (قرارداد لایهٔ ارائه):
 *    ۱) فقط توکن‌های --shafa-radius-* ؛ --radius-* یک پله عقب است
 *       (gotchas.md §2) و مقدار متفاوتی می‌دهد.
 *    ۲) هیچ hex خام. رنگ‌ها یا از توکن theme-aware می‌آیند یا از متغیرهای
 *       scope‌شدهٔ زیر که خودشان از همان توکن‌ها ساخته شده‌اند.
 *    ۳) چیدمان RTL با خواص منطقی (inset-inline-*) نه left/right.
 *    ۴) رنگ متغیر scope‌شده در .pp تعریف می‌شود تا هر دو تم از یک
 *       نقطهٔ حقیقت بخوانند؛ این فایل tokens.css را تغییر نمی‌دهد
 *       (AGENTS.md: tokens.css فقط دستی ویرایش می‌شود).
 * ===================================================================== */

/* =====================================================================
 *  ۱) ریشه — روی همهٔ نمایشگرها، چون max-width/100vw خودش محدود است
 * ===================================================================== */
.pp {
  /* متغیرهای scope‌شده: تنها جایی که رنگ پاپ‌آپ تعریف می‌شود. */
  --pp-panel-bg: var(--shafa-surface-card);
  --pp-panel-border: var(--shafa-surface-card-border);
  --pp-backdrop: var(--shadow_overlay);
  --pp-coupon-bg: var(--shafa-gold-subtle);
  --pp-coupon-border: rgba(var(--shafa-gold-satin-rgb), 0.34);
  --pp-close-hover-bg: var(--shafa-surface-muted);
  --pp-ring: var(--shafa-focus-ring);

  position: fixed;
  inset: 0;
  z-index: var(--shafa-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-3);
  /* visibility و نه display:none — تا focus-trap و اعلان صفحه‌خوان در
     حالت بسته هم بتوانند به ریشه برسند. cart-panel همین الگو را دارد. */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--shafa-duration-base) var(--shafa-ease-natural),
              visibility var(--shafa-duration-base);
}
.pp.is-open { visibility: visible; opacity: 1; pointer-events: auto; }

.pp__backdrop {
  position: absolute;
  inset: 0;
  background: var(--pp-backdrop);
  backdrop-filter: blur(3px);
}

/* =====================================================================
 *  ۲) پنل
 *  ---------------------------------------------------------------------
 *  max-width و max-height هر دو clamp/ترکیبی‌اند:
 *    • در ۳۲۰px هیچ اسکرول افقی رخ نمی‌دهد (calc(100vw - 32px)).
 *    • در نمایشگر کوتاه، پنل از صفحه بیرون نمی‌زند و متن بلند اسکرول
 *      داخلی می‌خورد نه اسکرول صفحه.
 * ===================================================================== */
.pp__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(520px, calc(100vw - 32px));
  max-height: min(80dvh, 640px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--pp-panel-bg);
  border: 1px solid var(--pp-panel-border);
  border-radius: var(--shafa-radius-2xl);
  box-shadow: var(--shafa-shadow-lg);
  transform: translateY(12px) scale(0.98);
  transition: transform var(--shafa-duration-slow) var(--shafa-ease-natural);
}
.pp.is-open .pp__panel { transform: translateY(0) scale(1); }

/* =====================================================================
 *  ۳) دکمهٔ بستن
 *  ---------------------------------------------------------------------
 *  ۴۴×۴۴ حداقل هدف لمسی (WCAG 2.5.5). inset-inline-start یعنی «راست» در
 *  RTL و «چپ» در LTR بدون نیاز به بازنویسی.
 * ===================================================================== */
.pp__close {
  position: absolute;
  inset-block-start: var(--s-2);
  inset-inline-end: var(--s-2);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--shafa-touch);
  height: var(--shafa-touch);
  padding: 0;
  border: 0;
  border-radius: var(--shafa-radius-full);
  background: transparent;
  color: var(--shafa-text-secondary);
  cursor: pointer;
  transition: background var(--shafa-duration-fast) var(--shafa-ease-natural),
              color var(--shafa-duration-fast) var(--shafa-ease-natural);
}
.pp__close img { width: 20px; height: 20px; }
.pp__close:hover { background: var(--pp-close-hover-bg); color: var(--shafa-text-primary); }
.pp__close:focus-visible { box-shadow: var(--pp-ring); }

/* =====================================================================
 *  ۴) تصویر
 * ===================================================================== */
.pp__media { margin: 0; }
.pp__media img,
.pp__media picture { display: block; }
.pp__media img {
  width: 100%;
  height: auto;
  /* تصویر عریض در پنل باریک کشیده نشود */
  object-fit: cover;
  aspect-ratio: 26 / 16;
  border-start-start-radius: var(--shafa-radius-2xl);
  border-start-end-radius: var(--shafa-radius-2xl);
  background: var(--shafa-surface-muted);
}

/* =====================================================================
 *  ۵) بدنه
 * ===================================================================== */
.pp__body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  /* clamp برای فاصلهٔ عمودی: در موبایل فشرده، در دسکتاپ باز */
  padding-block: clamp(var(--s-4), 5vw, var(--s-5)) clamp(var(--s-4), 5vw, var(--s-5));
  padding-inline: clamp(var(--s-4), 5vw, var(--s-5));
}
.pp__title {
  margin: 0;
  font-size: var(--shafa-fs-h3, 1.25rem);
  line-height: 1.5;
  color: var(--shafa-text-primary);
}
.pp__text {
  margin: 0;
  font-size: var(--shafa-fs-small, 0.875rem);
  line-height: 1.9;
  color: var(--shafa-text-secondary);
}

/* =====================================================================
 *  ۶) کوپن
 * ===================================================================== */
.pp__coupon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  flex-wrap: wrap;
  padding: var(--s-3);
  background: var(--pp-coupon-bg);
  border: 1px dashed var(--pp-coupon-border);
  border-radius: var(--shafa-radius-lg);
}
.pp__coupon-code {
  font-size: var(--shafa-fs-h4, 1.0625rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--shafa-gold-text);
  /* کد کوپن لاتین و چپ‌چین است حتی در متن فارسی */
  unicode-bidi: isolate;
}
.pp__copy {
  min-height: var(--shafa-touch);
  padding-inline: var(--s-3);
  border: 1px solid var(--pp-coupon-border);
  border-radius: var(--shafa-radius-md);
  background: transparent;
  color: var(--shafa-gold-text);
  font-size: var(--shafa-fs-small, 0.875rem);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--shafa-duration-fast) var(--shafa-ease-natural);
}
.pp__copy:hover { background: rgba(var(--shafa-gold-satin-rgb), 0.10); }
.pp__copy:focus-visible { box-shadow: var(--pp-ring); }
.pp__copy[data-state="copied"] { color: var(--shafa-text-primary); }

/* =====================================================================
 *  ۷) فرم خبرنامه
 *  ---------------------------------------------------------------------
 *  فرم با float_field() رندر می‌شود، پس کلاس .field--float از style.css
 *  می‌آید و اینجا فقط چیدمان داخل ظرف پاپ‌آپ تنظیم می‌شود.
 * ===================================================================== */
.pp__form { display: flex; flex-direction: column; gap: var(--s-2); }
.pp__field .field--float { margin: 0; }
.pp__field input[type="email"] { width: 100%; }
.pp__submit { width: 100%; }
.pp__hint {
  margin: 0;
  font-size: var(--shafa-fs-tiny, 0.75rem);
  color: var(--shafa-text-tertiary);
}

/* =====================================================================
 *  ۸) محصول
 * ===================================================================== */
.pp__product {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2);
  border: 1px solid var(--shafa-border-subtle);
  border-radius: var(--shafa-radius-lg);
}
.pp__product-thumb img {
  display: block;
  width: var(--shafa-touch-lg);
  height: var(--shafa-touch-lg);
  object-fit: cover;
  border-radius: var(--shafa-radius-md);
  background: var(--shafa-surface-muted);
}
.pp__product-info { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.pp__product-name {
  margin: 0;
  font-size: var(--shafa-fs-small, 0.875rem);
  color: var(--shafa-text-primary);
}
.pp__product-price {
  margin: 0;
  font-size: var(--shafa-fs-body, 1rem);
  font-weight: 700;
  color: var(--shafa-gold-text);
}
.pp__product-price-old {
  margin: 0;
  font-size: var(--shafa-fs-tiny, 0.75rem);
  text-decoration: line-through;
  color: var(--shafa-text-tertiary);
}

/* =====================================================================
 *  ۹) کنش‌ها
 * ===================================================================== */
.pp__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-block-start: var(--s-1);
}
.pp__actions:empty { display: none; }
.pp__cta { flex: 1 1 auto; min-width: 40%; }

/* =====================================================================
 *  ۱۰) تایمر شمارش معکوس
 * ===================================================================== */
.pp__countdown {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  margin-block-start: var(--s-2);
  padding: var(--s-2);
  background: var(--pp-coupon-bg);
  border: 1px dashed var(--pp-coupon-border);
  border-radius: var(--shafa-radius-lg);
}
.pp__countdown-label {
  margin: 0;
  font-size: var(--shafa-fs-small, 0.875rem);
  font-weight: 600;
  color: var(--shafa-gold-text);
}
.pp__countdown-time {
  font-variant-numeric: tabular-nums;
  font-size: var(--shafa-fs-h4, 1.0625rem);
  font-weight: 700;
  color: var(--shafa-text-primary);
}
.pp__countdown.is-expired {
  background: var(--shafa-surface-muted);
  border-style: solid;
  border-color: var(--shafa-border-subtle);
}

/* =====================================================================
 *  ۱۱) پیش‌نمایش پنل ادمین
 *  ---------------------------------------------------------------------
 *  popup_render_html(..., 'preview') ریشه را .pp-preview می‌کند: همان
 *  استایل .pp__* را می‌گیرد ولی در جریان صفحه می‌نشیند و همیشه دیده
 *  می‌شود. بدون این بلوک، .pp fixed و visibility:hidden می‌ماند و
 *  پیش‌نمایش پنل یک کادر خالی نشان می‌داد.
 * ===================================================================== */
.pp-preview {
  position: static;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  padding: var(--s-3);
}
.pp-preview .pp__panel {
  transform: none;
  box-shadow: var(--shafa-shadow-md);
}
.pp-preview .pp__backdrop { display: none; }

/* =====================================================================
 *  ۱۲) حرکت کاهش‌یافته
 *  ---------------------------------------------------------------------
 *  فقط fade، بدون transform. محتوا در هر دو حالت باز می‌ماند؛ آنچه کم
 *  می‌شود حرکت است، نه دسترسی.
 * ===================================================================== */
@media (prefers-reduced-motion: reduce) {
  .pp,
  .pp__panel,
  .pp__close,
  .pp__copy { transition: opacity var(--shafa-duration-fast) linear; }
  .pp__panel { transform: none; }
  .pp.is-open .pp__panel { transform: none; }
}