/* =====================================================================
   HA UX LAYER — لایه‌ی تجربه‌ی کاربری و میکرواینترکشن‌ها
   ---------------------------------------------------------------------
   - مستقل از build تلویند (output.css دست نمی‌خورد، چون content آن
     پلاگین‌های بیرون از قالب را هم اسکن می‌کند و rebuild خطرناک است).
   - چون tailwind با important:true ساخته شده، هر جا لازم است کلاس‌های
     utility را خنثی کنیم از !important با specificity بالاتر استفاده شده.
   - همه‌ی زمان‌ها از توکن‌های حرکت می‌آیند: 100 / 150 / 200 / 300ms.
   - همه‌ی حرکت‌ها در prefers-reduced-motion خاموش یا فقط opacity می‌شوند.
   ===================================================================== */

:root {
  --ha-motion-100: 100ms;
  --ha-motion-150: 150ms;
  --ha-motion-200: 200ms;
  --ha-motion-300: 300ms;
  --ha-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ha-ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --ha-accent: #e11d48;
  --ha-accent-ink: #be123c;
  --ha-ring: 0 0 0 2px #fff, 0 0 0 4px var(--ha-accent);
  --ha-surface: #fff;
  --ha-ink: #111;
  --ha-border: rgba(17, 17, 17, 0.08);
}
.dark {
  --ha-ring: 0 0 0 2px #111, 0 0 0 4px #fb7185;
  --ha-surface: #1a1a1a;
  --ha-ink: #fafafa;
  --ha-border: rgba(255, 255, 255, 0.1);
}

/* ---------------------------------------------------------------------
   1) پیوند «رفتن به محتوای اصلی» (Skip link)
   --------------------------------------------------------------------- */
.ha-skip-link {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--ha-ink);
  color: var(--ha-surface);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--ha-motion-150) var(--ha-ease-out);
}
.ha-skip-link:focus,
.ha-skip-link:focus-visible {
  transform: translateY(0);
  outline: none;
  box-shadow: var(--ha-ring);
}
#ha-main:focus { outline: none; }

/* ---------------------------------------------------------------------
   2) حلقه‌ی فوکوس یکدست و قابل‌دیدن (فقط برای کیبورد)
   specificity (0,2,1) تا بر .outline-none و focus:outline-none غلبه کند
   --------------------------------------------------------------------- */
html :is(a, button, summary, select, textarea, input, [tabindex], [role="button"]):focus-visible {
  outline: 2px solid var(--ha-accent) !important;
  outline-offset: 3px !important;
}
.dark :is(a, button, summary, select, textarea, input, [tabindex], [role="button"]):focus-visible {
  outline-color: #fb7185 !important;
}
/* فیلدهایی که خودشان حالت focus-within دارند حلقه‌ی دوم نمی‌گیرند */
html :is(#searchInput, #userContactInput):focus-visible {
  outline: none !important;
}
html #newsletterForm > div:focus-within {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

/* ---------------------------------------------------------------------
   3) هدر: حالت «اسکرول شده» با سایه‌ی نرم (فقط opacity انیمیت می‌شود)
   --------------------------------------------------------------------- */
.ha-header { isolation: isolate; }
.ha-header::after {
  content: "";
  position: absolute;
  inset: auto 0 -1px 0;
  height: 16px;
  transform: translateY(100%);
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(17, 17, 17, 0.06), transparent);
  opacity: 0;
  transition: opacity var(--ha-motion-200) var(--ha-ease-out);
}
.dark .ha-header::after { background: linear-gradient(to bottom, rgba(0, 0, 0, 0.45), transparent); }
.ha-header.is-scrolled::after { opacity: 1; }

/* زیرخط فعال برای آیتم منوی صفحه‌ی جاری */
.ha-header nav [aria-current="page"] {
  color: var(--ha-accent) !important;
}

/* ---------------------------------------------------------------------
   4) منوهای کشویی دسکتاپ با کیبورد (focus-within) + Escape از JS
   --------------------------------------------------------------------- */
html .ha-header nav li.group:focus-within > div.invisible,
html .ha-header nav li.group.is-open > div.invisible,
html .ha-header .group\/user:focus-within > div.invisible,
html .ha-header .group\/user.is-open > div.invisible {
  visibility: visible !important;
  opacity: 1 !important;
  --tw-translate-y: 0px !important;
}
html .ha-header nav li.group.is-closed > div.invisible,
html .ha-header .group\/user.is-closed > div.invisible {
  visibility: hidden !important;
  opacity: 0 !important;
}
html .ha-header nav li.group:focus-within > a svg {
  --tw-rotate: 180deg !important;
  color: var(--ha-accent) !important;
}
/* آیتم‌های زیرمنو: نوار کوچک کناری هنگام hover/فوکوس به‌جای تغییر رنگ کامل */
.ha-header nav li li > a { position: relative; }
.ha-header nav li li > a::before {
  content: "";
  position: absolute;
  right: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 3px;
  background: var(--ha-accent);
  opacity: 0;
  transform: scaleY(0.4);
  transition: opacity var(--ha-motion-150) var(--ha-ease-out), transform var(--ha-motion-150) var(--ha-ease-out);
}
.ha-header nav li li > a:hover::before,
.ha-header nav li li > a:focus-visible::before { opacity: 1; transform: scaleY(1); }

/* ---------------------------------------------------------------------
   5) جستجوی هدر در موبایل: به‌جای برخورد با لوگو، روی کل عرض هدر باز می‌شود
   --------------------------------------------------------------------- */
@media (max-width: 1023px) {
  html .ha-header form[role="search"]:focus-within {
    position: absolute !important;
    inset-inline: 12px !important;
    top: 50% !important;
    z-index: 45 !important;
    transform: translateY(-50%);
    padding: 0 !important;
    animation: ha-fade-in var(--ha-motion-150) var(--ha-ease-out);
  }
  html .ha-header form[role="search"]:focus-within > div {
    background: var(--ha-surface) !important;
    box-shadow: 0 8px 30px -12px rgba(0, 0, 0, 0.25);
    height: 48px !important;
  }
  html .ha-header:has(form[role="search"]:focus-within) a[aria-label="خانه"] {
    opacity: 0 !important;
  }
  html .ha-header form[role="search"]:focus-within input {
    width: 100% !important;
    padding-inline: 16px !important;
    font-size: 16px !important; /* جلوگیری از زوم خودکار iOS */
  }
}

/* ---------------------------------------------------------------------
   6) منوی موبایل: ورود پله‌ای آیتم‌ها + اهداف لمسی ۴۴px
   --------------------------------------------------------------------- */
#mobileMenu .mobile-toggle-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
#mobileMenu .mobile-sub-menu a { min-height: 44px; }
#mobileMenu.is-open .mobile-nav-container > ul > li {
  animation: ha-rise var(--ha-motion-300) var(--ha-ease-out) both;
}
#mobileMenu.is-open .mobile-nav-container > ul > li:nth-child(2) { animation-delay: 30ms; }
#mobileMenu.is-open .mobile-nav-container > ul > li:nth-child(3) { animation-delay: 60ms; }
#mobileMenu.is-open .mobile-nav-container > ul > li:nth-child(4) { animation-delay: 90ms; }
#mobileMenu.is-open .mobile-nav-container > ul > li:nth-child(5) { animation-delay: 120ms; }
#mobileMenu.is-open .mobile-nav-container > ul > li:nth-child(n+6) { animation-delay: 150ms; }
#overlay { animation: ha-fade-in var(--ha-motion-200) var(--ha-ease-out); }

/* ---------------------------------------------------------------------
   7) دکمه‌ها و لینک‌ها: بازخورد فشردن + حرکت ظریف فلش
   --------------------------------------------------------------------- */
html :is(a, button)[class*="rounded"]:not(.ha-no-press):active {
  transform: scale(0.98);
}
:is(a, button) svg.rtl\:rotate-180,
:is(a, button) svg.rotate-180 {
  transition: translate var(--ha-motion-200) var(--ha-ease-out);
}
:is(a, button):hover > svg.rtl\:rotate-180:last-child,
:is(a, button):hover > svg.rotate-180:last-child {
  translate: -3px 0; /* در RTL «جلو» یعنی سمت چپ */
}

/* ---------------------------------------------------------------------
   8) کارت‌ها: بالا آمدن ملایم‌تر و سایه‌ی یکدست (به‌جای پرش ۸ پیکسلی)
   --------------------------------------------------------------------- */
html article.group[class*="hover:-translate-y"]:hover {
  --tw-translate-y: -4px !important;
}
html article.group img {
  transition: transform var(--ha-motion-300) var(--ha-ease-out);
}
@media (hover: hover) {
  html article.group:hover img:not(.no-zoom) { transform: scale(1.03); }
}

/* ---------------------------------------------------------------------
   9) ظاهر شدن تدریجی بخش‌ها هنگام اسکرول (فقط وقتی JS فعال است)
   --------------------------------------------------------------------- */
.ha-js-ux .ha-reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--ha-motion-300) var(--ha-ease-out), transform var(--ha-motion-300) var(--ha-ease-out);
  transition-delay: var(--ha-delay, 0ms);
}
.ha-js-ux .ha-reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* ---------------------------------------------------------------------
   10) لینک‌های داخل متن مقاله: زیرخط که از راست کشیده می‌شود
   --------------------------------------------------------------------- */
:is(.prose, .entry-content, #ha-article) p a:not([class]),
:is(.prose, .entry-content, #ha-article) li a:not([class]) {
  text-decoration: none !important;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-position: 100% 100%;
  background-repeat: no-repeat;
  box-shadow: inset 0 -1px 0 rgba(225, 29, 72, 0.35);
  transition: background-size var(--ha-motion-300) var(--ha-ease-out), color var(--ha-motion-150);
}
:is(.prose, .entry-content, #ha-article) p a:not([class]):hover,
:is(.prose, .entry-content, #ha-article) li a:not([class]):hover {
  background-size: 100% 1px;
}

/* ---------------------------------------------------------------------
   11) لنگر تیترهای مقاله: کپی لینک مستقیم هر بخش (برای دانشنامه مهم است)
   --------------------------------------------------------------------- */
.ha-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-inline-start: 6px;
  border-radius: 8px;
  vertical-align: middle;
  color: #9ca3af;
  background: transparent;
  border: 0;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--ha-motion-150) var(--ha-ease-out), color var(--ha-motion-150), background-color var(--ha-motion-150);
}
:is(h2, h3):hover > .ha-anchor,
.ha-anchor:focus-visible { opacity: 1; }
.ha-anchor:hover { color: var(--ha-accent); background: rgba(225, 29, 72, 0.08); }
@media (hover: none) { .ha-anchor { opacity: 0.55; } }
.ha-anchor svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------------
   12) Toast — جایگزین alert() مرورگر
   --------------------------------------------------------------------- */
.ha-toast-region {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
  width: min(92vw, 420px);
}
.ha-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  background: #111;
  color: #fafafa;
  font-size: 14px;
  line-height: 1.8;
  box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: ha-toast-in var(--ha-motion-200) var(--ha-ease-out) both;
}
.dark .ha-toast { background: #fafafa; color: #111; border-color: rgba(0, 0, 0, 0.06); }
.ha-toast.is-leaving { animation: ha-toast-out var(--ha-motion-150) var(--ha-ease-in) both; }
.ha-toast__icon { flex: none; width: 20px; height: 20px; margin-top: 3px; }
.ha-toast--success .ha-toast__icon { color: #22c55e; }
.ha-toast--error .ha-toast__icon { color: #fb7185; }
.ha-toast__close {
  margin-inline-start: auto;
  flex: none;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
}
.ha-toast__close:hover { opacity: 1; }

/* خطای درون‌خطی فیلد (فرم‌ها) */
.ha-field-error {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: #e11d48;
  min-height: 1em;
}
.ha-shake { animation: ha-shake var(--ha-motion-300) var(--ha-ease-out); }

/* ---------------------------------------------------------------------
   13) دکمه‌ی تغییر تم: چرخش نرم آیکون + View Transition دایره‌ای
   --------------------------------------------------------------------- */
#theme-toggle svg,
[aria-label="تغییر حالت شب و روز"] svg {
  transition: transform var(--ha-motion-300) var(--ha-ease-out);
}
#theme-toggle:hover svg,
[aria-label="تغییر حالت شب و روز"]:hover svg { transform: rotate(-20deg); }

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* ---------------------------------------------------------------------
   14) دکمه‌ی بازگشت به بالا: حلقه‌ی پیشرفت مطالعه به‌جای هاله‌ی چشمک‌زن
   --------------------------------------------------------------------- */
#backToTopBtn .ha-progress-ring {
  position: absolute;
  inset: -3px;
  width: calc(100% + 6px);
  height: calc(100% + 6px);
  transform: rotate(-90deg);
  pointer-events: none;
}
#backToTopBtn .ha-progress-ring circle {
  fill: none;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* ---------------------------------------------------------------------
   15) شمارنده‌ی آمار: جلوگیری از پرش عرض هنگام شمارش
   --------------------------------------------------------------------- */
[data-ha-count] { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------
   17) Tutor LMS و ووکامرس
   --------------------------------------------------------------------- */
/* دکمه‌ی بازگشت به بالا روی نوار ثبت‌نام چسبان موبایل صفحه‌ی دوره نیفتد */
@media (max-width: 1023px) {
  body:has([data-mobile-enroll]) #backToTopBtn { bottom: 88px !important; }
}
/* فیلدهای فرم تسویه و پروفایل: فوکوس روشن و یکدست */
html .tutor-form-control:focus,
html .woocommerce form .input-text:focus,
html .woocommerce form select:focus {
  border-color: var(--ha-accent) !important;
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.15) !important;
  outline: none !important;
}
html .tutor-form-control:user-invalid,
html .woocommerce form .woocommerce-invalid .input-text {
  border-color: #e11d48 !important;
}
/* دکمه‌ی پرداخت: بازخورد فشردن و حالت غیرفعال واضح */
#tutor-checkout-pay-now-button,
.woocommerce #place_order {
  transition: transform var(--ha-motion-100) var(--ha-ease-out), opacity var(--ha-motion-150);
}
#tutor-checkout-pay-now-button:active,
.woocommerce #place_order:active { transform: scale(0.98); }
#tutor-checkout-pay-now-button[disabled] { opacity: 0.55; cursor: not-allowed; }
/* گزینه‌های روش پرداخت: کل کارت قابل کلیک با حالت انتخاب‌شده */
.tutor-checkout-payment-item { cursor: pointer; transition: border-color var(--ha-motion-150), background-color var(--ha-motion-150); }
.tutor-checkout-payment-item:has(input:checked) {
  border-color: var(--ha-accent) !important;
  background-color: rgba(225, 29, 72, 0.04) !important;
}

/* ---------------------------------------------------------------------
   Keyframes
   --------------------------------------------------------------------- */
@keyframes ha-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ha-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ha-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ha-toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(4px); } }
@keyframes ha-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}
/* جایگزین bounce بی‌پایان کارت آمار هیرو: یک‌بار ورود و تمام */
@keyframes ha-float-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.ha-float-in { animation: ha-float-in var(--ha-motion-300) var(--ha-ease-out) 300ms both; }

/* ---------------------------------------------------------------------
   16) کاهش حرکت (prefers-reduced-motion): همه‌ی حرکت‌ها خاموش
   --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html.scroll-smooth,
  html { scroll-behavior: auto !important; }
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
  }
  .ha-js-ux .ha-reveal { opacity: 1; transform: none; }
  html :is(a, button)[class*="rounded"]:active { transform: none; }
  html article.group:hover img { transform: none !important; }
  .hero-kenburns, .hero-slide { animation: none !important; }
  .hero-slide:not(:first-child) { opacity: 0 !important; }
  .hero-slide:first-child { opacity: 1 !important; }
}
