/* ==========================================================================
   نامی — لایهٔ حرکتی دکمه‌ها (Nami Motion Layer)
   انیمیشن‌های جذاب برای همهٔ دکمه‌های اپلیکیشن.
   تماماً مبتنی بر شبه‌عنصر (::before/::after) و یک لایهٔ سراسری خارج از React
   تا با رندر مجدد رابط کاربری از بین نرود.
   ========================================================================== */

:root {
  --nm-teal: #12b7a6;
  --nm-amber: #f5a524;
  --nm-ink: #0b1424;
  --nm-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --nm-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* --------------------------------------------------------------------------
   ۱) پایه: همهٔ دکمه‌ها فنری، سه‌بعدی و آمادهٔ افکت می‌شوند
   -------------------------------------------------------------------------- */
button,
[role="button"],
.btn,
.btn-accent,
.btn-ghost,
.chip {
  position: relative;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.42s var(--nm-spring),
    box-shadow 0.3s var(--nm-ease),
    filter 0.3s var(--nm-ease),
    background-color 0.2s var(--nm-ease),
    color 0.2s var(--nm-ease);
  will-change: transform;
}

button:active,
[role="button"]:active,
.btn:active,
.btn-accent:active,
.btn-ghost:active,
.chip:active {
  transform: scale(0.955);
  transition-duration: 0.12s;
}

button:disabled,
.btn-accent:disabled,
.btn:disabled {
  transform: none !important;
  filter: saturate(0.6);
}

/* --------------------------------------------------------------------------
   ۲) درخشش عبوری (Shine Sweep) — روی دکمه‌های اصلی
   -------------------------------------------------------------------------- */
.btn-accent::before,
.btn::before,
.nm-shine::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    115deg,
    transparent 20%,
    rgba(255, 255, 255, 0.42) 45%,
    rgba(255, 255, 255, 0.12) 55%,
    transparent 78%
  );
  background-size: 260% 100%;
  background-position: 220% 0;
  animation: nm-sweep 4.6s var(--nm-ease) infinite;
  mix-blend-mode: soft-light;
  opacity: 0.95;
}

.btn-ghost::before,
.chip::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    115deg,
    transparent 30%,
    rgba(18, 183, 166, 0.22) 50%,
    transparent 70%
  );
  background-size: 260% 100%;
  background-position: 220% 0;
  animation: nm-sweep 6.4s var(--nm-ease) infinite;
  opacity: 0;
  transition: opacity 0.3s;
}

.btn-ghost:hover::before,
.chip:hover::before,
.chip-active::before {
  opacity: 1;
}

@keyframes nm-sweep {
  0% { background-position: 220% 0; }
  38% { background-position: -120% 0; }
  100% { background-position: -120% 0; }
}

/* --------------------------------------------------------------------------
   ۳) هالهٔ زندهٔ گرادیانی (Aurora Glow) — پشت دکمه‌های اصلی
   -------------------------------------------------------------------------- */
.btn-accent::after,
.nm-aurora::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    var(--nm-teal),
    #46e0c8,
    var(--nm-amber),
    #7c6cff,
    var(--nm-teal)
  );
  background-size: 300% 100%;
  filter: blur(7px) saturate(1.2);
  opacity: 0.22;
  animation: nm-orbit 6s linear infinite;
}

.btn-accent:active::after {
  opacity: 0.4;
  filter: blur(10px) saturate(1.3);
}

.btn-accent:disabled::after {
  opacity: 0;
  animation-play-state: paused;
}

@keyframes nm-orbit {
  0% { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

/* --------------------------------------------------------------------------
   ۴) نبض ملایم برای دکمه‌های فراخوان اصلی
   -------------------------------------------------------------------------- */
.btn-accent:not(:disabled) {
  animation: nm-breathe 3.6s ease-in-out infinite;
}

@keyframes nm-breathe {
  0%, 100% { box-shadow: 0 6px 16px -10px rgba(11, 20, 36, 0.45); }
  50% { box-shadow: 0 14px 28px -12px rgba(11, 20, 36, 0.6); }
}

/* --------------------------------------------------------------------------
   ۵) حرکت آیکون داخل دکمه
   -------------------------------------------------------------------------- */
button svg,
[role="button"] svg {
  transition: transform 0.45s var(--nm-spring), filter 0.3s var(--nm-ease);
}

/* در هنگام نگه‌داشتن نشانگر، حرکت آیکون سریع‌تر و درخشان‌تر می‌شود */
button:hover svg,
[role="button"]:hover svg {
  animation-duration: 1.6s;
  filter: drop-shadow(0 3px 8px rgba(18, 183, 166, 0.45));
}

/* --------------------------------------------------------------------------
   ۵-ب) دکمه‌های کارتی (دسته‌بندی‌ها، خدمات، میان‌برها)
   -------------------------------------------------------------------------- */
#root button:not(.btn):not(.btn-accent):not(.btn-ghost):not(.chip) {
  transition:
    transform 0.42s var(--nm-spring),
    box-shadow 0.35s var(--nm-ease);
}

#root button:not(.btn):not(.btn-accent):not(.btn-ghost):not(.chip):hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 30px -18px rgba(11, 20, 36, 0.45);
}

/* شناور شدن آرام آیکون‌ها با تأخیر پلکانی */
#root button svg {
  animation: nm-float 4.6s ease-in-out infinite;
}
#root button:nth-of-type(3n + 1) svg { animation-delay: 0.35s; }
#root button:nth-of-type(3n + 2) svg { animation-delay: 0.8s; }
#root button:nth-of-type(4n) svg { animation-delay: 1.25s; }

@keyframes nm-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2.5px); }
}

/* حلقهٔ نورانی دکمهٔ میانی «دستیار» */
nav button:nth-child(3)::after,
footer button:nth-child(3)::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 34%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 999px;
  border: 1.5px solid rgba(18, 183, 166, 0.55);
  pointer-events: none;
  animation: nm-pulse-ring 2.6s var(--nm-ease) infinite;
}

@keyframes nm-pulse-ring {
  0% { transform: scale(0.72); opacity: 0.75; }
  70% { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}

/* --------------------------------------------------------------------------
   ۶) موج ضربه (Ripple) و ذرات جرقه — لایهٔ سراسری بیرون از React
   -------------------------------------------------------------------------- */
#nm-fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2147483000;
  overflow: hidden;
  contain: strict;
}

.nm-ripple {
  position: absolute;
  border-radius: 999px;
  transform: translate(-50%, -50%) scale(0);
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.75) 0%,
    rgba(18, 183, 166, 0.38) 45%,
    rgba(18, 183, 166, 0) 72%
  );
  animation: nm-ripple-out 0.62s var(--nm-ease) forwards;
  mix-blend-mode: screen;
}

@keyframes nm-ripple-out {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.nm-halo {
  position: absolute;
  border-radius: inherit;
  border: 2px solid rgba(18, 183, 166, 0.75);
  transform: translate(-50%, -50%) scale(0.85);
  animation: nm-halo-out 0.55s var(--nm-ease) forwards;
}

@keyframes nm-halo-out {
  0% { transform: translate(-50%, -50%) scale(0.85); opacity: 0.85; }
  100% { transform: translate(-50%, -50%) scale(1.14); opacity: 0; }
}

.nm-spark {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  opacity: 0;
  animation: nm-spark-fly 0.72s var(--nm-ease) forwards;
  box-shadow: 0 0 8px currentColor;
}

@keyframes nm-spark-fly {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 1; }
  70% { opacity: 0.9; }
  100% {
    transform: translate(calc(-50% + var(--nm-dx)), calc(-50% + var(--nm-dy))) scale(0.1);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   ۷) ورود مرحله‌ای دکمه‌ها هنگام نمایش صفحه
   -------------------------------------------------------------------------- */
.nm-enter {
  animation: nm-pop-in 0.5s var(--nm-spring) both;
}

@keyframes nm-pop-in {
  0% { opacity: 0; transform: translateY(12px) scale(0.94); }
  100% { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   ۸) حالت بارگذاری: نوار متحرک زیر دکمه
   -------------------------------------------------------------------------- */
.nm-busy {
  overflow: hidden;
}

.nm-busy::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fff, transparent);
  animation: nm-loading 1.05s linear infinite;
  filter: none;
  opacity: 0.9;
  z-index: 2;
}

@keyframes nm-loading {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

/* --------------------------------------------------------------------------
   ۹) دکمه‌های نوار پایین (Tab bar) — پرش فنری فعال
   -------------------------------------------------------------------------- */
nav button:active,
footer button:active {
  transform: scale(0.9);
}

/* --------------------------------------------------------------------------
   ۱۰) احترام به تنظیم کاهش حرکت سیستم
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.06s !important;
  }
}
