/*
 * Kengrid global loader: the one loader used on every page.
 * Shown while the page loads (layouts that ask for it) and while any
 * jQuery AJAX / fetch request runs (see /js/kg-loader.js).
 * Selectors are prefixed with #kgLoader so the theme's global resets
 * (e.g. "div, span { margin: 0 auto }") cannot change its layout.
 */
#kgLoader {
    --kg-accent: #e8701f;
    --kg-accent-soft: rgba(232, 112, 31, 0.18);
    --kg-ink: #1f2a44;
    position: fixed;
    inset: 0;
    z-index: 200000; /* above Bootstrap modals (1055) and DataTables; toastr stays on top */
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 16px;
    background: rgba(248, 250, 252, 0.62);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}

    #kgLoader.kg-loader--visible {
        opacity: 1;
        visibility: visible;
        pointer-events: all; /* blocks double clicks while a request runs */
        cursor: progress;
        transition: opacity 0.2s ease, visibility 0s;
    }

    #kgLoader *,
    #kgLoader *::before,
    #kgLoader *::after {
        box-sizing: border-box;
        margin: 0;
    }

    /* Indeterminate bar along the top of the window */
    #kgLoader .kg-loader__bar {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        overflow: hidden;
        background: var(--kg-accent-soft);
    }

        #kgLoader .kg-loader__bar::before {
            content: "";
            position: absolute;
            top: 0;
            bottom: 0;
            left: -40%;
            width: 40%;
            border-radius: 3px;
            background: linear-gradient(90deg, transparent, var(--kg-accent), transparent);
            animation: kg-loader-bar 1.15s cubic-bezier(0.65, 0, 0.35, 1) infinite;
        }

    #kgLoader .kg-loader__card {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        padding: 14px 18px 12px;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.92);
        box-shadow: 0 10px 30px rgba(31, 42, 68, 0.14), 0 2px 6px rgba(31, 42, 68, 0.08);
        transform: scale(0.92) translateY(6px);
        transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.3);
    }

    #kgLoader.kg-loader--visible .kg-loader__card {
        transform: scale(1) translateY(0);
    }

    #kgLoader .kg-loader__stage {
        position: relative;
        width: 60px;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Soft pulsing glow behind the logo */
    #kgLoader .kg-loader__halo {
        position: absolute;
        inset: 10px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(232, 112, 31, 0.35) 0%, rgba(232, 112, 31, 0) 70%);
        animation: kg-loader-halo 1.8s ease-in-out infinite;
    }

    /* Spinning gradient arc */
    #kgLoader .kg-loader__ring--outer {
        position: absolute;
        inset: 0;
        border-radius: 50%;
        background: conic-gradient(from 0deg, rgba(232, 112, 31, 0) 0deg, rgba(232, 112, 31, 0.15) 90deg, var(--kg-accent) 300deg, rgba(232, 112, 31, 0) 360deg);
        -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
        mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
        animation: kg-loader-spin 1.05s linear infinite;
    }

    /* Thin dashed ring turning the other way */
    #kgLoader .kg-loader__ring--inner {
        position: absolute;
        inset: 7px;
        border-radius: 50%;
        border: 1.5px dashed rgba(31, 42, 68, 0.18);
        animation: kg-loader-spin 3.2s linear infinite reverse;
    }

    /* Dot travelling around the arc */
    #kgLoader .kg-loader__orbit {
        position: absolute;
        inset: 0;
        animation: kg-loader-spin 1.05s linear infinite;
    }

        #kgLoader .kg-loader__orbit::before {
            content: "";
            position: absolute;
            top: -1.5px;
            left: 50%;
            width: 7px;
            height: 7px;
            margin-left: -3.5px;
            border-radius: 50%;
            background: var(--kg-accent);
            box-shadow: 0 0 0 3px rgba(232, 112, 31, 0.2), 0 0 10px rgba(232, 112, 31, 0.8);
        }

    #kgLoader .kg-loader__logo {
        position: relative;
        width: 36px;
        height: auto;
        display: block;
        filter: drop-shadow(0 4px 8px rgba(232, 112, 31, 0.35));
        animation: kg-loader-breathe 1.8s ease-in-out infinite;
        user-select: none;
        -webkit-user-drag: none;
    }

    #kgLoader .kg-loader__text {
        font: 600 10px/1 "Poppins", "Segoe UI", Arial, sans-serif;
        letter-spacing: 0.14em;
        text-transform: uppercase;
        color: var(--kg-ink);
        white-space: nowrap;
    }

        #kgLoader .kg-loader__text i {
            display: inline-block;
            font-style: normal;
            color: var(--kg-accent);
            animation: kg-loader-dot 1.2s ease-in-out infinite;
        }

            #kgLoader .kg-loader__text i:nth-child(2) {
                animation-delay: 0.15s;
            }

            #kgLoader .kg-loader__text i:nth-child(3) {
                animation-delay: 0.3s;
            }

/* DataTables has its own "Processing..." box; the global loader replaces it. */
div.dataTables_processing,
div.dataTables_wrapper div.dataTables_processing,
.dt-processing {
    display: none !important;
}

body.kg-loader-busy {
    cursor: progress;
}

@keyframes kg-loader-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes kg-loader-halo {
    0%, 100% {
        transform: scale(0.85);
        opacity: 0.55;
    }

    50% {
        transform: scale(1.25);
        opacity: 1;
    }
}

@keyframes kg-loader-breathe {
    0%, 100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }
}

@keyframes kg-loader-bar {
    0% {
        left: -40%;
    }

    100% {
        left: 100%;
    }
}

@keyframes kg-loader-dot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }

    30% {
        transform: translateY(-3px);
        opacity: 1;
    }
}

@media (max-width: 480px) {
    #kgLoader .kg-loader__card {
        padding: 12px 16px 10px;
        gap: 8px;
    }

    #kgLoader .kg-loader__stage {
        width: 54px;
        height: 54px;
    }

    #kgLoader .kg-loader__logo {
        width: 32px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #kgLoader .kg-loader__ring--outer,
    #kgLoader .kg-loader__orbit {
        animation-duration: 2.4s;
    }

    #kgLoader .kg-loader__halo,
    #kgLoader .kg-loader__ring--inner,
    #kgLoader .kg-loader__logo,
    #kgLoader .kg-loader__text i,
    #kgLoader .kg-loader__bar::before {
        animation: none;
    }
}
