/* Design system v2 — loader (ring). The ring shape lives ONLY in this file.
   Markup: <span class="sc-loader sc-loader--{xs|sm|md|lg}[ sc-loader--overlay]" role="status" aria-live="polite">
           <span class="sc-loader-ring"></span>[<span class="sc-loader-label">…</span>]</span>
   Blade x-sc.loader, JS siteclickUi.loader(size, label). */

.sc-loader {
    --sc-loader-size: 16px;
    --sc-loader-stroke: 2px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    vertical-align: middle;
    overflow: clip;
    color: var(--sc-color-primary);
}

.sc-loader--xs { --sc-loader-size: 12px; --sc-loader-stroke: 2px; gap: 6px; }
.sc-loader--sm { --sc-loader-size: 16px; --sc-loader-stroke: 2px; }
.sc-loader--md { --sc-loader-size: 24px; --sc-loader-stroke: 2.5px; }
.sc-loader--lg { --sc-loader-size: 36px; --sc-loader-stroke: 3px; }

.sc-loader--overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    justify-content: center;
    background: var(--sc-overlay-white-soft);
}

/* 270° arc: conic gradient in currentColor, hollowed by a radial mask. */
.sc-loader-ring {
    display: block;
    flex: none;
    width: var(--sc-loader-size);
    height: var(--sc-loader-size);
    border-radius: 50%;
    background: conic-gradient(currentColor 0 270deg, transparent 270deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--sc-loader-stroke)), currentColor calc(100% - var(--sc-loader-stroke) + .5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - var(--sc-loader-stroke)), currentColor calc(100% - var(--sc-loader-stroke) + .5px));
    animation: sc-loader-spin 700ms linear infinite;
}

/* Shimmer label, same sweep as .siteclick-thinking-text. */
.sc-loader-label {
    color: transparent;
    background: linear-gradient(
            90deg,
            var(--sc-shine-text) 0%,
            var(--sc-shine-text) 42%,
            var(--sc-shine-text-band) 50%,
            var(--sc-shine-text) 58%,
            var(--sc-shine-text) 100%
    );
    background-size: 300% 100%;
    background-position: 100% center;
    background-clip: text;
    -webkit-background-clip: text;
    animation: sc-loader-shimmer 4.2s linear infinite;
}

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

@keyframes sc-loader-shimmer {
    0% { background-position: 150% center; }
    100% { background-position: -50% center; }
}

@keyframes sc-loader-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

@media (prefers-reduced-motion: reduce) {
    .sc-loader-ring {
        animation: sc-loader-pulse 1.2s ease-in-out infinite;
    }

    .sc-loader-label {
        animation: none;
        color: var(--sc-shine-text);
    }
}

/* A parked loader ([hidden]) stays hidden: .sc-loader sets display. */
.sc-loader[hidden] {
    display: none;
}

/* Busy states drawn as the ring on a pseudo-element (no markup). */
.button[aria-busy="true"]::after,
.siteclick-form-component[aria-busy="true"]::after,
.siteclick-panel-close[aria-busy="true"]::after,
html.sc-busy .sc-bar-logo-mark::after {
    --sc-loader-size: 16px;
    --sc-loader-stroke: 2px;
    display: block;
    width: var(--sc-loader-size);
    height: var(--sc-loader-size);
    aspect-ratio: 1;
    border-radius: 50%;
    color: var(--sc-color-primary);
    background: conic-gradient(currentColor 0 270deg, transparent 270deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--sc-loader-stroke)), currentColor calc(100% - var(--sc-loader-stroke) + .5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - var(--sc-loader-stroke)), currentColor calc(100% - var(--sc-loader-stroke) + .5px));
    animation: sc-loader-spin 700ms linear infinite;
}

/* Busy button (UIX-2): xs ring centred, in the variant's ink. A button inside
   a field is already absolute and its own anchor. */
.button[aria-busy="true"]:not(.siteclick-input-with-button .button) {
    position: relative;
}

.button[aria-busy="true"]::after {
    content: '';
    --sc-loader-size: 12px;
    position: absolute;
    inset: 0;
    margin: auto;
    color: var(--sc-btn-ink);
    pointer-events: none;
}

/* Busy close button (UIX-8): icon hidden, xs ring centred in the button's own box. */
.siteclick-panel-close[aria-busy="true"] {
    display: grid;
    place-items: center;
}

.siteclick-panel-close[aria-busy="true"] > * {
    display: none;
}

.siteclick-panel-close[aria-busy="true"]::after {
    content: '';
    --sc-loader-size: 12px;
    pointer-events: none;
}

/* Busy field (UIX-3): xs ring on the right inside the field. */
.siteclick-form-component[aria-busy="true"] {
    position: relative;
}

.siteclick-form-component[aria-busy="true"]::after {
    content: '';
    --sc-loader-size: 12px;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 10px;
    margin: auto 0;
    pointer-events: none;
}

/* Document busy (r.19): 24 px ring centred on the logo image, the logo dims. */
.sc-bar-logo-mark img {
    transition: opacity var(--sc-dur-base);
}

html.sc-busy .sc-bar-logo-mark img {
    opacity: .25;
}

html.sc-busy .sc-bar-logo-mark::after {
    content: '';
    --sc-loader-size: 24px;
    --sc-loader-stroke: 2px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin: calc(var(--sc-loader-size) / -2);
    color: var(--sc-color-text-strong);
    pointer-events: none;
}

/* Run 38c (EDW-2, P18): one load moment = one loader. The logo ring gives way to a
   visible overlay loader in the viewer or the editor sidebars. Run 38n (EDW-N): also to an
   overlay that is a direct child of the viewer (the site-open loader, the open loader of
   openVisualEditor): the descendant form above never matched those. */
html.sc-busy:has(.siteclick-website-preview :not(.is-ready) > .sc-loader--overlay, .siteclick-website-preview > .sc-loader--overlay, .siteclick-editor-sidebars .siteclick-loader-template) .sc-bar-logo-mark::after {
    content: none;
}

/* Run 39c (EDW-2, O2): a parked (inactive) rest sidebar never shows a ring, even where its strip
   along the dock falls in view. */
.siteclick-sidebar-rest:not(.active) .sc-loader { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
    .button[aria-busy="true"]::after,
    .siteclick-form-component[aria-busy="true"]::after,
    html.sc-busy .sc-bar-logo-mark::after {
        animation: sc-loader-pulse 1.2s ease-in-out infinite;
    }
}
