/**
 * 999DEX COMPLETE ANIMATION SYSTEM
 *
 * Comprehensive animation coverage for EVERY interactive element
 * Based on pump.fun research (Agent 2) and design system foundation (Agent 9)
 *
 * Version: 1.0.0
 * Date: November 2, 2025
 * Agent: 20 - Complete Animation System Implementation
 *
 * PERFORMANCE RULES:
 * - GPU-accelerated properties only (transform, opacity)
 * - 60fps target on desktop, 50-60fps on mobile
 * - Respects prefers-reduced-motion
 * - Will-change used sparingly
 *
 * COVERAGE:
 * - Button states (hover, active, loading, disabled)
 * - Modal animations (enter, exit, backdrop)
 * - Toast notifications (slide in, auto-dismiss, stack)
 * - Form interactions (focus, blur, error, success)
 * - Number counters (count up effect)
 * - Progress bars (smooth filling)
 * - Micro-interactions (copy, hover tooltips, badges)
 */

/* ========================================
   BUTTON ANIMATIONS
   ======================================== */

/* Active/Pressed State - All Buttons */
.btn:active:not(:disabled),
.sidebar-create-btn:active:not(:disabled),
.sidebar-connect:active:not(:disabled),
button:not(.no-active):active:not(:disabled) {
  transform: scale(0.95);
  transition: transform 100ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Loading State - Button with Spinner */
.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-top: -9px;
  margin-left: -9px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--text-primary, white);
  border-radius: 50%;
  animation: btnSpinner 600ms linear infinite;
}

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

/* Button Ripple Effect (Material Design) */
.btn-ripple {
  position: relative;
  overflow: hidden;
}

.btn-ripple::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 600ms, height 600ms;
}

.btn-ripple:active::before {
  width: 300px;
  height: 300px;
}

/* Icon Button Animation */
.btn-icon {
  transition: transform var(--transition-normal, 200ms) ease-out;
}

.btn-icon:hover {
  transform: scale(1.1);
}

.btn-icon:active {
  transform: scale(0.9);
}

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

/* Modal Backdrop Fade In */
.modal-backdrop-enter {
  animation: modalBackdropFadeIn 200ms ease-out forwards;
}

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

/* Modal Backdrop Fade Out */
.modal-backdrop-exit {
  animation: modalBackdropFadeOut 150ms ease-in forwards;
}

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

/* Modal Content Slide Up + Scale */
.modal-enter {
  animation: modalEnter 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* Modal Content Exit */
.modal-exit {
  animation: modalExit 150ms cubic-bezier(0.4, 0, 1, 1) forwards;
}

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

/* Modal Shake (for errors) */
@keyframes modalShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
}

.modal-shake {
  animation: modalShake 400ms ease-in-out;
}

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

/* Toast Container */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-base);
  max-width: 400px;
  pointer-events: none;
}

.toast-container > * {
  pointer-events: auto;
}

/* Toast Base Styles */
.toast {
  background: var(--bg-secondary, rgba(20, 20, 30, 0.95));
  border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  padding: var(--spacing-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-base);
  min-width: 320px;
  max-width: 400px;
}

/* Toast Enter Animation - Slide In from Right */
.toast-enter {
  animation: toastSlideInRight 300ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* Toast Exit Animation - Fade Out + Slide Right */
.toast-exit {
  animation: toastSlideOutRight 200ms ease-in forwards;
}

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

/* Toast Progress Bar */
.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: currentColor;
  opacity: 0.5;
  transform-origin: left;
  animation: toastProgress 5000ms linear forwards;
}

@keyframes toastProgress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

/* Toast Types */
.toast-success {
  border-left: 4px solid var(--accent-green, #22c55e);
}

.toast-error {
  border-left: 4px solid var(--accent-red, #ef4444);
}

.toast-warning {
  border-left: 4px solid var(--accent-yellow, #f59e0b);
}

.toast-info {
  border-left: 4px solid var(--accent-blue, #3b82f6);
}

/* Toast Icon */
.toast-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Toast Content */
.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary, white);
  margin: 0 0 4px 0;
}

.toast-message {
  font-size: var(--font-size-sm);
  color: var(--text-secondary, rgba(255, 255, 255, 0.7));
  margin: 0;
  word-wrap: break-word;
}

/* Toast Close Button */
.toast-close {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-secondary, rgba(255, 255, 255, 0.5));
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 150ms ease-out;
}

.toast-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary, white);
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .toast-container {
    right: 12px;
    left: 12px;
    max-width: none;
  }

  .toast {
    min-width: 0;
    max-width: none;
  }
}

/* ========================================
   FORM ANIMATIONS
   ======================================== */

/* Input Focus Animation */
.form-input,
.form-select,
.form-textarea,
.search-input {
  transition: border-color 200ms ease-out,
              background-color 200ms ease-out,
              box-shadow 200ms ease-out;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
.search-input:focus {
  border-color: var(--accent-purple, #a855f7);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.1);
  outline: none;
}

/* Input Error Shake */
.form-input.error,
.form-select.error,
.form-textarea.error {
  animation: inputShake 400ms ease-in-out;
  border-color: var(--accent-red, #ef4444);
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* Input Success Animation */
.form-input.success,
.form-select.success,
.form-textarea.success {
  border-color: var(--accent-green, #22c55e);
  animation: inputSuccessPulse 500ms ease-out;
}

@keyframes inputSuccessPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
  }
}

/* Label Float Animation */
.form-label-float {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  color: var(--text-muted, rgba(255, 255, 255, 0.5));
  font-size: var(--font-size-sm);
}

.form-input:focus ~ .form-label-float,
.form-input:not(:placeholder-shown) ~ .form-label-float {
  top: 0;
  left: 12px;
  font-size: var(--font-size-xs);
  color: var(--accent-purple, #a855f7);
  background: var(--bg-secondary, rgba(20, 20, 30, 1));
  padding: 0 4px;
}

/* Checkbox Animation */
.form-checkbox {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-primary, rgba(255, 255, 255, 0.2));
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: all 150ms ease-out;
}

.form-checkbox:checked {
  background: var(--accent-purple, #a855f7);
  border-color: var(--accent-purple, #a855f7);
}

.form-checkbox:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 6px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  animation: checkmark 200ms ease-out;
}

@keyframes checkmark {
  0% {
    opacity: 0;
    transform: rotate(45deg) scale(0);
  }
  100% {
    opacity: 1;
    transform: rotate(45deg) scale(1);
  }
}

/* Radio Button Animation */
.form-radio {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-primary, rgba(255, 255, 255, 0.2));
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  transition: all 150ms ease-out;
}

.form-radio:checked {
  border-color: var(--accent-purple, #a855f7);
}

.form-radio:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  background: var(--accent-purple, #a855f7);
  border-radius: 50%;
  animation: radioCheck 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes radioCheck {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* File Upload Drag & Drop */
.file-upload-zone {
  transition: all 200ms ease-out;
  border: 2px dashed var(--border-primary, rgba(255, 255, 255, 0.2));
}

.file-upload-zone.dragging {
  border-color: var(--accent-purple, #a855f7);
  background: rgba(168, 85, 247, 0.1);
  transform: scale(1.02);
}

/* ========================================
   NUMBER COUNTER ANIMATIONS
   ======================================== */

/* Counter Digit Roll */
@keyframes counterRoll {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.counter-digit {
  display: inline-block;
  animation: counterRoll 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Counter Increment Highlight */
@keyframes counterHighlight {
  0% {
    color: var(--text-primary, white);
    transform: scale(1);
  }
  50% {
    color: var(--accent-green, #22c55e);
    transform: scale(1.2);
  }
  100% {
    color: var(--text-primary, white);
    transform: scale(1);
  }
}

.counter-increment {
  animation: counterHighlight 600ms ease-out;
}

/* Counter Decrement Highlight */
@keyframes counterDecrementHighlight {
  0% {
    color: var(--text-primary, white);
    transform: scale(1);
  }
  50% {
    color: var(--accent-red, #ef4444);
    transform: scale(1.2);
  }
  100% {
    color: var(--text-primary, white);
    transform: scale(1);
  }
}

.counter-decrement {
  animation: counterDecrementHighlight 600ms ease-out;
}

/* ========================================
   PROGRESS BAR ANIMATIONS
   ======================================== */

/* Progress Fill Animation */
.progress-bar-fill {
  transition: width 800ms cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

/* Progress Shimmer Effect */
.progress-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  animation: progressShimmer 2s ease-in-out infinite;
}

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

/* Progress Pulse (for loading states) */
.progress-pulse {
  animation: progressPulse 1.5s ease-in-out infinite;
}

@keyframes progressPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Indeterminate Progress Bar */
.progress-indeterminate {
  position: relative;
  overflow: hidden;
}

.progress-indeterminate::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 40%;
  height: 100%;
  background: var(--accent-purple, #a855f7);
  animation: progressIndeterminate 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes progressIndeterminate {
  0% {
    left: -40%;
  }
  100% {
    left: 100%;
  }
}

/* ========================================
   MICRO-INTERACTIONS
   ======================================== */

/* Copy to Clipboard Animation */
@keyframes copySuccess {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

.copy-success {
  animation: copySuccess 300ms ease-out;
}

/* Hover Tooltip Animation */
.tooltip-hover {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 200ms ease-out,
              transform 200ms ease-out;
  pointer-events: none;
}

.tooltip-trigger:hover .tooltip-hover {
  opacity: 1;
  transform: translateY(0);
}

/* Badge Pulse (Real-time Updates) */
@keyframes badgePulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

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

/* Badge Pop In (New Notification) */
@keyframes badgePopIn {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.badge-pop-in {
  animation: badgePopIn 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Live Indicator Pulse */
@keyframes liveIndicatorPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
  }
}

.live-indicator {
  animation: liveIndicatorPulse 2s ease-out infinite;
}

/* Heart Animation (Like Button) */
@keyframes heartBeat {
  0% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.3);
  }
  50% {
    transform: scale(1.1);
  }
  75% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

.heart-animate {
  animation: heartBeat 500ms ease-out;
}

/* Star Rating Animation */
@keyframes starFill {
  0% {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(0deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.star-fill {
  animation: starFill 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   CARD CLICK FEEDBACK
   ======================================== */

/* Card Active State */
.token-card:active,
.card-clickable:active {
  transform: translateY(-2px) scale(1.01) !important;
  transition: transform 100ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   DROPDOWN ANIMATIONS
   ======================================== */

/* Dropdown Slide Down */
.dropdown-enter {
  animation: dropdownSlideDown 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* Dropdown Slide Up */
.dropdown-exit {
  animation: dropdownSlideUp 150ms ease-in forwards;
}

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

/* ========================================
   SKELETON LOADER ENHANCEMENTS
   ======================================== */

/* Skeleton Fade In when loaded */
.skeleton-loaded {
  animation: skeletonFadeIn 400ms ease-out forwards;
}

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

/* ========================================
   ACCORDION ANIMATIONS
   ======================================== */

/* Accordion Expand */
.accordion-content-enter {
  animation: accordionExpand 300ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes accordionExpand {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 1000px;
  }
}

/* Accordion Collapse */
.accordion-content-exit {
  animation: accordionCollapse 200ms ease-in forwards;
}

@keyframes accordionCollapse {
  from {
    opacity: 1;
    max-height: 1000px;
  }
  to {
    opacity: 0;
    max-height: 0;
  }
}

/* ========================================
   ACCESSIBILITY: REDUCED MOTION
   ======================================== */

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

  /* Disable specific animations */
  .badge-pulse,
  .live-indicator,
  .progress-shimmer,
  .spinner {
    animation: none !important;
  }

  /* Keep essential feedback */
  .btn:active,
  .token-card:active,
  button:active {
    transform: scale(0.95);
  }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
  /* Remove all animations for print */
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  /* Hide interactive overlays */
  .modal-backdrop,
  .toast-container,
  .tooltip-hover {
    display: none !important;
  }
}
