/* ────────────────────────────────────────────────────────────────────
   styles/tokens.css — Young Bull design system supplement
   ────────────────────────────────────────────────────────────────────

   Reference, not replacement. The canonical token set lives in
   claude.css (see :root and html[data-yb-theme="light"] blocks).
   This file ADDS component-level utilities that consume those tokens:

     1. .skel          loading skeleton
     2. .yb-stat-grid  + .yb-stat-card   unified stat-card pattern
     3. .yb-status-dot live-connection status pill polish

   Every value here resolves to a claude.css token. No magic numbers.
   Light-mode inherits via the claude.css override at the parent level.

   Load order: claude.css → sovereign.css → polish.css → tokens.css
   tokens.css must load LAST so it can override page-specific inline
   styles via class precedence.

   Last updated: 2026-05-12 (design pass, Phase 2)
   ──────────────────────────────────────────────────────────────────── */


/* ═══════════════════════════════════════════════════════════════════
   1 · LOADING SKELETON
   Used wherever a stat card waits for an API response. Replaces the
   em-dash placeholder convention. Renders a subtle shimmer that stops
   when the parent picks up data-loaded="1" or the .skel class is
   removed.
   ═══════════════════════════════════════════════════════════════════ */

.skel {
  display: inline-block;
  background: linear-gradient(
    90deg,
    var(--surface-raised) 0%,
    var(--surface-elev) 50%,
    var(--surface-raised) 100%
  );
  background-size: 200% 100%;
  animation: yb-skel-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--radius);
  color: transparent !important;
  user-select: none;
  vertical-align: middle;
}

.skel-num   { width: 5.2em; height: 1em; }
.skel-pct   { width: 4.4em; height: 1em; }
.skel-label { width: 7.0em; height: 0.7em; }
.skel-line  { width: 100%;  height: 0.9em; display: block; margin: 4px 0; }
.skel-card  { width: 100%;  height: 84px;  display: block; border-radius: var(--radius); }

@keyframes yb-skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Respect reduced-motion: render flat surface, no shimmer. */
@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; background: var(--surface-elev); }
}

/* When the parent fills the value, downstream JS removes .skel and
   the element renders normal text. No explicit "done" state required. */


/* ═══════════════════════════════════════════════════════════════════
   2 · UNIFIED STAT-CARD COMPONENT
   The recurring 4-card grid (YTD / Today / Positions / Thesis) used
   on index.html and portfolio.html should use these classes. pro.html
   uses a 2-card variant. audit.html shadow-forecast uses 3.

   Markup contract:
     <div class="yb-stat-grid yb-stat-grid-4">
       <div class="yb-stat-card">
         <div class="yb-stat-label">YTD Return</div>
         <div class="yb-stat-value num gain">+36.30%</div>
         <div class="yb-stat-sub">vs SPY · live</div>
       </div>
       …
     </div>

   Variants: -2 / -3 / -4 control columns on desktop. Mobile collapses
   to 2 columns at 720px and 1 column at 480px regardless of variant.
   ═══════════════════════════════════════════════════════════════════ */

.yb-stat-grid {
  display: grid;
  gap: var(--gap);
  margin: var(--gap-lg) 0 0;
}
.yb-stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
.yb-stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.yb-stat-grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 880px) {
  .yb-stat-grid-3,
  .yb-stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .yb-stat-grid-2,
  .yb-stat-grid-3,
  .yb-stat-grid-4 { grid-template-columns: 1fr; }
}

.yb-stat-card {
  padding: 18px 20px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface-raised);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 110px;
  transition: border-color 160ms var(--ease-fast);
}
.yb-stat-card:hover { border-color: var(--accent-line); }

.yb-stat-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.yb-stat-value {
  font-family: var(--mono);
  font-size: clamp(24px, 2.4vw, 30px);
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.yb-stat-value.gain { color: var(--gain); }
.yb-stat-value.loss { color: var(--loss); }
.yb-stat-value.muted { color: var(--ink-dim); }
.yb-stat-value.serif {
  font-family: var(--serif);
  font-size: clamp(22px, 2vw, 26px);
  letter-spacing: -0.02em;
}

.yb-stat-sub {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-mute);
  letter-spacing: 0.02em;
}
.yb-stat-sub.gain { color: var(--gain); }
.yb-stat-sub.loss { color: var(--loss); }


/* ═══════════════════════════════════════════════════════════════════
   3 · STATUS DOT (live-connection indicator polish)
   live.js renders a "RECONNECTING" pill in the bottom-right corner
   when its Supabase connection is in a reconnect state. The default
   styling persists too aggressively. This block:

   - hides the pill once a successful fetch has resolved
     (script in live.js sets html[data-yb-live="ready"])
   - fades any remaining error indicator after 6s of healthy state
   ═══════════════════════════════════════════════════════════════════ */

.yb-live-status {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 60;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--surface-raised);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0.85;
  transition: opacity 320ms var(--ease);
}
.yb-live-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  box-shadow: 0 0 0 2px var(--surface-raised) inset;
}
.yb-live-status[data-state="connected"]::before { background: var(--gain); }
.yb-live-status[data-state="reconnecting"]::before { background: var(--warn); }
.yb-live-status[data-state="error"]::before { background: var(--loss); }

/* Auto-hide once connection is healthy. Page sets data-yb-live="ready"
   when at least one fetch resolved successfully. */
html[data-yb-live="ready"] .yb-live-status[data-state="connected"] {
  opacity: 0;
  pointer-events: none;
}

/* The existing heartbeat indicator from live.js uses a different class
   (.yb-heartbeat). Apply the same fade rule when live.js sets the ready
   flag, but only if the indicator is in a healthy (no -err, no -stale)
   state. Hovering over it brings it back. */
html[data-yb-live="ready"] .yb-heartbeat:not(.yb-heartbeat-err):not(.yb-heartbeat-stale) {
  opacity: 0;
  pointer-events: none;
  transition: opacity 600ms var(--ease);
}
html[data-yb-live="ready"] .yb-heartbeat:not(.yb-heartbeat-err):not(.yb-heartbeat-stale):hover {
  opacity: 0.85;
  pointer-events: auto;
}


/* ═══════════════════════════════════════════════════════════════════
   4 · HERO ECHO PATTERN
   Pages that match the index hero structure get .yb-hero on their main
   section. Locks consistent padding, max-width, and rhythm.
   Use sparingly: the structure varies on tools/audit/research stub and
   doesn't need to be forced.
   ═══════════════════════════════════════════════════════════════════ */

.yb-hero {
  padding: clamp(48px, 6vw, 80px) 0 clamp(28px, 3vw, 44px);
}
.yb-hero-eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 18px;
}
.yb-hero-title {
  font-family: var(--serif);
  font-size: clamp(38px, 5.4vw, 64px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.022em;
  margin: 0 0 18px;
  color: var(--ink);
}
.yb-hero-sub {
  font-size: clamp(15px, 1.8vw, 17px);
  line-height: 1.6;
  color: var(--ink-dim);
  max-width: 58ch;
  margin: 0;
}
