/*
 * FOUNDRY - Animations & Micro-interactions
 * Motion with meaning
 */

/* ============================================
   PAGE TRANSITIONS
   ============================================ */

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

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

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

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   ELEMENT ANIMATIONS
   ============================================ */

.animate-fade-in {
  animation: fadeIn var(--duration-normal) var(--ease-out) forwards;
}

.animate-fade-in-up {
  animation: fadeInUp var(--duration-normal) var(--ease-out) forwards;
}

.animate-fade-in-down {
  animation: fadeInDown var(--duration-normal) var(--ease-out) forwards;
}

.animate-fade-in-scale {
  animation: fadeInScale var(--duration-normal) var(--ease-out) forwards;
}

.animate-slide-in-left {
  animation: slideInLeft var(--duration-normal) var(--ease-out) forwards;
}

.animate-slide-in-right {
  animation: slideInRight var(--duration-normal) var(--ease-out) forwards;
}

/* Staggered animations */
.stagger-1 { animation-delay: 50ms; }
.stagger-2 { animation-delay: 100ms; }
.stagger-3 { animation-delay: 150ms; }
.stagger-4 { animation-delay: 200ms; }
.stagger-5 { animation-delay: 250ms; }

/* ============================================
   LOADING ANIMATIONS
   ============================================ */

/* Pulsing dot */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(0.95);
  }
}

.animate-pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* Bouncing dots (typing indicator) */
@keyframes bounce {
  0%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: var(--space-4);
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-tertiary);
  border-radius: var(--radius-full);
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

/* Spinner */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

/* ============================================
   SHIMMER / SKELETON
   ============================================ */

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

.shimmer {
  background: linear-gradient(
    90deg,
    var(--surface-secondary) 0%,
    var(--surface-tertiary) 50%,
    var(--surface-secondary) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* Skeleton components */
.skeleton-text {
  height: 16px;
  border-radius: var(--radius-sm);
}

.skeleton-text-sm {
  height: 12px;
}

.skeleton-text-lg {
  height: 24px;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

.skeleton-card {
  height: 120px;
  border-radius: var(--radius-lg);
}

/* ============================================
   BUTTON STATES
   ============================================ */

/* Ripple effect */
.btn-ripple {
  position: relative;
  overflow: hidden;
}

.btn-ripple::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-full);
  transform: translate(-50%, -50%);
  transition: width 0.3s ease-out, height 0.3s ease-out, opacity 0.3s ease-out;
  opacity: 0;
}

.btn-ripple:active::after {
  width: 200px;
  height: 200px;
  opacity: 1;
  transition: 0s;
}

/* Loading button state */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

.btn-primary.btn-loading::after {
  border-color: var(--text-inverse);
  border-right-color: transparent;
}

/* ============================================
   HOVER EFFECTS
   ============================================ */

/* Lift effect */
.hover-lift {
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Scale effect */
.hover-scale {
  transition: transform var(--duration-fast) var(--ease-out);
}

.hover-scale:hover {
  transform: scale(1.02);
}

/* Glow effect */
.hover-glow {
  transition: box-shadow var(--duration-fast) var(--ease-out);
}

.hover-glow:hover {
  box-shadow: 0 0 30px var(--accent-primary-glow);
}

/* ============================================
   CHAT MESSAGE ANIMATIONS
   ============================================ */

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

@keyframes messageSlideInLeft {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes messageSlideInRight {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.message {
  animation: messageSlideIn var(--duration-normal) var(--ease-out);
}

.message-assistant {
  animation: messageSlideInLeft var(--duration-normal) var(--ease-out);
}

.message-user {
  animation: messageSlideInRight var(--duration-normal) var(--ease-out);
}

/* Progress bar inside tool events */
@keyframes progressFill {
  from {
    width: 0%;
  }
  to {
    width: var(--progress, 100%);
  }
}

.tool-progress-bar {
  height: 4px;
  background: var(--surface-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.tool-progress-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: progressFill var(--duration-slower) var(--ease-out) forwards;
}

/* ============================================
   MODAL ANIMATIONS
   ============================================ */

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

@keyframes modalContentIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

.modal-overlay {
  animation: modalOverlayIn var(--duration-normal) var(--ease-out);
}

.modal-overlay.active .modal {
  animation: modalContentIn var(--duration-normal) var(--ease-out);
}

.modal-overlay.closing .modal {
  animation: modalContentOut var(--duration-fast) var(--ease-out);
}

/* ============================================
   SIDEBAR ANIMATIONS
   ============================================ */

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

.sidebar .nav-item {
  animation: sidebarIn var(--duration-normal) var(--ease-out) backwards;
}

.sidebar .nav-item:nth-child(1) { animation-delay: 50ms; }
.sidebar .nav-item:nth-child(2) { animation-delay: 75ms; }
.sidebar .nav-item:nth-child(3) { animation-delay: 100ms; }
.sidebar .nav-item:nth-child(4) { animation-delay: 125ms; }
.sidebar .nav-item:nth-child(5) { animation-delay: 150ms; }

/* ============================================
   NOTIFICATION / TOAST
   ============================================ */

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

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

.toast {
  animation: toastIn var(--duration-normal) var(--ease-out);
}

.toast.leaving {
  animation: toastOut var(--duration-fast) var(--ease-out);
}

/* ============================================
   FOCUS ANIMATIONS
   ============================================ */

@keyframes focusRing {
  0% {
    box-shadow: 0 0 0 0 var(--accent-primary-muted);
  }
  50% {
    box-shadow: 0 0 0 4px var(--accent-primary-muted);
  }
  100% {
    box-shadow: 0 0 0 4px var(--accent-primary-muted);
  }
}

.focus-animate:focus {
  animation: focusRing var(--duration-normal) var(--ease-out);
}

/* ============================================
   SUCCESS ANIMATIONS
   ============================================ */

@keyframes checkmark {
  0% {
    stroke-dashoffset: 100;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

.checkmark-icon {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: checkmark var(--duration-slow) var(--ease-out) forwards;
}

/* Confetti burst (for celebrations) */
@keyframes confetti {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(-200px) rotate(720deg);
    opacity: 0;
  }
}

.confetti-particle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent-primary);
  animation: confetti 1s ease-out forwards;
}

/* ============================================
   REDUCED MOTION
   Accessibility: Respect user preferences
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .animate-pulse {
    animation: none;
  }
  
  .typing-dots span {
    animation: none;
  }
}
