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

/* Page transition */
@keyframes pageFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.page-transition {
  animation: pageFadeIn 0.3s ease-out;
}

/* Toolbar button press */
.tool-btn:active {
  transform: scale(0.92);
}

/* Sidebar item hover lift */
.thumbnail-item {
  transition: all var(--transition), transform var(--transition-fast);
}

.thumbnail-item:hover {
  transform: translateY(-1px);
}

.thumbnail-item:active {
  transform: translateY(0) scale(0.98);
}

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

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

.btn-ripple:active::before {
  width: 200%;
  height: 200%;
  opacity: 1;
  transition: width 0s, height 0s, opacity 0s;
}

/* Pulse animation for active tool indicator */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

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

/* Skeleton loading for thumbnails */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-hover) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

/* Fade in/out utility */
.fade-in {
  animation: fadeIn 0.25s ease-out;
}

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

.fade-out {
  animation: fadeOut 0.2s ease-in forwards;
}

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

/* Slide transitions */
.slide-in-right {
  animation: slideInRight 0.3s ease-out;
}

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

.slide-in-left {
  animation: slideInLeft 0.3s ease-out;
}

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

.slide-in-up {
  animation: slideInUp 0.3s ease-out;
}

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

/* Scale in for modals and popovers */
.scale-in {
  animation: scaleIn 0.2s ease-out;
}

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

/* Bounce for attention */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

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

/* Rotate for loading/refresh */
@keyframes rotate360 {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.rotating {
  animation: rotate360 1s linear infinite;
}

/* Glow effect for active elements */
@keyframes glow {
  0%, 100% { box-shadow: 0 0 8px rgba(99, 145, 255, 0.2); }
  50% { box-shadow: 0 0 20px rgba(99, 145, 255, 0.4); }
}

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

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

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

/* Stagger children */
.stagger-children > * {
  opacity: 0;
  animation: slideInUp 0.3s ease-out forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.4s; }
.stagger-children > *:nth-child(9) { animation-delay: 0.45s; }

/* Smooth color transition for theme toggle */
body,
#header-bar,
#toolbar,
#left-sidebar,
#right-panel,
#status-bar,
#canvas-area,
.modal,
.toast {
  transition: background-color var(--transition-slow),
              border-color var(--transition-slow),
              color var(--transition-slow);
}

/* Drop zone drag-over animation */
@keyframes borderDance {
  0% { background-position: 0 0, 100% 0, 0 100%, 0 0; }
  100% { background-position: 100% 0, 100% 100%, 0 100%, 0 0; }
}

/* Progress bar animation */
@keyframes progressIndeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.progress-bar {
  height: 3px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: var(--radius-full);
  transition: width var(--transition-smooth);
}

.progress-bar-indeterminate .progress-bar-fill {
  width: 30%;
  animation: progressIndeterminate 1.5s ease-in-out infinite;
}

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