/* =============================================================================
   The app's loading spinner.

   A faint full ring with a tapered arc sweeping round it - solid at the
   leading edge, fading out behind, like a comet. Taken from the reference
   recording rather than invented.

   Built from a conic gradient punched into a ring by a radial mask, so there
   is no SVG and no baked-in colour: the arc is --color-primary and the track
   is --border-color, which means it follows the theme, including any dark
   mode those tokens describe.

   Usage:
       <div class="app-spinner" role="status">
           <span class="app-spinner-label">Loading…</span>
       </div>

   Size and weight are per-instance, so a button spinner and a page spinner
   share one definition:
       <div class="app-spinner app-spinner-sm"></div>
       <div class="app-spinner" style="--spinner-size: 64px"></div>
   ============================================================================= */

.app-spinner,
.loading {
    --spinner-size: 88px;
    --spinner-thickness: 7px;
    --spinner-speed: .9s;

    position: relative;
    width: var(--spinner-size);
    height: var(--spinner-size);
    border-radius: 50%;
    /* Never let a flex parent squash it into an oval. */
    flex: none;
}

    /* The track the arc runs on. */
    .app-spinner::before,
    .loading::before {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 50%;
        border: var(--spinner-thickness) solid var(--border-color, #e5e7eb);
        opacity: .55;
    }

    /* The comet. The conic gradient does the fade; the radial mask keeps only
       the outer ring of it, so the gradient reads as a tapering stroke rather
       than a filled pie. The small transparent run at the start is the gap
       between the head and the tail. */
    .app-spinner::after,
    .loading::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 50%;
        background: conic-gradient(from 0turn,
            rgba(0, 0, 0, 0) 0turn,
            rgba(0, 0, 0, 0) .08turn,
            var(--color-primary, #2563eb) .95turn,
            var(--color-primary, #2563eb) 1turn);
        -webkit-mask: radial-gradient(farthest-side,
            rgba(0, 0, 0, 0) calc(100% - var(--spinner-thickness)),
            #000 calc(100% - var(--spinner-thickness)));
        mask: radial-gradient(farthest-side,
            rgba(0, 0, 0, 0) calc(100% - var(--spinner-thickness)),
            #000 calc(100% - var(--spinner-thickness)));
        animation: app-spinner-rotate var(--spinner-speed) linear infinite;
    }

@keyframes app-spinner-rotate {
    to {
        transform: rotate(1turn);
    }
}

/* ---- Bootstrap's spinner, restyled in place ----
   Ten call sites across the app use .spinner-border, mostly inside buttons.
   Rather than rewrite that markup, the same comet is painted here. This
   layer loads after bootstrap.min.css, so it wins on equal specificity.

   currentColor, not --color-primary: these inherit their colour from the
   button or the .text-* class they sit in, and that has to keep working. */
.spinner-border,
.synx-modal-loading::before,
:is(.modal, [role="dialog"], .fg-modal-backdrop) .lm-org-loading:has(> .spinner-border)::before {
    --spinner-thickness: .25em;

    border: 0;
    background: conic-gradient(from 0turn,
        rgba(0, 0, 0, 0) 0turn,
        rgba(0, 0, 0, 0) .08turn,
        currentColor .95turn,
        currentColor 1turn);
    -webkit-mask: radial-gradient(farthest-side,
        rgba(0, 0, 0, 0) calc(100% - var(--spinner-thickness)),
        #000 calc(100% - var(--spinner-thickness)));
    mask: radial-gradient(farthest-side,
        rgba(0, 0, 0, 0) calc(100% - var(--spinner-thickness)),
        #000 calc(100% - var(--spinner-thickness)));
    animation: app-spinner-rotate .9s linear infinite;
}

.spinner-border-sm {
    --spinner-thickness: .2em;
}

/* ---- Sizes ----
   The default is the page-level spinner. Inline uses stay small on purpose:
   .app-spinner-sm sits in a button or beside a line of text, and doubling it
   would break those. */
.app-spinner-sm {
    --spinner-size: 20px;
    --spinner-thickness: 2.5px;
}

.app-spinner-lg {
    --spinner-size: 128px;
    --spinner-thickness: 9px;
}

/* ---- Centring helper, for a spinner standing in for a whole panel ---- */
.app-spinner-center {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 220px;
}

/* Panel loading stays local to the content being fetched; no page overlay. */
.app-loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    min-height: 220px;
    width: 100%;
    padding: 24px 16px;
    color: var(--theme-primary-text, #65748a);
    text-align: center;
    font-size: 13px;
}

.app-loading-state > p { margin: 0; }

.app-tab-error {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--theme-primary-border, #dce7fc);
    border-radius: 12px;
    background: var(--theme-surface, #fff);
    color: var(--theme-primary-text, #65748a);
}

.app-loading-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    color: var(--theme-primary-text, #65748a);
    font-size: 13px;
}

.synx-modal-loading::before,
:is(.modal, [role="dialog"], .fg-modal-backdrop) .lm-org-loading:has(> .spinner-border)::before {
    color: var(--color-primary, #2563eb);
}

/* ---- The label ----
   Kept in the markup for assistive tech and kept out of sight, so a spinner
   announces itself without putting a word on screen. */
.app-spinner-label,
.loading span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* Still turns, slowly, rather than strobing. */
@media (prefers-reduced-motion: reduce) {
    .app-spinner::after,
    .loading::after,
    .spinner-border,
    .synx-modal-loading::before,
    :is(.modal, [role="dialog"], .fg-modal-backdrop) .lm-org-loading:has(> .spinner-border)::before {
        animation-duration: 2.4s;
    }
}
