/**
 * AttestFlow ERP - Global Professional Logo Loading System Styles
 * High-performance, GPU-accelerated, theme-adaptive CSS animations.
 */

:root {
    --loader-ring-color: #2563EB;
    --loader-ring-glow: rgba(37, 99, 235, 0.25);
    --loader-particle-color: #38BDF8;
}

[data-theme="dark"] {
    --loader-ring-color: #3B82F6;
    --loader-ring-glow: rgba(59, 130, 246, 0.35);
    --loader-particle-color: #60A5FA;
}

/* ============================================================ */
/* 1. SLIM INDETERMINATE TOP LOADER (PAGE / ROUTE TRANSITIONS)  */
/* ============================================================ */

.app-top-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 9999999;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-100%);
    transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    background: transparent;
}

.app-top-loader.is-active {
    opacity: 1;
    transform: translateY(0);
}

.top-loader-bar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    background: linear-gradient(90deg, #2563EB, #06B6D4, #3B82F6, #6366F1, #2563EB);
    background-size: 200% 100%;
    animation: topLoaderMove 1.4s linear infinite;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.5), 0 0 4px rgba(6, 182, 212, 0.4);
}

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

/* ============================================================ */
/* ============================================================ */
/* 2. FULL-SCREEN LOGO LOADING OVERLAY                          */
/* ============================================================ */

/* If session is already active, suppress full-screen overlay during normal route transitions to prevent blinking */
html.af-skip-initial-loader #appGlobalLoader:not(.is-active) {
    display: none !important;
}

.app-global-loader {
    position: fixed;
    inset: 0;
    z-index: 9999998;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-global-loader.is-hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Translucent Soft Backdrop */
.loader-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(248, 250, 252, 0.90);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    transition: background 0.25s ease;
}

[data-theme="dark"] .loader-backdrop {
    background: rgba(15, 23, 42, 0.90);
}

/* Centered Floating Modern Card */
.loader-card {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 38px 46px;
    background: var(--bg-card, #FFFFFF);
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 24px;
    box-shadow: 0 25px 60px -15px rgba(15, 23, 42, 0.16), 
                0 0 0 1px rgba(15, 23, 42, 0.04);
    max-width: 380px;
    width: 90%;
    margin: 0 auto;
    box-sizing: border-box;
    animation: loaderCardEnter 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] .loader-card {
    background: var(--bg-card, #1E293B);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6), 
                0 0 0 1px rgba(255, 255, 255, 0.08);
}

@keyframes loaderCardEnter {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Logo Display Area with Orbital Spinner */
.loader-logo-wrapper {
    position: relative;
    width: 108px;
    height: 108px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 22px;
}

/* Subtle Glowing Halo behind the logo */
.loader-halo {
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--loader-ring-glow) 0%, rgba(37, 99, 235, 0) 70%);
    animation: loaderHaloPulse 2.2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes loaderHaloPulse {
    0%, 100% {
        transform: scale(0.95);
        opacity: 0.55;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.95;
    }
}

/* Rotating Orbital Outer Ring */
.loader-orbital-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px dashed rgba(37, 99, 235, 0.25);
    border-top-color: var(--loader-ring-color);
    border-right-color: var(--loader-ring-color);
    animation: loaderOrbitalSpin 2.0s linear infinite;
}

[data-theme="dark"] .loader-orbital-ring {
    border-color: rgba(96, 165, 250, 0.22);
    border-top-color: var(--loader-ring-color);
    border-right-color: var(--loader-ring-color);
}

.loader-orbital-ring .orbit-particle {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--loader-particle-color);
    box-shadow: 0 0 10px var(--loader-particle-color);
}

.loader-orbital-ring .particle-1 {
    top: 4px;
    right: 19px;
}

.loader-orbital-ring .particle-2 {
    bottom: 4px;
    left: 19px;
}

@keyframes loaderOrbitalSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Inner Circular Frame containing the Company Logo Emblem */
.loader-logo-frame {
    position: relative;
    width: 86px;
    height: 86px;
    border-radius: 50%;
    background: #FFFFFF;
    border: 2px solid rgba(226, 232, 240, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 12px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
    animation: loaderLogoPulse 2.4s ease-in-out infinite;
}

[data-theme="dark"] .loader-logo-frame {
    background: #FFFFFF;
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 20px rgba(59, 130, 246, 0.2);
}

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

/* Crisp rendering of logo */
.loader-brand-logo {
    max-width: 100%;
    max-height: 100%;
    width: 58px;
    height: 58px;
    object-fit: contain;
    display: block;
    image-rendering: -webkit-optimize-contrast;
}

.loader-brand-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-brand-svg {
    width: 52px;
    height: 52px;
    display: block;
}

/* Loader Text & Dynamic Status Message */
.loader-content {
    text-align: center;
    margin-bottom: 20px;
}

.loader-brand-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main, #0F172A);
    letter-spacing: -0.01em;
    margin-bottom: 5px;
}

.loader-status-msg {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted, #64748B);
    line-height: 1.4;
    transition: opacity 0.18s ease;
    min-height: 18px;
}

/* Bottom Progress Track with smooth indeterminate traveling pill */
.loader-shimmer-track {
    width: 170px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.2);
    overflow: hidden;
    position: relative;
}

[data-theme="dark"] .loader-shimmer-track {
    background: rgba(148, 163, 184, 0.15);
}

.loader-shimmer-indicator {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -40%;
    width: 45%;
    border-radius: 999px;
    background: linear-gradient(90deg, #2563EB, #06B6D4);
    animation: loaderShimmer 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes loaderShimmer {
    0% {
        left: -45%;
        width: 30%;
    }
    50% {
        width: 55%;
    }
    100% {
        left: 105%;
        width: 30%;
    }
}

/* ============================================================ */
/* 3. INLINE SECTION & TABLE LOADERS                             */
/* ============================================================ */

.app-section-loader {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: inherit;
    animation: fadeInSectionLoader 0.2s ease;
    padding: 24px;
    box-sizing: border-box;
}

[data-theme="dark"] .app-section-loader {
    background: rgba(30, 41, 59, 0.88);
}

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

.section-loader-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid rgba(148, 163, 184, 0.25);
    border-top-color: var(--primary, #2563EB);
    animation: sectionSpin 0.8s linear infinite;
}

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

.section-loader-text {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted, #64748B);
    text-align: center;
}

/* ============================================================ */
/* 4. BUTTON LOADING STATES                                     */
/* ============================================================ */

.btn.is-loading,
button.is-loading {
    position: relative !important;
    pointer-events: none !important;
    opacity: 0.85 !important;
    cursor: not-allowed !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
}

.btn-inline-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: sectionSpin 0.7s linear infinite;
    flex-shrink: 0;
}

/* ============================================================ */
/* 5. ACCESSIBILITY - REDUCED MOTION                            */
/* ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .top-loader-bar,
    .loader-halo,
    .loader-orbital-ring,
    .loader-logo-frame,
    .loader-shimmer-indicator,
    .section-loader-spinner,
    .btn-inline-spinner {
        animation: none !important;
    }

    .loader-orbital-ring {
        border-style: solid;
    }

    .loader-shimmer-indicator {
        left: 0;
        width: 100%;
    }
}
