/*
 * Page Loader Component
 * Beautiful building construction animation for page loads
 */

/* =============================================================================
   Page Loader Overlay
   ============================================================================= */

.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, var(--blue-invest-dark) 0%, var(--blue-invest-medium) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* =============================================================================
   Loader Content Container
   ============================================================================= */

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 2rem;
}

/* =============================================================================
   Building Construction Animation
   ============================================================================= */

.building-animation {
    width: 280px;
    height: 280px;
    position: relative;
    perspective: 1000px;
}

/* Building Foundation */
.building-foundation {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 8px;
    background: var(--blue-invest-accent);
    border-radius: 4px;
    animation: foundationPulse 2s ease-in-out infinite;
}

@keyframes foundationPulse {
    0%, 100% {
        opacity: 0.6;
        transform: translateX(-50%) scaleX(1);
    }
    50% {
        opacity: 1;
        transform: translateX(-50%) scaleX(1.05);
    }
}

/* Building Floors Container */
.building-floors {
    position: absolute;
    bottom: 38px;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    display: flex;
    flex-direction: column-reverse;
    gap: 4px;
}

/* Individual Floor */
.building-floor {
    width: 100%;
    height: 36px;
    background: var(--blue-invest-light);
    border: 2px solid var(--blue-invest-accent);
    border-radius: 4px;
    position: relative;
    transform-origin: bottom center;
    opacity: 0;
    animation: floorBuild 0.6s ease-out forwards;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Stagger floor animation delays */
.building-floor:nth-child(1) { animation-delay: 0s; }
.building-floor:nth-child(2) { animation-delay: 0.15s; }
.building-floor:nth-child(3) { animation-delay: 0.3s; }
.building-floor:nth-child(4) { animation-delay: 0.45s; }
.building-floor:nth-child(5) { animation-delay: 0.6s; }
.building-floor:nth-child(6) { animation-delay: 0.75s; }

@keyframes floorBuild {
    0% {
        opacity: 0;
        transform: scaleY(0) translateY(20px);
    }
    60% {
        transform: scaleY(1.1) translateY(-4px);
    }
    100% {
        opacity: 1;
        transform: scaleY(1) translateY(0);
    }
}

/* Windows on each floor */
.building-floor::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 12px;
    right: 12px;
    height: 60%;
    transform: translateY(-50%);
    background-image:
        linear-gradient(90deg, var(--blue-invest-dark) 2px, transparent 2px),
        linear-gradient(0deg, var(--blue-invest-dark) 2px, transparent 2px);
    background-size: 24px 100%, 100% 100%;
    background-position: 0 0, 0 0;
    opacity: 0;
    animation: windowsAppear 0.4s ease-out forwards;
    animation-delay: inherit;
}

@keyframes windowsAppear {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 0.6;
    }
}

/* Window lights effect */
.building-floor::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 14px;
    width: 8px;
    height: 8px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border-radius: 2px;
    box-shadow:
        24px 0 0 rgba(255, 255, 255, 0.9),
        48px 0 0 rgba(255, 255, 255, 0.9),
        72px 0 0 rgba(255, 255, 255, 0.9),
        96px 0 0 rgba(255, 255, 255, 0.9),
        120px 0 0 rgba(255, 255, 255, 0.9);
    opacity: 0;
    animation: lightsOn 0.3s ease-out forwards;
    animation-delay: calc(var(--floor-delay) + 0.3s);
}

.building-floor:nth-child(1)::after { --floor-delay: 0s; }
.building-floor:nth-child(2)::after { --floor-delay: 0.15s; }
.building-floor:nth-child(3)::after { --floor-delay: 0.3s; }
.building-floor:nth-child(4)::after { --floor-delay: 0.45s; }
.building-floor:nth-child(5)::after { --floor-delay: 0.6s; }
.building-floor:nth-child(6)::after { --floor-delay: 0.75s; }

@keyframes lightsOn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* Crane Animation */
.construction-crane {
    position: absolute;
    top: 0;
    right: 30px;
    width: 80px;
    height: 160px;
    opacity: 0;
    animation: craneAppear 0.6s ease-out 0.3s forwards;
}

@keyframes craneAppear {
    0% {
        opacity: 0;
        transform: translateY(-20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Crane arm */
.crane-arm {
    position: absolute;
    top: 40px;
    left: 10px;
    width: 60px;
    height: 4px;
    background: var(--blue-invest-accent);
    border-radius: 2px;
    transform-origin: left center;
    animation: craneSwing 3s ease-in-out infinite;
}

@keyframes craneSwing {
    0%, 100% {
        transform: rotate(0deg);
    }
    50% {
        transform: rotate(-8deg);
    }
}

/* Crane hook */
.crane-hook {
    position: absolute;
    right: 0;
    top: 100%;
    width: 2px;
    height: 30px;
    background: var(--blue-invest-accent);
    animation: hookMove 3s ease-in-out infinite;
}

@keyframes hookMove {
    0%, 100% {
        height: 30px;
    }
    50% {
        height: 45px;
    }
}

/* Crane base */
.crane-base {
    position: absolute;
    bottom: 0;
    left: 8px;
    width: 6px;
    height: 120px;
    background: var(--blue-invest-medium);
    border-radius: 3px;
}

/* Floating particles (construction dust) */
.construction-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: var(--blue-invest-accent);
    border-radius: 50%;
    opacity: 0;
    animation: particleFloat 2.5s ease-in-out infinite;
}

.particle:nth-child(1) {
    left: 20%;
    animation-delay: 0s;
}

.particle:nth-child(2) {
    left: 40%;
    animation-delay: 0.5s;
}

.particle:nth-child(3) {
    left: 60%;
    animation-delay: 1s;
}

.particle:nth-child(4) {
    left: 80%;
    animation-delay: 1.5s;
}

@keyframes particleFloat {
    0% {
        bottom: 30px;
        opacity: 0;
        transform: translateY(0) scale(1);
    }
    50% {
        opacity: 0.6;
    }
    100% {
        bottom: 200px;
        opacity: 0;
        transform: translateY(-20px) scale(0.5);
    }
}

/* =============================================================================
   Loading Text
   ============================================================================= */

.loader-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.loader-title {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: var(--font-weight-bold);
    color: var(--text-light);
    margin: 0;
    letter-spacing: 1px;
    animation: textPulse 2s ease-in-out infinite;
}

@keyframes textPulse {
    0%, 100% {
        opacity: 0.9;
    }
    50% {
        opacity: 1;
    }
}

.loader-subtitle {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    color: var(--blue-invest-accent);
    margin: 0;
    font-weight: var(--font-weight-medium);
}

/* Progress Dots */
.loader-dots {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--text-light);
    border-radius: 50%;
    animation: dotBounce 1.4s ease-in-out infinite;
}

.dot:nth-child(1) {
    animation-delay: 0s;
}

.dot:nth-child(2) {
    animation-delay: 0.2s;
}

.dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* =============================================================================
   Progress Bar
   ============================================================================= */

.loader-progress {
    width: 100%;
    max-width: 300px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 1rem;
}

.loader-progress-bar {
    height: 100%;
    background: linear-gradient(90deg,
        var(--blue-invest-accent),
        var(--text-light),
        var(--blue-invest-accent));
    background-size: 200% 100%;
    border-radius: 2px;
    animation: progressShine 1.5s ease-in-out infinite;
    transform-origin: left;
    animation: progressFill 2s ease-out forwards;
}

@keyframes progressFill {
    0% {
        transform: scaleX(0);
    }
    100% {
        transform: scaleX(1);
    }
}

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

/* =============================================================================
   Responsive Design
   ============================================================================= */

@media (max-width: 768px) {
    .building-animation {
        width: 220px;
        height: 220px;
        transform: scale(0.9);
    }

    .building-floors {
        width: 140px;
    }

    .building-floor {
        height: 32px;
    }

    .construction-crane {
        width: 70px;
        height: 140px;
        right: 20px;
    }

    .loader-content {
        gap: 1.5rem;
    }
}

@media (max-width: 480px) {
    .building-animation {
        width: 200px;
        height: 200px;
        transform: scale(0.8);
    }

    .building-floors {
        width: 120px;
    }

    .building-floor {
        height: 28px;
    }

    .construction-crane {
        width: 60px;
        height: 120px;
        right: 15px;
    }

    .loader-content {
        gap: 1rem;
        padding: 1rem;
    }

    .loader-progress {
        max-width: 250px;
    }
}

/* =============================================================================
   Reduced Motion Support
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    .page-loader,
    .building-floor,
    .crane-arm,
    .crane-hook,
    .particle,
    .loader-title,
    .dot,
    .loader-progress-bar {
        animation: none;
    }

    .building-floor {
        opacity: 1;
        transform: scaleY(1);
    }

    .building-floor::before,
    .building-floor::after {
        opacity: 1;
    }

    .construction-crane {
        opacity: 1;
    }

    .page-loader.hidden {
        transition: opacity 0.3s ease;
    }
}
