/* ==========================================================================
   QRBELL Store — LOADING SYSTEM
   --------------------------------------------------------------------------
   One place for every loading, skeleton, route-transition, smart-image and
   payment-processing style. Built only on the tokens in variables.css — navy
   (--qb-navy-*), gold (--color-primary / #F4B400), existing radii, shadows and
   motion. Loaded after components.css so it can extend .qb-skel.

   Every animation is disabled or reduced under prefers-reduced-motion (single
   block at the end of this file). Nothing here changes existing components —
   .qb-skel / .qb-empty / .qb-btn.is-loading keep their current rules.
   ========================================================================== */


/* ==========================================================================
   1. SKELETON EXTENSIONS  (base .qb-skel lives in components.css)
   ========================================================================== */

/* Faint gold tint for skeletons sitting on white cards — reads as "QRBELL
   is working" rather than a dead grey block. */
.qb-skel--gold::after {
  background: linear-gradient(
    90deg,
    transparent,
    rgba(244, 180, 0, 0.14),
    transparent
  );
}

.qb-skel--box    { width: 100%; height: 100%; border-radius: var(--radius-sm); }
.qb-skel--pill   { height: 12px; border-radius: var(--radius-pill); }
.qb-skel--chip   { height: 28px; width: 84px; border-radius: var(--radius-pill); }
.qb-skel--circle { border-radius: var(--radius-circle); }
.qb-skel--block  { border-radius: var(--radius-sm); }

/* A row of skeleton text lines. Last line is short, like real copy. */
.qb-skel-lines { display: flex; flex-direction: column; gap: var(--space-2); }
.qb-skel-lines > .qb-skel { height: 10px; border-radius: var(--radius-pill); }
.qb-skel-lines > .qb-skel:last-child { width: 60%; }


/* ==========================================================================
   2. SPINNER — small, functional, gold arc on a navy-tinted track
   ========================================================================== */

.qb-spinner {
  --qb-spinner-size: 18px;
  display: inline-block;
  width: var(--qb-spinner-size);
  height: var(--qb-spinner-size);
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-circle);
  animation: qb-spin 0.7s linear infinite;
  flex: 0 0 auto;
  vertical-align: -0.15em;
}
.qb-spinner--sm { --qb-spinner-size: 14px; border-width: 2px; }
.qb-spinner--lg { --qb-spinner-size: 28px; border-width: 3px; }

/* On a dark surface (payment overlay, boot) the track needs to be light. */
.qb-spinner--invert {
  border-color: rgba(255, 255, 255, 0.25);
  border-top-color: var(--color-primary);
}

/* Reduced-motion fallback: three pulsing dots instead of a spin. */
.qb-spinner-dots {
  display: none;
  align-items: center;
  gap: 4px;
}
.qb-spinner-dots span {
  width: 6px; height: 6px;
  border-radius: var(--radius-circle);
  background: var(--color-primary);
  animation: qb-dot-pulse 1s ease-in-out infinite;
}
.qb-spinner-dots span:nth-child(2) { animation-delay: 0.15s; }
.qb-spinner-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes qb-dot-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}


/* ==========================================================================
   3. INLINE / SECTION LOADING ROW
   ========================================================================== */

.qb-inline-load {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  color: var(--color-text-muted);
  font-size: var(--text-base);
}
.qb-inline-load--center { justify-content: center; text-align: center; }
.qb-inline-load__slow {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-faint);
}


/* ==========================================================================
   4. ROUTE PROGRESS BAR — thin gold bar pinned to the very top
   ========================================================================== */

.qb-routebar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: calc(var(--z-tooltip) + 5);
  background: transparent;
  opacity: 0;
  transition: opacity 180ms var(--ease-out);
  pointer-events: none;
}
.qb-routebar.is-active { opacity: 1; }
.qb-routebar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  background: linear-gradient(90deg, var(--qb-gold-600), var(--color-primary));
  box-shadow: 0 0 8px rgba(244, 180, 0, 0.6);
  animation: qb-routebar-slide 1.1s var(--ease-in-out) infinite;
}
@keyframes qb-routebar-slide {
  0%   { left: -40%; width: 40%; }
  50%  { left: 25%;  width: 55%; }
  100% { left: 100%; width: 40%; }
}


/* ==========================================================================
   5. PAGE LOADER — Suspense fallback / slow-load. Branded, holds layout.
   ========================================================================== */

.qb-pageloader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  min-height: 60vh;
  padding: var(--space-12) var(--space-5);
  text-align: center;
  opacity: 0;
  animation: qb-fade-in 260ms var(--ease-out) 150ms forwards;
}
.qb-pageloader__mark {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}
.qb-pageloader__msg {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
}
.qb-pageloader__bar,
.qb-boot__bar {
  position: relative;
  width: 160px;
  max-width: 60vw;
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  overflow: hidden;
}
.qb-pageloader__bar::after,
.qb-boot__bar > span {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 40%;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  animation: qb-bar-indeterminate 1.2s var(--ease-in-out) infinite;
}
@keyframes qb-bar-indeterminate {
  0%   { left: -40%; }
  100% { left: 100%; }
}
@keyframes qb-fade-in { to { opacity: 1; } }


/* ==========================================================================
   6. BOOT SPLASH — the pre-React paint. Mirror of the inline <style> in
   index.html; this rule is the fade-out hook used by main.tsx.
   ========================================================================== */

#qb-boot.qb-boot {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--qb-navy-900, #07091C);
  color: #F4F4F0;
  transition: opacity 240ms ease, visibility 240ms ease;
}
#qb-boot .qb-boot__mark {
  width: 56px; height: 56px;
  border-radius: 12px;
  object-fit: cover;
}
#qb-boot .qb-boot__word {
  font-family: var(--font-heading, 'Plus Jakarta Sans', sans-serif);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
#qb-boot .qb-boot__word span {
  color: var(--qb-gold-500, #F4B400);
  font-weight: 700;
}
#qb-boot .qb-boot__msg {
  margin: 0;
  font-size: 0.8125rem;
  color: #8890B0;
}
#qb-boot .qb-boot__bar { background: rgba(255, 255, 255, 0.12); }
#qb-boot.qb-boot--out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}


/* ==========================================================================
   7. SMART IMAGE — reserved aspect ratio, shimmer, fade-in, error fallback
   ========================================================================== */

.qb-img {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--color-surface-alt);
  border-radius: inherit;
  aspect-ratio: var(--qb-img-ratio, 1 / 1);
}

/* Wrapper is invisible: the <img> lays out in the parent *__media box (which
   already reserves the aspect ratio); the shimmer + fallback overlay it. */
.qb-img--bare { display: contents; }
.qb-img--bare > .qb-img__skel,
.qb-img--bare > .qb-img__fallback { position: absolute; inset: 0; }

/* Media boxes that host a bare SmartImage need a positioning context so the
   shimmer / fallback overlay lands on the box (not a distant ancestor).
   .qb-pcard__media / .qb-product__media / .home-tile are already relative. */
.cart-item__media,
.co-line__media,
.dash-order__media,
.od-item__media { position: relative; }

/* PDP main gallery frame — fills the aspect-locked .qb-gallery__stage. */
.qb-gallery__figure {
  flex: 0 0 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
}
.qb-gallery__figure .qb-img__el { object-fit: cover; }

/* `img.` specificity so the opacity fade wins over per-context rules that set
   `transition: transform …` on .qb-product__img / .qb-pcard__img — and keep
   their hover-zoom transition by re-declaring it here. */
img.qb-img__el {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 300ms var(--ease-out), transform var(--duration-slow) var(--ease-out);
}
img.qb-img__el.is-loaded { opacity: 1; }

.qb-img__skel {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--color-surface-alt);
}
.qb-img__skel::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: qb-shimmer 1.4s infinite;
}
.qb-img.is-loaded .qb-img__skel,
.qb-img.is-error  .qb-img__skel { display: none; }

.qb-img__fallback {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--color-text-faint);
  background: var(--color-surface-alt);
  font-size: 1.5rem;
}
.qb-img__fallback span {
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}
.qb-img.is-error .qb-img__el { display: none; }
.qb-img.is-error .qb-img__fallback { display: flex; }


/* ==========================================================================
   8. PAGE-CONTENT TRANSITION — fades only the routed content, not the shell
   ========================================================================== */

.qb-page-fade {
  animation: qb-page-in 190ms var(--ease-out);
}
@keyframes qb-page-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ==========================================================================
   9. GRID BUSY — keep results on screen while a refetch runs (filter / sort)
   ========================================================================== */

.qb-grid-busy {
  position: relative;
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 150ms var(--ease-out);
}

.qb-refetch-note {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Cart line: the quantity value slot shows a spinner while that row updates
   ([ − ] [ ⟳ ] [ + ]) — spec §5. Rest of the cart stays interactive. */
span.qb-qty__value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}


/* ==========================================================================
   10. PAYMENT PROCESSING OVERLAY — dedicated, non-dismissible
   ========================================================================== */

.qb-processing {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: rgba(7, 9, 28, 0.72);
  backdrop-filter: blur(2px);
  animation: qb-fade-in 160ms var(--ease-out) forwards;
  opacity: 0;
}
.qb-processing__card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-xl);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.qb-processing__lock {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px; height: 48px;
  border-radius: var(--radius-circle);
  background: var(--color-primary-soft);
  color: var(--color-on-primary);
  font-size: 1.35rem;
}
.qb-processing__title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}
.qb-processing__text {
  margin: 0;
  font-size: var(--text-base);
  color: var(--color-text-muted);
}
.qb-processing__warn {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}
.qb-processing__bar {
  position: relative;
  width: 100%;
  height: 4px;
  margin-top: var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  overflow: hidden;
}
.qb-processing__bar::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 40%;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  animation: qb-bar-indeterminate 1.2s var(--ease-in-out) infinite;
}


/* ==========================================================================
   11. CONTEXTUAL STEP MESSAGE (checkout step transitions)
   ========================================================================== */

.qb-step-note {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}


/* ==========================================================================
   12. SKELETON LAYOUT HELPERS for page-shaped skeletons
   ========================================================================== */

.qb-skel-stack   { display: flex; flex-direction: column; gap: var(--space-3); }
.qb-skel-stack-4 { display: flex; flex-direction: column; gap: var(--space-4); }
.qb-skel-row     { display: flex; align-items: center; gap: var(--space-3); }
.qb-skel-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-5);
}


/* ==========================================================================
   13. REDUCED MOTION — one place. Communicate with layout + text, not motion.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .qb-skel::after,
  .qb-skel--gold::after,
  .qb-img__skel::after {
    animation: none;
  }
  /* Swap the spin for a static dot pulse — never rely on rotation alone. */
  .qb-spinner { display: none; }
  .qb-spinner + .qb-spinner-dots { display: inline-flex; }

  .qb-routebar__fill,
  .qb-pageloader__bar::after,
  .qb-boot__bar > span,
  .qb-processing__bar::after {
    animation: none;
    left: 0;
    width: 100%;
    opacity: 0.9;
  }
  .qb-pageloader { animation: none; opacity: 1; }
  .qb-processing { animation: none; opacity: 1; }
  .qb-page-fade { animation: none; }
  img.qb-img__el { transition: none; opacity: 1; }
  #qb-boot.qb-boot { transition: opacity 1ms linear; }
}
