/* ── CardDex Shared UX Styles ──────────────────────────────────────
   Skeleton screens, toasts, autocomplete, accessibility, offline
   banner, real-time validation, and reduced-motion support.
   Loaded on all pages via <link rel="stylesheet" href="/ux.css">.
   ─────────────────────────────────────────────────────────────── */

/* ── Toast notifications ──────────────────────────────────────── */
#cdx-toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: 380px;
  pointer-events: none;
}

.cdx-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .2s, transform .2s;
}

.cdx-toast-show {
  opacity: 1;
  transform: translateY(0);
}

.cdx-toast-hide {
  opacity: 0;
  transform: translateY(12px);
}

.cdx-toast-icon { flex-shrink: 0; margin-top: 1px; }
.cdx-toast-msg { flex: 1; line-height: 1.4; }

.cdx-toast-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 0 0 6px;
  flex-shrink: 0;
}
.cdx-toast-close:hover { color: var(--text); }

.cdx-toast-success .cdx-toast-icon { color: var(--green); }
.cdx-toast-error .cdx-toast-icon { color: var(--red); }
.cdx-toast-warning .cdx-toast-icon { color: var(--yellow); }
.cdx-toast-info .cdx-toast-icon { color: var(--accent-blue); }

.cdx-toast-undo {
  display: inline-block;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  padding: 0;
  margin-left: 8px;
  text-decoration: underline;
}
.cdx-toast-undo:hover { opacity: .8; }

/* ── Skeleton screens ─────────────────────────────────────────── */
.cdx-skeleton-wrap {
  width: 100%;
}

.cdx-skeleton {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.cdx-skeleton-card {
  flex-direction: column;
  padding: 16px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.cdx-skeleton-cell {
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, var(--hover) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: cdx-shimmer 1.5s ease-in-out infinite;
}

/* Table-row skeletons live inside <tbody> as real <tr><td> so they don't get
   foster-parented out of the table. Match real row padding so swapping the
   skeleton for real data doesn't cause a vertical jump. */
.cdx-skeleton-row td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

/* Crossfade from skeleton to real content */
.cdx-skeleton-fade-in {
  animation: cdx-fadeIn .3s ease-out;
}
@keyframes cdx-fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

/* ── Autocomplete ─────────────────────────────────────────────── */
.cdx-autocomplete-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  display: none;
}

.cdx-autocomplete-list:not(:empty) {
  display: block;
}

.cdx-autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .1s;
}

.cdx-autocomplete-item:hover,
.cdx-autocomplete-item.active {
  background: var(--hover);
}

/* ── Real-time validation ─────────────────────────────────────── */
.cdx-field-error {
  display: block;
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
  min-height: 0;
}

.cdx-field-invalid {
  border-color: var(--red) !important;
}

/* ── Offline banner ───────────────────────────────────────────── */
.cdx-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  background: var(--red);
  color: #fff;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ── Last updated ─────────────────────────────────────────────── */
.cdx-last-updated {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

/* ── Header scroll shadow ──────────────────────────────────────
   A subtle shadow appears below the sticky header when the user
   scrolls down. Managed by a tiny IntersectionObserver in each page. */
header.cdx-scrolled {
  box-shadow: 0 1px 8px rgba(0, 0, 0, .25);
  border-bottom-color: transparent;
}
@media (prefers-reduced-motion: no-preference) {
  header {
    transition: box-shadow .25s ease, border-bottom-color .25s ease;
  }
}

/* ── Larger touch targets on mobile ───────────────────────────── */
@media (max-width: 768px) {
  button, .btn, [role="button"], a.btn {
    min-height: 44px;
    min-width: 44px;
  }

  .cdx-toast-close {
    min-height: 44px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ── Mobile hamburger menu ────────────────────────────────────── */
.cdx-mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  line-height: 1;
}

@media (max-width: 768px) {
  /* Burger menu hidden — bottom nav bar replaces it */
  .cdx-mobile-toggle { display: none; }

  .nav-tabs,
  .tcg-nav {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 8px 0;
    z-index: 99;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
  }

  .nav-tabs.open,
  .tcg-nav.open { display: flex; }

  .nav-tabs a,
  .tcg-nav a {
    padding: 12px 24px !important;
    border-bottom: none !important;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ── Accessibility: focus outlines ────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Accessibility: delta indicators ──────────────────────────── */
/* Add text arrows alongside color for colorblind users.
   Only target data cells (td), not headers or other elements. */
td .delta-pos::before { content: "\25B2 "; font-size: 9px; }
td .delta-neg::before { content: "\25BC "; font-size: 9px; }

/* ── Reduced motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .cdx-skeleton-cell {
    animation: none;
    background: var(--border);
  }

  .cdx-toast {
    transition: none;
  }

  .spinner {
    animation-duration: 0s !important;
  }

  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ── Interactive sparklines ───────────────────────────────────── */
.sparkline-wrap {
  position: relative;
  display: inline-block;
}

.sparkline-tooltip {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  display: none;
}

.sparkline-wrap:hover .sparkline-tooltip {
  display: block;
}

/* ── Column header info tooltips ─────────────────────────────── */
.th-info { position: relative; }
.th-info .th-tip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  white-space: normal;
  width: 220px;
  line-height: 1.5;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  pointer-events: none;
  text-align: left;
}
.th-info:hover .th-tip { display: block !important; }
.th-info-icon { font-size: 9px; opacity: .5; margin-left: 3px; }

/* ── Floating Beta badge ───────────────────────────────────────
   Appears in the bottom-right on every page until V1 ships.
   Sits below toasts (z-index 10000) and the auth modal (9999),
   but above page content. Honors prefers-reduced-motion. */
.app-beta {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 95;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  font-family: ui-monospace, 'SF Mono', monospace;
  color: #f59e0b;
  background: var(--surface);
  border: 1px solid #f59e0b;
  border-radius: 999px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  transition: background .15s, color .15s, transform .15s;
}
.app-beta::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  animation: app-beta-pulse 2.2s ease-out infinite;
}
.app-beta:hover {
  background: #f59e0b;
  color: #fff;
  transform: translateY(-1px);
}
.app-beta:hover::before { background: #fff; }
@keyframes app-beta-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(245, 158, 11, .55); }
  70%  { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0   rgba(245, 158, 11, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .app-beta::before { animation: none; }
}

/* ── Cosmic backdrop, hero strip, banners, illustrated states ─────────
   Shared across all pages. Each page picks its hero variant via a
   class on .cdx-hero (e.g. .cdx-hero--portfolio). Mobile crops are
   selected via media-query background swaps. Originals live under
   /img/dashboard/. ─────────────────────────────────────────────── */

body { position: relative; }
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('/img/dashboard/texture-bg.webp') center/600px auto repeat;
  opacity: .07;
  pointer-events: none;
  z-index: 0;
}
[data-theme="light"] body::before { opacity: 0; }
/* Lift content sections above the body::before texture (z-index: 0).
 * `header` is intentionally excluded — every page sets it sticky with
 * z-index: 100 inline, and including it here at z-index: 1 made the
 * sticky header lose its stacking context, which let `.cdx-hero`
 * (also z-index: 1, but later in the DOM with `isolation: isolate`)
 * paint over the user dropdown menu. */
.cdx-hero,
.stats-bar,
main,
.auth-overlay,
.mobile-menu { position: relative; z-index: 1; }

/* ── Hero strip ─────────────────────────────────────────────── */
.cdx-hero {
  position: relative;
  min-height: 220px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  isolation: isolate;
  background: var(--surface);
}
.cdx-hero__bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center right;
  z-index: -1;
  animation: cdxHeroFloat 30s ease-in-out infinite alternate;
}
.cdx-hero__bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 65%, var(--bg) 100%);
}
@keyframes cdxHeroFloat {
  0%   { transform: scale(1.04) translateX(0); }
  100% { transform: scale(1.08) translateX(-1.5%); }
}
@media (prefers-reduced-motion: reduce) {
  .cdx-hero__bg { animation: none; }
}
.cdx-hero__inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 44px 24px 40px;
  position: relative;
}
.cdx-hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--accent, #c9a030);
  margin-bottom: 10px;
  padding: 5px 12px;
  background: rgba(201, 160, 48, 0.1);
  border: 1px solid rgba(201, 160, 48, 0.35);
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.cdx-hero__title {
  font-size: clamp(26px, 4.2vw, 42px);
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.6px;
  margin: 0 0 10px;
  text-shadow: 0 2px 18px rgba(0,0,0,0.65);
  max-width: 760px;
  line-height: 1.15;
}
.cdx-hero__title em {
  font-style: normal;
  background: linear-gradient(90deg, #f0b90b 0%, #c9a030 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.cdx-hero__tagline {
  font-size: clamp(13px, 1.4vw, 16px);
  color: #cdd5e0;
  max-width: 560px;
  text-shadow: 0 1px 8px rgba(0,0,0,0.7);
  line-height: 1.5;
  margin: 0;
}

/* ── Market pulse sparklines (landing hero) ──────────────────── */

[data-theme="light"] .cdx-hero { background: #0b1525; }
@media (max-width: 720px) {
  .cdx-hero { min-height: 170px; }
  .cdx-hero__inner { padding: 26px 16px 24px; }
  .cdx-hero__eyebrow { font-size: 10px; padding: 4px 10px; }
}

/* Per-page hero variants. Each pairs a desktop image with a 92%-opacity
   left-to-right gradient and swaps to a mobile crop under 720px. */
.cdx-hero--dashboard .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero.webp');
}
.cdx-hero--dashboard.is-pokemon .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-pokemon.webp');
}
.cdx-hero--dashboard.is-mtg .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-mtg.webp');
}
.cdx-hero--dashboard.is-onepiece .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-onepiece.webp');
}
.cdx-hero--dashboard.is-dragonball .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-dragonball.webp');
}
.cdx-hero--dashboard.is-yugioh .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-yugioh.webp');
}
.cdx-hero--dashboard.is-lorcana .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-lorcana.webp');
}
.cdx-hero--landing .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.94) 0%, rgba(11,21,37,0.64) 40%, rgba(11,21,37,0.18) 80%, rgba(11,21,37,0) 100%),
    url('/img/dashboard/hero-landing.webp');
}
.cdx-hero--portfolio .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-portfolio.webp');
}
.cdx-hero--alerts .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-alerts.webp');
}
.cdx-hero--reports .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-reports.webp');
}
@media (max-width: 720px) {
  .cdx-hero--dashboard .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-mobile.webp');
    background-position: center;
  }
  .cdx-hero--dashboard.is-pokemon .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-pokemon-mobile.webp');
  }
  .cdx-hero--dashboard.is-mtg .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-mtg-mobile.webp');
  }
  .cdx-hero--dashboard.is-onepiece .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-onepiece-mobile.webp');
  }
  .cdx-hero--dashboard.is-dragonball .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-dragonball-mobile.webp');
  }
  .cdx-hero--dashboard.is-yugioh .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-yugioh-mobile.webp');
  }
  .cdx-hero--dashboard.is-lorcana .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-lorcana-mobile.webp');
  }
  .cdx-hero--landing .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.55) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-landing-mobile.webp');
    background-position: center;
  }
  .cdx-hero--portfolio .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-portfolio-mobile.webp');
    background-position: center;
  }
  .cdx-hero--alerts .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-alerts-mobile.webp');
    background-position: center;
  }
  .cdx-hero--reports .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-reports-mobile.webp');
    background-position: center;
  }
}

/* ── Section banners (Squeeze / Charts and friends) ──────────── */
.tcg-banner {
  position: relative;
  min-height: 130px;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 18px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 22px 28px;
  isolation: isolate;
}
.tcg-banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: -2;
}
.tcg-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(95deg, rgba(11,21,37,0.94) 0%, rgba(11,21,37,0.55) 55%, rgba(11,21,37,0.18) 100%);
  z-index: -1;
}
.tcg-banner.squeeze::before { background-image: url('/img/dashboard/banner-squeeze.webp'); }
.tcg-banner.charts::before  { background-image: url('/img/dashboard/banner-charts.webp'); }
.tcg-banner__title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.7);
  margin-bottom: 4px;
}
.tcg-banner__sub {
  font-size: 12.5px;
  color: #cdd5e0;
  max-width: 520px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.7);
  line-height: 1.5;
}
@media (max-width: 720px) {
  .tcg-banner { min-height: 96px; padding: 14px 16px; border-radius: 8px; margin-bottom: 12px; }
  .tcg-banner__title { font-size: 15px; }
  .tcg-banner__sub { font-size: 11.5px; }
}

/* ── Illustrated empty / error states ─────────────────────── */
.cdx-state-art {
  display: block;
  width: 220px;
  max-width: 70%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  margin: 0 auto 14px;
  opacity: .9;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
.cdx-state-art.empty { background-image: url('/img/dashboard/empty-state.webp'); }
.cdx-state-art.error { background-image: url('/img/dashboard/error-state.webp'); }

/* ── Ambient atmosphere (orbs + horizon glow + starfield) ─────────
   Layered on top of the base body::before texture tile to give the
   page real depth. Disabled in light mode and reduced-motion. */

body::before {
  /* Override of the earlier rule above — bigger nebula + starfield */
  background:
    /* Sparse star layer */
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,0.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 32%, rgba(255,255,255,0.55) 50%, transparent 51%),
    radial-gradient(1px 1px at 33% 71%, rgba(255,255,255,0.6) 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 84%, rgba(255,255,255,0.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 12%, rgba(255,255,255,0.5) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 20% 60%, rgba(255,255,255,0.45) 50%, transparent 51%),
    radial-gradient(1px 1px at 65% 52%, rgba(255,255,255,0.4) 50%, transparent 51%),
    /* Nebula tile */
    url('/img/dashboard/texture-bg.webp');
  background-size:
    420px 420px, 420px 420px, 420px 420px, 420px 420px,
    420px 420px, 420px 420px, 420px 420px,
    1400px auto;
  background-repeat: repeat;
  opacity: .12;
  animation: cdxStarDrift 240s linear infinite;
}
@keyframes cdxStarDrift {
  from { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: -210px -120px, 240px -180px, -150px 240px, 200px 150px,
                              -260px 180px, 130px -240px, -180px 90px, -700px 0; }
}
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
}
[data-theme="light"] body::before { opacity: 0; animation: none; }

/* Ambient gradient orbs — fixed, blurred, behind everything. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 950px 750px at 95% -8%, rgba(201,160,48,0.11) 0%, transparent 62%),
    radial-gradient(ellipse 850px 700px at -8% 92%, rgba(116,61,193,0.10) 0%, transparent 60%),
    radial-gradient(ellipse 720px 600px at 105% 55%, rgba(61,126,199,0.07) 0%, transparent 60%),
    radial-gradient(ellipse 600px 500px at 35% 35%, rgba(22,199,132,0.04) 0%, transparent 60%);
}
[data-theme="light"] body::after { display: none; }

/* Horizon glow under each hero — replaces the abrupt 1px border. */
.cdx-hero {
  border-bottom: none !important;
}
.cdx-hero::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(201,160,48,0) 10%,
    rgba(201,160,48,0.55) 50%,
    rgba(201,160,48,0) 90%,
    transparent 100%);
  box-shadow: 0 0 22px 2px rgba(201,160,48,0.18);
  z-index: 2;
  pointer-events: none;
}

/* ── KPI cards (stats bar redesign) ──────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1;
}
.kpi-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025) 0%, rgba(255,255,255,0) 100%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow: hidden;
  isolation: isolate;
  min-height: 84px;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  display: block;
  text-decoration: none;
  color: inherit;
}
.kpi-card:hover {
  border-color: rgba(201,160,48,0.55);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.kpi-card.up    { border-left: 3px solid var(--green); }
.kpi-card.down  { border-left: 3px solid var(--red); }
.kpi-card.flat  { border-left: 3px solid var(--muted); }
.kpi-card__label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.kpi-card__value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-card__value.buy  { color: var(--green); }
.kpi-card__value.sell { color: var(--red); }
.kpi-card__sub {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.kpi-card__sub .buy  { color: var(--green); font-weight: 600; }
.kpi-card__sub .sell { color: var(--red);   font-weight: 600; }
.kpi-card__bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.22;
  z-index: -1;
  filter: saturate(1.2);
  mask-image: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,1) 100%);
  -webkit-mask-image: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,1) 100%);
}
.kpi-card--gainer    .kpi-card__bg { background-image: url('/img/dashboard/kpi-gainer.webp'); }
.kpi-card--loser     .kpi-card__bg { background-image: url('/img/dashboard/kpi-loser.webp'); }
.kpi-card--turnover  .kpi-card__bg { background-image: url('/img/dashboard/kpi-turnover.webp'); }
.kpi-card .kpi-spark {
  position: absolute;
  bottom: 8px;
  right: 10px;
  opacity: 0.85;
  pointer-events: none;
}
@media (max-width: 720px) {
  /* Collapse the KPI grid into a single horizontally-scrollable strip
     so it occupies one short row instead of stacking five rows tall. */
  .kpi-row {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 8px 12px;
    gap: 8px;
  }
  .kpi-row::-webkit-scrollbar { display: none; }
  .kpi-card {
    flex: 0 0 auto;
    min-width: 0;
    min-height: 0;
    padding: 7px 11px;
    border-radius: 8px;
    border-left-width: 2px;
  }
  .kpi-card.up    { border-left-width: 2px; }
  .kpi-card.down  { border-left-width: 2px; }
  .kpi-card.flat  { border-left-width: 2px; }
  .kpi-card__label {
    font-size: 9px;
    margin-bottom: 1px;
    letter-spacing: 0.5px;
  }
  .kpi-card__value {
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
  }
  .kpi-card__sub { display: none; }
  .kpi-card__bg  { display: none; }
  .kpi-card .kpi-spark { display: none; }
  /* Top gainer/loser keep the % delta visible as a tiny secondary line. */
  .kpi-card--gainer .kpi-card__sub,
  .kpi-card--loser .kpi-card__sub,
  .kpi-card--turnover .kpi-card__sub {
    display: flex;
    margin-top: 1px;
    font-size: 9.5px;
    gap: 5px;
  }
  /* Cap product-name width on the gainer/loser cards. */
  .kpi-card--gainer .kpi-card__value,
  .kpi-card--loser .kpi-card__value {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Lightweight "last updated" footer line below the kpi-row. */
.cdx-meta-bar {
  position: relative;
  z-index: 1;
  padding: 6px 24px 0;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
@media (max-width: 720px) {
  .cdx-meta-bar { padding: 4px 12px 0; font-size: 10.5px; }
}

/* Hero variants for account and beta. */
.cdx-hero--account .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-account.webp');
}
.cdx-hero--beta .cdx-hero__bg {
  background-image:
    linear-gradient(95deg, rgba(11,21,37,0.96) 0%, rgba(11,21,37,0.72) 38%, rgba(11,21,37,0.28) 72%, rgba(11,21,37,0.05) 100%),
    url('/img/dashboard/hero-beta.webp');
}
@media (max-width: 720px) {
  .cdx-hero--account .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-account-mobile.webp');
    background-position: center;
  }
  .cdx-hero--beta .cdx-hero__bg {
    background-image:
      linear-gradient(180deg, rgba(11,21,37,0.65) 0%, rgba(11,21,37,0.85) 80%, var(--bg) 100%),
      url('/img/dashboard/hero-beta-mobile.webp');
    background-position: center;
  }
}
