/* ===========================================================
   ANIMATIONS.CSS — Микро-анимации и эффекты Gramaton Messenger
   Кастомные кривые Безье, stagger, parallax, волна аудио
   Все анимации оптимизированы под 60-120 FPS (GPU accelerated)
   =========================================================== */

/* ── Кастомные easing-функции ──────────────────────────────── */
:root {
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
  --ease-in-out-expo: cubic-bezier(0.87, 0, 0.13, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-premium: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-glass: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Анимация появления сообщений ──────────────────────────── */
@keyframes messageIn {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message-enter {
  animation: messageIn 0.3s var(--ease-premium) forwards;
}

/* ── Анимация для собственных сообщений (справа) ──────────── */
@keyframes messageInMine {
  0% {
    opacity: 0;
    transform: translateX(20px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

.message-enter-mine {
  animation: messageInMine 0.3s var(--ease-premium) forwards;
}

/* ── Анимация для чужих сообщений (слева) ─────────────────── */
@keyframes messageInOther {
  0% {
    opacity: 0;
    transform: translateX(-20px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

.message-enter-other {
  animation: messageInOther 0.3s var(--ease-premium) forwards;
}

/* ── Parallax для Drawer (основной контент) ────────────────── */
.drawer-parallax {
  transition: transform 0.35s var(--ease-premium),
              opacity 0.35s var(--ease-premium),
              filter 0.35s var(--ease-premium);
  will-change: transform;
}

.drawer-parallax.active {
  transform: scale(0.96) translate3d(85%, 0, 0);
  opacity: 0.9;
  filter: blur(8px);
}

/* ── Каскадное появление (Stagger) ─────────────────────────── */
.stagger-item {
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.4s var(--ease-premium);
}

.stagger-item.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Микро-анимация статуса "печатает" ─────────────────────── */
@keyframes typingDot {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

.typing-indicator span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--border-purple);
  border-radius: 50%;
  animation: typingDot 1.4s ease-in-out infinite;
  margin-right: 3px;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ── Пульс для индикатора "онлайн" ─────────────────────────── */
@keyframes onlinePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.status-dot.online::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  animation: onlinePulse 2s ease-in-out infinite;
}

/* ── Анимация непрочитанного badge ─────────────────────────── */
@keyframes badgePop {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.badge-new {
  animation: badgePop 0.35s var(--ease-spring) forwards;
}

/* ── Анимация загрузки сообщений (skeleton) ────────────────── */
@keyframes shimmerSlide {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(122, 34, 166, 0.1) 25%,
    rgba(122, 34, 166, 0.2) 50%,
    rgba(122, 34, 166, 0.1) 75%
  );
  background-size: 800px 100%;
  animation: shimmerSlide 1.5s ease-in-out infinite;
  border-radius: 6px;
}

.skeleton-line {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    rgba(122, 34, 166, 0.08) 25%,
    rgba(122, 34, 166, 0.15) 50%,
    rgba(122, 34, 166, 0.08) 75%
  );
  background-size: 800px 100%;
  animation: shimmerSlide 1.5s ease-in-out infinite;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(
    90deg,
    rgba(122, 34, 166, 0.08) 25%,
    rgba(122, 34, 166, 0.15) 50%,
    rgba(122, 34, 166, 0.08) 75%
  );
  background-size: 800px 100%;
  animation: shimmerSlide 1.5s ease-in-out infinite;
}

/* ── Аудио-волна (Canvas) ──────────────────────────────────── */
@keyframes waveMove {
  0% { transform: scaleY(1); }
  50% { transform: scaleY(0.6); }
  100% { transform: scaleY(1); }
}

.audio-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
}

.audio-wave .bar {
  width: 3px;
  height: 100%;
  background: var(--neon-purple);
  border-radius: 2px;
  animation: waveMove 0.8s ease-in-out infinite;
}

.audio-wave .bar:nth-child(1) { animation-delay: 0s; }
.audio-wave .bar:nth-child(2) { animation-delay: 0.1s; }
.audio-wave .bar:nth-child(3) { animation-delay: 0.2s; }
.audio-wave .bar:nth-child(4) { animation-delay: 0.3s; }
.audio-wave .bar:nth-child(5) { animation-delay: 0.4s; }
.audio-wave .bar:nth-child(6) { animation-delay: 0.5s; }
.audio-wave .bar:nth-child(7) { animation-delay: 0.6s; }

/* ── Анимация смахивания (Swipe hint) ──────────────────────── */
@keyframes swipeHint {
  0% { transform: translateX(0); opacity: 0.5; }
  50% { transform: translateX(20px); opacity: 1; }
  100% { transform: translateX(0); opacity: 0.5; }
}

.swipe-hint {
  animation: swipeHint 2s var(--ease-premium) infinite;
}

/* ── Анимация отправки сообщения ───────────────────────────── */
@keyframes sendSuccess {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
  100% { transform: scale(1); opacity: 1; }
}

.send-success {
  animation: sendSuccess 0.3s ease;
}

/* ── Анимация загрузки файла ───────────────────────────────── */
@keyframes fileUpload {
  0% { width: 0%; }
  100% { width: 100%; }
}

.file-progress {
  height: 2px;
  background: var(--neon-purple);
  animation: fileUpload 2s var(--ease-premium) forwards;
}

/* ── Неоновая подсветка при фокусе ─────────────────────────── */
@keyframes neonGlow {
  0%, 100% {
    box-shadow: 0 0 5px rgba(122, 34, 166, 0.2),
                0 0 10px rgba(122, 34, 166, 0.1);
  }
  50% {
    box-shadow: 0 0 10px rgba(122, 34, 166, 0.4),
                0 0 20px rgba(122, 34, 166, 0.2);
  }
}

input:focus, textarea:focus, select:focus {
  animation: neonGlow 2s ease-in-out infinite;
}

/* ── Анимация появления Drawer (мобильное меню) ────────────── */
@keyframes drawerSlideIn {
  0% { transform: translate3d(-100%, 0, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.drawer-slide-in {
  animation: drawerSlideIn 0.35s var(--ease-premium) forwards;
  will-change: transform;
}

/* ── Анимация закрытия Drawer ──────────────────────────────── */
@keyframes drawerSlideOut {
  0% { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(-100%, 0, 0); }
}

.drawer-slide-out {
  animation: drawerSlideOut 0.25s var(--ease-premium) forwards;
  will-change: transform;
}

/* ── Fade для оверлея ──────────────────────────────────────── */
@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.overlay-fade-in {
  animation: overlayFadeIn 0.35s var(--ease-premium) forwards;
}

.overlay-fade-out {
  animation: overlayFadeOut 0.25s var(--ease-premium) forwards;
}

/* ── Анимация для галереи медиа-статусов ───────────────────── */
@keyframes statusRing {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.status-ring {
  animation: statusRing 2s linear infinite;
}

/* ── Reduce Motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Анимация для голосовых сообщений ──────────────────────── */
@keyframes recordingPulse {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}

.recording-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #EF4444;
  animation: recordingPulse 1s ease-in-out infinite;
}

/* ── Анимация тени карточек при hover ──────────────────────── */
.glass-card {
  transition: transform 0.3s var(--ease-glass),
              box-shadow 0.3s var(--ease-glass),
              border-color 0.3s var(--ease-glass);
}

.glass-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.4),
    0 0 30px rgba(122, 34, 166, 0.08);
  border-color: rgba(122, 34, 166, 0.5);
}