/* ==========================================================================
   UI STATES — holding placeholders, pending buttons, error blocks.
   --------------------------------------------------------------------------
   Three states every section needs, drawn in one place:
     .sts-skeleton*  the holding placeholder shown while data loads
     .sts-spinner    the inline spinner on a button that is working
     .sts-error*     a readable failure with a Retry button

   The palette is NOT redefined here. Every colour comes from the tokens
   unified-theme.css already publishes:
     --ds-navy / --ds-navy-soft / --ds-ink / --ds-ink-muted / --ds-line
     --ds-r-lg / --ds-r-md / --ds-bw / --ds-sh-1..4 (hard offset shadows)
     --bg-primary / --bg-secondary / --bg-tertiary
     --text-primary / --text-secondary / --text-muted
     --accent / --danger / --glass-border
   There is deliberately no hex literal in this file: a palette change must
   happen in the design system, never here.

   Theme rule that this file obeys: a FIXED surface takes FIXED ink. The
   error block sits on a fixed paper surface, so its text uses the fixed
   --ds-ink tokens and never --text-*, which flip with the theme and can
   land near-white on a light surface while the body has no theme class.
   The placeholders have no surface of their own — they take the surface of
   the section they stand in, so they follow --bg-* like the section does.

   Companion script: modules/ui-states.js
   ========================================================================== */

/* --- Holding placeholders ------------------------------------------------ */

.sts-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.sts-skeleton-lines {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.sts-skeleton-line {
  display: block;
  height: 14px;
  border-radius: 999px;
  background-color: var(--bg-tertiary);
  background-image: linear-gradient(90deg, transparent, var(--bg-secondary), transparent);
  background-size: 220% 100%;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px var(--glass-border);
  animation: stsShimmer 1.5s ease-in-out infinite;
}

.sts-skeleton-line-short {
  width: 60%;
}

.sts-skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 22px;
  width: 100%;
}

.sts-skeleton-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.sts-skeleton-block {
  display: block;
  border-radius: var(--ds-r-md);
  background-color: var(--bg-tertiary);
  background-image: linear-gradient(90deg, transparent, var(--bg-secondary), transparent);
  background-size: 220% 100%;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px var(--glass-border);
  animation: stsShimmer 1.5s ease-in-out infinite;
}

.sts-skeleton-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
}

.sts-skeleton-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 18px;
  width: 100%;
}

.sts-skeleton-stat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.sts-skeleton-stat-value {
  height: 28px;
  width: 70%;
}

.sts-skeleton-stat-label {
  height: 12px;
  width: 50%;
}

/* The storefront landing is a fixed light surface (the sticker layer), so its
   placeholders are fixed light too instead of following a theme that may not
   be applied to the body yet. */
#view-landing .sts-skeleton-line,
#view-landing .sts-skeleton-block {
  background-color: var(--ds-line);
  background-image: linear-gradient(90deg, transparent, var(--ds-navy-soft), transparent);
}

/* --- Pending button ------------------------------------------------------ */

.sts-spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: stsSpin 0.75s linear infinite;
}

.sts-spinner-sm {
  width: 12px;
  height: 12px;
  border-width: 2px;
}

.sts-btn-pending,
.sts-btn-pending:disabled {
  cursor: progress;
  opacity: 0.82;
}

.sts-btn-label {
  display: inline-block;
}

/* --- Error state --------------------------------------------------------- */
/* Fixed paper surface, fixed ink: readable whatever the body theme is. */

.sts-error {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 20px;
  border: var(--ds-bw, 2.5px) solid var(--ds-navy);
  border-radius: var(--ds-r-lg);
  background: var(--ds-navy-soft);
  color: var(--ds-ink);
  box-shadow: var(--ds-sh-2);
}

.sts-error-icon {
  flex: none;
  font-size: 26px;
  color: var(--danger);
}

.sts-error-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.sts-error-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ds-ink);
}

.sts-error-message {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ds-ink);
  overflow-wrap: anywhere;
}

.sts-error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

/* The retry button keeps the house .btn shape but takes the fixed colours,
   so it stays readable on the fixed error surface. */
.sts-error .sts-error-retry {
  align-self: flex-start;
  background: var(--ds-navy);
  color: var(--ds-navy-soft);
  border: var(--ds-bw, 2.5px) solid var(--ds-navy);
  border-radius: var(--ds-r-md);
}

.sts-error .sts-error-retry:hover {
  background: var(--ds-navy-soft);
  color: var(--ds-navy);
}

/* --- Motion -------------------------------------------------------------- */

@keyframes stsShimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

@keyframes stsSpin {
  to { transform: rotate(360deg); }
}

/* The visitor asked for calm animations: hold the placeholders still and
   stop the spinner. The JS class covers the same ground for a runtime
   change of the preference. */
@media (prefers-reduced-motion: reduce) {
  .sts-skeleton-line,
  .sts-skeleton-block,
  .sts-spinner {
    animation: none !important;
  }
  .sts-spinner {
    opacity: 0.55;
  }
}

.sts-reduced .sts-skeleton-line,
.sts-reduced .sts-skeleton-block,
.sts-reduced .sts-spinner {
  animation: none;
}
