/* ═══════════════════════════════════════════════════════
   PRELOADER — RMS IC System
   Modern loading screen with animated gradient & logo pulse
   ═══════════════════════════════════════════════════════ */

#sitePreloader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 40%, #0f172a 100%);
    background-size: 300% 300%;
    animation: preloaderBgShift 6s ease infinite;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#sitePreloader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

@keyframes preloaderBgShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ── Animated particles ── */
.preloader-particles {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}
.preloader-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(99, 102, 241, 0.6);
    border-radius: 50%;
    animation: particleFloat 8s ease-in-out infinite;
}
.preloader-particle:nth-child(1)  { left: 10%; top: 20%; animation-delay: 0s; animation-duration: 7s; }
.preloader-particle:nth-child(2)  { left: 25%; top: 60%; animation-delay: 1.2s; animation-duration: 9s; }
.preloader-particle:nth-child(3)  { left: 45%; top: 30%; animation-delay: 2.4s; animation-duration: 8.5s; }
.preloader-particle:nth-child(4)  { left: 60%; top: 70%; animation-delay: 0.6s; animation-duration: 7.5s; }
.preloader-particle:nth-child(5)  { left: 75%; top: 15%; animation-delay: 3s; animation-duration: 10s; }
.preloader-particle:nth-child(6)  { left: 85%; top: 55%; animation-delay: 1.8s; animation-duration: 8s; }
.preloader-particle:nth-child(7)  { left: 15%; top: 80%; animation-delay: 2.1s; animation-duration: 9.5s; }
.preloader-particle:nth-child(8)  { left: 50%; top: 45%; animation-delay: 0.3s; animation-duration: 6.5s; }
.preloader-particle:nth-child(9)  { left: 70%; top: 85%; animation-delay: 3.5s; animation-duration: 11s; }
.preloader-particle:nth-child(10) { left: 35%; top: 10%; animation-delay: 1.5s; animation-duration: 8.8s; }

@keyframes particleFloat {
    0%, 100% { transform: translateY(0) translateX(0) scale(1); opacity: 0.3; }
    25% { transform: translateY(-40px) translateX(15px) scale(2); opacity: 0.8; }
    50% { transform: translateY(-20px) translateX(-10px) scale(1.5); opacity: 0.5; }
    75% { transform: translateY(-50px) translateX(-20px) scale(2.5); opacity: 0.9; }
}

/* ── Logo / Icon container ── */
.preloader-logo-wrap {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* Outer glow ring */
.preloader-ring {
    position: relative;
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preloader-ring::before {
    content: '';
    position: absolute;
    inset: -12px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: rgba(99, 102, 241, 0.8);
    border-right-color: rgba(139, 92, 246, 0.5);
    animation: ringSpin 1.4s linear infinite;
}

.preloader-ring::after {
    content: '';
    position: absolute;
    inset: -20px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-bottom-color: rgba(99, 102, 241, 0.4);
    border-left-color: rgba(139, 92, 246, 0.25);
    animation: ringSpin 2s linear infinite reverse;
}

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

/* Center logo icon */
.preloader-icon {
    width: 58px;
    height: 58px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 8px 32px rgba(79, 70, 229, 0.5);
    animation: iconPulse 2s ease-in-out infinite;
    position: relative;
    z-index: 2;
}

.preloader-icon svg {
    width: 30px;
    height: 30px;
}

@keyframes iconPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 32px rgba(79, 70, 229, 0.5); }
    50% { transform: scale(1.08); box-shadow: 0 14px 44px rgba(79, 70, 229, 0.7); }
}

/* Loading text */
.preloader-text {
    color: #94a3b8;
    font-family: 'Kanit', 'Prompt', sans-serif;
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

/* Animated dots */
.preloader-dots {
    display: inline-flex;
    gap: 0.15rem;
}
.preloader-dots span {
    width: 5px;
    height: 5px;
    background: #6366f1;
    border-radius: 50%;
    animation: dotBounce 1.2s ease-in-out infinite;
}
.preloader-dots span:nth-child(2) { animation-delay: 0.15s; }
.preloader-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* Progress bar */
.preloader-bar-wrap {
    width: 180px;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 0.25rem;
}
.preloader-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #7c3aed, #a78bfa);
    border-radius: 10px;
    animation: barProgress 2.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes barProgress {
    0% { width: 0%; }
    30% { width: 45%; }
    60% { width: 75%; }
    85% { width: 92%; }
    100% { width: 100%; }
}

/* ── Brand subtitle ── */
.preloader-brand {
    color: rgba(148, 163, 184, 0.6);
    font-family: 'Kanit', 'Prompt', sans-serif;
    font-size: 0.72rem;
    font-weight: 300;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-top: -0.5rem;
}

/* ── Mobile tweaks ── */
@media (max-width: 480px) {
    .preloader-ring { width: 72px; height: 72px; }
    .preloader-ring::before { inset: -10px; }
    .preloader-ring::after  { inset: -16px; }
    .preloader-icon { width: 48px; height: 48px; border-radius: 14px; }
    .preloader-icon svg { width: 24px; height: 24px; }
    .preloader-text { font-size: 0.82rem; }
    .preloader-bar-wrap { width: 150px; }
}
