/* ====================================
   Animations & Transitions
   Micro-interactions & Polish
   ==================================== */

/* ====================
   Transition Foundation
   ==================== */

:root {
  --transition-fast: 150ms ease-in-out;
  --transition-base: 200ms ease-in-out;
  --transition-slow: 300ms ease-in-out;
  --transition-duration: 300ms;
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====================
   Page Transitions
   ==================== */

/* Fade in on page load */
.page {
  animation: pageIn 0.4s var(--ease-out) forwards;
}

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

/* Slide in from side */
.page.slide-in {
  animation: pageSlideIn 0.4s var(--ease-out) forwards;
}

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

/* ====================
   Button Interactions
   ==================== */

button, .btn, input[type="button"], a.button {
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
}

/* Button press ripple effect */
button::before, .btn::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%);
  pointer-events: none;
}

button:active::before, .btn:active::before {
  animation: buttonRipple 0.6s ease-out;
}

@keyframes buttonRipple {
  to {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}

/* Button hover scale */
button:hover:not(:disabled),
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

button:active,
.btn:active {
  transform: translateY(0);
}

/* Disabled state */
button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ====================
   Card Animations
   ==================== */

.card, [class*="card"] {
  transition: all var(--transition-base);
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Card hover elevation */
.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Card stagger animation (for lists) */
.card:nth-child(1) { animation: cardSlideIn 0.3s var(--ease-out) 0.0s forwards; }
.card:nth-child(2) { animation: cardSlideIn 0.3s var(--ease-out) 0.1s forwards; }
.card:nth-child(3) { animation: cardSlideIn 0.3s var(--ease-out) 0.2s forwards; }
.card:nth-child(n+4) { animation: cardSlideIn 0.3s var(--ease-out) 0.3s forwards; }

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

/* ====================
   Input & Form Animations
   ==================== */

input, textarea, select {
  transition: all var(--transition-base);
}

input:focus, textarea:focus, select:focus {
  transform: scale(1.01);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Input underline animation */
.form-group input::after,
.form-group textarea::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-primary);
  transition: width var(--transition-base);
}

.form-group input:focus::after,
.form-group textarea:focus::after {
  width: 100%;
}

/* ====================
   Toggle Switch Animation
   ==================== */

.toggle-switch, .settings-toggle {
  position: relative;
  transition: all var(--transition-base);
}

.toggle-switch input:checked,
.settings-toggle input:checked {
  animation: toggleCheck 0.3s var(--ease-out);
}

@keyframes toggleCheck {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ====================
   Navigation Animations
   ==================== */

/* Sidebar slide in/out */
.sidebar {
  transition: transform var(--transition-base), opacity var(--transition-base);
}

/* Nav item active indicator */
.nav-item, .sidebar-item {
  position: relative;
  transition: all var(--transition-fast);
}

.nav-item.active::after,
.sidebar-item.active::before {
  content: '';
  position: absolute;
  background: var(--color-primary);
  animation: activeIndicator 0.3s var(--ease-out);
}

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

/* ====================
   Loading States
   ==================== */

/* Skeleton loading animation */
.skeleton {
  animation: skeletonLoading 1.5s infinite;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.15) 50%,
    rgba(255, 255, 255, 0.1) 100%
  );
  background-size: 200% 100%;
}

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

/* Spinner animation */
.spinner {
  animation: spin 1s linear infinite;
}

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

/* Pulse loading */
.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ====================
   Modal Animations
   ==================== */

.modal {
  animation: modalFadeIn 0.3s var(--ease-out);
}

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

.modal-content {
  animation: modalSlideUp 0.3s var(--ease-out);
}

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

/* ====================
   Notification Animations
   ==================== */

.toast, .notification {
  animation: toastSlideIn 0.3s var(--ease-out) forwards;
}

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

/* Toast exit animation */
.toast.exit {
  animation: toastSlideOut 0.3s var(--ease-in) forwards;
}

@keyframes toastSlideOut {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* ====================
   Dropdown Animations
   ==================== */

.dropdown, [role="menu"] {
  animation: dropdownFadeIn 0.2s var(--ease-out);
}

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

/* ====================
   Badge Animations
   ==================== */

.badge {
  animation: badgeBounce 0.4s var(--ease-out);
}

@keyframes badgeBounce {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ====================
   Fade Animations
   ==================== */

/* Fade in */
.fade-in {
  animation: fadeIn 0.4s var(--ease-out) forwards;
}

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

/* Fade out */
.fade-out {
  animation: fadeOut 0.4s var(--ease-in) forwards;
}

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

/* ====================
   Scale Animations
   ==================== */

.scale-in {
  animation: scaleIn 0.3s var(--ease-out) forwards;
}

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

.scale-out {
  animation: scaleOut 0.3s var(--ease-in) forwards;
}

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

/* ====================
   Slide Animations
   ==================== */

.slide-in-up {
  animation: slideInUp 0.3s var(--ease-out) forwards;
}

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

.slide-in-down {
  animation: slideInDown 0.3s var(--ease-out) forwards;
}

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

.slide-in-left {
  animation: slideInLeft 0.3s var(--ease-out) forwards;
}

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

.slide-in-right {
  animation: slideInRight 0.3s var(--ease-out) forwards;
}

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

/* ====================
   Bounce Animations
   ==================== */

.bounce {
  animation: bounce 0.6s ease-in-out;
}

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

/* ====================
   Jiggle Animation
   ==================== */

.jiggle {
  animation: jiggle 0.4s ease-in-out;
}

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

/* ====================
   Glow Effect
   ==================== */

.glow {
  animation: glow 2s ease-in-out infinite;
  text-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

@keyframes glow {
  0%, 100% { text-shadow: 0 0 10px rgba(99, 102, 241, 0.5); }
  50% { text-shadow: 0 0 20px rgba(99, 102, 241, 0.8); }
}

/* ====================
   Shimmer Effect
   ==================== */

.shimmer {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 2s infinite;
}

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

/* ====================
   Reduce Motion Support
   ==================== */

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

/* ====================
   Dark Mode Animations
   ==================== */

@media (prefers-color-scheme: dark) {
  /* Adjust glow colors for dark mode */
  .glow {
    text-shadow: 0 0 10px rgba(129, 140, 248, 0.5);
  }
}

/* ====================
   Performance Optimization
   ==================== */

/* Use GPU acceleration for animations */
.page, .card, .modal, .sidebar {
  will-change: auto;
}

.page.animated, .card:hover, .modal.active {
  will-change: transform, opacity;
}

/* Backface visibility for 3D transforms */
.animated-element {
  backface-visibility: hidden;
  perspective: 1000px;
}
