/*
 * Global preloader: covers the page (or, beside a sidebar, just the content area) until it has
 * loaded, then fades out.
 * Markup and script: resources/views/partials/preloader.blade.php (every layout).
 * Spinner: "loader" from Uiverse.io by JesusRafaelNavaCruz, in the site's teal.
 */

/* Kept before the content-area offsets below, so its "inset: 0" doesn't override them. */
.fg-preloader {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f2f6;
    transition: opacity .6s cubic-bezier(.22, 1, .36, 1), visibility 0s;
}

[data-theme="dark"] .fg-preloader {
    background: #101828;
}

/*
 * Just the content area, from the layouts' own sizes so it's right from the first paint:
 * member (feelgood/global/base.css, partials/topbar.css) and admin (Vanguard's 70px navbar,
 * admin/global/theme.css). Below 992px both sidebars are off screen.
 */
.fg-preloader--member {
    top: var(--fg-topbar-height, 68px);
    left: var(--fg-sidebar-width, 327px);
}

.fg-preloader--admin {
    top: 70px;
    left: var(--fg-admin-sidebar-width, 250px);
}

.sidebar-collapsed .fg-preloader--admin {
    left: 80px;
}

@media (max-width: 991.98px) {
    .fg-preloader--member,
    .fg-preloader--admin,
    .sidebar-collapsed .fg-preloader--admin {
        left: 0;
    }
}

/*
 * While it shows, the sidebar and top bar sit above it, so they stay usable and are never covered,
 * even where the cover overlaps them (the mobile sidebar drawer, a sidebar wider than expected).
 */
.fg-preloader--member:not(.is-hidden) ~ .fg-shell .fg-sidebar,
.fg-preloader--member:not(.is-hidden) ~ .fg-shell .fg-topbar,
.fg-preloader--admin:not(.is-hidden) ~ .navbar,
.fg-preloader--admin:not(.is-hidden) ~ .container-fluid .sidebar {
    z-index: 2001;
}

.fg-preloader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    /* A gentle ease-out fade; it only becomes hidden once the fade is done (and shows again at once). */
    transition: opacity .6s cubic-bezier(.22, 1, .36, 1), visibility 0s linear .6s;
}

/* The ring goes first, so the cover fades out empty rather than with a spinner in it. */
.fg-preloader.is-hidden .fg-loader {
    opacity: 0;
}

.fg-loader {
    --fg-loader-color: #00897b;
    width: 4rem;
    height: 4rem;
    box-sizing: border-box;
    border-radius: 50%;
    border-top: 8px solid var(--fg-loader-color);
    border-left: 8px solid var(--fg-loader-color);
    border-right: 8px solid transparent;
    animation: fg-loader-spin .7s infinite linear;
    transition: opacity .25s ease-out;
}

[data-theme="dark"] .fg-loader {
    --fg-loader-color: #00bba7;
}

@keyframes fg-loader-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .fg-preloader,
    .fg-preloader.is-hidden {
        transition: none;
    }

    .fg-loader {
        animation-duration: 2s;
        transition: none;
    }
}
