/*
    Loading feedback: a bar across the top while a page is on its way, and a spinner in
    whichever button was pressed.

    Both exist for the same reason. On a slow connection the gap between pressing Save and the
    next page arriving is long enough that people press it again, and a second POST of a
    quotation or a payment is not a harmless thing. The spinner says the press registered; the
    guard in loading.js is what actually stops the second one.
*/

/* ---------------------------------------------------------------- the top bar */

.crm-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s ease;
}

.crm-progress.is-on {
    opacity: 1;
}

.crm-progress__bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #0f766e, #2875ef 55%, #f97316);
    box-shadow: 0 0 8px rgba(40, 117, 239, .55);
    transition: width .25s ease;
}

/*
    The bar is driven by JavaScript up to 90% and only completes when the page actually
    changes, so it never claims to have finished something that is still running.
*/

/* ---------------------------------------------------------------- the button */

.crm-busy {
    position: relative;
    pointer-events: none;
    cursor: progress;
}

/*
    Dimmed rather than disabled. A disabled submit button is not serialised with the form, so
    disabling it would drop the button's own name and value from the POST - which is how an
    "Approve" and a "Reject" button that share a form end up indistinguishable.
*/
.crm-busy {
    opacity: .72;
}

.crm-busy__spinner {
    display: inline-block;
    width: .85em;
    height: .85em;
    margin-right: .45em;
    vertical-align: -.1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: crm-spin .6s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .crm-busy__spinner { animation-duration: 2s; }
    .crm-progress__bar { transition: none; }
}

/* ---------------------------------------------------------------- a slow page */

/*
    Shown only when a page has been on its way for a second and a half. Small, at the top, and
    never in the way of what is already on screen.
*/
.crm-slow {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2001;
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .4rem .85rem;
    border-radius: 999px;
    background: #0f172a;
    color: #fff;
    font-size: .8125rem;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .25);
    pointer-events: none;
    animation: crm-slow-in .2s ease-out;
}

@keyframes crm-slow-in {
    from { opacity: 0; transform: translate(-50%, -6px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------- whole-page veil */

/*
    Used only where a form submit does not navigate quickly enough for the bar alone to read
    as progress - long reports and exports opt in with data-loading-veil.
*/
.crm-veil {
    position: fixed;
    inset: 0;
    z-index: 1999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    background: rgba(248, 250, 252, .72);
    backdrop-filter: blur(1.5px);
    font-weight: 600;
    color: #0f172a;
}
