/* 
 * Motion Design System for WashU Car Wash Portal
 * World-class UI polish with tasteful motion design
 * Performance-optimized with GPU-accelerated animations
 * Respects accessibility preferences
 */

/* ===== DESIGN TOKENS ===== */
:root {
  /* Timing Functions */
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
  --ease-out-quart: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-out-back: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-spring: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Duration Scale */
  --duration-instant: 100ms;
  --duration-fast: 200ms;
  --duration-normal: 300ms;
  --duration-slow: 500ms;
  --duration-slower: 700ms;
  --duration-slowest: 1000ms;
  
  /* Spring Physics */
  --spring-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --spring-smooth: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  
  /* Transform Origins */
  --origin-center: center center;
  --origin-top: center top;
  --origin-bottom: center bottom;
  
  /* Shadows with Depth */
  --shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.15);
  --shadow-2xl: 0 24px 48px rgba(0, 0, 0, 0.18);
  --shadow-glow: 0 0 40px rgba(26, 133, 184, 0.15);
  
  /* Blur Values */
  --blur-sm: 4px;
  --blur-md: 8px;
  --blur-lg: 16px;
  --blur-xl: 24px;
}

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

/* Button Press Animation */
.btn, 
button:not(.no-motion) {
  position: relative;
  transition: all var(--duration-fast) var(--ease-smooth);
  will-change: transform;
}

.btn::before,
button:not(.no-motion)::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(145deg, rgba(255,255,255,0.1), transparent);
  border-radius: inherit;
  opacity: 0;
  transition: opacity var(--duration-fast) ease;
  pointer-events: none;
}

.btn:hover,
button:not(.no-motion):hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn:hover::before,
button:not(.no-motion):hover::before {
  opacity: 1;
}

.btn:active,
button:not(.no-motion):active {
  transform: translateY(0) scale(0.98);
  transition-duration: var(--duration-instant);
}

/* Card Hover - Clean lift effect */
.card,
.enhanced-module-card,
.kpi-card,
.content-card {
  transition: all var(--duration-normal) var(--ease-smooth);
  will-change: transform;
}

.card:hover,
.enhanced-module-card:hover,
.kpi-card:hover,
.content-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-xl);
}

/* Ripple Effect for Clickable Elements */
.ripple-effect {
  position: relative;
  overflow: hidden;
}

.ripple-effect::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.5), transparent);
  transform: translate(-50%, -50%);
  transition: width var(--duration-slow) ease-out, height var(--duration-slow) ease-out;
}

.ripple-effect:active::after {
  width: 300px;
  height: 300px;
}

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

/* Magnetic Hover */
.magnetic-hover {
  transition: transform var(--duration-fast) var(--ease-smooth);
}

/* Glow Effect on Focus */
.form-control,
.form-select,
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  transition: all var(--duration-normal) var(--ease-smooth);
  position: relative;
}

.form-control:focus,
.form-select:focus,
input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  transform: translateY(-1px);
  box-shadow: 0 0 0 3px rgba(26, 133, 184, 0.1), var(--shadow-md);
  border-color: var(--primary);
}

/* ===== SKELETON LOADERS ===== */

.skeleton {
  position: relative;
  overflow: hidden;
  background: linear-gradient(90deg, #f0f0f0 0%, #f8f8f8 20%, #f0f0f0 40%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: var(--border-radius);
}

.skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  transform: translateX(-100%);
  animation: shimmer-wave 1.5s infinite;
}

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

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

/* Skeleton Variants */
.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
  border-radius: 4px;
}

.skeleton-title {
  height: 1.5em;
  width: 40%;
  margin-bottom: 1em;
  border-radius: 4px;
}

.skeleton-card {
  height: 200px;
  border-radius: var(--border-radius-lg);
  margin-bottom: 1.5rem;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-button {
  height: 40px;
  width: 120px;
  border-radius: var(--border-radius);
}

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

/* Dots Loader */
.dots-loader {
  display: inline-flex;
  gap: 4px;
}

.dots-loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: dots-pulse 1.4s infinite ease-in-out both;
}

.dots-loader span:nth-child(1) { animation-delay: -0.32s; }
.dots-loader span:nth-child(2) { animation-delay: -0.16s; }
.dots-loader span:nth-child(3) { animation-delay: 0; }

@keyframes dots-pulse {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

/* Spinner Loader */
.spinner-loader {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(26, 133, 184, 0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Progress Bar Loader */
.progress-loader {
  height: 4px;
  background: rgba(26, 133, 184, 0.1);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.progress-loader::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 40%;
  background: var(--primary);
  border-radius: 2px;
  animation: progress-slide 1.5s ease-in-out infinite;
}

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

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

/* Fade In Up */
/* Note: We gate the hidden state behind :not(.visible) so components that
 * render with fade-in-up already applied do not stay transparent when MotionController
 * or custom scripts fail to reapply .visible on soft reloads. */
.fade-in-up:not(.visible) {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp var(--duration-normal) var(--ease-smooth) forwards;
}

.fade-in-up.visible,
.animated-fade-in.visible {
  opacity: 1 !important;
  transform: translateY(0) !important;
  animation: none !important;
}

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

/* Slide In */
.slide-in-left {
  transform: translateX(-100%);
  animation: slideInLeft var(--duration-normal) var(--ease-smooth) forwards;
}

.slide-in-right {
  transform: translateX(100%);
  animation: slideInRight var(--duration-normal) var(--ease-smooth) forwards;
}

@keyframes slideInLeft {
  to { transform: translateX(0); }
}

@keyframes slideInRight {
  to { transform: translateX(0); }
}

/* Scale In */
.scale-in {
  transform: scale(0.9);
  opacity: 0;
  animation: scaleIn var(--duration-normal) var(--ease-spring) forwards;
}

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

/* ===== STAGGER ANIMATIONS ===== */

.stagger-children > *:not(.visible) {
  opacity: 0;
  transform: translateY(20px);
  /* Animation will start when .visible class is added */
}

.stagger-children > *.visible {
  opacity: 1;
  transform: translateY(0);
  animation: staggerFadeIn var(--duration-normal) var(--ease-smooth) forwards;
}

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

@keyframes staggerFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.no-motion .fade-in-up,
.no-motion .animated-fade-in,
.no-motion .stagger-children > *,
.no-motion .table tbody tr {
  opacity: 1 !important;
  transform: none !important;
  animation: none !important;
}

/* ===== CARD ANIMATIONS ===== */

/* Flip Card */
.flip-card {
  transform-style: preserve-3d;
  transition: transform var(--duration-slow) var(--ease-smooth);
}

.flip-card.flipped {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.flip-card-back {
  transform: rotateY(180deg);
}

/* Card Lift */
.card-lift {
  transition: all var(--duration-normal) var(--ease-smooth);
  cursor: pointer;
}

.card-lift:hover {
  transform: translateY(-12px) scale(1.02);
  box-shadow: var(--shadow-2xl);
}

.card-lift:hover::before {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 10%;
  right: 10%;
  height: 20px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.2), transparent);
  filter: blur(8px);
  opacity: 0.6;
}

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

/* Nav Link Underline */
.nav-link {
  position: relative;
  transition: color var(--duration-fast) ease;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--primary);
  transform: translateX(-50%);
  transition: width var(--duration-normal) var(--ease-spring);
}

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

/* Dropdown Slide */
.dropdown-menu {
  display: block;
  transform-origin: top center;
  transform: scaleY(0);
  opacity: 0;
  transition: all var(--duration-fast) var(--ease-smooth);
  pointer-events: none;
}

.dropdown.show .dropdown-menu {
  transform: scaleY(1);
  opacity: 1;
  pointer-events: auto;
}

/* ===== MODAL ANIMATIONS ===== */

/* Modal Backdrop */
.modal-backdrop {
  backdrop-filter: blur(var(--blur-sm));
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn var(--duration-normal) ease;
}

/* Modal Content */
.modal.fade .modal-dialog {
  transform: scale(0.9) translateY(-50px);
  opacity: 0;
  transition: all var(--duration-normal) var(--ease-spring);
}

.modal.show .modal-dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* ===== TOAST NOTIFICATIONS ===== */

.toast {
  animation: slideInRight var(--duration-normal) var(--ease-spring);
  transform-origin: right center;
}

.toast.hiding {
  animation: slideOutRight var(--duration-normal) var(--ease-smooth) forwards;
}

@keyframes slideOutRight {
  to {
    transform: translateX(110%);
    opacity: 0;
  }
}

/* ===== KPI CARDS ENHANCEMENTS ===== */

.kpi-card,
.ucheck-stat-card {
  position: relative;
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-smooth);
}

.kpi-card::before,
.ucheck-stat-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(26, 133, 184, 0.1), transparent);
  opacity: 0;
  transition: opacity var(--duration-slow) ease;
  pointer-events: none;
}

.kpi-card:hover::before,
.ucheck-stat-card:hover::before {
  opacity: 1;
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Number Counter Animation */
.kpi-value,
.ucheck-stat-number {
  display: inline-block;
  animation: countUp var(--duration-slowest) ease-out;
}

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

/* Progress Bar Fill Animation */
.progress-bar,
.kpi-progress .progress-bar {
  animation: fillProgress var(--duration-slower) var(--ease-smooth) forwards;
  transform-origin: left center;
}

@keyframes fillProgress {
  from {
    transform: scaleX(0);
  }
}

/* ===== TABLE ENHANCEMENTS ===== */

/* Table Row Hover - Only for standard Bootstrap tables, not enhanced tables */
.table:not(.table-enhanced) tbody tr {
  transition: background-color var(--duration-fast) ease;
  position: relative;
}

.table:not(.table-enhanced) tbody tr:hover {
  background: rgba(26, 133, 184, 0.05);
  box-shadow: inset 4px 0 0 var(--primary);
}

/* Table Row Fade In */
.table tbody tr {
  opacity: 0;
  animation: tableRowFadeIn var(--duration-normal) var(--ease-smooth) forwards;
}

.table tbody tr:nth-child(1) { animation-delay: 0ms; }
.table tbody tr:nth-child(2) { animation-delay: 50ms; }
.table tbody tr:nth-child(3) { animation-delay: 100ms; }
.table tbody tr:nth-child(4) { animation-delay: 150ms; }
.table tbody tr:nth-child(5) { animation-delay: 200ms; }

@keyframes tableRowFadeIn {
  to {
    opacity: 1;
  }
}

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

.badge {
  animation: badgePop var(--duration-normal) var(--ease-spring);
}

@keyframes badgePop {
  0% {
    transform: scale(0);
  }
  80% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* Notification Badge Pulse */
.badge-notification {
  position: relative;
}

.badge-notification::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: inherit;
  background: inherit;
  animation: notification-pulse 2s ease-in-out infinite;
}

@keyframes notification-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.5);
    opacity: 0;
  }
}

/* ===== ICON ANIMATIONS ===== */

/* Icon Rotate on Hover */
.icon-rotate:hover {
  animation: iconRotate var(--duration-normal) ease;
}

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

/* Icon Bounce */
.icon-bounce {
  animation: iconBounce 2s ease-in-out infinite;
}

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

/* Icon Shake */
.icon-shake:hover {
  animation: iconShake var(--duration-fast) ease;
}

@keyframes iconShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ===== ACCESSIBILITY ===== */

/* Focus Visible Enhancement */
*:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  transition: outline-offset var(--duration-fast) ease;
}

*:focus-visible:hover {
  outline-offset: 4px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    animation-delay: 0ms !important;
  }
  
  .skeleton::after {
    display: none;
  }
  
  .dots-loader span {
    animation: none;
    opacity: 1;
  }
}

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

/* Smooth Scroll */
.smooth-scroll {
  scroll-behavior: smooth;
}

/* No Motion */
.no-motion {
  animation: none !important;
  transition: none !important;
}

/* Hardware Acceleration */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Interaction States */
.is-loading {
  pointer-events: none;
  opacity: 0.6;
}

.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

/* Hover Lift */
.hover-lift {
  transition: transform var(--duration-fast) var(--ease-smooth);
}

.hover-lift:hover {
  transform: translateY(-4px);
}

/* Hover Scale */
.hover-scale {
  transition: transform var(--duration-fast) var(--ease-smooth);
}

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

/* Click Feedback */
.click-feedback {
  transition: transform var(--duration-instant) ease;
}

.click-feedback:active {
  transform: scale(0.95);
}

/* Glassmorphism Effect */
.glass {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Neumorphism Effect */
.neumorphic {
  background: linear-gradient(145deg, #ffffff, #f0f0f0);
  box-shadow: 20px 20px 60px #d1d1d1, -20px -20px 60px #ffffff;
  transition: all var(--duration-normal) ease;
}

.neumorphic:hover {
  box-shadow: 10px 10px 30px #d1d1d1, -10px -10px 30px #ffffff;
}

/* ===== CUSTOM SCROLL BAR ===== */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
  transition: background var(--duration-fast) ease;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--primary) #f1f1f1;
}

/* ===== CAROUSEL NAVIGATION BUTTON OVERRIDES ===== */
/* Prevent motion system from affecting carousel navigation buttons */
.media-nav-btn,
.media-nav-btn::before {
  transform: translateY(-50%) !important;
  transition: background-color var(--duration-fast) ease, opacity var(--duration-fast) ease !important;
  will-change: background-color, opacity !important;
}

.media-nav-btn:hover,
.media-nav-btn:hover::before {
  transform: translateY(-50%) !important;
}

.media-nav-btn:active,
.media-nav-btn:active::before {
  transform: translateY(-50%) !important;
}

.media-nav-btn:disabled,
.media-nav-btn:disabled::before {
  transform: translateY(-50%) !important;
}
