/**
 * Matrix Theme - Animation Components
 * Optimized animations for Matrix aesthetic
 */

/* Matrix Glow Animation */
.animate-matrix-glow {
  animation: matrix-glow 3s ease-in-out infinite alternate;
}

@keyframes matrix-glow {
  0% {
    box-shadow: 0 0 5px var(--matrix-green);
    transform: translateZ(0);
  }
  100% {
    box-shadow: 0 0 15px var(--matrix-green), 0 0 25px var(--matrix-green);
    transform: translateZ(0);
  }
}

/* Matrix Pulse Animation */
.animate-matrix-pulse {
  animation: matrix-pulse 2.5s ease-in-out infinite;
}

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

/* Matrix Fade Out Animation (for deletions) */
@keyframes matrix-fade-out {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
  50% {
    opacity: 0.5;
    transform: translateY(-10px) scale(0.98);
    filter: brightness(0.7);
  }
  100% {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    filter: brightness(0.3);
  }
}

/* Mobile-First Animation Strategy */
/* Mobile: Elements are visible by default, simple fade-in only */
/* Desktop: Full animation suite with scroll triggers */

/* Base mobile behavior - visible by default */
.animate-matrix-fade-in {
  opacity: 1; /* Mobile-first: visible by default */
}

.animate-matrix-fade-in-up {
  opacity: 1; /* Mobile-first: visible by default */
}

.animate-matrix-fade-in-down {
  opacity: 1; /* Mobile-first: visible by default */
}

.animate-matrix-fade-in-left {
  opacity: 1; /* Mobile-first: visible by default */
}

.animate-matrix-fade-in-right {
  opacity: 1; /* Mobile-first: visible by default */
}

/* Desktop animations (tablets and up) */
@media (min-width: 768px) {
  .animate-matrix-fade-in {
    opacity: 0;
  }
  
  .animate-matrix-fade-in.animate-on-scroll {
    animation: matrix-fade-in 0.6s ease-out forwards;
  }
  
  .animate-matrix-fade-in-up {
    opacity: 0;
  }
  
  .animate-matrix-fade-in-up.animate-on-scroll {
    animation: matrix-fade-in-up 0.6s ease-out forwards;
  }
  
  .animate-matrix-fade-in-down {
    opacity: 0;
  }
  
  .animate-matrix-fade-in-down.animate-on-scroll {
    animation: matrix-fade-in-down 0.6s ease-out forwards;
  }
  
  .animate-matrix-fade-in-left {
    opacity: 0;
  }
  
  .animate-matrix-fade-in-left.animate-on-scroll {
    animation: matrix-fade-in-left 0.6s ease-out forwards;
  }
  
  .animate-matrix-fade-in-right {
    opacity: 0;
  }
  
  .animate-matrix-fade-in-right.animate-on-scroll {
    animation: matrix-fade-in-right 0.6s ease-out forwards;
  }
}

/* Optional: Simple mobile animations (reduced motion) */
@media (max-width: 767px) and (prefers-reduced-motion: no-preference) {
  .animate-matrix-fade-in.animate-on-scroll {
    animation: matrix-fade-in-mobile 0.3s ease-out forwards;
  }
  
  .animate-matrix-fade-in-up.animate-on-scroll,
  .animate-matrix-fade-in-down.animate-on-scroll,
  .animate-matrix-fade-in-left.animate-on-scroll,
  .animate-matrix-fade-in-right.animate-on-scroll {
    animation: matrix-fade-in-mobile 0.3s ease-out forwards;
  }
}

@keyframes matrix-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes matrix-fade-in-up {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes matrix-fade-in-down {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes matrix-fade-in-left {
  from {
    opacity: 0;
    transform: translateX(-50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes matrix-fade-in-right {
  from {
    opacity: 0;
    transform: translateX(50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Matrix Rain Animation */
.matrix-rain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  opacity: 0.1;
}

/* Text Glow Effect */
.text-matrix-glow {
  text-shadow: 0 0 10px var(--matrix-green);
  animation: text-pulse-glow 2s infinite;
}

@keyframes text-pulse-glow {
  0%, 100% {
    text-shadow: 0 0 5px var(--matrix-green);
  }
  50% {
    text-shadow: 0 0 20px var(--matrix-green), 0 0 30px var(--matrix-green);
  }
}

/* Scan Line Effect */
.matrix-scanline {
  position: relative;
  overflow: hidden;
}

.matrix-scanline::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--matrix-green), transparent);
  animation: scan-line 3s linear infinite;
}

@keyframes scan-line {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Loading Matrix Animation */
.loading-matrix {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.loading-matrix::after {
  content: '';
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-top: 2px solid var(--matrix-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Hover Effects */
.matrix-hover-glow {
  transition: all 0.3s ease;
}

.matrix-hover-glow:hover {
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.4);
  transform: translateY(-2px);
}

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

/* Mobile-specific animations */
@keyframes matrix-fade-in-mobile {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

/* Mobile Animation Optimization */
@media (max-width: 767px) {
  .animate-matrix-glow,
  .animate-matrix-pulse {
    animation: none;
  }
  
  /* Reduce complex animations on mobile for performance */
  .text-matrix-glow {
    animation: none;
    text-shadow: 0 0 5px var(--matrix-green);
  }
  
  .matrix-scanline::before {
    animation: none;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .matrix-hover-glow:hover {
    transform: none; /* Disable hover transforms on touch devices */
  }
}

/* Error Ticket Specific Animations */

/* Critical Error Pulse */
.animate-error-critical {
  animation: error-critical-pulse 2s ease-in-out infinite;
}

@keyframes error-critical-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.3);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
  }
}

/* Error Frequency Indicator */
.animate-error-frequent {
  animation: error-frequency-flash 3s ease-in-out infinite;
}

@keyframes error-frequency-flash {
  0%, 90%, 100% {
    opacity: 1;
  }
  95% {
    opacity: 0.7;
    box-shadow: 0 0 15px rgba(255, 170, 0, 0.6);
  }
}

/* Status Change Animation */
.animate-status-change {
  animation: status-change-highlight 1s ease-out;
}

@keyframes status-change-highlight {
  0% {
    background-color: rgba(0, 255, 65, 0.3);
    transform: scale(1.05);
  }
  100% {
    background-color: transparent;
    transform: scale(1);
  }
}

/* Error Stream Animation */
.animate-error-stream {
  position: relative;
  overflow: hidden;
}

.animate-error-stream::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 68, 68, 0.1),
    transparent
  );
  animation: error-stream-scan 4s linear infinite;
}

@keyframes error-stream-scan {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Loading Spinner for Error Processing */
.animate-error-processing {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.animate-error-processing::after {
  content: '';
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-top: 2px solid #ff4444;
  border-right: 2px solid rgba(255, 68, 68, 0.3);
  border-radius: 50%;
  animation: error-processing-spin 1s linear infinite;
}

@keyframes error-processing-spin {
  to { transform: rotate(360deg); }
}

/* Timeline Pulse Animation */
.animate-timeline-pulse {
  animation: timeline-pulse 2s ease-in-out infinite;
}

@keyframes timeline-pulse {
  0%, 100% {
    box-shadow: 0 0 5px rgba(0, 255, 65, 0.3);
  }
  50% {
    box-shadow: 0 0 15px rgba(0, 255, 65, 0.6);
  }
}

/* Resolution Success Animation */
.animate-resolution-success {
  animation: resolution-success 0.8s ease-out;
}

@keyframes resolution-success {
  0% {
    background-color: rgba(0, 255, 65, 0.5);
    transform: scale(1.1);
  }
  100% {
    background-color: rgba(0, 255, 65, 0.1);
    transform: scale(1);
  }
}

/* Error Count Badge Animation */
.animate-error-count {
  animation: error-count-bounce 0.6s ease-out;
}

@keyframes error-count-bounce {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

/* Matrix Terminal Boot Animation */
.animate-terminal-boot {
  animation: terminal-boot 0.5s ease-out;
}

@keyframes terminal-boot {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Reduced Motion Alternatives for Error Animations */
@media (prefers-reduced-motion: reduce) {
  .animate-error-critical,
  .animate-error-frequent,
  .animate-error-stream::before,
  .animate-timeline-pulse {
    animation: none !important;
  }
  
  .animate-error-critical {
    border: 2px solid #ff4444 !important;
  }
  
  .animate-error-frequent {
    border-left: 4px solid #ffaa00 !important;
  }
  
  .animate-status-change,
  .animate-resolution-success {
    animation: none !important;
    background-color: rgba(0, 255, 65, 0.1) !important;
  }
}

/* Mobile Error Animation Optimizations */
@media (max-width: 767px) {
  .animate-error-critical,
  .animate-error-frequent,
  .animate-timeline-pulse {
    animation-duration: 3s; /* Slower animations on mobile */
  }
  
  .animate-error-stream::before {
    animation: none; /* Disable complex scanning on mobile */
  }
  
  .animate-error-processing::after {
    width: 0.8rem;
    height: 0.8rem;
  }
}