/* MartinsTech Platform - Animation Library v3.0 */
/* Smooth, elegant animations with natural easing */

/* ========== KEYFRAMES ========== */

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

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

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

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

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

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

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

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

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

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(-8px);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

@keyframes ping {
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

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

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

/* Fade animations */
.animate-fade-in {
  animation: fadeIn var(--duration-200) var(--ease-out) forwards;
}

.animate-fade-out {
  animation: fadeOut var(--duration-200) var(--ease-out) forwards;
}

/* Slide animations */
.animate-slide-up {
  animation: slideInUp var(--duration-300) var(--ease-out) forwards;
}

.animate-slide-down {
  animation: slideInDown var(--duration-300) var(--ease-out) forwards;
}

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

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

/* Scale animation */
.animate-scale-in {
  animation: scaleIn var(--duration-200) var(--ease-out) forwards;
}

/* Continuous animations */
.animate-pulse {
  animation: pulse 2s var(--ease-in-out) infinite;
}

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

.animate-bounce {
  animation: bounce 1s infinite;
}

.animate-ping {
  animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.animate-shimmer {
  background: linear-gradient(
    90deg,
    var(--color-surface) 25%,
    var(--color-bg) 50%,
    var(--color-surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

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

/* Staggered page entrance */
.page-enter > * {
  opacity: 0;
  animation: slideInUp var(--duration-300) var(--ease-out) forwards;
}

.page-enter > *:nth-child(1) { animation-delay: 0ms; }
.page-enter > *:nth-child(2) { animation-delay: 50ms; }
.page-enter > *:nth-child(3) { animation-delay: 100ms; }
.page-enter > *:nth-child(4) { animation-delay: 150ms; }
.page-enter > *:nth-child(5) { animation-delay: 200ms; }
.page-enter > *:nth-child(6) { animation-delay: 250ms; }
.page-enter > *:nth-child(7) { animation-delay: 300ms; }
.page-enter > *:nth-child(8) { animation-delay: 350ms; }

/* Grid stagger */
.stagger-grid > * {
  opacity: 0;
  animation: scaleIn var(--duration-300) var(--ease-out) forwards;
}

.stagger-grid > *:nth-child(1) { animation-delay: 0ms; }
.stagger-grid > *:nth-child(2) { animation-delay: 40ms; }
.stagger-grid > *:nth-child(3) { animation-delay: 80ms; }
.stagger-grid > *:nth-child(4) { animation-delay: 120ms; }
.stagger-grid > *:nth-child(5) { animation-delay: 160ms; }
.stagger-grid > *:nth-child(6) { animation-delay: 200ms; }
.stagger-grid > *:nth-child(7) { animation-delay: 240ms; }
.stagger-grid > *:nth-child(8) { animation-delay: 280ms; }

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

.hover-lift {
  transition: transform var(--duration-200) var(--ease-out),
              box-shadow var(--duration-200) var(--ease-out);
}

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

.hover-scale {
  transition: transform var(--duration-150) var(--ease-out);
}

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

.hover-glow {
  transition: box-shadow var(--duration-200) var(--ease-out);
}

.hover-glow:hover {
  box-shadow: 0 0 20px rgba(0, 53, 102, 0.15);
}

[data-theme="dark"] .hover-glow:hover {
  box-shadow: 0 0 20px rgba(245, 204, 0, 0.1);
}

/* ========== FOCUS EFFECTS ========== */

.focus-ring {
  transition: box-shadow var(--duration-150) var(--ease-out),
              outline var(--duration-150) var(--ease-out);
}

.focus-ring:focus-visible {
  outline: var(--ring-width) solid var(--ring-color);
  outline-offset: var(--ring-offset);
}

/* ========== STATE TRANSITIONS ========== */

.transition-colors {
  transition: color var(--duration-150) var(--ease-out),
              background-color var(--duration-150) var(--ease-out),
              border-color var(--duration-150) var(--ease-out);
}

.transition-shadow {
  transition: box-shadow var(--duration-200) var(--ease-out);
}

.transition-transform {
  transition: transform var(--duration-200) var(--ease-out);
}

.transition-all {
  transition: all var(--duration-200) var(--ease-out);
}

/* ========== LOADING STATES ========== */

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

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

/* Skeleton loading */
.skeleton-loading {
  background: linear-gradient(
    90deg,
    var(--color-bg) 25%,
    var(--color-surface) 50%,
    var(--color-bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

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

/* ========== ENTRANCE ANIMATIONS ========== */

/* For use with JavaScript - add 'is-visible' class when element enters viewport */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--duration-500) var(--ease-out),
              transform var(--duration-500) var(--ease-out);
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-scale {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity var(--duration-500) var(--ease-out),
              transform var(--duration-500) var(--ease-out);
}

.reveal-scale.is-visible {
  opacity: 1;
  transform: scale(1);
}

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

/* Button press — decisive scale feedback */
.btn-press {
  transition: transform 100ms var(--ease-out), box-shadow 100ms var(--ease-out);
}

.btn-press:active {
  transform: scale(0.97);
}

/* Input focus glow — gold ring on dark, navy ring on light */
.input-glow {
  transition: border-color var(--duration-150) var(--ease-out),
              box-shadow var(--duration-150) var(--ease-out);
}

.input-glow:focus {
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

/* Stagger list children — each child fades in sequentially */
.stagger-list > * {
  opacity: 0;
  transform: translateY(6px);
  animation: slideInUp var(--duration-300) var(--ease-out) forwards;
}

.stagger-list > *:nth-child(1)  { animation-delay: 0ms; }
.stagger-list > *:nth-child(2)  { animation-delay: 50ms; }
.stagger-list > *:nth-child(3)  { animation-delay: 100ms; }
.stagger-list > *:nth-child(4)  { animation-delay: 150ms; }
.stagger-list > *:nth-child(5)  { animation-delay: 200ms; }
.stagger-list > *:nth-child(6)  { animation-delay: 250ms; }
.stagger-list > *:nth-child(7)  { animation-delay: 300ms; }
.stagger-list > *:nth-child(8)  { animation-delay: 350ms; }
.stagger-list > *:nth-child(9)  { animation-delay: 400ms; }
.stagger-list > *:nth-child(10) { animation-delay: 450ms; }
.stagger-list > *:nth-child(n+11) { animation-delay: 500ms; }

/* Stagger cards — entrance with scale */
.stagger-cards > * {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  animation: scaleIn var(--duration-300) cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.stagger-cards > *:nth-child(1) { animation-delay: 0ms; }
.stagger-cards > *:nth-child(2) { animation-delay: 80ms; }
.stagger-cards > *:nth-child(3) { animation-delay: 160ms; }
.stagger-cards > *:nth-child(4) { animation-delay: 240ms; }
.stagger-cards > *:nth-child(5) { animation-delay: 320ms; }
.stagger-cards > *:nth-child(6) { animation-delay: 400ms; }

/* Progress bar shimmer — moving highlight over fill */
@keyframes progressShimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(200%); }
}

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

.progress-shimmer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.25) 50%,
    transparent 100%
  );
  width: 50%;
  animation: progressShimmer 1.8s var(--ease-in-out) infinite;
}

/* Number count-up — CSS-only tabular nums transition */
.number-animate {
  font-variant-numeric: tabular-nums;
  transition: transform var(--duration-300) var(--ease-out);
}

/* Floating idle — subtle vertical bob for empty states */
@keyframes floatIdle {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

.float-idle {
  animation: floatIdle 3s var(--ease-in-out) infinite;
}

/* Ripple highlight — brief flash on element */
@keyframes rippleHighlight {
  0%   { background-color: rgba(245, 204, 0, 0.15); }
  100% { background-color: transparent; }
}

.ripple-highlight {
  animation: rippleHighlight 600ms var(--ease-out);
}

/* Glow pulse — for active/selected state emphasis */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 204, 0, 0.2); }
  50%      { box-shadow: 0 0 0 4px rgba(245, 204, 0, 0.1); }
}

.glow-pulse {
  animation: glowPulse 2s var(--ease-in-out) infinite;
}

/* Slide transitions for multi-step flows */
@keyframes slideOutLeft {
  to { opacity: 0; transform: translateX(-16px); }
}

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

.step-enter {
  animation: slideInRight var(--duration-200) var(--ease-out);
}

/* Expand/collapse height */
.collapse-enter {
  overflow: hidden;
  animation: collapseIn var(--duration-200) var(--ease-out);
}

@keyframes collapseIn {
  from { opacity: 0; max-height: 0; }
  to   { opacity: 1; max-height: 500px; }
}

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

@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-ping,
  .animate-shimmer,
  .skeleton-loading {
    animation: none;
  }

  .reveal,
  .reveal-scale,
  .page-enter > *,
  .stagger-grid > *,
  .stagger-list > *,
  .stagger-cards > *,
  .float-idle,
  .glow-pulse,
  .step-enter {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .progress-shimmer::after {
    animation: none;
  }
}
