/* ════════════════════════════════════════════════════════════════════
   Backtest tab — config form, KPI grid, sweep / optimal layouts, weekly table
   ════════════════════════════════════════════════════════════════════ */

.bt-config {
  padding-bottom: 16px;
  /* Positioning context for the .tdd-snake-border SVG overlay (the
     loading wrap that traces the card perimeter during a backtest). */
  position: relative;
}
/* Form layout: vertical stack of logical sections (Token / Vesting /
   Deal terms / Backtest config). Each section pairs a small Lucide
   header with a horizontal row of fields, so the user reads top-to-
   bottom in deal-flow order and like-to-like inputs sit shoulder-to-
   shoulder. The previous flat 6-column grid put unrelated fields
   (e.g. Hedge next to Discount next to Size) at equal visual weight
   and forced the user to scan a 6-by-2 matrix to find what they
   wanted to tweak. */
.bt-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.bt-form-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bt-form-section-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-foreground);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.bt-form-section-header svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
}
.bt-form-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 16px;
  /* Top-align cells so the LABELS share a baseline across the row.
     With `end` alignment, a cell carrying a hint (e.g. Hedge's
     "single + sweep cards") was taller than its siblings, which
     pushed its label + input up while everyone else's stayed pinned
     to the bottom — the row read crooked. With `start` alignment all
     labels sit at row 1, inputs at row 2, and the hint hangs below
     Hedge without shifting the others. The Run button's `&nbsp;`
     label keeps its row-1 spacer so the button itself still drops
     into row 2 alongside the other inputs. */
  align-items: start;
}

/* Field cell — label on top, bordered input below, optional hint
   text. Mirrors the funding scanner's `.fsc-field*` pattern (same
   border-radius, padding, focus-within ring) so the two surfaces
   read as the same design system. */
.bt-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bt-field > label {
  color: var(--muted-foreground); font-size: 10px;
  text-transform: uppercase; letter-spacing: .1em; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
}
/* The 14px default hint is too tall next to a 10px uppercase label —
   shrink so the glyph sits visually centered with the caps. */
.bt-field > label .hint {
  width: 11px; height: 11px; font-size: 8px;
}
/* Card-title hint — slightly smaller than default so it doesn't
   visually outweigh the title text it sits next to. */
.bt-results .card-title .hint,
.bt-config .card-title .hint {
  width: 13px; height: 13px; font-size: 9px;
  margin-left: 2px;
  vertical-align: middle;
}
/* KPI-tile label hint — labels are 12px, glyph at 12px reads cleanly. */
.bt-kpi-grid .kpi-label .hint {
  width: 12px; height: 12px; font-size: 8px;
  margin-left: 4px;
  vertical-align: 1px;
}
/* Funding pill row — small label inline with the row, hint matches. */
.bt-venues .bt-venues-label .hint {
  width: 11px; height: 11px; font-size: 8px;
  margin-left: 4px;
}
.bt-field-input {
  display: flex;
  align-items: stretch;
  gap: 4px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
  font-family: var(--font-mono);
}
.bt-field-input:focus-within {
  border-color: var(--ring, var(--foreground));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--foreground) 12%, transparent);
}
.bt-field-input input,
.bt-field-input select {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--foreground);
  font: inherit;
  font-size: 13px;
  min-width: 0;
  padding: 4px 2px;
}
.bt-field-input select { cursor: pointer; }
.bt-field-input--select { padding-right: 4px; }
.bt-field-prefix, .bt-field-suffix {
  color: var(--muted-foreground);
  font-size: 12px;
  font-family: var(--font-mono);
  align-self: center;
  padding: 0 2px;
  user-select: none;
}
.bt-field-hint {
  color: var(--muted-foreground);
  font-size: 10px;
  font-family: var(--font-mono);
  font-style: italic;
}

/* Ticker badge — same Token DD search styling, just bigger so it
   reads as the form's primary anchor. The shared `.ticker-badge`
   rules in deals.css already do the colored input + grayed symbol
   typography; we only override sizes here. */
.bt-ticker-badge {
  padding: 8px 12px;
  gap: 10px;
  align-self: flex-start;
  /* Shared CSS variable picked up by `.ticker-input` — colored uppercase
     ticker text. Updated from JS via `setProperty('--ticker-color', ...)`
     whenever the ticker changes. */
}
.bt-ticker-badge .ticker-input {
  width: 140px;
  font-size: 18px;
}
.bt-ticker-badge .symbol-arrow {
  font-size: 16px;
}
.bt-ticker-badge .symbol-input {
  width: 140px;
  font-size: 13px;
}

.bt-actions { align-self: stretch; }
.bt-actions button { width: 100%; padding: 8px 14px; }
.bt-status { margin-top: 12px; padding: 8px 12px; border-radius: var(--radius); min-height: 18px; }
.bt-status.error   { color: var(--loss);       background: rgba(228,0,20,.06); border: 1px solid rgba(228,0,20,.25); }
.bt-status.loading { color: var(--status-dev); }
.bt-status.ok      { color: var(--profit); }

.bt-kpi-grid { grid-template-columns: repeat(4, 1fr); }
.bt-summary-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
/* Same min-width:0 guard as chart-grid — without it, wide tables inside
   the summary cards push the grid past the viewport. */
.bt-summary-grid > *,
.bt-optimal-charts > * { min-width: 0; min-height: 0; }

table.bt-table { width: 100%; }
table.bt-table td { padding: 8px 12px; border-bottom: 1px solid rgba(22,22,22,.4); font-size: 12px; }
table.bt-table td:first-child { color: var(--muted-foreground); width: 55%; }
table.bt-table td:last-child  { text-align: right; font-family: var(--font-mono); color: var(--foreground); }

/* Sit the stats table with breathing room on both sides — pushes it down
   away from the card title and adds whitespace to the chart below so its
   top-edge "In Cliff →" / "Vesting →" labels aren't crowded by the table. */
.bt-sweep-stats { margin-top: 8px; margin-bottom: 28px; }

/* Sweep average summary row visually separated from the per-scenario rows
   above by a subtle top border. */
#bt-sweep-table .bt-sweep-summary > td {
  border-top: 1px solid var(--border-strong);
  background: var(--surface-tinted, transparent);
}

/* Optimal hedge sweep — Net P&L distribution and APR distribution placed
   side-by-side instead of stacked, so the analyst can compare the two
   metrics at a glance. Collapses to a single column on narrower screens. */
.bt-optimal-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 1100px) {
  .bt-optimal-charts { grid-template-columns: 1fr; }
}

.bt-weekly-wrap { max-height: 480px; overflow-y: auto; }
#bt-weekly-table thead th { position: sticky; top: 0; z-index: 1; background: var(--card); }
.phase-cliff { color: var(--chart-3); }
.phase-vest  { color: var(--otc-hedge); }
.phase-done  { color: var(--muted-foreground); }

.bt-granularity {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* Snap-slider: range input on top, clickable tick labels below in a flex row.
   Both elements are display: block inside an inline-block container — no
   absolute positioning, so the layout doesn't depend on the parent context. */
.bt-snap {
  display: inline-block;
  width: 200px;
  vertical-align: middle;
}
.bt-snap input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 4px;
  margin: 4px 0 6px;
  padding: 0;
  background: var(--border);
  border: 0;
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
.bt-snap input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
}
.bt-snap input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  border: 0;
}
.bt-snap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--otc-hedge);
  border: 2px solid var(--background);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}
.bt-snap input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--otc-hedge);
  border: 2px solid var(--background);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}

/* Tick labels are absolutely positioned so they line up with the thumb's
   actual snap centers — not at 0/33/67/100% of the track but at the thumb
   centers, which are inset by half a thumb-width on each side. */
.bt-snap-ticks {
  display: block;
  position: relative;
  width: 100%;
  height: 14px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--muted-foreground);
  user-select: none;
}
.bt-snap-ticks > span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
  transition: color 120ms ease, background 120ms ease;
  white-space: nowrap;
}
.bt-snap-ticks > span:hover { color: var(--foreground); }
.bt-snap-ticks > span.active {
  color: var(--foreground);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 500;
}
.bt-snap-ticks > span[data-idx="0"] { left: 7px; }
.bt-snap-ticks > span[data-idx="1"] { left: calc(7px + (100% - 14px) / 3); }
.bt-snap-ticks > span[data-idx="2"] { left: calc(7px + (100% - 14px) * 2 / 3); }
.bt-snap-ticks > span[data-idx="3"] { left: calc(100% - 7px); }

/* ── Funding-source venue pills ────────────────────────────────────── */
/* Mirrors the Funding Scanner's `.fsc-venue-chip` row: same rounded-pill
   geometry, same `--vc` (per-venue brand color) hook, same dimmed-+-
   dashed-border treatment for unselected pills. Differences from the
   funding scanner: pills are radios (one venue at a time, OI-weighted is
   the default); a disabled state replaces the dimmed/clickable look for
   venues that don't list the current ticker; the leading `OI-weighted`
   pill carries no logo (uses a Σ glyph instead) since it represents a
   blend rather than a single venue. */
.bt-venues {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.bt-venues-label {
  color: var(--muted-foreground);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-right: 4px;
  display: inline-flex; align-items: center; gap: 4px;
}
.bt-venue-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  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;
}
/* Visually hide the radio but keep it focusable (matches the funding
   scanner pattern — chip itself is the click target via wrapping label). */
.bt-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;
}
.bt-venue-chip:hover {
  background: color-mix(in srgb, var(--vc, var(--foreground)) 8%, var(--surface-elevated));
}
.bt-venue-chip:has(input:checked) {
  border-color: color-mix(in srgb, var(--vc, var(--foreground)) 65%, transparent);
  background: color-mix(in srgb, var(--vc, var(--foreground)) 10%, var(--surface-elevated));
}
.bt-venue-chip:has(input:focus-visible) {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--vc, var(--foreground)) 35%, transparent);
}
/* Unchecked but available — should still read as a clickable button
   waiting for input. Solid border + nearly full text opacity; only the
   colored fill and outer halo of the selected state are missing. The
   funding scanner can lean harder on dim/dashed treatment because every
   chip there is always selectable; here we have to reserve the obviously-
   off look (dashed border, hatch, grayscale) for `.is-unavailable` so
   the two states don't read identically. */
.bt-venue-chip:has(input:not(:checked)):not(.is-unavailable) {
  opacity: 0.92;
  border-style: solid;
  border-color: var(--border);
}
.bt-venue-chip:has(input:not(:checked)):not(.is-unavailable):hover {
  opacity: 1;
  border-color: color-mix(in srgb, var(--vc, var(--foreground)) 40%, var(--border));
}
/* Disabled — venue probe came back empty (no perp listing for this
   ticker on this exchange). The combination of: low opacity, full
   grayscale, dashed thin border, AND a diagonal hatch on the chip
   background is what distinguishes this state from "available, not
   selected". Any one of those tweaks alone reads as just-dimmer; the
   stack reads as universally-recognised "disabled control". */
.bt-venue-chip.is-unavailable {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(1);
  border-style: dashed;
  border-color: color-mix(in srgb, var(--foreground) 18%, transparent);
  background:
    repeating-linear-gradient(
      -45deg,
      transparent 0,
      transparent 4px,
      color-mix(in srgb, var(--foreground) 6%, transparent) 4px,
      color-mix(in srgb, var(--foreground) 6%, transparent) 5px
    ),
    var(--surface-elevated);
}
.bt-venue-chip.is-unavailable:hover {
  opacity: 0.42;
  border-color: color-mix(in srgb, var(--foreground) 18%, transparent);
}
/* Strike through the venue name on disabled pills as a final, unambiguous
   "this can't be picked" cue. Targets the badge label injected by
   cexBadge() — both the per-venue `.tdd-cex-name` and the OI-weighted
   blend's `.bt-blend-name` (defensive, even though OI-weighted is never
   itself flagged unavailable). */
.bt-venue-chip.is-unavailable .tdd-cex-name,
.bt-venue-chip.is-unavailable .bt-blend-name {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.bt-venue-chip-content { display: inline-flex; align-items: center; }

/* Annualized funding % badge — shown on each pill once the server has
   fetched that venue's funding history. Mirrors the funding scanner's
   per-venue time pill in shape (small mono-spaced badge tucked at the
   chip's right edge); coloured by sign so the user can see at a glance
   which venues had positive vs. negative carry over the lookback. The
   `:empty` selector hides the badge until populated so unfilled pills
   (initial render, unavailable venues, mid-fetch) don't flash a stray
   background. */
.bt-venue-pct {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--vc, var(--foreground)) 10%, transparent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bt-venue-pct:empty { display: none; }
.bt-venue-pct.is-positive { color: var(--profit, #22c55e); }
.bt-venue-pct.is-negative { color: var(--loss, #ef4444); }
.bt-venue-pct.is-zero    { color: var(--muted-foreground); }

/* OI-weighted pill — no logo, just a Σ glyph + label so the eye reads
   it as "the blend" rather than another exchange. Matches the per-venue
   pill height so the row stays optically aligned. */
.bt-venue-chip-content--blend {
  gap: 6px;
  font-family: var(--font-mono);
}
.bt-blend-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--foreground) 12%, transparent);
  color: var(--foreground);
  /* Lucide icons live inline as 24x24 SVGs; size them down to fit the
     rounded square tile and use currentColor so the glyph follows the
     chip's text color (including the dimmed/disabled states). */
}
.bt-blend-glyph svg {
  width: 14px;
  height: 14px;
  display: block;
}
.bt-blend-name { color: var(--foreground); font-weight: 500; }
.bt-venue-chip--blend { --vc: var(--foreground); }

/* Per-venue brand color hooks — match the funding scanner's table so a
   pill's outline glows in that venue's brand on selection. */
.bt-venue-chip[data-venue="binance"]     { --vc: #F0B90B; }
.bt-venue-chip[data-venue="bybit"]       { --vc: #F7A600; }
.bt-venue-chip[data-venue="okx"]         { --vc: var(--foreground); }
.bt-venue-chip[data-venue="hyperliquid"] { --vc: #50D2C1; }
.bt-venue-chip[data-venue="lighter"]     { --vc: var(--foreground); }
.bt-venue-chip[data-venue="bitget"]      { --vc: #00F0FF; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .bt-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  /* The Backtest section's row goes 4 → 2 cols (Lookback/Broker on top,
     Exec/Run on bottom) which keeps the Run button reachable without
     a giant scroll. Other sections naturally stay readable at 4 cols
     on widths down to ~1100px; 1280px is the trigger because below
     that the input borders start to bunch tightly. */
  .bt-form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bt-summary-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .bt-form-row { grid-template-columns: 1fr; }
  .bt-ticker-badge .ticker-input { width: 100px; font-size: 16px; }
  .bt-ticker-badge .symbol-input { width: 110px; }
  .bt-venue-chip { flex-wrap: wrap; row-gap: 2px; }
}
