/**
 * Animations & Transitions - Smaiz Bag Theme
 * Smooth, app-like micro-interactions
 */

/* ========================================
   KEYFRAME ANIMATIONS
======================================== */

/* 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);
  }
}

/* Slide In Left */
@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Slide In Right */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

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

/* Bounce */
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

/* Shimmer (for loading states) */
@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

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

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

/* ========================================
   PAGE LOAD ANIMATIONS
======================================== */

.site-header {
  animation: fadeInDown 0.6s ease-out;
}

.site-main {
  animation: fadeIn 0.8s ease-out;
}

.site-footer {
  animation: fadeInUp 0.6s ease-out 0.2s both;
}

/* ========================================
   CONTENT ANIMATIONS
======================================== */

/* Staggered fade-in for grid items */
.posts-grid .post-card,
.products-grid .product-card {
  opacity: 0;
  animation: fadeInUp 0.6s ease-out forwards;
}

.posts-grid .post-card:nth-child(1),
.products-grid .product-card:nth-child(1) {
  animation-delay: 0.1s;
}

.posts-grid .post-card:nth-child(2),
.products-grid .product-card:nth-child(2) {
  animation-delay: 0.2s;
}

.posts-grid .post-card:nth-child(3),
.products-grid .product-card:nth-child(3) {
  animation-delay: 0.3s;
}

.posts-grid .post-card:nth-child(4),
.products-grid .product-card:nth-child(4) {
  animation-delay: 0.4s;
}

.posts-grid .post-card:nth-child(5),
.products-grid .product-card:nth-child(5) {
  animation-delay: 0.5s;
}

.posts-grid .post-card:nth-child(6),
.products-grid .product-card:nth-child(6) {
  animation-delay: 0.6s;
}

/* Subsequent items load without delay */
.posts-grid .post-card:nth-child(n+7),
.products-grid .product-card:nth-child(n+7) {
  animation-delay: 0s;
  opacity: 1;
}

/* ========================================
   HOVER ANIMATIONS
======================================== */

/* Button hover effects */
.btn {
  position: relative;
  overflow: hidden;
}

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

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

/* Card hover lift */
.post-card,
.product-card {
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.post-card:hover,
.product-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-xl);
}

/* Image zoom on hover */
.post-thumbnail,
.product-thumbnail {
  overflow: hidden;
}

.post-thumbnail img,
.product-thumbnail img {
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.post-card:hover .post-thumbnail img,
.product-card:hover .product-thumbnail img {
  transform: scale(1.08);
}

/* Link underline animation */
.animated-link {
  position: relative;
  display: inline-block;
}

.animated-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background-color: var(--primary);
  transition: width var(--transition-base);
}

.animated-link:hover::after {
  width: 100%;
}

/* ========================================
   MOBILE NAV ANIMATIONS
======================================== */

.mobile-nav-overlay {
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.mobile-nav-overlay.active .mobile-nav-content {
  animation: slideInRight 0.4s ease-out;
}

.mobile-menu li {
  opacity: 0;
  animation: fadeInLeft 0.4s ease-out forwards;
}

.mobile-nav-overlay.active .mobile-menu li:nth-child(1) { animation-delay: 0.1s; }
.mobile-nav-overlay.active .mobile-menu li:nth-child(2) { animation-delay: 0.15s; }
.mobile-nav-overlay.active .mobile-menu li:nth-child(3) { animation-delay: 0.2s; }
.mobile-nav-overlay.active .mobile-menu li:nth-child(4) { animation-delay: 0.25s; }
.mobile-nav-overlay.active .mobile-menu li:nth-child(5) { animation-delay: 0.3s; }
.mobile-nav-overlay.active .mobile-menu li:nth-child(6) { animation-delay: 0.35s; }

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

/* ========================================
   SEARCH OVERLAY ANIMATIONS
======================================== */

.search-overlay {
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.search-overlay.active .search-form-wrapper {
  animation: scaleIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ========================================
   CART BADGE ANIMATIONS
======================================== */

.cart-count {
  animation: scaleIn 0.3s ease-out;
}

.cart-count.updated {
  animation: pulse 0.5s ease-in-out;
}

/* ========================================
   BACK TO TOP BUTTON
======================================== */

.back-to-top {
  transition: opacity var(--transition-base), 
              visibility var(--transition-base),
              transform var(--transition-base),
              background-color var(--transition-fast);
}

.back-to-top.visible {
  animation: fadeInUp 0.4s ease-out;
}

.back-to-top:hover {
  transform: translateY(-5px);
}

.back-to-top:active {
  transform: translateY(-3px);
}

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

.skeleton,
.loading-placeholder {
  background: linear-gradient(
    90deg,
    var(--brown-200) 0%,
    var(--brown-100) 50%,
    var(--brown-200) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

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

/* ========================================
   BADGE ANIMATIONS
======================================== */

.product-badge {
  animation: fadeInDown 0.4s ease-out;
}

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

.badge-new {
  animation: fadeInDown 0.4s ease-out 0.2s both;
}

/* ========================================
   SMOOTH SCROLL BEHAVIOR
======================================== */

html {
  scroll-behavior: smooth;
}

/* Custom scroll for smooth sections */
.smooth-scroll {
  scroll-behavior: smooth;
}

/* ========================================
   FOCUS ANIMATIONS
======================================== */

*:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
  transition: outline-offset var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(166, 124, 82, 0.1);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/* ========================================
   RIPPLE EFFECT (Click feedback)
======================================== */

.ripple {
  position: relative;
  overflow: hidden;
}

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

.ripple:active::after {
  width: 200px;
  height: 200px;
  transition: width 0s, height 0s;
}

/* ========================================
   TOAST NOTIFICATIONS (Future use)
======================================== */

.toast {
  animation: slideInRight 0.4s ease-out;
}

.toast.closing {
  animation: slideOutRight 0.4s ease-out;
}

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

/* ========================================
   MODAL ANIMATIONS (Future use)
======================================== */

.modal {
  animation: fadeIn 0.3s ease-out;
}

.modal-content {
  animation: scaleIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ========================================
   PROGRESSIVE ENHANCEMENT
======================================== */

/* Only apply animations if user hasn't requested reduced motion */
@media (prefers-reduced-motion: no-preference) {
  /* All animations enabled by default */
}

/* Disable complex animations on lower-end devices */
@media (max-width: 768px) and (pointer: coarse) {
  .post-card,
  .product-card {
    animation: none;
    opacity: 1;
  }
  
  .post-thumbnail img,
  .product-thumbnail img {
    transition: none;
  }
}

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

.animate-fadeIn {
  animation: fadeIn 0.6s ease-out;
}

.animate-fadeInUp {
  animation: fadeInUp 0.6s ease-out;
}

.animate-fadeInDown {
  animation: fadeInDown 0.6s ease-out;
}

.animate-slideInLeft {
  animation: slideInLeft 0.6s ease-out;
}

.animate-slideInRight {
  animation: slideInRight 0.6s ease-out;
}

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

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

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

/* Delay utilities */
.delay-100 { animation-delay: 0.1s; }
.delay-200 { animation-delay: 0.2s; }
.delay-300 { animation-delay: 0.3s; }
.delay-400 { animation-delay: 0.4s; }
.delay-500 { animation-delay: 0.5s; }

/* Duration utilities */
.duration-fast { animation-duration: 0.15s; }
.duration-base { animation-duration: 0.25s; }
.duration-slow { animation-duration: 0.35s; }
.duration-slower { animation-duration: 0.5s; }