/* =====================================================================
 *  lead-magnet.css — دیزاین‌سیستم مشترک Lead Magnet
 *  ----------------------------------------------------------------------
 *  هر سه واریانت (سلول گرید / standalone / inline فشرده) از یک پایهٔ
 *  بصری مشترک به ارث می‌برند که DNA کارت محصول را کپی می‌کند:
 *  نوارک یک‌سل، قاب inset طلایی، hover-lift و کنتراست طلایی متن.
 *
 *  چرا یک فایل: lead-magnet.css آخرین ورودی bundle است
 *  (build_css_bundle.js ORDER)، پس هر selector عمومی اینجا بر
 *  utilities.css غلبه می‌کند. به همین دلیل همهٔ قاعده‌ها تا حد ممکن
 *  با کلاس پایه scope شده‌اند و هیچ selector سراسری تازه‌ای اضافه
 *  نشده است.
 *
 *  ── قراردادهای زنده که این فایل باید حفظ کند ──────────────────────────
 *    • .nl-toast .............. newsletter.js آن را می‌سازد و کلاس
 *                                 is-visible / --success / --error می‌زند.
 *    • .lead-magnet.is-exit-intent  newsletter.js exit-intent.
 *    • .error-illustration .... صفحهٔ lead-magnet.php.
 *    • .lead-magnet__row ...... newsletter.js لینک دانلود را به همین
 *                                 ردیف اضافه می‌کند (پس باید وجود داشته
 *                                 باشد و wrap-safe باشد).
 *    • .lead-magnet-inline .... مصرف‌کنندهٔ زنده: credentials-section.php
 *                                 از طریق render_lead_magnet_inline().
 *  ===================================================================== */

/* =====================================================================
 *  ۱. Toast اعلان عمومی
 * ===================================================================== */
.nl-toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(24px + env(safe-area-inset-bottom)));
  transform: translateX(-50%) translateY(14px);
  min-width: 260px;
  max-width: calc(100vw - 32px);
  background: var(--shafa-lm-toast-bg);
  color: var(--shafa-lm-toast-text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms, transform 180ms ease;
  z-index: 4000;
  box-shadow: var(--shafa-shadow-lg);
  pointer-events: none;
}
.nl-toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
.nl-toast--success { background: var(--shafa-lm-toast-success); }
.nl-toast--error   { background: var(--shafa-lm-toast-error); }

/* =====================================================================
 *  ۲. پایهٔ مشترک — DNA کارت محصول
 *  ---------------------------------------------------------------------
 *  متغیرهای اختصاصی روی همین root تعریف می‌شوند، نه در :root —
 *  tokens.css فقط دستی ویرایش می‌شود (AGENTS.md) و lead magnet نباید
 *  توکن سراسری جدید تحمیل کند. تم تاریک خودبه‌خود از همین متغیرها
 *  پیروی می‌کند چون مقدارشان از توکن‌های --shafa-lm-* می‌آید.
 * ===================================================================== */
.lead-magnet-base {
  --lm-card-bg: var(--shafa-lm-bg);
  --lm-border: rgba(197, 160, 89, 0.28);
  --lm-border-hover: rgba(197, 160, 89, 0.65);
  --lm-frame: rgba(197, 160, 89, 0.12);
  --lm-frame-hover: rgba(197, 160, 89, 0.35);
  --lm-radius: 20px;
  --lm-accent: var(--shafa-lm-accent);
  --lm-accent-hover: var(--shafa-lm-accent-hover);
  --lm-badge-bg: var(--shafa-lm-badge-bg);
  --lm-badge-border: var(--shafa-lm-badge-border);
  --lm-sub: var(--shafa-lm-sub);
  --lm-hint: var(--shafa-lm-hint);
  --lm-ring: var(--shafa-lm-ring);
  --lm-shadow: var(--shafa-lm-shadow);
  --lm-shadow-lg: var(--shafa-lm-shadow-lg);

  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--lm-card-bg);
  border: 1px solid var(--lm-border);
  border-radius: var(--lm-radius);
  box-shadow:
    0 4px 20px -2px rgba(24, 22, 20, 0.05),
    0 0 0 1px var(--lm-ring) inset;
  overflow: hidden;
  transition:
    transform 450ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 450ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 450ms ease;
}

/* نوارک یک‌سل — فقط روی hover ظاهر می‌شود، دقیقاً مثل کارت محصول. */
.lead-magnet-base::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('../../img/honeycomb-luxury.svg');
  background-repeat: repeat;
  background-size: 42px 72px;
  opacity: 0;
  transition: opacity 450ms ease;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(circle at 50% 100%, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 80%);
  -webkit-mask-image: radial-gradient(circle at 50% 100%, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 80%);
}
.lead-magnet-base:hover::before { opacity: 0.22; }

/* قاب inset طلایی. z-index:1 عمداً است: محتوای واقعی z-index:2 دارد تا
   این خط روی input/button ننشیند. */
.lead-magnet-base::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid var(--lm-frame);
  border-radius: calc(var(--lm-radius) - 6px);
  pointer-events: none;
  z-index: 1;
  transition: border-color 300ms ease;
}
.lead-magnet-base:hover::after { border-color: var(--lm-frame-hover); }

.lead-magnet-base > * {
  position: relative;
  z-index: 2;
}

.lead-magnet-base:hover {
  transform: translateY(-8px) scale(1.01);
  border-color: var(--lm-border-hover);
  box-shadow:
    0 24px 48px -10px rgba(197, 160, 89, 0.25),
    0 6px 18px rgba(24, 22, 20, 0.06);
}

/* فوکوس کیبورد داخل کارت (input یا دکمه). بدون این، کل focus ring
   داخل کارت گم می‌شود — همان دلیلی که .product-card دارد. */
.lead-magnet-base:focus-within {
  outline: 2px solid var(--shafa-gold-text);
  outline-offset: 4px;
}

/* =====================================================================
 *  ۳. عناصر داخلی مشترک
 * ===================================================================== */
.lead-magnet__inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* تراز متن. utility متناظر «شروع» در utilities.css تعریف نشده (فقط
   text-left هست که در RTL برعکسِ intent است)، پس اینجا scope‌دار
   تعریف می‌شود. کلاس text-center از utilities می‌آید. */
.lead-magnet__header.text-start,
.lead-magnet__footer.text-start { text-align: start; }

/* input ایمیل. کلاس قدیمی `field` روی خودِ input می‌نشست در حالی که
   قاعدهٔ .field در forms.css روی *فرزند* آن است (`.field input`)، پس
   هیچ border/background‌ای اعمال نمی‌شد. اینجا صریح تعریف می‌شود. */
.lead-magnet__input {
  width: 100%;
  min-width: 0;
  background: var(--shafa-input-bg);
  border: 1px solid rgba(197, 160, 89, 0.30);
  border-radius: var(--shafa-radius-full);
  color: var(--shafa-text-primary);
  transition: border-color var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.lead-magnet__input::placeholder { color: var(--shafa-text-faint); }
.lead-magnet__input:focus {
  outline: none;
  border-color: var(--shafa-border-focus);
  box-shadow: var(--focus-ring);
}

.lead-magnet__header {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.lead-magnet__badge {
  align-self: flex-start;
  background: var(--lm-badge-bg);
  color: var(--lm-accent);
  border: 1px solid var(--lm-badge-border);
  border-radius: var(--shafa-radius-full);
  padding: 3px 11px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.lead-magnet__title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--lm-accent);
  margin: 0;
}

.lead-magnet__sub {
  color: var(--lm-sub);
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
}

/* فرم. min-width:0 تا input در گرید بتواند واقعاً جمع شود و row
   از عرض کارت بیرون نزند. */
.lead-magnet__form {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-width: 0;
  margin: 0;
}

/* newsletter.js لینک دانلود را به انتهای همین ردیف اضافه می‌کند، پس
   روی دسکتاپ سه آیتم می‌شود. flex-wrap ضروری است: بدون آن لینک
   دانلود از کارت بیرون می‌زند (کارت overflow:hidden دارد و بریده
   می‌شود). */
.lead-magnet__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}

.lead-magnet__row > .field--sm {
  flex: 1 1 180px;
  min-width: 0;
}

.lead-magnet__row > .btn {
  flex: 0 0 auto;
}

.lead-magnet__footer {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-top: auto;
  padding-top: var(--s-3);
  border-top: 1px solid rgba(197, 160, 89, 0.16);
}

.lead-magnet__hint {
  color: var(--lm-hint);
  font-size: var(--fs-small);
  line-height: 1.6;
  margin: 0;
}

/* نوار اعتماد: سه نشان کوتاه با آیکون. */
.lead-magnet__trust {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-3);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 11px;
  color: var(--lm-hint);
}
.lead-magnet__trust li {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
/* آیکون‌ها SVG با width/height ‏1em رندر می‌شوند (style.css:239-240)،
   پس font-size اندازهٔ واقعی را تعیین می‌کند. */
.lead-magnet__trust .lead-magnet__trust-icon {
  font-size: 15px;
  color: var(--lm-accent);
  flex-shrink: 0;
}

/* لینک دانلودی که newsletter.js در ردیف فرم می‌سازد. flex-basis
   کامل یعنی همیشه به خط خودش می‌رود و عرض را به input/button
   محدودهٔ باریک تحمیل نمی‌کند. */
.lead-magnet__row .nl-download-link {
  flex: 1 0 100%;
  justify-content: center;
  margin-top: var(--s-1);
}

/* =====================================================================
 *  ۴. واریانت ۱ — سلول داخل گرید محصولات (products.php)
 *  ---------------------------------------------------------------------
 *  min-height ثابت (320px قبلاً) با کارت محصول هم‌تراز نبود چون ارتفاع
 *  واقعی محصولات محتوا-وابسته است. گرید به‌صورت پیش‌فرض
 *  align-items:stretch دارد، پس این سلول خودش تا ارتفاع ردیف کشیده
 *  می‌شود؛ فقط باید اجازهٔ کش آمدن بدهد و محتوا را space-between
 *  توزیع کند. padding سلول = padding کارت محصول (var(--s-4)).
 * ===================================================================== */
.lead-magnet-cell {
  height: 100%;
  min-width: 0;
  padding: var(--s-4);
  text-align: center;
}
.lead-magnet-cell .lead-magnet__inner {
  gap: var(--s-4);
  text-align: center;
}
.lead-magnet-cell .lead-magnet__header {
  align-items: center;
  text-align: center;
}
.lead-magnet-cell .lead-magnet__footer {
  align-items: center;
  text-align: center;
}

/* =====================================================================
 *  ۵. واریانت ۲ — بخش standalone (about.php)
 * ===================================================================== */
.lead-magnet {
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  padding: var(--s-6) var(--s-5);
  text-align: center;
}
.lead-magnet .lead-magnet__inner {
  gap: var(--s-4);
  text-align: center;
}
.lead-magnet .lead-magnet__header,
.lead-magnet .lead-magnet__footer {
  align-items: center;
  text-align: center;
}

/* =====================================================================
 *  ۶. واریانت ۳ — inline فشرده (product.php و credentials-section.php)
 *  ---------------------------------------------------------------------
 *  ریشه inline-flex است تا در نوار/ستون باریک عرض محتوا را بگیرد، ولی
 *  محتوای داخلی ستونی می‌ماند چون عنوان + فرم در عرض ۳۶۰px کنار هم
 *  جا نمی‌شوند.
 * ===================================================================== */
.lead-magnet-inline {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  max-width: 360px;
  width: 100%;
  padding: var(--s-4);
  text-align: center;
}
.lead-magnet-inline .lead-magnet__inner {
  gap: var(--s-3);
  text-align: center;
}
.lead-magnet-inline .lead-magnet__header,
.lead-magnet-inline .lead-magnet__footer {
  align-items: center;
  text-align: center;
}
.lead-magnet-inline .lead-magnet__title { font-size: 15px; }
.lead-magnet-inline .lead-magnet__sub   { font-size: 12px; }
.lead-magnet-inline .lead-magnet__badge { padding: 2px 9px; }
.lead-magnet-inline .lead-magnet__footer {
  margin-top: 0;
  padding-top: var(--s-2);
}

/* =====================================================================
 *  ۷. Exit-intent reveal
 *  فقط برای standalone؛ سلول grid آن را هدف نمی‌گیرد (newsletter.js
 *  fallback عمداً سلول را رد می‌کند چون در آن صفحه exit-intent هدف
 *  مناسبی نیست).
 * ===================================================================== */
.lead-magnet.is-exit-intent {
  animation: lmFadeIn 0.4s ease-out both;
  position: relative;
  z-index: 3800;
}
@keyframes lmFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
 *  ۸. موبایل و کاهش حرکت
 * ===================================================================== */
@media (max-width: 640px) {
  .lead-magnet-cell,
  .lead-magnet,
  .lead-magnet-inline {
    padding: var(--s-4);
  }
  /* ردیف فرم ستونی: input و دکمه هر دو تمام‌عرض. بدون این، دکمهٔ
     nowrap در عرض ۳۹۰px از کارت بیرون می‌زند. */
  .lead-magnet__row {
    flex-direction: column;
    align-items: stretch;
  }
  .lead-magnet__row > .field--sm,
  .lead-magnet__row > .btn,
  .lead-magnet__row .nl-download-link {
    flex: 1 1 auto;
    width: 100%;
    margin-top: 0;
  }
  .lead-magnet-base:hover {
    transform: none;
  }
}

/* hover-lift و fade باید برای کاربری که reduced-motion دارد حذف شود؛
   قاب inset و نوارک می‌مانند چون حرکت نیستند. */
@media (prefers-reduced-motion: reduce) {
  .lead-magnet-base,
  .lead-magnet-base::before,
  .lead-magnet-base::after {
    transition: none;
  }
  .lead-magnet-base:hover {
    transform: none;
  }
  .lead-magnet.is-exit-intent {
    animation: none;
  }
}

/* =====================================================================
 *  ۹. Error pages illustrations (lead-magnet.php)
 *  این بخش به redesign سلول گرید ربطی ندارد و حذف نمی‌شود.
 * ===================================================================== */
.error-illustration {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--shafa-lm-badge-bg);
  color: var(--shafa-lm-accent);
}
.error-illustration .material-symbols-outlined {
  font-size: 40px;
}
