/*
 * MBI water loader (DLRPTL-8364).
 * Re-skins every existing loader hook (custom .loader/.contained-loader, Bootstrap .spinner-border
 * and Kendo's loading mask) so pages keep their current show/hide logic and markup.
 * Loaded after the theme/Kendo stylesheets in _Layout so these rules win at equal specificity.
 *
 * Each loader draws two layers of the MBI mark: ::before is the faint outline, ::after is the full-colour mark
 * revealed by a rising, drifting waterline (mask). The animation lives on the element rather than inside the
 * SVG because every copy of an SVG image shares one clock; on the element, each loader starts empty when shown.
 */

.loader,
.contained-loader,
.spinner-border:not(.btn .spinner-border),
.mbi-loading-card__icon {
    position: relative;
}

.loader::before,
.loader::after,
.contained-loader::before,
.contained-loader::after,
.spinner-border:not(.btn .spinner-border)::before,
.spinner-border:not(.btn .spinner-border)::after,
.mbi-loading-card__icon::before,
.mbi-loading-card__icon::after,
.k-loading-mask .k-loading-image::before,
.k-loading-mask .k-loading-image::after {
    content: "";
    position: absolute;
    inset: 0;
    background: url("../img/loaders/mbi-mark.svg") center / contain no-repeat;
}

.loader::before,
.contained-loader::before,
.spinner-border:not(.btn .spinner-border)::before,
.mbi-loading-card__icon::before,
.k-loading-mask .k-loading-image::before {
    opacity: .14;
}

.loader::after,
.contained-loader::after,
.spinner-border:not(.btn .spinner-border)::after,
.mbi-loading-card__icon::after,
.k-loading-mask .k-loading-image::after {
    -webkit-mask: url("../img/loaders/mbi-water-mask.svg") 0 -100% / 200% 200% repeat-x;
    mask: url("../img/loaders/mbi-water-mask.svg") 0 -100% / 200% 200% repeat-x;
    animation: mbi-water-fill var(--mbi-fill-duration) linear infinite;
}

/*
 * Fill cycle: the original MBI water rise (cubic-bezier(.4, 0, .2, 1), sampled) at its original pace, starting with
 * water already in the mark's tip, then a 0.1s hold and 0.15s fade back to the outline before the next fill.
 * x drifts the wave the whole time. The mask is twice the loader's height, so y 35% clears the wave above it.
 * --mbi-fill-duration is one full cycle; the rise keeps its original pace only at 2.95s. The idle time between
 * fills is the last two keyframes (hold, then fade).
 */
:root {
    --mbi-fill-duration: 2.95s;
}

@keyframes mbi-water-fill {
    0% { -webkit-mask-position: 0% -66.2%; mask-position: 0% -66.2%; opacity: 1; }
    6.1% { -webkit-mask-position: 3.6% -50.4%; mask-position: 3.6% -50.4%; }
    18.3% { -webkit-mask-position: 10.8% -17.2%; mask-position: 10.8% -17.2%; }
    30.5% { -webkit-mask-position: 18% 4.7%; mask-position: 18% 4.7%; }
    42.7% { -webkit-mask-position: 25.2% 18.3%; mask-position: 25.2% 18.3%; }
    54.9% { -webkit-mask-position: 32.4% 26.7%; mask-position: 32.4% 26.7%; }
    67.1% { -webkit-mask-position: 39.6% 31.7%; mask-position: 39.6% 31.7%; }
    79.3% { -webkit-mask-position: 46.8% 34.2%; mask-position: 46.8% 34.2%; }
    91.5% { -webkit-mask-position: 54% 35%; mask-position: 54% 35%; }
    94.9% { -webkit-mask-position: 56% 35%; mask-position: 56% 35%; opacity: 1; }
    100% { -webkit-mask-position: 59% 35%; mask-position: 59% 35%; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {

    .loader::before,
    .contained-loader::before,
    .spinner-border:not(.btn .spinner-border)::before,
    .mbi-loading-card__icon::before,
    .k-loading-mask .k-loading-image::before {
        display: none;
    }

    .loader::after,
    .contained-loader::after,
    .spinner-border:not(.btn .spinner-border)::after,
    .mbi-loading-card__icon::after,
    .k-loading-mask .k-loading-image::after {
        -webkit-mask: none;
        mask: none;
        animation: none;
    }
}

/* Custom page/section loaders */
.loader,
.contained-loader {
    display: inline-block;
    width: 80px;
    height: 70px;
}

/* Bootstrap spinners: keep their size/display so existing inline placement and jQuery show/hide still work */
.spinner-border:not(.btn .spinner-border) {
    width: 2.3rem;
    height: 2rem;
    border: 0;
    border-radius: 0;
    animation: none;
}

.spinner-border-sm:not(.btn .spinner-border) {
    width: 1.15rem;
    height: 1rem;
}

/* Kendo grid / kendo.ui.progress loading mask: replace Kendo's ring (drawn on the same pseudo-elements) */
.k-loading-mask .k-loading-image::before,
.k-loading-mask .k-loading-image::after {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    width: 80px;
    height: 70px;
    margin: -35px 0 0 -40px;
    border: 0;
    border-radius: 0;
    font-size: inherit;
    box-sizing: border-box;
}

.k-loading-mask .k-loading-image::before {
    animation: none;
}

/* Kendo's default 30% wash is too light for the pale water mark to read over grid rows */
.k-loading-mask .k-loading-color {
    opacity: .7;
}

/* Loading card (js/mbi-loader.js): rotates through everything queued */
.mbi-loading-card {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 20000;
    /* above Bootstrap modals and Kendo windows */
    display: flex;
    justify-content: center;
    min-width: 220px;
    max-width: calc(100vw - 48px);
    padding: 16px 24px 14px;
    border-top: 5px solid #0075b5;
    border-radius: 8px;
    text-align: center;
    background: #fff;
    box-shadow: 0 8px 28px rgba(23, 59, 101, .2);
    color: #173b65;
    font-size: 1rem;
    font-weight: 600;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s;
}

.mbi-loading-card.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition-delay: 0s;
}


.mbi-loading-card__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

/* Rotating between queued items: only the wording moves; the old label slides up and out, the new one up from below */
.mbi-loading-card__text.is-leaving {
    opacity: 0;
    transform: translateY(-10px);
    transition-timing-function: ease-in;
}

.mbi-loading-card__text.is-entering {
    opacity: 0;
    transform: translateY(10px);
    transition: none;
}

.mbi-loading-card__icon {
    flex: none;
    width: 64px;
    height: 56px;
}




.mbi-loading-card__text {
    max-width: 340px;
    transition: opacity var(--mbi-swap-ms, 200ms) ease-out, transform var(--mbi-swap-ms, 200ms) ease-out;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mbi-loading-card__announcer {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {

    .mbi-loading-card,
    .mbi-loading-card__text.is-leaving,
    .mbi-loading-card__text.is-entering {
        transform: none;
    }

    .mbi-loading-card {
        transition: opacity .25s ease, visibility 0s linear .25s;
    }
}
