/**
 * Optimized Animations CSS
 * Fixes glitchy card loading and smooth sidebar transitions
 */

/* Hardware Acceleration & Performance */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Force GPU acceleration for animated elements */
.car-card,
.reveal-section,
.car-metric-card,
#mobile-menu,
[x-transition],
.glass {
    will-change: auto;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Prevent layout shifts during animations */
.car-card {
    contain: layout style paint;
}

/* Mobile sidebar - ultra smooth slide */
#mobile-menu {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateX(-100%);
}

#mobile-menu.open {
    transform: translateX(0);
}

/* Dropdown animations - no jank */
[x-cloak] {
    display: none !important;
}

/* Alpine transitions - optimized */
[x-transition\:enter] {
    transition-property: opacity, transform;
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

[x-transition\:leave] {
    transition-property: opacity, transform;
    transition-timing-function: cubic-bezier(0.4, 0, 1, 1);
}

/* Hover effects - smooth and performant */
.car-card {
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.car-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.dark .car-card:hover {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* Button transitions */
button,
a {
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Glassmorphism - optimized */
.glass {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transform: translateZ(0);
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Smooth scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.dark ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(249, 115, 22, 0.5);
}

/* Loading skeleton - smooth pulse */
@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.skeleton {
    animation: skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    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: 200% 100%;
}

.dark .skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 25%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 75%
    );
}

/* Notification animations */
.notification-enter {
    animation: slideInRight 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.notification-exit {
    animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 1, 1);
}

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

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

/* Modal animations */
.modal-backdrop {
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    animation: scaleIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

/* Optimize filter sidebar transitions */
.filter-sidebar {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.3s ease-out;
    will-change: transform, opacity;
}

/* Card grid optimization */
.car-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

@media (min-width: 768px) {
    .car-grid {
        gap: 2rem;
    }
}

/* Prevent layout shift on image load */
.aspect-ratio-box {
    position: relative;
    overflow: hidden;
}

.aspect-ratio-box::before {
    content: '';
    display: block;
    padding-top: 75%; /* 4:3 aspect ratio */
}

.aspect-ratio-box > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
