/* ============================================================================
   ImgCraft PWA - Animations & Transitions Stylesheet
   Provides smooth, app-like transitions and animations
   ============================================================================ */

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

:root {
  --transition-duration: 300ms;
  --transition-easing: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-easing-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Fade-in animation for page loads */
html {
  opacity: 1;
  animation: pageEnter 0.4s var(--transition-easing) forwards;
}

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

/* Slide transition for tool pages */
.tool-container {
  animation: slideInRight 0.3s var(--transition-easing) forwards;
}

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

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

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

/* ============================================================================
   BUTTON ANIMATIONS
   ============================================================================ */

button,
.btn,
[role="button"] {
  transition: all 0.2s var(--transition-easing);
  position: relative;
}

button:hover,
.btn:hover,
[role="button"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

button:active,
.btn:active,
[role="button"]:active {
  transform: translateY(0);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Ripple effect on button press */
@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

button::after,
.btn::after,
[role="button"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ripple 0.6s ease-out;
  opacity: 0;
}

button:active::after,
.btn:active::after,
[role="button"]:active::after {
  animation: ripple 0.6s ease-out;
}

/* ============================================================================
   MODAL & DIALOG ANIMATIONS
   ============================================================================ */

.modal {
  animation: modalEnter 0.3s var(--transition-easing) forwards;
}

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

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

.modal.closing {
  animation: modalExit 0.3s var(--transition-easing) forwards;
}

/* Modal backdrop */
.modal-backdrop {
  animation: fadeIn 0.3s var(--transition-easing) forwards;
}

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

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

/* ============================================================================
   NAVIGATION ANIMATIONS
   ============================================================================ */

.navbar {
  animation: slideDownEnter 0.3s var(--transition-easing) forwards;
}

@keyframes slideDownEnter {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.navbar a,
.nav-link {
  position: relative;
}

.navbar a::after,
.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: currentColor;
  transition: width 0.3s var(--transition-easing);
}

.navbar a:hover::after,
.nav-link:hover::after {
  width: 100%;
}

/* ============================================================================
   FORM & INPUT ANIMATIONS
   ============================================================================ */

input,
textarea,
select {
  transition: all 0.2s var(--transition-easing);
}

input:focus,
textarea:focus,
select:focus {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Input label animation */
label {
  transition: all 0.2s var(--transition-easing);
}

input:focus + label,
input:not(:placeholder-shown) + label {
  transform: translateY(-24px) scale(0.85);
  color: #667eea;
}

/* ============================================================================
   LOADING ANIMATIONS
   ============================================================================ */

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

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

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

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.05) 25%,
    rgba(0, 0, 0, 0.1) 50%,
    rgba(0, 0, 0, 0.05) 75%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite;
}

/* ============================================================================
   TOAST & NOTIFICATION ANIMATIONS
   ============================================================================ */

.toast {
  animation: slideInUp 0.3s var(--transition-easing) forwards;
}

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

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

.toast.closing {
  animation: slideOutDown 0.3s var(--transition-easing) forwards;
}

.notification-badge {
  animation: bounce 0.6s var(--transition-easing-bounce);
}

@keyframes bounce {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* ============================================================================
   IMAGE UPLOAD & PREVIEW ANIMATIONS
   ============================================================================ */

.image-preview {
  animation: fadeInScale 0.4s var(--transition-easing) forwards;
}

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

/* Image processing animation */
.image-processing {
  position: relative;
  overflow: hidden;
}

.image-processing::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  animation: slide 2s infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* ============================================================================
   DROPDOWN ANIMATIONS
   ============================================================================ */

.dropdown-menu {
  animation: expandDown 0.2s var(--transition-easing) forwards;
  transform-origin: top;
  opacity: 0;
}

.dropdown-menu.show {
  animation: expandDown 0.2s var(--transition-easing) forwards;
  opacity: 1;
}

@keyframes expandDown {
  from {
    transform: scaleY(0);
    opacity: 0;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes shrinkUp {
  from {
    transform: scaleY(1);
    opacity: 1;
  }
  to {
    transform: scaleY(0);
    opacity: 0;
  }
}

.dropdown-menu.hide {
  animation: shrinkUp 0.2s var(--transition-easing) forwards;
}

/* ============================================================================
   CARD & CONTAINER ANIMATIONS
   ============================================================================ */

.card {
  animation: cardEnter 0.4s var(--transition-easing) forwards;
}

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

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
  transition: all 0.3s var(--transition-easing);
}

/* ============================================================================
   DARK/LIGHT THEME TRANSITION
   ============================================================================ */

body {
  transition: background-color 0.3s var(--transition-easing),
              color 0.3s var(--transition-easing);
}

body.dark-theme {
  background-color: #1a1a1a;
  color: #ffffff;
}

body.light-theme {
  background-color: #ffffff;
  color: #1a1a1a;
}

/* ============================================================================
   PROGRESS BAR ANIMATIONS
   ============================================================================ */

.progress-bar {
  animation: progress 0.6s ease-out forwards;
}

@keyframes progress {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

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

@keyframes progressIndeterminate {
  0% {
    width: 0;
  }
  50% {
    width: 100%;
  }
  100% {
    width: 0;
  }
}

/* ============================================================================
   CHECKBOX & RADIO ANIMATIONS
   ============================================================================ */

input[type="checkbox"],
input[type="radio"] {
  accent-color: #667eea;
}

input[type="checkbox"] + label,
input[type="radio"] + label {
  transition: all 0.2s var(--transition-easing);
}

input[type="checkbox"]:checked + label,
input[type="radio"]:checked + label {
  color: #667eea;
}

/* ============================================================================
   SCROLL ANIMATIONS (AOS-like)
   ============================================================================ */

.fade-in-up {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.6s var(--transition-easing) forwards;
}

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

.fade-in-down {
  opacity: 0;
  transform: translateY(-20px);
  animation: fadeInDown 0.6s var(--transition-easing) forwards;
}

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

.fade-in-left {
  opacity: 0;
  transform: translateX(-20px);
  animation: fadeInLeft 0.6s var(--transition-easing) forwards;
}

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

.fade-in-right {
  opacity: 0;
  transform: translateX(20px);
  animation: fadeInRight 0.6s var(--transition-easing) forwards;
}

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

.zoom-in {
  opacity: 0;
  transform: scale(0.8);
  animation: zoomIn 0.4s var(--transition-easing) forwards;
}

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================================
   FLOAT ANIMATION
   ============================================================================ */

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

@keyframes floating {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-20px);
  }
}

/* ============================================================================
   BLUR TRANSITION (for loading states)
   ============================================================================ */

.blur-transition {
  animation: blurInOut 0.4s var(--transition-easing) forwards;
}

@keyframes blurInOut {
  0% {
    filter: blur(0);
    opacity: 1;
  }
  50% {
    filter: blur(4px);
    opacity: 0.7;
  }
  100% {
    filter: blur(0);
    opacity: 1;
  }
}

/* ============================================================================
   PWA-SPECIFIC ANIMATIONS
   ============================================================================ */

/* Splash screen animation */
.splash-screen {
  animation: splashFadeOut 0.8s var(--transition-easing) forwards;
  animation-delay: 2s;
}

@keyframes splashFadeOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(1.1);
  }
}

/* Install prompt notification */
.pwa-update-notification {
  animation: notificationSlide 0.4s var(--transition-easing) forwards;
}

.pwa-update-notification.show {
  animation: notificationSlide 0.4s var(--transition-easing) forwards;
}

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

/* Offline status indicator */
.offline-indicator {
  animation: pulse 2s ease-in-out infinite;
}

/* Sync animation */
.syncing {
  animation: sync-rotate 1.5s linear infinite;
}

@keyframes sync-rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* ============================================================================
   ACCESSIBILITY - Reduce motion
   ============================================================================ */

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

/* ============================================================================
   RESPONSIVE ANIMATIONS
   ============================================================================ */

@media (max-width: 768px) {
  @keyframes slideInRight {
    from {
      transform: translateX(50px);
      opacity: 0;
    }
    to {
      transform: translateX(0);
      opacity: 1;
    }
  }

  button:hover,
  .btn:hover,
  [role="button"]:hover {
    transform: translateY(-1px);
  }

  .card:hover {
    transform: translateY(-2px);
  }
}
