/*
 * Loading + busy states, site-wide.
 *
 * Three surfaces, because there are three genuinely different waits:
 *
 *   .hh-progress   a full-page navigation. The browser gives a tab spinner the
 *                  customer is not looking at, so we draw our own line.
 *   .hh-overlay    a blocking in-page wait (catalog filtering is ~4s). Covers
 *                  the viewport, locks scroll, and says what it is doing.
 *   .is-hh-busy    a single control that has been pressed and is working.
 *
 * Everything is anchored to the VIEWPORT, never to a container. The overlay
 * this replaces was position:absolute inside a static ancestor, so its
 * containing block was the initial one -- a viewport-sized box pinned to the
 * top of the document. On a 2,257px-tall grid it rendered ~1,000px above where
 * the customer was looking. It worked perfectly and nobody ever saw it.
 */

:root {
    --hh-load-ink: #111111;
    --hh-load-accent: #FEDD00;
    --hh-load-surface: #ffffff;
    --hh-load-track: rgba(17, 17, 17, 0.10);
    --hh-load-veil: rgba(17, 17, 17, 0.46);
    --hh-load-z: 2147483000;   /* above the nav drawer (10000) and side cart */
}

/* ===== 1. Navigation progress line ===== */

.hh-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: var(--hh-load-z);
    pointer-events: none;
    opacity: 0;
    transition: opacity 180ms ease 120ms;   /* fades out AFTER the bar completes */
}

.hh-progress.is-active {
    opacity: 1;
    transition-delay: 0s;
}

.hh-progress__bar {
    height: 100%;
    width: 0;
    background: var(--hh-load-accent);
    /* The trailing glow is what stops this reading as a default library bar. */
    box-shadow: 0 0 8px rgba(254, 221, 0, 0.9), 0 0 2px rgba(254, 221, 0, 1);
    transform-origin: 0 50%;
    transition: width 240ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ===== 2. Blocking overlay ===== */

.hh-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--hh-load-z);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--hh-load-veil);
    -webkit-backdrop-filter: saturate(140%) blur(2px);
    backdrop-filter: saturate(140%) blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 160ms ease, visibility 0s linear 160ms;
}

.hh-overlay.is-active {
    opacity: 1;
    visibility: visible;
    transition: opacity 160ms ease, visibility 0s;
}

.hh-overlay__card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 26px;
    background: var(--hh-load-surface);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.12);
    /* Rises very slightly as it lands. Any more than this reads as a toy. */
    transform: translateY(6px) scale(0.985);
    transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
    max-width: min(88vw, 420px);
}

.hh-overlay.is-active .hh-overlay__card {
    transform: none;
}

.hh-overlay__spinner {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border: 3px solid var(--hh-load-track);
    border-top-color: var(--hh-load-accent);
    border-radius: 50%;
    animation: hh-load-spin 720ms linear infinite;
}

.hh-overlay__msg {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.35;
    color: var(--hh-load-ink);
    letter-spacing: 0.01em;
}

.hh-overlay__sub {
    display: block;
    margin-top: 3px;
    font-weight: 400;
    font-size: 13px;
    color: rgba(17, 17, 17, 0.58);
}

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

/* ===== 3. Scroll lock ===== */

/* padding-right is set inline by the JS to the measured scrollbar width, so
   locking does not shift the page sideways. */
body.hh-scroll-locked {
    overflow: hidden !important;
    touch-action: none;
}

/* ===== 4. Busy control ===== */

.is-hh-busy {
    position: relative;
    pointer-events: none;   /* the double-submit guard that CSS can enforce */
    cursor: progress;
}

.is-hh-busy > .hh-busy-label {
    visibility: hidden;
}

.is-hh-busy::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 17px;
    height: 17px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(17, 17, 17, 0.25);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: hh-load-spin 640ms linear infinite;
}

/* A dark control needs a light spinner track. */
.is-hh-busy.hh-btn-dark::after,
.is-hh-busy[class*="--dark"]::after {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
}

/* ===== 5. Region busy (a grid being replaced) ===== */

[aria-busy="true"].hh-busy-region {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity 140ms ease;
}

/* ===== Reduced motion =====
   Not one of the site's existing spinners honoured this. Rotation is replaced
   with a pulse; the bar still reports progress but stops sliding. */
@media (prefers-reduced-motion: reduce) {
    .hh-overlay__spinner,
    .is-hh-busy::after {
        animation: hh-load-pulse 1.1s ease-in-out infinite;
    }
    .hh-progress__bar,
    .hh-overlay,
    .hh-overlay__card {
        transition-duration: 1ms;
    }
    @keyframes hh-load-pulse {
        0%, 100% { opacity: 1; }
        50%      { opacity: 0.35; }
    }
}
