/* ============================================
   Professional Motion Patterns
   Based on Motion Dict best practices
   ============================================ */

/* ============================================
   Motion Variables - Professional Timing & Easing
   ============================================ */

:root {
  /* Timing - Based on Motion Dict standards */
  --motion-instant: 0ms;
  --motion-fast: 150ms;
  --motion-normal: 250ms;
  --motion-moderate: 400ms;
  --motion-slow: 600ms;

  /* Easing - Professional curves */
  --ease-entrance: cubic-bezier(0, 0, 0.2, 1);        /* Smooth deceleration for entrances */
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);            /* Smooth acceleration for exits */
  --ease-interaction: cubic-bezier(0.4, 0, 0.2, 1);   /* Balanced for hover/press */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);   /* Subtle bounce */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);        /* General purpose */
}

/* ============================================
   Reduced Motion Support - Accessibility First
   ============================================ */

@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;
  }
}

/* ============================================
   1. Page Transitions - Fade + Slide Pattern
   Duration: 300ms (fast enough to feel responsive)
   ============================================ */

.page {
  display: none;
  min-height: 100vh;
  opacity: 0;
  transform: translateY(20px);
}

.page.active {
  display: block;
  animation: pageEnter var(--motion-normal) var(--ease-entrance) forwards;
}

.page.exiting {
  animation: pageExit var(--motion-fast) var(--ease-exit) forwards;
}

@keyframes pageEnter {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ============================================
   2. Button Interactions - Scale on Press Pattern
   Duration: 100-150ms (immediate feedback)
   ============================================ */

.btn-primary,
.btn-secondary,
.btn-trade,
.btn-nav,
.btn-back {
  position: relative;
  transition: transform var(--motion-fast) var(--ease-interaction),
              box-shadow var(--motion-fast) var(--ease-interaction),
              background-color var(--motion-fast) var(--ease-interaction);
  will-change: transform;
}

.btn-primary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled),
.btn-trade:hover:not(:disabled),
.btn-nav:hover:not(:disabled),
.btn-back:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled),
.btn-trade:active:not(:disabled),
.btn-nav:active:not(:disabled),
.btn-back:active:not(:disabled) {
  transform: scale(0.96);
  transition-duration: var(--motion-fast);
}

/* Button Loading State Pattern */
.btn-loading {
  pointer-events: none;
  position: relative;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: buttonSpinner 600ms linear infinite;
}

@keyframes buttonSpinner {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   3. Progress Bar - Smooth Fill Pattern
   Duration: 400ms (feels responsive but not rushed)
   ============================================ */

.progress-fill {
  transition: width var(--motion-moderate) var(--ease-entrance);
  will-change: width;
}

/* Progress percentage fade in */
.progress-percentage {
  animation: fadeIn var(--motion-normal) var(--ease-entrance);
}

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

/* ============================================
   4. Decision Pressure Block - Spotlight Pattern
   Duration: 500ms (attention-grabbing but not jarring)
   ============================================ */

.decision-pressure-section {
  animation: spotlightEnter var(--motion-slow) var(--ease-entrance);
  transform-origin: center;
}

@keyframes spotlightEnter {
  0% {
    opacity: 0;
    transform: scale(0.95);
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Pulse animation for high pressure */
.decision-pressure-section.high-pressure {
  animation: spotlightEnter var(--motion-slow) var(--ease-entrance),
             pressurePulse 2s var(--ease-smooth) 1s infinite;
}

@keyframes pressurePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(245, 158, 11, 0);
  }
}

/* ============================================
   5. News List - Staggered Load Pattern
   Duration: 50-100ms delay per item
   ============================================ */

.news-item {
  opacity: 0;
  transform: translateX(-20px);
  animation: newsItemEnter var(--motion-normal) var(--ease-entrance) forwards;
}

.news-item:nth-child(1) { animation-delay: 0ms; }
.news-item:nth-child(2) { animation-delay: 50ms; }
.news-item:nth-child(3) { animation-delay: 100ms; }
.news-item:nth-child(4) { animation-delay: 150ms; }
.news-item:nth-child(5) { animation-delay: 200ms; }
.news-item:nth-child(6) { animation-delay: 250ms; }

@keyframes newsItemEnter {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* High impact news - extra emphasis */
.news-item.high-impact {
  animation: newsItemEnterEmphasis var(--motion-moderate) var(--ease-spring) forwards;
}

@keyframes newsItemEnterEmphasis {
  0% {
    opacity: 0;
    transform: translateX(-20px) scale(0.95);
  }
  60% {
    transform: translateX(0) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ============================================
   6. Community Chat - Optimized Scroll Pattern
   Duration: 40s (smooth, not distracting)
   ============================================ */

.chat-messages {
  animation: chatScroll 40s linear infinite;
  will-change: transform;
}

.chat-container:hover .chat-messages {
  animation-play-state: paused;
}

@keyframes chatScroll {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(-50%);
  }
}

/* Individual message entrance */
.chat-message {
  opacity: 0;
  animation: chatMessageFadeIn var(--motion-normal) var(--ease-entrance) forwards;
}

.chat-message:nth-child(1) { animation-delay: 0ms; }
.chat-message:nth-child(2) { animation-delay: 100ms; }
.chat-message:nth-child(3) { animation-delay: 200ms; }
.chat-message:nth-child(4) { animation-delay: 300ms; }
.chat-message:nth-child(5) { animation-delay: 400ms; }

@keyframes chatMessageFadeIn {
  to {
    opacity: 1;
  }
}

/* Sentiment pulse for panic/fomo */
.chat-message.sentiment-panic .message-avatar,
.chat-message.sentiment-fomo .message-avatar {
  animation: sentimentPulse 2s var(--ease-smooth) infinite;
}

@keyframes sentimentPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

/* ============================================
   7. Modal - Fast Fade Pattern
   Duration: 200ms (quick focus, not theatrical)
   ============================================ */

.modal-overlay {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-fast) var(--ease-entrance);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  transform: scale(0.95) translateY(20px);
  opacity: 0;
  transition: transform var(--motion-fast) var(--ease-entrance),
              opacity var(--motion-fast) var(--ease-entrance);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Modal exit animation */
.modal-overlay.exiting {
  opacity: 0;
  transition-duration: var(--motion-fast);
}

.modal-overlay.exiting .modal {
  transform: scale(0.95) translateY(10px);
  opacity: 0;
}

/* ============================================
   8. Expert Opinions - Card Entrance Pattern
   ============================================ */

.expert-card {
  opacity: 0;
  transform: translateY(10px);
  animation: expertCardEnter var(--motion-normal) var(--ease-entrance) forwards;
}

.expert-card:nth-child(1) { animation-delay: 0ms; }
.expert-card:nth-child(2) { animation-delay: 80ms; }
.expert-card:nth-child(3) { animation-delay: 160ms; }

@keyframes expertCardEnter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   9. Sentiment Indicator - Smooth Slide Pattern
   ============================================ */

.sentiment-indicator {
  transition: left var(--motion-moderate) var(--ease-smooth);
  will-change: left;
}

/* ============================================
   10. Scenario Cards - Hover Lift Pattern
   Duration: 200ms (subtle, not aggressive)
   ============================================ */

.scenario-card {
  transition: transform var(--motion-fast) var(--ease-interaction),
              box-shadow var(--motion-fast) var(--ease-interaction);
  will-change: transform;
}

.scenario-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.scenario-card:active {
  transform: translateY(-2px);
  transition-duration: var(--motion-fast);
}

/* ============================================
   11. Toast Notification Pattern
   ============================================ */

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  transform: translateY(100px) scale(0.8);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--motion-normal) var(--ease-entrance),
              opacity var(--motion-normal) var(--ease-entrance);
  z-index: var(--z-tooltip);
}

.toast.active {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.toast.exiting {
  transform: translateY(20px) scale(0.9);
  opacity: 0;
  transition-duration: var(--motion-fast);
}

/* ============================================
   12. Loading Skeleton - Shimmer Pattern
   ============================================ */

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.skeleton {
  position: relative;
  overflow: hidden;
  background-color: var(--bg-tertiary);
}

.skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.4) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: shimmer 2s infinite;
}

/* ============================================
   13. Utility Classes
   ============================================ */

/* Fade utilities */
.fade-in {
  animation: fadeIn var(--motion-normal) var(--ease-entrance);
}

.fade-out {
  animation: fadeOut var(--motion-fast) var(--ease-exit);
}

@keyframes fadeOut {
  to {
    opacity: 0;
  }
}

/* Slide utilities */
.slide-up {
  animation: slideUp var(--motion-normal) var(--ease-entrance);
}

.slide-down {
  animation: slideDown var(--motion-normal) var(--ease-entrance);
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

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

/* Scale utilities */
.scale-in {
  animation: scaleIn var(--motion-normal) var(--ease-spring);
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================
   14. Performance Optimizations
   ============================================ */

/* Use GPU acceleration for animated elements */
.page,
.modal,
.btn-primary,
.btn-secondary,
.btn-trade,
.progress-fill,
.sentiment-indicator,
.chat-messages {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Prevent layout thrashing */
.news-item,
.expert-card,
.chat-message {
  contain: layout style paint;
}
