/**
 * Animations and Micro-interactions
 * 
 * Микро-анимации для улучшения UX
 * 
 * @package Mebel39
 */

/* ========================================
   Base Animation Keyframes
======================================== */

/* Fade In */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Fade In Up */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Fade In Down */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Fade In Left */
@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Fade In Right */
@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

/* Bounce */
@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translateY(0);
  }
  40%, 43% {
    transform: translateY(-10px);
  }
  70% {
    transform: translateY(-5px);
  }
  90% {
    transform: translateY(-2px);
  }
}

/* Pulse */
@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

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

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

/* Float */
@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Slide In From Bottom */
@keyframes slideInBottom {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ========================================
   Animation Classes
======================================== */

.animate-fade-in {
  animation: fadeIn 0.5s ease-out forwards;
}

.animate-fade-in-up {
  animation: fadeInUp 0.6s ease-out forwards;
}

.animate-fade-in-down {
  animation: fadeInDown 0.6s ease-out forwards;
}

.animate-fade-in-left {
  animation: fadeInLeft 0.6s ease-out forwards;
}

.animate-fade-in-right {
  animation: fadeInRight 0.6s ease-out forwards;
}

.animate-scale-in {
  animation: scaleIn 0.4s ease-out forwards;
}

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

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

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

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

.animate-float {
  animation: float 3s ease-in-out infinite;
}

/* Staggered Animation Delays */
.animate-delay-100 { animation-delay: 0.1s; }
.animate-delay-200 { animation-delay: 0.2s; }
.animate-delay-300 { animation-delay: 0.3s; }
.animate-delay-400 { animation-delay: 0.4s; }
.animate-delay-500 { animation-delay: 0.5s; }
.animate-delay-600 { animation-delay: 0.6s; }
.animate-delay-700 { animation-delay: 0.7s; }
.animate-delay-800 { animation-delay: 0.8s; }

/* Animation on scroll - initially visible for SEO/accessibility, animate when in view */
.animate-on-scroll {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

/* Only apply hidden state when JS is enabled */
.js .animate-on-scroll {
  opacity: 0;
  transform: translateY(20px);
}

.js .animate-on-scroll.animated,
.js .animate-on-scroll.animate-in,
.js .animate-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Fallback - show elements after page load even without scroll */
.animate-on-scroll:not(.animated):not(.animate-in):not(.is-visible) {
  animation: fadeInOnLoad 0.6s ease forwards;
  animation-delay: 0.5s;
}

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

/* ========================================
   Button Animations
======================================== */

.btn {
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.btn::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.6s ease, height 0.6s ease;
}

.btn:hover::before {
  width: 300px;
  height: 300px;
}

.btn:active {
  transform: scale(0.98);
}

/* Button Loading State */
.btn.loading {
  pointer-events: none;
  position: relative;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.product-card,
.category-card,
.feature-item,
.testimonial-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product-card:hover,
.category-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.feature-item:hover {
  transform: translateY(-3px);
}

.feature-item:hover .feature-icon {
  animation: pulse 0.5s ease;
}

/* ========================================
   Form Animations
======================================== */

.form-input,
.form-select,
.form-textarea {
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15);
}

/* Input Error Shake */
.form-input.error,
.form-select.error,
.form-textarea.error {
  border-color: #ef4444;
  animation: shake 0.5s ease;
}

/* Input Success */
.form-input.success,
.form-select.success,
.form-textarea.success {
  border-color: #22c55e;
}

/* Radio/Checkbox Animation */
.radio-label:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.radio-label input {
  transition: transform 0.2s ease;
}

.radio-label:active input {
  transform: scale(0.9);
}

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

.main-nav-list a {
  position: relative;
}

.main-nav-list a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-primary);
  transition: width 0.3s ease;
}

.main-nav-list a:hover::after,
.main-nav-list a.current::after {
  width: 100%;
}

/* Mobile Menu Animation */
.mobile-nav {
  transition: transform 0.3s ease, left 0.3s ease;
}

.mobile-nav-overlay {
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.modal {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.is-active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s ease;
}

.modal.is-active .modal-content {
  transform: scale(1) translateY(0);
}

/* ========================================
   Loading Animations
======================================== */

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-dots {
  display: flex;
  gap: 8px;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  background: var(--color-primary);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

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

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

.notification {
  animation: slideInBottom 0.3s ease-out;
}

.notification.hiding {
  animation: fadeIn 0.3s ease-out reverse forwards;
}

/* Toast Notification */
.toast {
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.toast.show {
  transform: translateX(0);
}

/* ========================================
   Counter Animation
======================================== */

.stat-number {
  transition: transform 0.3s ease;
}

.stat-item:hover .stat-number {
  transform: scale(1.1);
}

/* ========================================
   Image Hover Effects
======================================== */

.portfolio-item-image,
.category-card-image {
  transition: transform 0.5s ease;
}

.portfolio-item:hover .portfolio-item-image,
.category-card:hover .category-card-image {
  transform: scale(1.05);
}

/* ========================================
   Scroll Reveal Animations
   ======================================== */

/* Default visible state for SEO/accessibility */
[data-animate] {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

/* Only hide when JS is enabled */
.js [data-animate] {
  opacity: 0;
  transform: translateY(30px);
}

[data-animate].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Animation types - only apply transforms when JS is enabled */
.js [data-animate="fade-in-up"] {
  transform: translateY(40px);
}

.js [data-animate="fade-in-left"] {
  transform: translateX(-40px);
}

.js [data-animate="fade-in-right"] {
  transform: translateX(40px);
}

.js [data-animate="scale-in"] {
  transform: scale(0.9);
}

[data-animate="fade-in-up"].is-visible,
[data-animate="fade-in-left"].is-visible,
[data-animate="fade-in-right"].is-visible,
[data-animate="scale-in"].is-visible {
  transform: translate(0) scale(1);
}

/* Staggered children animation - visible by default */
[data-animate-stagger] > * {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Only hide when JS is enabled */
.js [data-animate-stagger] > * {
  opacity: 0;
  transform: translateY(20px);
}

[data-animate-stagger].is-visible > *:nth-child(1) { transition-delay: 0.1s; }
[data-animate-stagger].is-visible > *:nth-child(2) { transition-delay: 0.2s; }
[data-animate-stagger].is-visible > *:nth-child(3) { transition-delay: 0.3s; }
[data-animate-stagger].is-visible > *:nth-child(4) { transition-delay: 0.4s; }
[data-animate-stagger].is-visible > *:nth-child(5) { transition-delay: 0.5s; }
[data-animate-stagger].is-visible > *:nth-child(6) { transition-delay: 0.6s; }
[data-animate-stagger].is-visible > *:nth-child(7) { transition-delay: 0.7s; }
[data-animate-stagger].is-visible > *:nth-child(8) { transition-delay: 0.8s; }

[data-animate-stagger].is-visible > * {
  opacity: 1;
  transform: translateY(0);
}

/* ========================================
   Back to Top Button Animation
======================================== */

.back-to-top {
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ========================================
   Theme Toggle Animation
======================================== */

.theme-toggle-icon {
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.theme-toggle:hover .theme-toggle-icon {
  transform: rotate(15deg);
}

/* ========================================
   Reduced Motion
======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .animate-on-scroll {
    opacity: 1;
  }
  
  [data-animate] {
    opacity: 1;
    transform: none;
  }
}
