/* =============================================================
   ReimburseOS v2 — Loading State Module
   loading-state.css

   Tokens: pulls from reimburseos-design.css when available.
   Literal fallbacks ensure portability if :root tokens not loaded.

   Sections:
     1. Progress bar (top-of-viewport, indeterminate)
     2. Skeleton shimmer
     3. Inline spinner
     4. Error / retry state
     5. Reduced-motion overrides
   ============================================================= */

/* ------------------------------------------------------------
   1. TOP PROGRESS BAR
   ------------------------------------------------------------ */

#rb-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 99999;
  pointer-events: none;
  overflow: hidden;
  /* hidden by default; JS adds .rb-bar--active */
  opacity: 0;
  transition: opacity 0.15s ease;
}

#rb-progress-bar.rb-bar--active {
  opacity: 1;
}

#rb-progress-bar.rb-bar--done {
  opacity: 0;
  transition: opacity 0.4s ease 0.2s;
}

#rb-progress-bar__track {
  position: absolute;
  inset: 0;
  background: var(--cc-accent, #00D4FF);
  transform-origin: left center;
  /* Indeterminate: slide right across 200% width, repeat */
  animation: rb-indeterminate 1.6s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
  will-change: transform;
}

@keyframes rb-indeterminate {
  0%   { transform: translateX(-100%) scaleX(0.4); }
  50%  { transform: translateX(40%)  scaleX(0.7); }
  100% { transform: translateX(120%) scaleX(0.4); }
}

/* When "done", freeze the track at full width — transition in JS by removing active class */
#rb-progress-bar.rb-bar--done #rb-progress-bar__track {
  animation: none;
  transform: translateX(0) scaleX(1);
  transition: transform 0.25s var(--cc-ease-expo, cubic-bezier(0.22, 1, 0.36, 1));
}

/* Glow beneath the bar for premium feel */
#rb-progress-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--cc-accent, #00D4FF);
  opacity: 0.35;
  filter: blur(4px);
  pointer-events: none;
}


/* ------------------------------------------------------------
   2. SKELETON SHIMMER
   ------------------------------------------------------------ */

/*
  Usage: add .rb-skeleton to a container to auto-shimmer its
  direct .rb-skel children, OR use the utility classes below
  directly on placeholder elements.
*/

.rb-skel,
.rb-skeleton .rb-skel-auto {
  background: linear-gradient(
    90deg,
    var(--cc-bg-card, #141417) 25%,
    rgba(255, 255, 255, 0.06) 50%,
    var(--cc-bg-card, #141417) 75%
  );
  background-size: 400% 100%;
  animation: rb-shimmer 1.5s ease infinite;
  border-radius: 6px;
  will-change: background-position;
}

@keyframes rb-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* Preset skeleton shapes */
.rb-skel-text {
  display: block;
  height: 14px;
  border-radius: 4px;
  width: 100%;
  max-width: 320px;
  margin-bottom: 10px;
}

.rb-skel-text--sm {
  height: 11px;
  max-width: 200px;
}

.rb-skel-text--lg {
  height: 20px;
  max-width: 480px;
}

.rb-skel-heading {
  display: block;
  height: 28px;
  border-radius: 5px;
  width: 60%;
  margin-bottom: 14px;
}

.rb-skel-pill {
  display: inline-block;
  height: 24px;
  width: 72px;
  border-radius: 100px;
}

.rb-skel-box {
  display: block;
  height: 80px;
  border-radius: 10px;
  width: 100%;
}

.rb-skel-card {
  display: block;
  height: 120px;
  border-radius: 12px;
  width: 100%;
  margin-bottom: 12px;
}

.rb-skel-avatar {
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Container: shows a generic skeleton placeholder until cleared */
.rb-skeleton {
  position: relative;
}

.rb-skeleton > .rb-skel-auto {
  display: block;
}

/* aria-busy visual cue on the container itself */
[aria-busy="true"] {
  cursor: wait;
}


/* ------------------------------------------------------------
   3. INLINE SPINNER
   ------------------------------------------------------------ */

.rb-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--cc-border, rgba(255, 255, 255, 0.12));
  border-top-color: var(--cc-accent, #00D4FF);
  border-radius: 50%;
  animation: rb-spin 0.7s linear infinite;
  vertical-align: middle;
  flex-shrink: 0;
  will-change: transform;
}

.rb-spinner--sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.rb-spinner--lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

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

/* Centered spinner wrapper for full-section loading */
.rb-spinner-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--cc-fg-muted, #8f8f8f);
  font-family: var(--cc-font-body, "IBM Plex Sans", -apple-system, sans-serif);
  font-size: var(--cc-text-sm, 0.875rem);
}


/* ------------------------------------------------------------
   4. ERROR / RETRY STATE
   ------------------------------------------------------------ */

.rb-error-state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(220, 47, 61, 0.08);
  border: 1px solid rgba(220, 47, 61, 0.28);
  border-radius: 10px;
  font-family: var(--cc-font-body, "IBM Plex Sans", -apple-system, sans-serif);
  font-size: var(--cc-text-sm, 0.875rem);
  color: var(--cc-fg, #d9d9d9);
}

.rb-error-state__icon {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  /* Unicode warning sign — no emoji dependency */
  color: #DC2F3D;
}

.rb-error-state__message {
  flex: 1;
  min-width: 0;
}

.rb-error-state__label {
  font-weight: 600;
  color: #DC2F3D;
  margin-bottom: 2px;
}

.rb-error-state__detail {
  color: var(--cc-fg-muted, #8f8f8f);
  font-size: var(--cc-text-xs, 0.8125rem);
  margin: 0;
}

.rb-retry-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  border: 1px solid var(--cc-accent, #00D4FF);
  border-radius: 6px;
  background: transparent;
  color: var(--cc-accent, #00D4FF);
  font-family: var(--cc-font-body, "IBM Plex Sans", -apple-system, sans-serif);
  font-size: var(--cc-text-sm, 0.875rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.rb-retry-btn:hover,
.rb-retry-btn:focus-visible {
  background: var(--cc-accent, #00D4FF);
  color: var(--cc-accent-ink, #04121a);
  outline: none;
}

.rb-retry-btn:focus-visible {
  box-shadow: 0 0 0 3px var(--cc-accent-glow, rgba(0, 212, 255, 0.16));
}

/* Compact inline error (no icon, fits in tight spaces) */
.rb-error-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #DC2F3D;
  font-family: var(--cc-font-body, "IBM Plex Sans", -apple-system, sans-serif);
  font-size: var(--cc-text-sm, 0.875rem);
}


/* ------------------------------------------------------------
   5. REDUCED-MOTION OVERRIDES
   ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  #rb-progress-bar__track {
    animation: none;
    /* Stationary full-width bar as fallback indicator */
    transform: none;
    width: 60%;
    opacity: 0.7;
  }

  .rb-skel,
  .rb-skeleton .rb-skel-auto {
    animation: none;
    background: var(--cc-bg-card, #141417);
    opacity: 0.7;
  }

  .rb-spinner {
    animation: rb-spin 1.4s linear infinite;
  }

  #rb-progress-bar,
  #rb-progress-bar.rb-bar--active,
  #rb-progress-bar.rb-bar--done {
    transition: none;
  }

  .rb-retry-btn {
    transition: none;
  }
}
