/*
 * The app's one loading indicator (the pulsing logo with the sliding bar, built by showBPBytesLoadingOverlay() in
 * js/loadingOverlay.js). Its own file so the main app (tpls/_head.tpl) and the Select popups (js/style.js) share it.
 */
@keyframes bpbytes-spin {
    to {
        transform: rotate(360deg);
    }
}

/*
 * Shared loading overlay — a plain JS-created/removed div (no YUI Panel involved), so it needs
 * none of #ajaxloading's positioning workarounds above; centering with fixed + flex is enough.
 * Reuses the same conic-gradient spinner and card/backdrop treatment as #ajaxloading/#loadingPage
 * so every loading state in the app looks like one system rather than a one-off per feature.
 * Currently used by the "PDF Report" download flow (custom/include/SugarFields/Fields/Pdf/
 * pdf_template_popup.js) — swap the message text, not the look, for other loading states.
 */
.bpbytes-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.82);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: calc(var(--bp-z-dropdown) + 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Cover the page area only, so the sidebar and top bar stay visible (as on the mobile app,
   where the header stays visible under the loader) */
body:has(.bpbytes-sidebar) .bpbytes-loading-overlay {
    top: var(--bp-topbar-height);
    left: var(--bp-sidebar-width);
}

body.bpbytes-sidebar-collapsed .bpbytes-loading-overlay {
    left: var(--bp-sidebar-collapsed-width);
}

@media (max-width: 991px) {
    body:has(.bpbytes-sidebar) .bpbytes-loading-overlay {
        left: var(--bp-sidebar-collapsed-width);
    }
}

.bpbytes-loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 26px;
    font-family: var(--bp-font);
}

/* The logo mark, drawn from the white "bP" PNG used as a mask so it can carry the brand gradient */
.bpbytes-loading-mark,
#loadingPage::before {
    position: relative;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #02c5f3 0%, #3693d9 50%, #5547b5 100%);
    -webkit-mask: url("../images/company_logo_sort.png") center / contain no-repeat;
    mask: url("../images/company_logo_sort.png") center / contain no-repeat;
    animation: bpbytes-pulse 1.4s ease-out infinite;
}

/* The soft ring that spreads out from behind the mark */
.bpbytes-loading-ring {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(85, 71, 181, 0.35);
    animation: bpbytes-ring 1.4s ease-out infinite;
}

.bpbytes-loading-logo {
    position: relative;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The sliding bar: a short pill moving along a track */
#loadingPage::after {
    content: "";
    display: block;
    width: 96px;
    height: 4px;
    border-radius: 2px;
    background-color: rgba(85, 71, 181, 0.2);
    background-image: linear-gradient(var(--bp-primary), var(--bp-primary));
    background-repeat: no-repeat;
    background-size: 56px 100%;
    background-position: -56px 0;
    animation: bpbytes-slide 1.1s ease-in-out infinite;
}

/* The overlay's bar slides with a transform, so it keeps moving while the page is busy (background-position froze) */
.bpbytes-loading-bar {
    position: relative;
    display: block;
    width: 96px;
    height: 4px;
    border-radius: 2px;
    overflow: hidden;
    background-color: rgba(85, 71, 181, 0.2);
}

.bpbytes-loading-bar::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 56px;
    height: 100%;
    border-radius: 2px;
    background: var(--bp-primary);
    will-change: transform;
    animation: bpbytes-slide-x 1.1s ease-in-out infinite;
}

/* ---- Ring variant: ring spinner in a white card over a dimmed page ---- */
.bpbytes-loading-overlay--ring {
    background: rgba(30, 27, 75, 0.45);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

body:has(.bpbytes-sidebar) .bpbytes-loading-overlay--ring,
body.bpbytes-sidebar-collapsed .bpbytes-loading-overlay--ring {
    top: 0;
    left: 0;
}

@media (max-width: 991px) {
    body:has(.bpbytes-sidebar) .bpbytes-loading-overlay--ring {
        left: 0;
    }
}

.bpbytes-loading-overlay--ring .bpbytes-loading-card {
    gap: 14px;
    width: 172px;
    height: 148px;
    padding: 16px;
    box-sizing: border-box;
    background: var(--bp-surface);
    border-radius: var(--bp-radius-lg);
    box-shadow: var(--bp-shadow-lg);
}

.bpbytes-loading-spinner {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0deg, var(--bp-accent) 110deg, var(--bp-primary) 340deg, transparent 360deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 5px));
    animation: bpbytes-spin 0.85s linear infinite;
}

.bpbytes-loading-overlay--ring .bpbytes-loading-message {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--bp-text-muted);
}

/* Small inline version of the same ring, for a loading state sitting next to a button or in a line of text
   (e.g. "Add Note" in the Activities and Notes panel) - replaces the old img_loading.gif. */
.bpbytes-inline-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    vertical-align: middle;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0deg, var(--bp-accent) 110deg, var(--bp-primary) 340deg, transparent 360deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
    animation: bpbytes-spin 0.85s linear infinite;
}

.bpbytes-loading-message {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@keyframes bpbytes-pulse {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes bpbytes-ring {
    0%   { transform: scale(1); opacity: 0.35; }
    100% { transform: scale(2.1); opacity: 0; }
}

@keyframes bpbytes-slide-x {
    0%   { transform: translateX(-56px); }
    100% { transform: translateX(96px); }
}

@keyframes bpbytes-slide {
    0%   { background-position: -56px 0; }
    100% { background-position: 96px 0; }
}
