﻿/* ==========================================================================
   loader.css
   مؤشر الانتظار المشترك لكل طلب يذهب إلى الخادم. يُحمَّل بعد motion.css.

   Same convention as responsive.css / motion.css: every selector starts with
   :root. loader.js builds the two elements and toggles the classes:

     .ld-bar      thin line under the top edge: every request, link and form
                  post. Never blocks the page (a file download starts a
                  navigation that never finishes).
     .ld-overlay  scrim + card for AJAX requests. It blocks clicks at once but
                  only becomes visible after a short delay, so a fast request
                  does not flash.
     .ld-busy     the button that started the request.
   ========================================================================== */

:root {
    --ld-delay: .18s;
    --ld-z: 10100;
}

@keyframes ld-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes ld-trickle {
    0% {
        width: 0;
    }

    15% {
        width: 45%;
    }

    45% {
        width: 72%;
    }

    100% {
        width: 92%;
    }
}


/* --------------------------------------------------------------------------
   1. Top line
   -------------------------------------------------------------------------- */

:root .ld-bar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: calc(var(--ld-z) + 10);
    height: 3px;
    pointer-events: none;
}

:root .ld-bar > span {
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(to left, var(--mo-gold, #b7872e), var(--mo-gold-soft, #d9bd84));
    box-shadow: 0 0 8px rgba(183, 135, 46, .6);
    opacity: 0;
}

:root .ld-bar.ld-on > span {
    opacity: 1;
    animation: ld-trickle 10s cubic-bezier(.1, .6, .2, 1) forwards;
}

:root .ld-bar.ld-done > span {
    width: 100% !important;
    opacity: 0;
    transition: width .2s ease-out, opacity .3s ease .2s;
}


/* --------------------------------------------------------------------------
   2. Overlay
   -------------------------------------------------------------------------- */

:root .ld-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: var(--ld-z);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 30, 15, .38);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

:root .ld-overlay.ld-on {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    cursor: progress;
    transition: opacity .2s ease var(--ld-delay);
}

:root .ld-box {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 100%;
    padding: 16px 22px;
    direction: rtl;
    color: var(--mo-green, #00522a);
    background: #fff;
    border: 1px solid var(--ui-hair, rgba(183, 135, 46, .22));
    border-radius: var(--ui-r-box, 10px);
    box-shadow: var(--mo-shadow-2, 0 6px 14px rgba(92, 62, 10, .12));
}

:root .ld-text {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.6;
}

:root .ld-ring {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: 3px solid var(--mo-gold-soft, #d9bd84);
    border-top-color: var(--mo-green, #00522a);
    border-radius: 50%;
    animation: ld-spin .8s linear infinite;
}


/* --------------------------------------------------------------------------
   3. The button that started the request
   -------------------------------------------------------------------------- */

:root .ld-busy {
    pointer-events: none !important;
    opacity: .85;
}

/* the spinner takes the place of the button's own icon */
:root .ld-busy > i:first-child {
    display: none;
}

:root .ld-busy::before {
    content: "";
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-left: .45em;
    vertical-align: -.15em;
    border: 2px solid currentColor;
    border-left-color: transparent;
    border-radius: 50%;
    animation: ld-spin .7s linear infinite;
}


/* responsive.css stops every animation for reduced motion; a spinner is the
   only sign that something is happening, so it keeps turning, slowly */
@media (prefers-reduced-motion: reduce) {
    :root .ld-ring,
    :root .ld-busy::before {
        animation-duration: 1.6s !important;
        animation-iteration-count: infinite !important;
    }
}
