/* ════════════════════════════════════════════════════════════════════
   Funding Scanner page.
   ───────────────────────────────────────────────────────────────────
   Visual cousin of Token DD: same snake-border progress chrome on the
   search/filter card (re-uses .tdd-snake-border + .tdd-snake-fill so
   nothing about that animation differs between pages), the same card
   background tokens, the same numeric font in the results table.
   ════════════════════════════════════════════════════════════════════ */

/* ── Search/filter card ─────────────────────────────────────────────── */
.fsc-search-card {
  position: relative;
  /* Clip horizontal overflow as a safety net — the snake border SVG
     extends slightly past the card via its drop-shadow filter, but
     any content overflow (long labels, wide inputs) gets contained
     so nothing pushes past the viewport on mobile. */
  overflow-x: clip;
}

.fsc-filters {
  display: grid;
  /* On wide viewports, fit as many ~180px columns as possible. On mobile
     (≤ ~340px after the card padding), `minmax(min(180px, 100%), 1fr)`
     drops to one column at full width so the prefix + input chip stops
     overflowing horizontally. The `min(180px, 100%)` form is the
     standard CSS-grid mobile-safe pattern. */
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: 14px 16px;
  margin-top: 14px;
}
.fsc-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  font-size: 12px;
  min-width: 0;
}
.fsc-field-input { min-width: 0; }
.fsc-field-label {
  color: var(--muted-foreground);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 10.5px;
}
.fsc-field-input {
  display: flex;
  align-items: stretch;
  gap: 4px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
  font-family: 'Geist Mono', monospace;
}
.fsc-field-input:focus-within {
  border-color: var(--foreground);
  box-shadow: 0 0 0 2px rgba(127,127,127,.15);
}
.fsc-field-input input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--foreground);
  font: inherit;
  font-size: 14px;
  min-width: 0;
}
.fsc-field-prefix, .fsc-field-suffix {
  color: var(--muted-foreground);
  font-size: 13px;
  align-self: center;
  padding: 0 2px;
}
.fsc-field-hint {
  color: var(--muted-foreground);
  font-size: 11px;
  font-style: italic;
}

.fsc-venues {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.fsc-venues-label {
  color: var(--muted-foreground);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-right: 4px;
}
/* Venue chips — picker/filter row at the top of the search card. The
   visual is the same rounded-square brand logo + name pair Token DD
   uses on its CEX coverage card (via cexBadge()), wrapped in a
   pill-shaped chip with checkbox state. The native checkbox is hidden
   off-screen but stays focusable; the chip itself acts as the click
   target via the wrapping <label>. --vc is the per-venue brand color
   (set on the chip from JS) and drives the on-state border/halo. */
.fsc-venue-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  /* Symmetric horizontal padding (12px L/R) so the logo's leading edge
     and the time pill's trailing edge sit equidistant from the chip's
     rounded sides. The badge itself doesn't need extra inset — the
     `tdd-cex-logo-wrap` already provides a 1px border that visually
     separates the logo from the chip background. */
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-elevated);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: background-color 100ms ease-out, border-color 100ms ease-out, opacity 100ms ease-out, box-shadow 100ms ease-out;
}
/* Hide the native checkbox visually but keep it in the focus order so
   keyboard users can tab through and toggle with space. */
.fsc-venue-chip input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.fsc-venue-chip:hover {
  background: color-mix(in srgb, var(--vc, var(--foreground)) 8%, var(--surface-elevated));
}
.fsc-venue-chip:has(input:checked) {
  border-color: color-mix(in srgb, var(--vc, var(--foreground)) 55%, transparent);
}
.fsc-venue-chip:has(input:focus-visible) {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--vc, var(--foreground)) 35%, transparent);
}
.fsc-venue-chip:has(input:not(:checked)) {
  opacity: 0.45;
  border-style: dashed;
}
.fsc-venue-chip:has(input:not(:checked)):hover { opacity: 0.7; }

/* The injected cexBadge content — already styled by tdd-cex-* rules in
   tokendd.css. We just need to make sure the inline-flex baseline
   aligns with the time pill at the right edge. */
.fsc-venue-chip-content { display: inline-flex; align-items: center; }

/* Per-venue time badge — rendered inline at the right edge of each chip
   so the user sees relative cost (~0.6s vs ~5s) at a glance. JS fills
   the textContent on bind from the empirical VENUE_COSTS table. */
.fsc-venue-time {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--muted-foreground);
  padding: 1px 5px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--vc, var(--foreground)) 10%, transparent);
  font-variant-numeric: tabular-nums;
}

.fsc-search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.fsc-actions { display: flex; gap: 8px; align-items: center; }
.fsc-actions .ghost { font-size: 12px; }
/* Disabled run button — shown when no venues are checked. The base
   .primary class doesn't define a disabled state, so we lower opacity +
   neutralize hover here. */
.fsc-actions .primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

/* Live total estimate near the Run button — sits between actions and
   status. Updates whenever a venue toggles. The number is intentionally
   shown bold so it reads at a glance; the surrounding text + the
   "selected venues" caption stay muted. */
.fsc-time-total {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.fsc-time-total strong {
  color: var(--foreground);
  font-weight: 600;
  font-family: 'Geist Mono', monospace;
}
.fsc-time-total.is-warn { color: #e57373; }

/* Share-URL row chrome lives in components/inputs.css under the shared
   .share-url-row / .share-url-input / .share-url-copy classes. The
   Backtest, Token DD, and Funding Scanner cards all reuse those styles
   verbatim — no per-page overrides needed here. */

/* Mobile (≤ 720px) — stack the search row vertically so the Run +
   Reset buttons, the live time estimate, and the status text don't
   compete for one cramped row. The venue chip strip already wraps via
   flex-wrap; we just need to give it some breathing room and shrink
   the inputs to one column. */
@media (max-width: 720px) {
  .fsc-search-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .fsc-time-total { text-align: left; flex: 0 0 auto; }
  .fsc-actions { width: 100%; }
  .fsc-actions .primary { flex: 1; }
  /* Per-venue time pill ends up on its own line on narrow widths once
     the chip exceeds available space — let the chip wrap so the logo
     and pill don't get clipped at the right edge. */
  .fsc-venue-chip { flex-wrap: wrap; row-gap: 2px; }
}

/* ── Live progress card ─────────────────────────────────────────────── */
.fsc-progress-card {
  padding-bottom: 14px;
  /* The card hosts an inline SVG snake-border overlay; it needs to be
     the positioning context so the absolute-positioned SVG fills it. */
  position: relative;
  /* Same overflow-clip as the search card — prevents the per-task bars
     and long log lines from escaping the card's right edge on mobile. */
  overflow-x: clip;
}

/* Top-right elapsed/estimated counter — anchored in the card title row.
   Driven by the same elapsed/estimated ratio that drives the snake
   fill, so the user reads one consistent answer to "how close to done?". */
.fsc-elapsed-counter {
  margin-left: auto;
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--foreground) 6%, transparent);
}
.fsc-elapsed-counter .fsc-elapsed-est { color: var(--foreground); }
.fsc-elapsed-counter .fsc-elapsed-sep { opacity: 0.5; margin: 0 1px; }
/* Once we cross the estimate, tint the counter so the user sees the
   scan is running long. The snake stays at 98% until completion. */
.fsc-elapsed-counter.is-over {
  background: color-mix(in srgb, #f29c4f 22%, transparent);
  color: #f29c4f;
}
.fsc-elapsed-counter.is-over .fsc-elapsed-est { color: #f29c4f; }

.fsc-tasks {
  display: grid;
  /* Cap the column at parent width regardless of children's intrinsic
     min-content. Without this, the long "Fetching 30D funding history
     (per token)" label inside a child sets the implicit grid track to
     its intrinsic width and drags the whole card past the viewport on
     mobile (the bar then renders flush with that overflowed width). */
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin: 8px 0 12px;
}
.fsc-task {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  min-width: 0;
}
.fsc-task-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  font-family: 'Geist Mono', monospace;
  /* min-width:0 mirrors the same fix one level up — the head is a flex
     row inside a grid item; without it the elapsed/counter on the
     right + the wrapped label can still stretch the row. */
  min-width: 0;
}
.fsc-task-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsc-task-counter { color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.fsc-task-cur { color: var(--foreground); }
.fsc-task-elapsed { font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }

.fsc-task-bar {
  height: 5px;
  border-radius: 3px;
  background: rgba(127,127,127,.16);
  overflow: hidden;
}
.fsc-task-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f29c4f, #3eb489);
  transition: width 200ms ease-out;
  border-radius: 3px;
}
.fsc-task.is-done .fsc-task-bar-fill { background: #3eb489; }
.fsc-task.is-done .fsc-task-label { color: var(--muted-foreground); }

.fsc-log {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  height: 220px;
  overflow-y: auto;
  font-family: 'Geist Mono', monospace;
  font-size: 11.5px;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.fsc-log::-webkit-scrollbar { width: 8px; }
.fsc-log::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }

.fsc-log-row {
  display: grid;
  grid-template-columns: 56px 14px 1fr;
  gap: 6px;
  align-items: baseline;
}
.fsc-log-ts { font-size: 10.5px; }
.fsc-log-glyph { text-align: center; font-weight: 600; }
.fsc-log-msg { word-break: break-word; }
.fsc-log-ok    .fsc-log-glyph { color: #3eb489; }
.fsc-log-err   .fsc-log-glyph { color: #e57373; }
.fsc-log-warn  .fsc-log-glyph { color: #f29c4f; }
.fsc-log-phase .fsc-log-glyph { color: var(--foreground); }
.fsc-log-phase .fsc-log-msg   { color: var(--foreground); font-weight: 600; }
.fsc-log-info  .fsc-log-glyph { color: var(--muted-foreground); }

/* ── Results card ───────────────────────────────────────────────────── */
.fsc-results-card { padding-bottom: 12px; }

.fsc-results-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 8px;
}
.fsc-results-search {
  flex: 1;
  max-width: 280px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--foreground);
  font-family: inherit;
  outline: none;
  transition: border-color 100ms ease-out;
}
.fsc-results-search:focus { border-color: var(--foreground); }

.fsc-results-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.fsc-results-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Geist Mono', monospace;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.fsc-results-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-elevated);
  font-weight: 600;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.fsc-results-table thead th[data-sort]::after {
  content: ' ▾';
  color: transparent;
  margin-left: 2px;
  font-size: 10px;
}
.fsc-results-table thead th.is-sort-desc::after { color: var(--foreground); content: ' ▾'; }
.fsc-results-table thead th.is-sort-asc::after  { color: var(--foreground); content: ' ▴'; }

.fsc-results-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.fsc-results-table tbody tr:last-child td { border-bottom: 0; }
/* Numeric columns — both header AND body cells align right so the
   header label sits flush above its column of values. The selectors
   below need to outrank the broader `.fsc-results-table thead th`
   text-align:left rule above, hence the table-scoped selector. */
.fsc-results-table thead th.fsc-th-num,
.fsc-results-table tbody td.fsc-td-num { text-align: right; }
.fsc-results-table thead th.fsc-th-venues,
.fsc-results-table tbody td.fsc-td-venues { text-align: left; }

.fsc-row {
  cursor: pointer;
  transition: background-color 90ms ease-out;
}
.fsc-row:hover { background: rgba(127,127,127,.08); }
.fsc-row:focus-visible {
  outline: 2px solid var(--foreground);
  outline-offset: -2px;
}

/* Token cell — wrapper is inline-flex inside a vanilla <td> so the table's
   own vertical-align logic still works on the row. Putting display:flex on
   the <td> itself made the row collapse and dropped the icon out of
   alignment with the data cells. */
.fsc-td-token { font-family: 'Geist Mono', monospace; }
.fsc-token-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.fsc-token-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-elevated);
  color: var(--ticker-color, var(--foreground));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: 0 0 22px;
  position: relative;
  border: 1px solid var(--border);
}
.fsc-token-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 50%;
}
.fsc-token-icon-fallback {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ticker-color, var(--muted-foreground));
}
.fsc-token-icon[data-painted] {
  background: transparent;
  border-color: transparent;
}
.fsc-token-icon[data-painted] .fsc-token-icon-fallback { display: none; }

/* Token text block — name (small muted, above) + ticker (bold, below).
   Both are inline-flex stacked so the ticker stays vertically centred
   when the name is empty (uniform row height across with-name and
   without-name rows). */
.fsc-token-text {
  display: inline-flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  line-height: 1.15;
}
.fsc-token-name {
  font-size: 9.5px;
  color: var(--muted-foreground);
  font-weight: 500;
  font-family: var(--font-sans, system-ui, sans-serif);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fsc-token-name:empty { display: none; }
.fsc-token-sym { font-weight: 700; }
.fsc-token-arrow {
  color: var(--muted-foreground);
  font-size: 14px;
  opacity: 0;
  transition: opacity 90ms ease-out, transform 90ms ease-out;
}
.fsc-row:hover .fsc-token-arrow { opacity: 1; transform: translateX(2px); }

.fsc-funding, .fsc-apr {
  font-weight: 600;
}
.fsc-pos    { color: #3eb489; }
/* Previously missing — every scanner's negative-funding column was
   silently inheriting body color. Adding the matching red completes
   the pos/neg pair so funding, APR, PnL, and current-funding columns
   read green/red consistently across all three scanners. */
.fsc-neg    { color: #e57373; }
.fsc-neutral { color: var(--foreground); }
.fsc-mild   { color: var(--muted-foreground); }
.fsc-pnl.pos { color: #3eb489; font-weight: 600; }
.fsc-pnl.neg { color: #e57373; font-weight: 600; }
/* PnL cell — amount + venue logo on the same line, right-aligned. The
   logo signals which venue the backtest was actually run on (highest
   30D funding among OI-eligible venues). */
.fsc-pnl-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.fsc-pnl-venue { display: inline-flex; align-items: center; }
.fsc-pnl-venue .tdd-cex-logo-wrap {
  width: 16px;
  height: 16px;
  border-radius: 3px;
}
.fsc-px.pos  { color: #3eb489; }
.fsc-px.neg  { color: #e57373; }
.fsc-px.muted { color: var(--muted-foreground); }

/* Venues cell — inline-flex wrapper inside a vanilla <td>. flex-wrap
   contains the chips inside the cell instead of overflowing into the
   neighbouring cell on a wrap (which is what made the spot-venues column
   look "empty" while the perp cell appeared to bleed two rows tall). */
.fsc-td-venues { vertical-align: middle; }
.fsc-venues-cell {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
  max-width: 100%;
  vertical-align: middle;
}
/* Per-row venue tag in the results table — just the rounded-square
   brand logo (no label). The rounded-square wrapper from cexBadge has
   its own 1px border, which is enough; we don't add an outer ring. */
.fsc-venue-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* Default size — 18px squares fit two columns of venues without
   bloating row height the way the 24px coverage-card squares would. */
.fsc-venue-tag .tdd-cex-logo-wrap {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}
/* Primary venue — just larger, no border treatment. The size step alone
   reads as "this is the dominant venue" without adding any ring or
   recoloring that would clash with the brand mark inside. */
.fsc-venue-pri .tdd-cex-logo-wrap {
  width: 24px;
  height: 24px;
  border-radius: 5px;
}
.fsc-pri-sep { color: var(--muted-foreground); margin: 0 4px; align-self: center; }

/* Per-venue brand color — same source values as CEX_META.color in
   public/js/core/cex-meta.js. Set on every venue tag + picker chip so
   color-mix() in the rules above gets the right tint. Matches Token
   DD's accent treatment. */
.fsc-venue-binance     { --vc: #F0B90B; }
.fsc-venue-bybit       { --vc: #F7A600; }
.fsc-venue-okx         { --vc: var(--foreground); }
.fsc-venue-hyperliquid { --vc: #50D2C1; }
.fsc-venue-lighter     { --vc: var(--foreground); }
.fsc-venue-bitget      { --vc: #00F0FF; }

/* Stock Basis Scanner specifics. The Sources column on its results
   table pairs the brand badge with a secondary label (the HIP-3
   builder name, or "main" / "Bybit" for the non-HIP-3 rows). This
   sits inside the same .fsc-venues-cell wrapper crypto rows use, so
   the only extra rule is a muted monospace tag for the label. */
.fsc-venue-label {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* The stock token cell has no resolved logo (no Yahoo/Finnhub icon
   feed). Keep the rounded square but soften it — a faint border + the
   first two letters of the ticker, centered. The flat treatment makes
   it visibly distinct from a crypto row that's still resolving its
   icon (which paints with a dashed --ticker-color border). */
.fsc-token-icon--stock {
  background: color-mix(in srgb, var(--foreground) 6%, transparent);
  border-color: color-mix(in srgb, var(--foreground) 20%, transparent);
}
.fsc-token-icon--stock .fsc-token-icon-fallback {
  font-size: 10px;
  font-weight: 700;
  color: var(--foreground);
  letter-spacing: 0.02em;
}

/* "Tokens that just missed the cut" expandable list. */
.fsc-missing { margin-top: 12px; }
.fsc-missing summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted-foreground);
  padding: 4px 0;
}
.fsc-missing summary:hover { color: var(--foreground); }
.fsc-missing-list {
  margin: 4px 0 0;
  padding: 6px 12px;
  list-style: disc;
  background: var(--surface-elevated);
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Geist Mono', monospace;
  max-height: 180px;
  overflow-y: auto;
}
.fsc-missing-list li { margin: 2px 0; }
.fsc-missing-base { font-weight: 700; }

/* Earn Scanner specifics — the Verify column links out to the venue's
   Earn section. Muted until the row is hovered so the table doesn't read
   as a wall of links; underline only on link hover (it IS a link, the
   arrow already signals it). */
.fsc-th-verify,
.fsc-td-verify { text-align: right; }
.ern-verify-link {
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
}
.fsc-row:hover .ern-verify-link { color: var(--foreground); }
.ern-verify-link:hover { text-decoration: underline; }
