/* ============================================================================
   FUNDS BENCHMARK — Skeleton Loading System

   Port of preview/component-skeleton.html from the design-system bundle.
   Exports three skeleton patterns:

     1. .fb-sk-line          Horizontal shimmer text placeholder (short/med/long)
     2. .fb-sk-chart          Gold-spark SVG that draws a path on loop
     3. .fb-sk-row            List-row placeholder (glyph + name + price + delta)

   Plus composites:
     .fb-sk-card-fund        Full fund-card skeleton (brand + stats + bar)
     .fb-sk-card-stat        Stat chip skeleton
     .fb-sk-card-hero        Hero stat skeleton (big number + label)
     .fb-sk-card-table       Table skeleton (header + N rows)
     .fb-sk-card-allocation  Sector allocation skeleton

   Activation: add `.fb-is-loading` to any widget container; the page-specific
   JS (fundbenchmark-skeletons.js) will replace its innerHTML with the right
   skeleton shape based on a `data-sk` attribute. When data arrives, set the
   container's innerHTML back to real content.

   All animations loop until the skeleton is removed. No explicit stop — they
   vanish with the DOM.
   ============================================================================ */

/* ── Keyframes ────────────────────────────────────────────────────────── */
@keyframes fb-sk-slide {
  0%   { background-position: -240% 0; }
  100% { background-position: 240% 0; }
}
@keyframes fb-sk-draw {
  0%   { stroke-dasharray: 0 600; }
  55%  { stroke-dasharray: 600 600; }
  75%  { stroke-dasharray: 600 600; opacity: 1; }
  100% { stroke-dasharray: 600 0;   opacity: 0; }
}
@keyframes fb-sk-spark-run {
  0%   { offset-distance: 0%;   opacity: 0; }
  8%   { opacity: 1; }
  55%  { offset-distance: 100%; opacity: 1; }
  65%  { opacity: 0; }
  100% { offset-distance: 100%; opacity: 0; }
}
@keyframes fb-sk-pulse-dot {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50%      { opacity: 1; transform: scale(1.1); }
}
@keyframes fb-sk-row-in {
  0%, 8%     { opacity: 0; transform: translateY(4px); }
  20%        { opacity: 1; transform: translateY(0); }
  78%        { opacity: 1; transform: translateY(0); }
  92%, 100%  { opacity: 0.25; transform: translateY(-2px); }
}
@keyframes fb-sk-text-slide {
  0%   { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

/* ── 1. Base line shimmer ────────────────────────────────────────────── */
.fb-sk-line {
  height: 11px;
  border-radius: 3px;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}
.fb-sk-line::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(201, 169, 98, 0.10) 45%,
    rgba(255, 245, 216, 0.18) 50%,
    rgba(201, 169, 98, 0.10) 55%,
    transparent 100%
  );
  background-size: 240% 100%;
  animation: fb-sk-slide 2s linear infinite;
}
.fb-sk-line.sm    { height: 9px; }
.fb-sk-line.md    { height: 11px; }
.fb-sk-line.lg    { height: 14px; }
.fb-sk-line.xl    { height: 20px; }
.fb-sk-line.xxl   { height: 32px; }
.fb-sk-line.short { width: 38%; }
.fb-sk-line.mid   { width: 62%; }
.fb-sk-line.long  { width: 84%; }
.fb-sk-line.full  { width: 100%; }

/* ── 2. Chart skeleton (gold-spark SVG that draws a path on loop) ─────── */
.fb-sk-chart {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-5);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--sp-3);
  min-height: 300px;
}
/* Inside the Fund Detail chart wrapper, the skeleton should fill the full
   400px the real chart occupies — keeps the layout stable through swap. */
#fdLWChartContainer .fb-sk-chart,
.fd-lw-chart-container .fb-sk-chart {
  min-height: 100%;
  height: 100%;
  width: 100%;
}
.fb-sk-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.fb-sk-chart-ticker {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
}
.fb-sk-chart-ticker::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(201, 169, 98, 0.8);
  animation: fb-sk-pulse-dot 1.4s ease-in-out infinite;
}
.fb-sk-chart-legend {
  display: flex;
  gap: var(--sp-3);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.fb-sk-chart-legend i { font-style: normal; color: var(--text-2); }
.fb-sk-chart-legend i.gold { color: var(--gold); }

.fb-sk-chart-svg {
  width: 100%;
  height: 128px;
  display: block;
  overflow: visible;
}
.fb-sk-chart-grid { stroke: var(--border-soft); stroke-width: 1; stroke-dasharray: 2 4; }
.fb-sk-chart-ghost {
  fill: none;
  stroke: rgba(201, 169, 98, 0.10);
  stroke-width: 1.5;
  stroke-linecap: round;
}
.fb-sk-chart-draw {
  fill: none;
  stroke: url(#fbSkSparkGrad);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 0 600;
  animation: fb-sk-draw 2.6s cubic-bezier(0.65, 0.05, 0.36, 1) infinite;
  filter: drop-shadow(0 0 4px rgba(201, 169, 98, 0.55));
}
.fb-sk-chart-spark {
  fill: #fff5d8;
  filter: drop-shadow(0 0 6px rgba(228, 212, 164, 0.9))
          drop-shadow(0 0 12px rgba(201, 169, 98, 0.6));
  animation: fb-sk-spark-run 2.6s cubic-bezier(0.65, 0.05, 0.36, 1) infinite;
}

.fb-sk-chart-readout {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: var(--sp-2);
}
.fb-sk-chart-num {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  background: linear-gradient(
    90deg,
    var(--text-muted) 0%,
    var(--text-muted) 40%,
    rgba(228, 212, 164, 0.9) 50%,
    var(--text-muted) 60%,
    var(--text-muted) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: fb-sk-text-slide 2.2s linear infinite;
}
.fb-sk-chart-ts {
  color: var(--text-muted);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}

/* ── 3. Ticker row skeleton (list items materialize in sequence) ──────── */
.fb-sk-rows {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-2) 0;
  box-shadow: var(--shadow-card);
}
.fb-sk-row {
  display: grid;
  grid-template-columns: 18px 1fr 80px 64px;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border-soft);
  opacity: 0;
  animation: fb-sk-row-in 2.4s ease-in-out infinite;
}
.fb-sk-row:first-child { border-top: none; }
.fb-sk-row:nth-child(1) { animation-delay: 0s; }
.fb-sk-row:nth-child(2) { animation-delay: 0.18s; }
.fb-sk-row:nth-child(3) { animation-delay: 0.36s; }
.fb-sk-row:nth-child(4) { animation-delay: 0.54s; }
.fb-sk-row:nth-child(5) { animation-delay: 0.72s; }
.fb-sk-row:nth-child(6) { animation-delay: 0.90s; }
.fb-sk-row:nth-child(7) { animation-delay: 1.08s; }
.fb-sk-row:nth-child(8) { animation-delay: 1.26s; }

.fb-sk-row .glyph {
  width: 18px;
  height: 18px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fb-sk-row .glyph::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.55;
}
.fb-sk-row .name {
  height: 11px;
  border-radius: 3px;
  background: var(--surface-2);
  width: 70%;
  position: relative;
  overflow: hidden;
}
.fb-sk-row .name::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 245, 216, 0.16), transparent);
  background-size: 200% 100%;
  animation: fb-sk-slide 1.8s linear infinite;
}
.fb-sk-row .price {
  text-align: right;
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 12px;
  color: transparent;
  background: linear-gradient(
    90deg,
    var(--text-2) 0%,
    var(--text-2) 40%,
    rgba(228, 212, 164, 0.9) 50%,
    var(--text-2) 60%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: fb-sk-text-slide 2.2s linear infinite;
}
.fb-sk-row .delta {
  text-align: right;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(74, 222, 128, 0.6);
}

/* ── 4. Stat chip skeleton ────────────────────────────────────────────── */
.fb-sk-stat {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.fb-sk-stat .fb-sk-line.label { width: 50%; height: 8px; }
.fb-sk-stat .fb-sk-line.value { width: 70%; height: 20px; }

/* Wrapper for a grid of fund-card skeletons. Sits as a single grid cell
   inside #fundsGrid (which is repeat(3, 1fr)) and spans all columns so the
   skeletons can lay out in their own 3-col grid. Responsive down to 1 col. */
.fb-sk-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-3);
  width: 100%;
  grid-column: 1 / -1;
}
@media (max-width: 1024px) { .fb-sk-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px)  { .fb-sk-card-grid { grid-template-columns: 1fr; } }

/* ── 5. Fund card skeleton (Fund Finder placeholder) ─────────────────── */
.fb-sk-fund-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
}
.fb-sk-fund-card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.fb-sk-fund-card-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.fb-sk-fund-card-logo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(201, 169, 98, 0.10) 45%,
    rgba(255, 245, 216, 0.18) 50%,
    rgba(201, 169, 98, 0.10) 55%,
    transparent 100%
  );
  background-size: 240% 100%;
  animation: fb-sk-slide 2s linear infinite;
}
.fb-sk-fund-card-brand  { flex: 1; }
.fb-sk-fund-card-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.fb-sk-fund-card-badge {
  width: 36px;
  height: 14px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
}
.fb-sk-fund-card-name {
  height: 16px;
  border-radius: 3px;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
  width: 85%;
}
.fb-sk-fund-card-name::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(201, 169, 98, 0.10) 45%,
    rgba(255, 245, 216, 0.18) 50%,
    rgba(201, 169, 98, 0.10) 55%,
    transparent 100%
  );
  background-size: 240% 100%;
  animation: fb-sk-slide 2s linear infinite;
}
.fb-sk-fund-card-meta {
  height: 10px;
  width: 55%;
  border-radius: 3px;
  background: var(--surface-2);
}
.fb-sk-fund-card-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border-soft);
}
.fb-sk-fund-card-bar {
  display: block;
  width: 100%;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}
.fb-sk-fund-card-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(201, 169, 98, 0.15) 45%,
    rgba(255, 245, 216, 0.30) 50%,
    rgba(201, 169, 98, 0.15) 55%,
    transparent 100%
  );
  background-size: 240% 100%;
  animation: fb-sk-slide 1.8s linear infinite;
}
.fb-sk-fund-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.fb-sk-fund-card-action {
  height: 36px;
  border-radius: var(--r-md);
  background: var(--surface-2);
}

/* ── 6. Hero stat skeleton (big number + label) ──────────────────────── */
.fb-sk-hero-stat {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
}
.fb-sk-hero-stat .fb-sk-line.value { width: 40%; height: 32px; }
.fb-sk-hero-stat .fb-sk-line.label { width: 25%; height: 10px; }

/* ── 7. Allocation / breakdown skeleton ───────────────────────────────── */
.fb-sk-allocation {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
}
.fb-sk-allocation-row {
  display: grid;
  grid-template-columns: 110px 1fr 48px;
  gap: var(--sp-3);
  align-items: center;
}
.fb-sk-allocation-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: var(--r-pill);
  position: relative;
  overflow: hidden;
}
.fb-sk-allocation-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(201, 169, 98, 0.15) 45%,
    rgba(255, 245, 216, 0.30) 50%,
    rgba(201, 169, 98, 0.15) 55%,
    transparent 100%
  );
  background-size: 240% 100%;
  animation: fb-sk-slide 1.8s linear infinite;
}

/* ── 8. Helper: container with "loading" state ────────────────────────── */
/* Use `.fb-is-loading` on a widget container. The accompanying JS replaces
   innerHTML with the appropriate skeleton shape based on `data-sk` attr. */
.fb-is-loading {
  position: relative;
  min-height: 80px;
  pointer-events: none;
}
.fb-is-loading > *:not([data-sk-skeleton]) {
  display: none;
}

/* Respect reduced motion — collapse all skeleton animations to static. */
@media (prefers-reduced-motion: reduce) {
  .fb-sk-line::after,
  .fb-sk-chart-draw,
  .fb-sk-chart-spark,
  .fb-sk-chart-num,
  .fb-sk-row,
  .fb-sk-row .name::after,
  .fb-sk-row .price,
  .fb-sk-fund-card-logo::after,
  .fb-sk-fund-card-name::after,
  .fb-sk-fund-card-bar::after,
  .fb-sk-allocation-bar::after,
  .fb-sk-chart-ticker::before {
    animation: none !important;
  }
}
