/**
 * Sovereign Terminal — crypto markets section (front page).
 * Markup: inc/crypto.php. Chart behaviour: assets/js/crypto.js.
 * Uses the tokens defined in main.css.
 */

/* ── Section head ─────────────────────────────────────────────────────────── */
.cx__head {
  margin-bottom: var(--space-8);
}

.cx__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-body);
}

.cx__meta-sep {
  color: var(--ink-faint);
}

/* ── Shared bits ──────────────────────────────────────────────────────────── */
.cx-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cx-delta {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.cx-delta--up { color: var(--data-up); }
.cx-delta--down { color: var(--data-down); }
.cx-delta--flat { color: var(--ink-muted); }

.is-deep .cx-delta--up { color: #6fbf9b; }
.is-deep .cx-delta--down { color: #e2897c; }
.is-deep .cx-delta--flat { color: rgba(252, 250, 246, 0.6); }

.cx-coin__icon {
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: var(--sunken);
}

/* ── Stat tiles ───────────────────────────────────────────────────────────── */
.cx__stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.cx-stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-6);
  background: var(--elevated);
  border: 1px solid var(--gold-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* Gold tick on the top edge — the same accent the desks panels carry. */
.cx-stat::before {
  content: "";
  position: absolute;
  top: -1px;
  left: var(--space-6);
  width: 28px;
  height: 2px;
  background: var(--gold);
}

.cx-stat__label {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.cx-stat__value {
  font-family: var(--font-headline);
  font-size: clamp(1.5rem, 2.2vw, 1.875rem);
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.cx-stat__foot {
  margin-top: auto;
  font-size: 0.8125rem;
  color: var(--ink-body);
}

.cx-stat__foot b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Dominance bar */
.cx-dom {
  display: flex;
  height: 6px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--sunken);
}

.cx-dom__seg--btc { background: var(--gold); }
.cx-dom__seg--eth { background: var(--ink-muted); }
.cx-dom__seg--alt { background: var(--gold-hairline-strong); }

.cx-dom__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
}

.cx-dom__key {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 2px;
}

.cx-dom__key--eth { background: var(--ink-muted); }
.cx-dom__key--alt { background: var(--gold-hairline-strong); }

/* Fear & Greed gauge */
.cx-fng {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.cx-fng__gauge {
  width: 104px;
  height: auto;
  flex-shrink: 0;
  overflow: visible;
}

.cx-fng__arc {
  fill: none;
  stroke-width: 9;
}

.cx-fng__arc--1 { stroke: #a33f31; }
.cx-fng__arc--2 { stroke: #c97a52; }
.cx-fng__arc--3 { stroke: #d1b06a; }
.cx-fng__arc--4 { stroke: #7f9e6e; }
.cx-fng__arc--5 { stroke: #2e6a55; }

.cx-fng__needle {
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
}

.cx-fng__hub {
  fill: var(--ink);
}

.cx-fng__read {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cx-fng__label {
  font-family: var(--font-label);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

/* ── Main row: chart + table ──────────────────────────────────────────────── */
.cx__main {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: stretch;
}

/* No chart data yet (first minutes after deploy, or upstream down). */
.cx__main--solo {
  grid-template-columns: minmax(0, 1fr);
}

/* Chart panel — ink, like the ticker rail and the brief band */
.cx-chart {
  display: flex;
  flex-direction: column;
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(176, 141, 63, 0.16), transparent 60%),
    var(--deep);
  border: 1px solid rgba(227, 201, 131, 0.14);
  box-shadow: var(--shadow-lg);
  min-width: 0;
}

.cx-chart__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.cx-tabs {
  display: inline-flex;
  padding: 3px;
  border: 1px solid rgba(252, 250, 246, 0.12);
  border-radius: var(--radius-full);
  background: rgba(252, 250, 246, 0.04);
}

.cx-tabs__btn {
  min-width: 48px;
  min-height: 32px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: rgba(252, 250, 246, 0.62);
  font-family: var(--font-label);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.cx-tabs__btn:hover {
  color: var(--base);
}

.cx-tabs__btn[aria-pressed="true"] {
  background: var(--gold-bright);
  color: var(--ink);
}

.cx-tabs__btn:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.cx-chart__quote {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-6) 0 var(--space-4);
}

.cx-chart__name {
  width: 100%;
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-bright);
}

.cx-chart__price {
  font-family: var(--font-headline);
  font-size: clamp(2rem, 3.6vw, 2.75rem);
  font-weight: 600;
  line-height: 1;
  color: var(--base);
  font-variant-numeric: tabular-nums;
}

.cx-chart__change {
  font-size: 1rem;
}

.cx-chart__plot {
  position: relative;
  flex: 1;
  min-height: 240px;
  touch-action: pan-y;
  cursor: crosshair;
}

.cx-chart__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.cx-chart__grid line {
  stroke: rgba(252, 250, 246, 0.08);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

.cx-chart__line {
  fill: none;
  stroke: var(--gold-bright);
  stroke-width: 2;
  stroke-linejoin: round;
}

.cx-chart__cross {
  stroke: rgba(252, 250, 246, 0.35);
  stroke-width: 1;
  opacity: 0;
}

.cx-chart__ylabels span {
  position: absolute;
  right: 0;
  transform: translateY(-120%);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  /* Ink chip so the label stays legible where the line runs underneath. */
  background: rgba(20, 18, 16, 0.72);
  font-size: 0.6875rem;
  color: rgba(252, 250, 246, 0.5);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.cx-chart__dot {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 0 4px rgba(227, 201, 131, 0.22);
  opacity: 0;
  pointer-events: none;
}

.cx-chart__tip {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: 12px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid rgba(227, 201, 131, 0.3);
  border-radius: var(--radius-md);
  background: rgba(20, 18, 16, 0.92);
  white-space: nowrap;
  font-size: 0.75rem;
  color: rgba(252, 250, 246, 0.6);
  opacity: 0;
  pointer-events: none;
}

.cx-chart__tip.is-left {
  transform: translateX(-100%);
  margin-left: -12px;
}

.cx-chart__tip b {
  font-size: 0.9375rem;
  color: var(--base);
  font-variant-numeric: tabular-nums;
}

.cx-chart__plot.is-hover .cx-chart__cross,
.cx-chart__plot.is-hover .cx-chart__dot,
.cx-chart__plot.is-hover .cx-chart__tip {
  opacity: 1;
}

.cx-chart__foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid rgba(252, 250, 246, 0.08);
  font-size: 0.75rem;
  color: rgba(252, 250, 246, 0.5);
}

.cx-chart__hl {
  display: flex;
  gap: var(--space-5);
}

.cx-chart__hl b {
  color: var(--base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Top-10 table ─────────────────────────────────────────────────────────── */
.cx-table {
  display: flex;
  flex-direction: column;
  padding: var(--space-2) var(--space-5);
  background: var(--elevated);
  border: 1px solid var(--gold-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.cx-table__row {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto 4.5rem 4.5rem;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-height: 46px;
  border-bottom: 1px solid var(--gold-hairline);
  font-size: 0.875rem;
}

.cx-table__row:last-child {
  border-bottom: 0;
}

.cx-table__row--head {
  flex: 0;
  min-height: 40px;
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.cx-table__rank {
  font-size: 0.75rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.cx-coin {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.cx-coin__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink);
}

.cx-coin__sym {
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.cx-table__price {
  color: var(--ink);
}

.cx-table__spark-col {
  display: flex;
  justify-content: flex-end;
}

.cx-spark {
  width: 72px;
  height: 26px;
  overflow: visible;
}

.cx-spark polyline {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.cx-spark--up polyline { stroke: var(--data-up); }
.cx-spark--down polyline { stroke: var(--data-down); }
.cx-spark--flat polyline { stroke: var(--ink-muted); }

/* ── Movers ───────────────────────────────────────────────────────────────── */
.cx__movers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  margin-top: var(--space-5);
}

.cx-movers {
  padding: var(--space-5) var(--space-6);
  background: var(--elevated);
  border: 1px solid var(--gold-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.cx-movers__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.cx-movers__title::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}

.cx-movers--up .cx-movers__title::before { border-bottom: 7px solid var(--data-up); }
.cx-movers--down .cx-movers__title::before { border-top: 7px solid var(--data-down); }

.cx-movers__list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}

.cx-mover {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "icon sym"
    "price price"
    "delta delta";
  align-items: center;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--base);
  border: 1px solid var(--gold-hairline);
  min-width: 0;
}

.cx-mover .cx-coin__icon { grid-area: icon; }

.cx-mover__sym {
  grid-area: sym;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--ink);
}

.cx-mover__price {
  grid-area: price;
  font-size: 0.8125rem;
  color: var(--ink-body);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cx-mover .cx-delta {
  grid-area: delta;
  font-size: 1rem;
}

.cx__disclaimer {
  margin-top: var(--space-5);
  font-size: 0.75rem;
  color: var(--ink-muted);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .cx__stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cx__main {
    grid-template-columns: minmax(0, 1fr);
  }

  .cx__movers {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  /* Two small figures side by side; the bar and the gauge need the width. */
  .cx__stats {
    gap: var(--space-3);
  }

  .cx-stat {
    padding: var(--space-4);
  }

  .cx-stat::before {
    left: var(--space-4);
  }

  .cx-stat:nth-child(n + 3) {
    grid-column: 1 / -1;
  }

  .cx-chart {
    padding: var(--space-5) var(--space-4);
  }

  .cx-chart__plot {
    min-height: 200px;
  }

  .cx-chart__foot {
    flex-wrap: wrap;
    justify-content: center;
  }

  .cx-chart__foot [data-cx-from],
  .cx-chart__foot [data-cx-to] {
    display: none;
  }

  .cx-table {
    padding-inline: var(--space-4);
  }

  .cx-table__row {
    grid-template-columns: 1.25rem minmax(0, 1fr) auto 4rem;
  }

  .cx-table__spark-col {
    display: none;
  }

  .cx-coin__sym {
    display: none;
  }

  .cx-movers {
    padding: var(--space-4);
  }

  .cx-movers__list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .cx-tabs__btn {
    transition: none;
  }
}
