/**
 * Playful Loading Animations for Occupancy Monitor
 * Fun, engaging animations that relate to the occupancy monitoring theme
 */

/* Main loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(33, 37, 41, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Loading container */
.loading-container {
    text-align: center;
    color: #fff;
}

.loading-text {
    font-size: 1.2rem;
    margin-top: 20px;
    opacity: 0.8;
}

/* 1. People Walking Animation */
.people-walking {
    width: 200px;
    height: 60px;
    position: relative;
    margin: 0 auto;
}

.person {
    position: absolute;
    width: 30px;
    height: 50px;
    background: linear-gradient(135deg, #6c757d, #495057);
    border-radius: 15px 15px 5px 5px;
    animation: walk 2s infinite ease-in-out;
}

.person::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    background: #ffc107;
    border-radius: 50%;
}

.person::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 2px;
    width: 8px;
    height: 8px;
    background: #6c757d;
    border-radius: 50%;
    box-shadow: 18px 0 #6c757d;
}

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

.person:nth-child(2) {
    left: 50px;
    animation-delay: 0.5s;
}

.person:nth-child(3) {
    left: 100px;
    animation-delay: 1s;
}

.person:nth-child(4) {
    left: 150px;
    animation-delay: 1.5s;
}

@keyframes walk {
    0%, 100% {
        transform: translateY(0px);
        background: linear-gradient(135deg, #6c757d, #495057);
    }
    25% {
        transform: translateY(-3px);
        background: linear-gradient(135deg, #0d6efd, #0b5ed7);
    }
    50% {
        transform: translateY(0px);
        background: linear-gradient(135deg, #198754, #157347);
    }
    75% {
        transform: translateY(-3px);
        background: linear-gradient(135deg, #ffc107, #ffca2c);
    }
}

/* 2. Building Occupancy Bars */
.building-occupancy {
    width: 180px;
    height: 80px;
    position: relative;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.building-floor {
    width: 20px;
    background: linear-gradient(to top, #0d6efd, #6610f2);
    border-radius: 3px 3px 0 0;
    position: relative;
    animation: occupancy-pulse 1.5s infinite ease-in-out;
}

.building-floor::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 1px;
}

.building-floor:nth-child(1) {
    height: 20px;
    animation-delay: 0s;
}

.building-floor:nth-child(2) {
    height: 35px;
    animation-delay: 0.2s;
}

.building-floor:nth-child(3) {
    height: 50px;
    animation-delay: 0.4s;
}

.building-floor:nth-child(4) {
    height: 65px;
    animation-delay: 0.6s;
}

.building-floor:nth-child(5) {
    height: 45px;
    animation-delay: 0.8s;
}

.building-floor:nth-child(6) {
    height: 30px;
    animation-delay: 1s;
}

.building-floor:nth-child(7) {
    height: 55px;
    animation-delay: 1.2s;
}

@keyframes occupancy-pulse {
    0%, 100% {
        transform: scaleY(1);
        opacity: 0.7;
    }
    50% {
        transform: scaleY(1.3);
        opacity: 1;
    }
}

/* 3. Sensor Dots Network */
.sensor-network {
    width: 200px;
    height: 100px;
    position: relative;
    margin: 0 auto;
}

.sensor-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #28a745;
    border-radius: 50%;
    animation: sensor-blink 2s infinite;
}

.sensor-dot::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border: 2px solid rgba(40, 167, 69, 0.3);
    border-radius: 50%;
    animation: sensor-ripple 2s infinite;
}

.sensor-dot:nth-child(1) {
    top: 20px;
    left: 30px;
    animation-delay: 0s;
}

.sensor-dot:nth-child(2) {
    top: 10px;
    left: 90px;
    animation-delay: 0.3s;
}

.sensor-dot:nth-child(3) {
    top: 50px;
    left: 150px;
    animation-delay: 0.6s;
}

.sensor-dot:nth-child(4) {
    top: 70px;
    left: 20px;
    animation-delay: 0.9s;
}

.sensor-dot:nth-child(5) {
    top: 40px;
    left: 80px;
    animation-delay: 1.2s;
}

@keyframes sensor-blink {
    0%, 50%, 100% {
        background: #28a745;
        box-shadow: 0 0 5px rgba(40, 167, 69, 0.8);
    }
    25%, 75% {
        background: #ffc107;
        box-shadow: 0 0 15px rgba(255, 193, 7, 0.8);
    }
}

@keyframes sensor-ripple {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* 4. Spinning Gauge Animation */
.loading-gauge {
    width: 120px;
    height: 120px;
    margin: 0 auto;
    position: relative;
}

.gauge-circle {
    width: 100%;
    height: 100%;
    border: 8px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    position: relative;
    overflow: hidden;
}

.gauge-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 8px solid transparent;
    border-top: 8px solid #28a745;
    border-right: 8px solid #ffc107;
    border-bottom: 8px solid #dc3545;
    border-radius: 50%;
    animation: gauge-spin 2s linear infinite;
}

.gauge-needle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 40px;
    background: #fff;
    transform-origin: bottom center;
    transform: translate(-50%, -100%) rotate(0deg);
    animation: needle-sweep 3s ease-in-out infinite;
}

.gauge-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

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

@keyframes needle-sweep {
    0%, 100% {
        transform: translate(-50%, -100%) rotate(-45deg);
    }
    50% {
        transform: translate(-50%, -100%) rotate(45deg);
    }
}

/* 5. Data Stream Animation */
.data-stream {
    width: 200px;
    height: 60px;
    position: relative;
    margin: 0 auto;
    overflow: hidden;
}

.data-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #0d6efd;
    border-radius: 50%;
    animation: stream-flow 3s linear infinite;
}

.data-particle:nth-child(1) {
    top: 10px;
    animation-delay: 0s;
    background: #28a745;
}

.data-particle:nth-child(2) {
    top: 25px;
    animation-delay: 0.3s;
    background: #ffc107;
}

.data-particle:nth-child(3) {
    top: 40px;
    animation-delay: 0.6s;
    background: #dc3545;
}

.data-particle:nth-child(4) {
    top: 15px;
    animation-delay: 0.9s;
    background: #6f42c1;
}

.data-particle:nth-child(5) {
    top: 35px;
    animation-delay: 1.2s;
    background: #20c997;
}

@keyframes stream-flow {
    0% {
        left: -10px;
        opacity: 0;
        transform: scale(0.5);
    }
    10% {
        opacity: 1;
        transform: scale(1);
    }
    90% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        left: 210px;
        opacity: 0;
        transform: scale(0.5);
    }
}

/* Loading states for specific elements */
.loading-card {
    position: relative;
    overflow: hidden;
}

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

@keyframes card-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Micro-loading animations for buttons */
.btn-loading {
    position: relative;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: button-spin 1s linear infinite;
}

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

/* Skeleton loading for text */
.skeleton-text {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 25%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 2s infinite;
    border-radius: 4px;
    height: 1em;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
    .people-walking,
    .building-occupancy,
    .sensor-network,
    .data-stream {
        transform: scale(0.8);
    }
    
    .loading-gauge {
        width: 100px;
        height: 100px;
    }
    
    .loading-text {
        font-size: 1rem;
    }
}