/* ================================
   Three-Stage Loading Animation
   0-3s: Radar Scanning (Brand Presence)
   3-6s: Neural Network (AI Analysis)
   6-8s: Data Convergence (Insights Generation)
   ================================ */

/* Base Loading Container */
.diagnosis-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

/* Three-Stage Animation Container */
.loading-stages {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 0 auto 40px;
}

.loading-stages > div {
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Stage 1: Radar Scanning (0-3s) */
.stage-radar {
    position: absolute;
    inset: 0;
    opacity: 1;
    animation: stageTransition 8s ease-in-out;
}

.radar-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.radar-circle {
    position: absolute;
    inset: 0;
    border: 2px solid rgba(99, 102, 241, 0.2);
    border-radius: 50%;
}

.radar-circle:nth-child(1) {
    transform: scale(0.8);
}

.radar-circle:nth-child(2) {
    transform: scale(0.6);
}

.radar-circle:nth-child(3) {
    transform: scale(0.4);
}

.radar-sweep {
    position: absolute;
    inset: 0;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        rgba(99, 102, 241, 0.6) 30deg,
        transparent 60deg
    );
    border-radius: 50%;
    animation: radarSweep 2s linear infinite;
}

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

/* Blip animations */
.radar-blip {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #6366f1;
    border-radius: 50%;
    animation: blipPulse 2s ease-in-out infinite;
}

.radar-blip:nth-child(5) {
    top: 30%;
    left: 70%;
    animation-delay: 0.2s;
}

.radar-blip:nth-child(6) {
    top: 60%;
    left: 20%;
    animation-delay: 0.5s;
}

.radar-blip:nth-child(7) {
    top: 80%;
    left: 60%;
    animation-delay: 0.8s;
}

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

/* Stage 2: Neural Network (3-6s) */
.stage-neural {
    position: absolute;
    inset: 0;
    opacity: 0;
    animation: stageTransition 8s ease-in-out;
    animation-delay: 3s;
}

.neural-network {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Neural nodes */
.neural-node {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #6366f1;
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.6);
}

.neural-node:nth-child(1) { top: 20%; left: 50%; transform: translateX(-50%); }
.neural-node:nth-child(2) { top: 40%; left: 20%; }
.neural-node:nth-child(3) { top: 40%; left: 80%; }
.neural-node:nth-child(4) { top: 60%; left: 30%; }
.neural-node:nth-child(5) { top: 60%; left: 70%; }
.neural-node:nth-child(6) { top: 80%; left: 50%; transform: translateX(-50%); }

/* Neural connections */
.neural-connection {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        #6366f1 50%, 
        transparent 100%
    );
    transform-origin: left center;
    animation: neuralPulse 1.5s ease-in-out infinite;
}

.neural-connection:nth-child(7) {
    top: 30%;
    left: 50%;
    width: 100px;
    transform: rotate(30deg);
}

.neural-connection:nth-child(8) {
    top: 30%;
    left: 50%;
    width: 100px;
    transform: rotate(-30deg);
}

.neural-connection:nth-child(9) {
    top: 50%;
    left: 25%;
    width: 120px;
    transform: rotate(15deg);
}

.neural-connection:nth-child(10) {
    top: 50%;
    left: 55%;
    width: 120px;
    transform: rotate(-15deg);
}

@keyframes neuralPulse {
    0%, 100% {
        opacity: 0.3;
        background-size: 0% 100%;
    }
    50% {
        opacity: 1;
        background-size: 100% 100%;
    }
}

/* Stage 3: Data Convergence (6-8s) */
.stage-convergence {
    position: absolute;
    inset: 0;
    opacity: 0;
    animation: stageTransition 8s ease-in-out;
    animation-delay: 6s;
}

.convergence-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Central core */
.convergence-core {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 50%;
    position: relative;
    animation: corePulse 1s ease-in-out infinite;
}

@keyframes corePulse {
    0%, 100% {
        transform: scale(0.9);
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.6);
    }
    50% {
        transform: scale(1);
        box-shadow: 0 0 0 20px rgba(99, 102, 241, 0);
    }
}

/* Data particles */
.data-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #6366f1;
    border-radius: 50%;
}

.data-particle:nth-child(2) {
    animation: particleOrbit1 3s linear infinite;
}

.data-particle:nth-child(3) {
    animation: particleOrbit2 3s linear infinite;
    animation-delay: 0.5s;
}

.data-particle:nth-child(4) {
    animation: particleOrbit3 3s linear infinite;
    animation-delay: 1s;
}

.data-particle:nth-child(5) {
    animation: particleOrbit4 3s linear infinite;
    animation-delay: 1.5s;
}

@keyframes particleOrbit1 {
    from {
        transform: rotate(0deg) translateX(100px) rotate(0deg);
    }
    to {
        transform: rotate(360deg) translateX(100px) rotate(-360deg);
    }
}

@keyframes particleOrbit2 {
    from {
        transform: rotate(90deg) translateX(120px) rotate(-90deg);
    }
    to {
        transform: rotate(450deg) translateX(120px) rotate(-450deg);
    }
}

@keyframes particleOrbit3 {
    from {
        transform: rotate(180deg) translateX(90px) rotate(-180deg);
    }
    to {
        transform: rotate(540deg) translateX(90px) rotate(-540deg);
    }
}

@keyframes particleOrbit4 {
    from {
        transform: rotate(270deg) translateX(110px) rotate(-270deg);
    }
    to {
        transform: rotate(630deg) translateX(110px) rotate(-630deg);
    }
}

/* Stage transition animation */
@keyframes stageTransition {
    0%, 37.5% {
        opacity: 0;
    }
    37.5%, 62.5% {
        opacity: 1;
    }
    62.5%, 100% {
        opacity: 0;
    }
}

/* Progress Bar */
.loading-progress-bar {
    width: 300px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 40px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 2px;
    width: 0%;
    animation: progressFill 8s ease-out forwards;
}

@keyframes progressFill {
    0% { width: 0%; }
    37.5% { width: 37.5%; }
    75% { width: 75%; }
    100% { width: 100%; }
}

/* Loading Text */
.loading-text {
    font-size: 24px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 8px;
    text-align: center;
}

/* Loading Progress */
.loading-progress {
    font-size: 16px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 16px;
    text-align: center;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Courier New', monospace;
    letter-spacing: 0.5px;
}

.loading-stage-text {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    min-height: 24px;
}

/* Stage-specific text animations */
.stage-text-scanning {
    animation: textFade 8s ease-in-out;
}

.stage-text-analyzing {
    opacity: 0;
    animation: textFade 8s ease-in-out;
    animation-delay: 3s;
}

.stage-text-generating {
    opacity: 0;
    animation: textFade 8s ease-in-out;
    animation-delay: 6s;
}

@keyframes textFade {
    0%, 37.5% {
        opacity: 0;
    }
    37.5%, 62.5% {
        opacity: 1;
    }
    62.5%, 100% {
        opacity: 0;
    }
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .loading-stages {
        width: 240px;
        height: 240px;
    }
    
    .loading-progress-bar {
        width: 240px;
    }
    
    .loading-text {
        font-size: 20px;
    }
    
    .loading-stage-text {
        font-size: 14px;
    }
    
    .loading-progress {
        font-size: 14px;
    }
}

/* Fade animations */
.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

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

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

/* Loading Overlay Styles */
.diagnosis-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(20px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.diagnosis-loading-container {
    text-align: center;
    position: relative;
}

.brand-display {
    font-size: 32px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 40px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.loading-animation {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 30px;
}

.progress-ring {
    transform: rotate(-90deg);
}

.progress-ring__bg {
    fill: none;
    stroke: rgba(99, 102, 241, 0.1);
    stroke-width: 8;
}

.progress-ring__circle {
    fill: none;
    stroke: url(#progress-gradient);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s ease;
}

.center-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
}

.center-icon svg {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.center-icon svg.active {
    opacity: 1;
}

.loading-stage-text {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 8px;
}

.loading-substage-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    transition: opacity 0.3s ease;
}

.loading-dots::after {
    content: '';
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0% { content: ''; }
    33% { content: '.'; }
    66% { content: '..'; }
    100% { content: '...'; }
}

.progress-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #6366f1;
    border-radius: 50%;
    opacity: 0;
    top: 50%;
    left: 50%;
    transition: all 2s ease;
}

.particle.active {
    opacity: 1;
    transform: translate(var(--tx), var(--ty));
}

.success-checkmark {
    display: none;
    width: 52px;
    height: 52px;
    margin: 0 auto;
}

.success-checkmark.show {
    display: block;
}

.checkmark-circle {
    stroke: #10b981;
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 157;
    stroke-dashoffset: 157;
    transform-origin: center;
}

.checkmark-circle.animate {
    animation: circleAnimation 0.6s ease-out forwards;
}

.checkmark-check {
    stroke: #10b981;
    stroke-width: 3;
    fill: none;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
}

.checkmark-check.animate {
    animation: checkAnimation 0.3s 0.5s ease-out forwards;
}

@keyframes circleAnimation {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes checkAnimation {
    to {
        stroke-dashoffset: 0;
    }
}