/* Animation Styles - Smooth transitions and micro-interactions */

/* ===== KEYFRAME ANIMATIONS ===== */

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

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

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

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

@keyframes scaleOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.8);
  }
}

@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translate3d(0, 0, 0);
  }
  40%, 43% {
    transform: translate3d(0, -30px, 0);
  }
  70% {
    transform: translate3d(0, -15px, 0);
  }
  90% {
    transform: translate3d(0, -4px, 0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.8;
  }
}

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

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

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

@keyframes wiggle {
  0%, 7% {
    transform: rotateZ(0);
  }
  15% {
    transform: rotateZ(-15deg);
  }
  20% {
    transform: rotateZ(10deg);
  }
  25% {
    transform: rotateZ(-10deg);
  }
  30% {
    transform: rotateZ(6deg);
  }
  35% {
    transform: rotateZ(-4deg);
  }
  40%, 100% {
    transform: rotateZ(0);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-20px);
  }
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 5px var(--brokerly-primary);
  }
  50% {
    box-shadow: 0 0 20px var(--brokerly-primary), 0 0 30px var(--brokerly-primary);
  }
}

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

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

/* ===== CARD ANIMATIONS ===== */

.card-enter {
  animation: fadeIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card-exit {
  animation: fadeOut 0.3s ease-out;
}

.card-flip {
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.card-flip.flipped {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.card-back {
  transform: rotateY(180deg);
}

/* Swipe animations for action cards */
.card-swipe-left {
  animation: slideOutLeft 0.3s ease-out forwards;
}

.card-swipe-right {
  animation: slideOutRight 0.3s ease-out forwards;
}

@keyframes slideOutLeft {
  to {
    transform: translateX(-100%) rotate(-10deg);
    opacity: 0;
  }
}

@keyframes slideOutRight {
  to {
    transform: translateX(100%) rotate(10deg);
    opacity: 0;
  }
}

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

.button-press {
  transform: scale(0.95);
  transition: transform 0.1s ease-out;
}

.button-hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-medium);
  transition: all var(--transition-fast);
}

.button-loading {
  position: relative;
  color: transparent;
}

.button-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ===== TAB ANIMATIONS ===== */

.tab-switching-out {
  animation: tabOut 0.3s ease-out;
}

.tab-switching-in {
  animation: tabIn 0.3s ease-out;
}

@keyframes tabOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0.5;
    transform: scale(0.95);
  }
}

@keyframes tabIn {
  from {
    opacity: 0.5;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* AI tab special animation */
.ai-tab .ai-border-gradient {
  animation: rotate 3s linear infinite;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.ai-tab.active .ai-border-gradient,
.ai-tab:hover .ai-border-gradient {
  opacity: 1;
}

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

.modal-overlay {
  animation: modalOverlayIn 0.3s ease-out;
}

.modal-overlay.closing {
  animation: modalOverlayOut 0.3s ease-out;
}

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

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

.modal {
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.closing {
  animation: modalOut 0.3s ease-out;
}

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

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

/* ===== TOAST ANIMATIONS ===== */

.toast {
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.show {
  animation: toastShow 0.3s ease-out;
}

.toast.hide {
  animation: toastOut 0.3s ease-out;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-100%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

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

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

.loading-spinner {
  animation: spin 1s linear infinite;
}

.loading-dots::after {
  content: '';
  animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
  0%, 20% {
    content: '.';
  }
  40% {
    content: '..';
  }
  60%, 100% {
    content: '...';
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--brokerly-tertiary-background) 25%,
    var(--brokerly-border-light) 50%,
    var(--brokerly-tertiary-background) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

.progress-bar {
  overflow: hidden;
  position: relative;
}

.progress-fill {
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-indeterminate {
  position: relative;
  overflow: hidden;
}

.progress-indeterminate::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: var(--brokerly-primary);
  animation: progressIndeterminate 2s infinite;
}

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

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

.hover-lift {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

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

.hover-scale {
  transition: transform var(--transition-fast);
}

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

.hover-glow {
  transition: box-shadow var(--transition-fast);
}

.hover-glow:hover {
  box-shadow: 0 0 20px var(--brokerly-primary-light);
}

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

.focus-ring {
  transition: box-shadow var(--transition-fast);
}

.focus-ring:focus-visible {
  box-shadow: 0 0 0 3px var(--brokerly-primary-light);
}

/* ===== GESTURE ANIMATIONS ===== */

.swipe-indicator {
  position: relative;
  overflow: hidden;
}

.swipe-indicator::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  animation: swipeHint 3s infinite;
}

@keyframes swipeHint {
  0% {
    left: -100%;
  }
  50% {
    left: 100%;
  }
  100% {
    left: 100%;
  }
}

/* ===== RIPPLE EFFECT ===== */

.ripple-effect {
  position: relative;
  overflow: hidden;
}

.ripple-effect::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 0.3s, height 0.3s;
}

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

/* ===== STAGGER ANIMATIONS ===== */

.stagger-item {
  opacity: 0;
  transform: translateY(20px);
  animation: staggerIn 0.5s ease-out forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0.1s; }
.stagger-item:nth-child(2) { animation-delay: 0.2s; }
.stagger-item:nth-child(3) { animation-delay: 0.3s; }
.stagger-item:nth-child(4) { animation-delay: 0.4s; }
.stagger-item:nth-child(5) { animation-delay: 0.5s; }
.stagger-item:nth-child(6) { animation-delay: 0.6s; }

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

/* ===== UTILITY ANIMATION CLASSES ===== */

.animate-fadeIn { animation: fadeIn 0.5s ease-out; }
.animate-fadeOut { animation: fadeOut 0.3s ease-out; }
.animate-slideInUp { animation: slideInUp 0.5s ease-out; }
.animate-slideInDown { animation: slideInDown 0.5s ease-out; }
.animate-slideInLeft { animation: slideInLeft 0.5s ease-out; }
.animate-slideInRight { animation: slideInRight 0.5s ease-out; }
.animate-scaleIn { animation: scaleIn 0.3s ease-out; }
.animate-scaleOut { animation: scaleOut 0.3s ease-out; }
.animate-bounce { animation: bounce 1s ease-out; }
.animate-pulse { animation: pulse 2s ease-in-out infinite; }
.animate-spin { animation: spin 1s linear infinite; }
.animate-shake { animation: shake 0.5s ease-out; }
.animate-wiggle { animation: wiggle 1s ease-out; }
.animate-float { animation: float 3s ease-in-out infinite; }
.animate-glow { animation: glow 2s ease-in-out infinite; }

/* ===== TRANSITION UTILITIES ===== */

.transition-none { transition: none; }
.transition-all { transition: all var(--transition-normal); }
.transition-fast { transition: all var(--transition-fast); }
.transition-slow { transition: all var(--transition-slow); }

.transition-colors {
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}

.transition-opacity { transition: opacity var(--transition-fast); }
.transition-transform { transition: transform var(--transition-fast); }
.transition-shadow { transition: box-shadow var(--transition-fast); }

/* ===== REDUCED MOTION SUPPORT ===== */

@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-pulse,
  .animate-spin,
  .animate-bounce,
  .animate-float,
  .animate-glow {
    animation: none !important;
  }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

.will-change-scroll {
  will-change: scroll-position;
}

.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* ===== CUSTOM EASING FUNCTIONS ===== */

.ease-spring {
  transition-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ease-bounce {
  transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.ease-smooth {
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

.ease-sharp {
  transition-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
}

.ease-emphasis {
  transition-timing-function: cubic-bezier(0.0, 0, 0.2, 1);
}
