/* Smooth Animation System for ARIBA */

/* Keyframe Animations */
@keyframes smoothFadeIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
        filter: blur(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

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

@keyframes smoothExpand {
    from {
        opacity: 0;
        max-height: 0;
        transform: scaleY(0);
        transform-origin: top;
    }
    to {
        opacity: 1;
        max-height: 2000px;
        transform: scaleY(1);
    }
}

@keyframes gentlePulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
}

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

/* Loading Animation Classes */
.smooth-loading {
    position: relative;
    overflow: hidden;
}

.smooth-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    100% {
        left: 100%;
    }
}

/* Transition Classes */
.smooth-transition {
    transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.smooth-transition-fast {
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

.smooth-transition-slow {
    transition: all 1s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Family Grid Animation */
#familyGrid {
    transition: opacity 0.6s cubic-bezier(0.23, 1, 0.32, 1),
                transform 0.6s cubic-bezier(0.23, 1, 0.32, 1),
                filter 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

#familyGrid.loading {
    opacity: 0.3;
    filter: blur(2px);
    transform: scale(0.98);
}

#familyGrid.entering {
    animation: smoothFadeIn 0.8s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* Family Card Animations */
.family-card {
    opacity: 0;
    animation: smoothFadeIn 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1),
                box-shadow 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

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

/* Staggered Animation */
.family-card:nth-child(1) { animation-delay: 0.05s; }
.family-card:nth-child(2) { animation-delay: 0.1s; }
.family-card:nth-child(3) { animation-delay: 0.15s; }
.family-card:nth-child(4) { animation-delay: 0.2s; }
.family-card:nth-child(5) { animation-delay: 0.25s; }
.family-card:nth-child(6) { animation-delay: 0.3s; }
.family-card:nth-child(7) { animation-delay: 0.35s; }
.family-card:nth-child(8) { animation-delay: 0.4s; }
.family-card:nth-child(9) { animation-delay: 0.45s; }
.family-card:nth-child(10) { animation-delay: 0.5s; }
.family-card:nth-child(n+11) { animation-delay: 0.55s; }

/* Trade Filter Panel Animation */
#tradeFilterPanel {
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

#tradeFilterPanel.hiding {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    pointer-events: none;
}

#tradeFilterPanel.hidden {
    display: none;
}

/* Empty State Animation */
.empty-state {
    animation: smoothFadeIn 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.empty-state i {
    animation: gentlePulse 3s ease-in-out infinite;
}

.empty-state.exiting {
    animation: smoothFadeOut 0.4s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

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

/* Content Morphing */
.content-morph {
    position: relative;
    min-height: 400px;
}

.content-morph > * {
    transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

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

/* Loading State for Buttons */
.trade-btn.loading {
    position: relative;
    color: transparent;
}

.trade-btn.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 2px solid #ddd;
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 0.8s linear infinite;
}

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

/* Smooth Height Transitions */
.smooth-height {
    overflow: hidden;
    transition: max-height 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Crossfade Effect */
.crossfade-container {
    position: relative;
}

.crossfade-item {
    transition: opacity 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

.crossfade-item.fading-out {
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

.crossfade-item.fading-in {
    opacity: 1;
}

/* Smooth Color Transitions */
.smooth-color {
    transition: background-color 0.4s cubic-bezier(0.23, 1, 0.32, 1),
                color 0.4s cubic-bezier(0.23, 1, 0.32, 1),
                border-color 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Enhanced Loading Container Smooth Transitions */
.loading-container {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1),
                backdrop-filter 0.8s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Loading Content Box Enhancement */
.loading-content {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 24px !important;
    padding: 48px !important;
    text-align: center;
    transform: scale(0.95);
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.loading-container[style*="opacity: 1"] .loading-content {
    transform: scale(1);
}

/* Enhanced 3D Cube Animation */
.loading-cube {
    width: 80px !important;
    height: 80px !important;
    position: relative;
    margin: 0 auto 24px !important;
    transform-style: preserve-3d !important;
    animation: rotateCube 2.5s infinite cubic-bezier(0.4, 0, 0.6, 1) !important;
}

@keyframes rotateCube {
    0% {
        transform: rotateX(0deg) rotateY(0deg);
    }
    25% {
        transform: rotateX(90deg) rotateY(90deg);
    }
    50% {
        transform: rotateX(180deg) rotateY(180deg);
    }
    75% {
        transform: rotateX(270deg) rotateY(270deg);
    }
    100% {
        transform: rotateX(360deg) rotateY(360deg);
    }
}

.loading-cube .face {
    position: absolute;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    opacity: 0.85 !important;
}

.loading-cube .front {
    transform: translateZ(40px);
}

.loading-cube .back {
    transform: rotateY(180deg) translateZ(40px);
}

.loading-cube .top {
    transform: rotateX(90deg) translateZ(40px);
}

.loading-cube .bottom {
    transform: rotateX(-90deg) translateZ(40px);
}

.loading-cube .left {
    transform: rotateY(-90deg) translateZ(40px);
}

.loading-cube .right {
    transform: rotateY(90deg) translateZ(40px);
}

/* Enhanced Loading Text */
.loading-text {
    color: white !important;
    font-size: 20px !important;
    font-weight: 400 !important;
    margin-bottom: 8px !important;
    opacity: 0.95 !important;
    letter-spacing: 0.5px;
}

#loadingPercentage {
    color: rgba(255, 255, 255, 0.65) !important;
    font-size: 15px !important;
    font-weight: 300 !important;
    margin-top: 8px !important;
    letter-spacing: 1px;
}

/* Enhanced Progress Bar */
.loading-progress {
    width: 280px !important;
    height: 3px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border-radius: 3px !important;
    overflow: hidden;
    margin: 24px auto 0 !important;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #f093fb 100%) !important;
    border-radius: 3px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.6);
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

/* Improved Trade Filter Panel Transitions */
#tradeFilterPanel {
    transition: all 1.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    transform-origin: center top;
    will-change: opacity, transform;
}

/* Families View Smooth Entry with Delay */
#familiesView {
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1) 0.2s,
                transform 0.8s cubic-bezier(0.4, 0, 0.2, 1) 0.2s !important;
}

/* GPU Acceleration for Smooth Animations */
.loading-cube,
.loading-container,
#tradeFilterPanel,
#familiesView,
.progress-bar {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}