/* ============================================================================
   sma-terminal.css — Smart Money API data-page terminal kit (tk-*)
   ----------------------------------------------------------------------------
   Shared component layer for the DATA & CHART pages (screener, options, ETF,
   onchain, mood, historical, heatmap, news, swaps, performance).
   Design goals, in priority order:
     1. Most decision-relevant info above the fold — compact command header,
        KPI ribbon, hero visualization.
     2. Purposeful density — hairline separators instead of padding walls.
     3. Readability — tabular/mono numerals, right-aligned figures, ≥4.5:1.
     4. Progressive disclosure — educational prose folds into .tk-guide.
   Every class is namespaced `tk-` so nothing leaks into non-adopting pages.
   Tokens bridge to theme-aura.css / theme.js vars with dark fallbacks.
   ============================================================================ */

:root {
  /* Obsidian & Brass — coherent with the global nav.js v82 design system.
     Backgrounds obsidian ink; BRASS is the editorial/location accent (labels,
     KPI accents, column heads, active markers) — NEVER a button color.
     Blue stays interactive-only. Green/red = data direction ONLY. */
  --tk-bg: var(--bg-primary, #07090c);
  --tk-bg-2: #0c0f16;
  --tk-panel: rgba(255, 255, 255, 0.012);
  --tk-panel-hi: rgba(255, 255, 255, 0.035);
  --tk-line: rgba(148, 163, 184, 0.14);      /* hairline, no blur */
  --tk-line-soft: rgba(148, 163, 184, 0.07); /* inner rules */
  --tk-line-strong: rgba(148, 163, 184, 0.22);
  --tk-text: var(--text-primary, #f1f5f9);
  --tk-text-2: var(--text-secondary, #94a3b8);
  --tk-text-3: #64748b;
  --tk-text-4: #475569;
  /* Brass accent (from the logo candles) */
  --tk-gold: var(--sma-gold, #c9a96a);
  --tk-gold-bright: #e2c894;
  --tk-gold-06: rgba(201, 169, 106, 0.06);
  --tk-gold-12: rgba(201, 169, 106, 0.12);
  --tk-gold-25: rgba(201, 169, 106, 0.25);
  --tk-gold-45: rgba(201, 169, 106, 0.45);
  /* brand = editorial/location accent → brass (labels, ticks, active heads) */
  --tk-brand: var(--sma-gold, #c9a96a);
  /* blue = interactive only (links/buttons/focus) */
  --tk-interactive: #3d81e3;
  --tk-cyan: #22d3ee;
  --tk-up: #34d399;      /* data-up only */
  --tk-down: #f87171;    /* data-down only */
  --tk-warn: #fbbf24;    /* caution only */
  --tk-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --tk-ease: cubic-bezier(.2, .8, .2, 1);
}

/* Light / editorial themes: raise the hairlines + panel fills so the kit
   stays visible when theme.js flips --bg-primary to a pale background. */
[data-theme="light"], [data-theme="editorial"] {
  --tk-panel: rgba(15, 23, 42, 0.03);
  --tk-panel-hi: rgba(15, 23, 42, 0.055);
  --tk-line: rgba(15, 23, 42, 0.14);
  --tk-line-soft: rgba(15, 23, 42, 0.07);
  --tk-line-strong: rgba(15, 23, 42, 0.22);
  --tk-text-3: #475569;
  --tk-text-4: #64748b;
  --tk-gold: #a07d3c;
  --tk-brand: #a07d3c;
}

/* ── Command header ───────────────────────────────────────────────────────── */
.tk-head {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  justify-content: space-between; gap: 8px 16px;
  padding-bottom: 12px; margin-bottom: 14px;
  border-bottom: 1px solid var(--tk-line);
}
.tk-head-eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--tk-gold); margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
/* leading brass tick on eyebrows + section labels */
.tk-head-eyebrow::before {
  content: ''; width: 14px; height: 1.5px; background: var(--tk-gold);
  display: inline-block; flex: none; border-radius: 1px;
}
.tk-head h1 {
  font-size: clamp(20px, 2.6vw, 27px); font-weight: 800;
  letter-spacing: -0.02em; line-height: 1.1; margin: 0;
  color: var(--tk-text);
}
.tk-head-sub { font-size: 12px; color: var(--tk-text-3); margin-top: 4px; max-width: 68ch; }
.tk-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tk-status .tk-clock { font-family: var(--tk-mono); font-size: 11px; color: var(--tk-text-4); font-variant-numeric: tabular-nums; }

/* live / demo pills */
.tk-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.tk-pill-live { background: rgba(52, 211, 153, 0.1); color: #34d399; border: 1px solid rgba(52, 211, 153, 0.25); }
.tk-pill-demo { background: rgba(251, 191, 36, 0.1); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.25); }
.tk-pill-dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
/* Tailwind's .hidden loads BEFORE this sheet — restate so JS toggles still work */
.tk-pill.hidden, .tk-kpi.hidden, .tk-panel-card.hidden, .tk-guide.hidden { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .tk-pill-live .tk-pill-dot { animation: tk-pulse 2s ease-in-out infinite; }
  @keyframes tk-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
}

/* ── KPI ribbon (above the fold) ──────────────────────────────────────────── */
.tk-ribbon {
  display: grid; gap: 0;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  border: 1px solid var(--tk-line); border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.012));
  overflow: hidden; margin-bottom: 14px;
}
/* thin brass top rule on the ribbon — reads as a premium instrument */
.tk-ribbon { position: relative; }
.tk-ribbon::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--tk-gold-45), transparent);
  pointer-events: none;
}
.tk-kpi {
  position: relative; padding: 12px 14px 11px; min-width: 0;
  border-left: 1px solid var(--tk-line);
}
.tk-kpi:first-child { border-left: none; }
/* when the auto-fit grid wraps to a new row, draw a top hairline */
.tk-kpi { border-top: 1px solid var(--tk-line); margin-top: -1px; }
.tk-kpi-label {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--tk-text-4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tk-kpi-value {
  font-family: var(--tk-mono); font-variant-numeric: tabular-nums;
  font-size: 19px; font-weight: 700; color: var(--tk-text);
  line-height: 1.25; margin-top: 2px; letter-spacing: -0.01em;
  white-space: nowrap;
}
.tk-kpi-value.tk-sm { font-size: 15px; }
.tk-kpi-sub {
  font-size: 10px; color: var(--tk-text-4); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tk-kpi-spark { position: absolute; right: 10px; bottom: 9px; width: 64px; height: 22px; opacity: 0.9; }
.tk-kpi .tk-delta { margin-left: 6px; }

/* delta chips */
.tk-delta {
  display: inline-block; font-family: var(--tk-mono); font-variant-numeric: tabular-nums;
  font-size: 10.5px; font-weight: 600; padding: 0 5px; border-radius: 4px; line-height: 16px;
  vertical-align: 2px;
}
.tk-delta-up { color: var(--tk-up); background: rgba(52, 211, 153, 0.1); }
.tk-delta-down { color: var(--tk-down); background: rgba(248, 113, 113, 0.1); }
.tk-delta-flat { color: var(--tk-text-3); background: rgba(148, 163, 184, 0.1); }

/* ── Panels ───────────────────────────────────────────────────────────────── */
.tk-panel-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.012));
  border: 1px solid var(--tk-line); border-radius: 14px;
}
@media (max-width: 640px) { .tk-panel-card { border-radius: 10px; } }
.tk-panel-hd {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--tk-line);
}
.tk-panel-hd h2, .tk-panel-hd h3 {
  font-size: 12px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--tk-text-2); margin: 0;
}
.tk-panel-hd .tk-meta { font-size: 10.5px; color: var(--tk-text-4); margin-left: auto; font-family: var(--tk-mono); font-variant-numeric: tabular-nums; }
.tk-panel-bd { padding: 12px 14px; }
.tk-panel-bd.tk-flush { padding: 0; }

/* ── Dense data table ─────────────────────────────────────────────────────── */
.tk-scroll { overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.tk-scroll::-webkit-scrollbar { height: 5px; }
.tk-scroll::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 3px; }

.tk-table { width: 100%; border-collapse: collapse; }
.tk-table th {
  position: sticky; top: 0; z-index: 2;
  background: #111318; /* solid — sticky headers can't be translucent */
  padding: 7px 10px; text-align: right;
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--tk-text-4); white-space: nowrap;
  border-bottom: 1px solid var(--tk-line-strong);
  user-select: none;
}
[data-theme="light"] .tk-table th, [data-theme="editorial"] .tk-table th { background: #eef0f4; }
.tk-table th.tk-left, .tk-table td.tk-left { text-align: left; }
.tk-table th[data-sort] { cursor: pointer; transition: color 0.18s var(--tk-ease); }
.tk-table th[data-sort]:hover { color: var(--tk-text-2); }
.tk-table th.tk-sort-active, .tk-table th.sort-active { color: var(--tk-gold); }
.tk-table td {
  padding: 6px 10px; text-align: right; white-space: nowrap;
  font-family: var(--tk-mono); font-variant-numeric: tabular-nums;
  font-size: 12px; color: var(--tk-text-2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
}
[data-theme="light"] .tk-table td, [data-theme="editorial"] .tk-table td { border-bottom-color: rgba(15, 23, 42, 0.06); }
.tk-table td.tk-left { font-family: 'Inter', sans-serif; }
.tk-table tbody tr:hover td { background: var(--tk-gold-06); }
.tk-table tbody tr:last-child td { border-bottom: none; }
.tk-table .tk-num-strong { color: var(--tk-text); font-weight: 600; }
.tk-up-c { color: var(--tk-up) !important; }
.tk-down-c { color: var(--tk-down) !important; }
.tk-warn-c { color: var(--tk-warn) !important; }

/* sticky first column (symbol) for mobile scanning */
.tk-table .tk-sticky-col { position: sticky; left: 0; z-index: 1; background: var(--tk-bg); }
.tk-table th.tk-sticky-col { z-index: 3; }
.tk-table tbody tr:hover .tk-sticky-col { background: #101623; }
[data-theme="light"] .tk-table .tk-sticky-col, [data-theme="editorial"] .tk-table .tk-sticky-col { background: var(--bg-primary, #f8fafc); }

/* in-cell meter: value sits above a thin signed bar */
.tk-meter { position: relative; display: block; height: 3px; margin-top: 3px; border-radius: 2px; background: rgba(148, 163, 184, 0.12); overflow: hidden; }
.tk-meter > i { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.tk-meter-c { left: 50%; }                    /* centered signed bar grows from middle */
.tk-meter-c.neg { left: auto; right: 50%; }

/* split long/short bar */
.tk-split { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: rgba(148, 163, 184, 0.12); min-width: 70px; }
.tk-split > i:first-child { background: var(--tk-cyan); }
.tk-split > i:last-child { background: var(--tk-down); }

/* ── Guide: progressive disclosure for explanatory prose ─────────────────── */
.tk-guide {
  border: 1px solid var(--tk-line); border-radius: 12px;
  background: var(--tk-panel); margin-bottom: 14px;
}
.tk-guide > summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 14px; list-style: none;
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--tk-text-3); border-radius: 12px;
  transition: color 0.15s;
}
.tk-guide > summary:hover { color: var(--tk-text-2); }
.tk-guide > summary::-webkit-details-marker { display: none; }
.tk-guide > summary::before {
  content: ''; width: 7px; height: 7px; flex: none;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.18s; margin-top: -2px;
}
.tk-guide[open] > summary::before { transform: rotate(45deg); margin-top: -4px; }
.tk-guide[open] > summary { border-bottom: 1px solid var(--tk-line); border-radius: 12px 12px 0 0; }
.tk-guide-bd { padding: 12px 16px 14px; font-size: 12.5px; line-height: 1.65; color: var(--tk-text-2); }
.tk-guide-bd h3, .tk-guide-bd h4 { color: var(--tk-text); font-size: 12.5px; font-weight: 600; margin: 0 0 4px; }
.tk-guide-bd p { margin: 0 0 8px; }
.tk-guide-bd p:last-child { margin-bottom: 0; }
.tk-guide-grid { display: grid; gap: 12px 20px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

/* ── Segmented tabs ───────────────────────────────────────────────────────── */
.tk-tabs { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--tk-line); border-radius: 9px; background: rgba(0, 0, 0, 0.25); }
[data-theme="light"] .tk-tabs, [data-theme="editorial"] .tk-tabs { background: rgba(15, 23, 42, 0.05); }
.tk-tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-size: 11px; font-weight: 600; color: var(--tk-text-3);
  padding: 4px 12px; border-radius: 7px; transition: color 0.15s, background 0.15s;
  font-family: inherit;
}
.tk-tab:hover { color: var(--tk-text-2); }
.tk-tab.active { background: rgba(61, 129, 227, 0.16); color: #8fb8f5; }
.tk-tab:focus-visible { outline: 2px solid var(--tk-interactive); outline-offset: 1px; }

/* ── Chips / badges ───────────────────────────────────────────────────────── */
.tk-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 5px; white-space: nowrap;
}
.tk-chip-up    { background: rgba(52, 211, 153, 0.12); color: #4ade80; border: 1px solid rgba(52, 211, 153, 0.25); }
.tk-chip-down  { background: rgba(248, 113, 113, 0.12); color: #f87171; border: 1px solid rgba(248, 113, 113, 0.25); }
.tk-chip-warn  { background: rgba(251, 191, 36, 0.12); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.25); }
.tk-chip-info  { background: var(--tk-gold-12); color: var(--tk-gold-bright); border: 1px solid var(--tk-gold-25); }
.tk-chip-mute  { background: rgba(148, 163, 184, 0.08); color: #94a3b8; border: 1px solid rgba(148, 163, 184, 0.18); }

/* ── Heat cells (funding heatmap, matrices) ───────────────────────────────── */
.tk-heat {
  display: flex; align-items: center; justify-content: center;
  height: 30px; border-radius: 5px;
  font-family: var(--tk-mono); font-variant-numeric: tabular-nums;
  font-size: 10px; font-weight: 600; cursor: default;
  transition: filter 0.12s, transform 0.12s;
}
.tk-heat:hover { filter: brightness(1.35); }
@media (prefers-reduced-motion: no-preference) { .tk-heat:hover { transform: scale(1.04); } }

/* ── Layout helpers ───────────────────────────────────────────────────────── */
.tk-grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
.tk-grid-3 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .tk-grid-2 { grid-template-columns: 1fr 1fr; }
  .tk-grid-3 { grid-template-columns: repeat(3, 1fr); }
}
.tk-caption { font-size: 10.5px; color: var(--tk-text-4); line-height: 1.5; }
.tk-hair { border: 0; border-top: 1px solid var(--tk-line); margin: 14px 0; }

/* rank rows (top gainers / losers) */
.tk-rank { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.035); font-size: 12px; }
.tk-rank:last-child { border-bottom: none; }
.tk-rank .tk-rank-n { font-family: var(--tk-mono); font-size: 10px; color: var(--tk-text-4); width: 16px; flex: none; }
.tk-rank .tk-rank-sym { font-weight: 600; color: var(--tk-text); width: 62px; flex: none; }
.tk-rank .tk-rank-bar { flex: 1; height: 4px; border-radius: 2px; background: rgba(148, 163, 184, 0.1); overflow: hidden; }
.tk-rank .tk-rank-bar > i { display: block; height: 100%; border-radius: 2px; }
.tk-rank .tk-rank-val { font-family: var(--tk-mono); font-variant-numeric: tabular-nums; font-size: 11.5px; font-weight: 600; width: 76px; text-align: right; flex: none; }

/* focus ring for interactive kit elements — blue = interactive */
.tk-guide > summary:focus-visible, .tk-table th[data-sort]:focus-visible {
  outline: 2px solid var(--tk-interactive); outline-offset: 1px; border-radius: 6px;
}

/* keep every wide thing inside its own scroller — never the page */
.tk-ribbon, .tk-panel-card { min-width: 0; max-width: 100%; }
