/* ═══════════════════════════════════════════════════════════════
   الحركة والأنيميشن

   قاعدة اتبعناها: **كل حركة لها سبب**. إما تدل على شي (البوت شغّال
   الحين)، أو تربط بين حالتين (ضغطت زر ← ظهرت النتيجة). ما فيه حركة
   للزينة بس - الحركة الزايدة تتعب العين وتخلي الموقع يحس أبطأ.

   وبالآخر نحترم prefers-reduced-motion: اللي يطفي الحركات بجهازه
   (حساسية، دوخة، أو ذوق) نطفيها له بدون ما يطلب.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --ease: cubic-bezier(.4, 0, .2, 1);
  /* spring = يتجاوز الهدف شوي ويرجع، يعطي إحساس حي مو آلي */
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --fast: .16s;
  --mid: .28s;
  --slow: .5s;
}

/* ═══════════ حركات الدخول ═══════════ */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: none; }
}

/* نبضة النقطة الخضراء - تدل إن البوت **حي الحين** مو صورة ثابتة */
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(87, 242, 135, .55); }
  70%      { box-shadow: 0 0 0 7px rgba(87, 242, 135, 0); }
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

@keyframes growBar {
  to { height: 62%; }
}

/* ═══════════ التدرّج بالظهور ═══════════
   التأخير المتدرّج (stagger) هو سر الإحساس الحلو: العين تمشي مع
   العناصر وحدة وحدة بدل ما تنصدم بكل شي مرة وحدة.
   نسويه بـ nth-child مو بجافاسكربت - أسرع وما ينتظر تحميل سكربت. */

.page-head,
.bot-head,
.page > .card,
.settings-layout,
.fade-up {
  animation: fadeUp var(--mid) var(--ease) both;
}

.page-head { animation-delay: .02s; }
.page > .card:nth-of-type(1) { animation-delay: .06s; }
.page > .card:nth-of-type(2) { animation-delay: .12s; }
.page > .card:nth-of-type(3) { animation-delay: .18s; }
.settings-layout { animation-delay: .08s; }

.bot-grid .bot-card { animation: fadeUp var(--mid) var(--ease) both; }
.bot-grid .bot-card:nth-child(1) { animation-delay: .05s; }
.bot-grid .bot-card:nth-child(2) { animation-delay: .10s; }
.bot-grid .bot-card:nth-child(3) { animation-delay: .15s; }
.bot-grid .bot-card:nth-child(4) { animation-delay: .20s; }
.bot-grid .bot-card:nth-child(5) { animation-delay: .25s; }
.bot-grid .bot-card:nth-child(6) { animation-delay: .30s; }
.bot-grid .bot-card:nth-child(7) { animation-delay: .35s; }
.bot-grid .bot-card:nth-child(8) { animation-delay: .40s; }
.bot-grid .bot-card:nth-child(9) { animation-delay: .45s; }

.field { animation: fadeIn var(--mid) var(--ease) both; }
.field:nth-child(2) { animation-delay: .04s; }
.field:nth-child(3) { animation-delay: .08s; }
.field:nth-child(4) { animation-delay: .12s; }
.field:nth-child(5) { animation-delay: .16s; }
.field:nth-child(6) { animation-delay: .20s; }

.alert { animation: slideDown var(--mid) var(--spring) both; }
.card-login,
.card-state { animation: popIn var(--slow) var(--spring) both; }

/* ═══════════ البطاقة الحية ═══════════ */

.bot-dot.on { animation: livePulse 2.4s ease-out infinite; }

.bot-card {
  position: relative;
  overflow: hidden;
  transition: transform var(--mid) var(--spring),
              border-color var(--fast) var(--ease),
              box-shadow var(--mid) var(--ease);
}
.bot-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(88, 101, 242, .18);
}

/* خط ضوئي يعبر الحافة العلوية عند المرور */
.bot-card::before {
  content: "";
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  transform: translateX(-100%);
  transition: transform var(--slow) var(--ease);
}
.bot-card:hover::before { transform: translateX(100%); }

.bot-emoji {
  font-size: 1.05rem;
  flex-shrink: 0;
  transition: transform var(--mid) var(--spring);
}
.bot-card:hover .bot-emoji { transform: scale(1.18) rotate(-6deg); }

.pill { transition: transform var(--fast) var(--spring); }
.bot-card:hover .pill { transform: scale(1.04); }

/* ═══════════ الأزرار ═══════════ */

.btn {
  position: relative;
  overflow: hidden;
  transition: background var(--fast) var(--ease),
              transform var(--fast) var(--spring),
              box-shadow var(--fast) var(--ease);
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(88, 101, 242, .28);
}
/* الضغط ينزل - إحساس ملموس إن الزر انضغط فعلاً */
.btn:active { transform: translateY(1px) scale(.985); box-shadow: none; }
.btn-ghost:hover { box-shadow: none; }

/* موجة تنتشر وقت الضغط */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, .28), transparent 60%);
  opacity: 0;
  transform: scale(.4);
  transition: opacity .5s, transform .5s;
  pointer-events: none;
}
.btn:active::after { opacity: 1; transform: scale(1.6); transition: 0s; }

/* ═══════════ القائمة الجانبية ═══════════ */

.settings-nav-item {
  transition: background var(--fast) var(--ease),
              color var(--fast) var(--ease),
              padding-inline-start var(--fast) var(--ease);
}
.settings-nav-item:hover:not(.active) { padding-inline-start: 18px; }

.settings-nav-item.active { position: relative; overflow: hidden; }
.settings-nav-item.active::before {
  content: "";
  position: absolute;
  inset-inline-end: 0;
  top: 50%;
  width: 3px;
  height: 0;
  background: #fff;
  border-radius: 3px;
  transform: translateY(-50%);
  animation: growBar var(--mid) var(--ease) forwards;
}

/* ═══════════ الشريط العلوي ═══════════ */

.nav-links a { transition: background var(--fast) var(--ease), color var(--fast) var(--ease); }

.brand-mark {
  display: inline-block;
  transition: transform var(--slow) var(--spring);
}
.brand:hover .brand-mark { transform: rotate(-12deg) scale(1.12); }

.avatar { transition: transform var(--mid) var(--spring), border-color var(--fast) var(--ease); }
.nav-user:hover .avatar { transform: scale(1.08); border-color: var(--accent); }

/* ═══════════ الحقول ═══════════ */

.input {
  transition: border-color var(--fast) var(--ease),
              background var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
}
.input:focus { box-shadow: 0 0 0 3px rgba(88, 101, 242, .18); }

.switch-track { transition: background var(--mid) var(--ease); }
.switch-thumb { transition: transform var(--mid) var(--spring); }
/* الإبهام يصغر وقت الضغط - يأكد للعين إن الحالة تبدّلت */
.switch input:active + .switch-track .switch-thumb { transform: scale(.88); }

.check {
  transition: border-color var(--fast) var(--ease),
              background var(--fast) var(--ease),
              transform var(--fast) var(--spring);
}
.check:hover { transform: translateY(-1px); }
.check:has(input:checked) { border-color: var(--accent); background: rgba(88, 101, 242, .1); }

.field-toggle:hover .toggle-text strong { color: #fff; }

/* ═══════════ صفحات الحالة ═══════════ */

.card-state {
  max-width: 560px;
  margin-inline: auto;
  text-align: center;
}
.card-state h1 { margin: 6px 0 10px; font-size: 1.4rem; }

.state-mark {
  font-size: 3.4rem;
  line-height: 1;
  animation: floaty 3.4s ease-in-out infinite;
}
.state-text { margin: 0 auto; max-width: 44ch; }

.state-steps {
  text-align: start;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 34px 16px 16px;
  margin: 20px 0 0;
  display: grid;
  gap: 8px;
}
.state-steps li { animation: fadeUp var(--mid) var(--ease) both; }
.state-steps li:nth-child(1) { animation-delay: .10s; }
.state-steps li:nth-child(2) { animation-delay: .18s; }
.state-steps li:nth-child(3) { animation-delay: .26s; }
.state-steps li:nth-child(4) { animation-delay: .34s; }

.state-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

.back-link {
  display: inline-block;
  margin-bottom: 18px;
  color: var(--text-dim);
  transition: transform var(--fast) var(--ease), color var(--fast) var(--ease);
}
.back-link:hover { color: var(--text); transform: translateX(4px); text-decoration: none; }

/* ═══════════ حالة الحفظ ═══════════ */

.is-saving {
  position: relative;
  pointer-events: none;
  opacity: .75;
}
.is-saving::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(88, 101, 242, .14), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
  border-radius: inherit;
}

/* ═══════════ احترام تفضيل المستخدم ═══════════ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
