/* ═══════════════════════════════════════
   ANIMATIONS — красивые плавные эффекты
   Все анимации отключаются при prefers-reduced-motion
   ═══════════════════════════════════════ */

/* ═══════════════════════════════════════
   KEYFRAMES — базовые анимации
   ═══════════════════════════════════════ */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

@keyframes floatSlow {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-12px) rotate(2deg); }
}

@keyframes pulseGlow {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(61, 139, 78, 0.35);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 8px 32px rgba(61, 139, 78, 0.55);
    transform: scale(1.03);
  }
}

@keyframes pulseDot {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.3);
  }
}

@keyframes gradientShift {
  0%, 100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

@keyframes rotate360 {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
}

@keyframes slideInNumber {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ═══════════════════════════════════════
   UTILITY CLASSES — применяй к элементам
   ═══════════════════════════════════════ */

/* Scroll-triggered animations (через IntersectionObserver) */
.animate-on-scroll {
  opacity: 0;
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.animate-on-scroll.is-visible {
  opacity: 1;
}

.animate-fade-up.is-visible {
  animation: fadeInUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.animate-fade-in.is-visible {
  animation: fadeIn 0.6s ease forwards;
}

.animate-fade-scale.is-visible {
  animation: fadeInScale 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.animate-slide-left.is-visible {
  animation: slideInLeft 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.animate-slide-right.is-visible {
  animation: slideInRight 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.animate-bounce-in.is-visible {
  animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

/* Stagger delays для детей */
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.1s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.25s; }
.stagger > *:nth-child(6) { animation-delay: 0.3s; }
.stagger > *:nth-child(7) { animation-delay: 0.35s; }
.stagger > *:nth-child(8) { animation-delay: 0.4s; }

/* Непрерывные анимации */
.float {
  animation: float 3s ease-in-out infinite;
}

.float-slow {
  animation: floatSlow 5s ease-in-out infinite;
}

.pulse-glow {
  animation: pulseGlow 2.5s ease-in-out infinite;
}

.pulse-dot {
  animation: pulseDot 1.8s ease-in-out infinite;
}

.breathe {
  animation: breathe 3s ease-in-out infinite;
}

.blink {
  animation: blink 1.5s ease-in-out infinite;
}

.rotate-slow {
  animation: rotate360 20s linear infinite;
}

.spin {
  animation: spin 1s linear infinite;
}

/* Живой градиент */
.animated-gradient {
  background-size: 200% 200%;
  animation: gradientShift 8s ease infinite;
}

/* Shimmer (loading) */
.shimmer {
  background: linear-gradient(
    90deg,
    var(--surface-2, #F2F7F2) 25%,
    rgba(255, 255, 255, 0.6) 50%,
    var(--surface-2, #F2F7F2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* ═══════════════════════════════════════
   INTERACTIVE — hover и click эффекты
   ═══════════════════════════════════════ */

/* Ripple effect (JS добавляет .ripple-element) */
.ripple-element {
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: scale(0);
  animation: ripple 0.6s linear;
  pointer-events: none;
}

.ripple-dark .ripple {
  background: rgba(28, 43, 28, 0.15);
}

/* Tilt 3D эффект при hover */
.tilt-card {
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.3s ease;
  transform-style: preserve-3d;
}

.tilt-card:hover {
  box-shadow: 0 12px 32px rgba(28, 43, 28, 0.18);
}

/* Magnetic button (притягивается к курсору) */
.magnetic-btn {
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

/* Scale on click */
.click-scale {
  transition: transform 0.15s ease;
}

.click-scale:active {
  transform: scale(0.95);
}

/* Shake для ошибок */
.shake {
  animation: shake 0.5s ease;
}

/* Hover lift */
.hover-lift {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(28, 43, 28, 0.15);
}

/* Hover glow */
.hover-glow {
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.hover-glow:hover {
  box-shadow: 0 0 0 4px rgba(61, 139, 78, 0.15),
              0 8px 24px rgba(61, 139, 78, 0.25);
}

/* ═══════════════════════════════════════
   SPECIFIC ELEMENTS — улучшаем существующие
   ═══════════════════════════════════════ */

/* Quick action icons — добавляем float при hover */
.qi-icon {
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.3s ease;
}

.qi:hover .qi-icon {
  animation: float 2s ease-in-out infinite;
  box-shadow: 0 12px 28px rgba(61, 139, 78, 0.25);
}

/* Vitals cards — tilt on hover */
.v-card {
  perspective: 1000px;
}

/* FAB кнопка — постоянное свечение */
.nav-fab {
  animation: pulseGlow 2.5s ease-in-out infinite;
}

.nav-fab:hover {
  animation: none;
  transform: scale(1.08);
}

/* Status dot — пульсация */
.status-icons span:last-child {
  animation: breathe 2s ease-in-out infinite;
}

/* Toast — плавное появление */
.toast {
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Patient card — мягкая анимация появления */
.patient-card {
  animation: fadeInDown 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Bar chart bars — staggered animation */
.bc-fill {
  transform-origin: bottom;
  animation: fadeInUp 0.8s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.bc-col:nth-child(1) .bc-fill { animation-delay: 0.1s; }
.bc-col:nth-child(2) .bc-fill { animation-delay: 0.2s; }
.bc-col:nth-child(3) .bc-fill { animation-delay: 0.3s; }
.bc-col:nth-child(4) .bc-fill { animation-delay: 0.4s; }
.bc-col:nth-child(5) .bc-fill { animation-delay: 0.5s; }
.bc-col:nth-child(6) .bc-fill { animation-delay: 0.6s; }
.bc-col:nth-child(7) .bc-fill { animation-delay: 0.7s; }

/* Sparkline bars — последовательное появление */
.spark .sp-b {
  animation: fadeInUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.spark .sp-b:nth-child(1) { animation-delay: 0.05s; }
.spark .sp-b:nth-child(2) { animation-delay: 0.1s; }
.spark .sp-b:nth-child(3) { animation-delay: 0.15s; }
.spark .sp-b:nth-child(4) { animation-delay: 0.2s; }
.spark .sp-b:nth-child(5) { animation-delay: 0.25s; }
.spark .sp-b:nth-child(6) { animation-delay: 0.3s; }
.spark .sp-b:nth-child(7) { animation-delay: 0.35s; }

/* Progress fill — плавное заполнение */
.progress-fill {
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Med check — bounce при активации */
.med-check.taken {
  animation: bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Dark card — анимированный градиент */
.dark-card {
  background: linear-gradient(
    135deg,
    var(--dark) 0%,
    var(--dark-2) 50%,
    var(--dark) 100%
  );
  background-size: 200% 200%;
  animation: gradientShift 10s ease infinite;
}

/* Modal sheet — плавное появление */
.modal-sheet {
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Bottom nav — плавное появление */
.bottom-nav {
  animation: fadeInUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.3s backwards;
}

/* Pill buttons — ripple + scale */
.pill {
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.pill:active {
  transform: scale(0.95);
}

/* Circle buttons — rotate on hover */
.circle-btn {
  transition: transform 0.3s ease, background 0.2s ease;
}

.circle-btn:hover {
  transform: rotate(15deg);
}

/* Folder chevron — плавный поворот */
.folder-chevron {
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Toggle — плавный переход */
.toggle::after {
  transition: left 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              background 0.3s ease;
}

/* ═══════════════════════════════════════
   COUNTER — для анимации чисел
   ═══════════════════════════════════════ */

.counter-value {
  display: inline-block;
  transition: transform 0.3s ease;
}

.counter-value.counting {
  animation: slideInNumber 0.3s ease;
}

/* ═══════════════════════════════════════
   MARQUEE — бегущая строка
   ═══════════════════════════════════════ */

.marquee {
  overflow: hidden;
  white-space: nowrap;
}

.marquee-content {
  display: inline-block;
  animation: marquee 30s linear infinite;
}

.marquee-content:hover {
  animation-play-state: paused;
}

/* ═══════════════════════════════════════
   LOADING SKELETON — состояние загрузки
   ═══════════════════════════════════════ */

.skeleton-text {
  height: 14px;
  border-radius: 4px;
  margin: 6px 0;
}

.skeleton-title {
  height: 20px;
  width: 60%;
  border-radius: 4px;
  margin-bottom: 8px;
}

.skeleton-circle {
  border-radius: 50%;
}

/* ═══════════════════════════════════════
   ACCESSIBILITY — отключаем анимации
   ═══════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .animate-on-scroll {
    opacity: 1 !important;
    transform: none !important;
  }

  .nav-fab,
  .qi:hover .qi-icon {
    animation: none !important;
  }
}

/* ═══════════════════════════════════════
   PERFORMANCE — оптимизация
   ═══════════════════════════════════════ */

/* GPU-ускорение для анимаций */
.tilt-card,
.magnetic-btn,
.nav-fab,
.qi-icon,
.float,
.float-slow,
.pulse-glow {
  will-change: transform;
}

/* Отключаем will-change после анимации */
.animate-fade-up.is-visible,
.animate-fade-in.is-visible,
.animate-slide-left.is-visible,
.animate-slide-right.is-visible {
  will-change: auto;
}