/* AI Backtester styles — fully scoped under .bt-shell so they don't bleed into
   the rest of Flash Finance. Light pro theme — same family as the /technicals,
   /strategies and market pages (ff-* design language). */

.bt-shell {
  --bt-bg: #f7f9fc;
  --bt-panel: #ffffff;
  --bt-panel-2: #f1f5f9;
  --bt-border: #e5e7eb;
  --bt-border-soft: #eef1f6;
  --bt-text: #1f2937;
  --bt-muted: #6b7280;
  --bt-mute-2: #9ca3af;
  --bt-primary: #1a365d;
  --bt-accent: #2c7be5;
  --bt-accent-2: #1a56db;
  --bt-green: #16a34a;
  --bt-red: #dc2626;
  --bt-yellow: #d97706;
  --bt-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);

  background: var(--bt-bg);
  color: var(--bt-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  margin: 0;
  max-width: none;
  width: 100%;
}

.bt-shell * { box-sizing: border-box; }

/* ─── Page header (inside the shell, not the site header) ──── */
.bt-shell .bt-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--bt-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  background: var(--bt-panel);
  gap: 12px;
  flex-wrap: wrap;
}
.bt-shell .bt-header h1 {
  font-size: 22px;
  margin: 0 0 4px;
  color: var(--bt-primary);
  font-weight: 800;
  line-height: 1.2;
}
.bt-shell .bt-sub {
  color: var(--bt-muted);
  font-size: 13px;
  max-width: 720px;
}
.bt-shell .bt-meta {
  color: var(--bt-mute-2);
  font-size: 12px;
  white-space: nowrap;
}
.bt-shell code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  background: #e7f0fc;
  color: var(--bt-accent-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

/* ─── Page-specific disclaimer (educational use only) ──────── */
.bt-shell .bt-disclaimer {
  margin: 12px 16px 0;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: #92400e;
  font-size: 12.5px;
  line-height: 1.55;
}
.bt-shell .bt-disclaimer strong { color: #b45309; }

.bt-shell .meta,
.bt-shell .muted { color: var(--bt-muted); font-size: 12px; }
.bt-shell .muted-list { margin: 0 0 0 18px; padding: 0; color: var(--bt-muted); }
.bt-shell .muted-list li { margin: 4px 0; }

/* ─── Layout: 2 cols on top, full width below for results ──── */
.bt-shell .layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}
.bt-shell .col-left, .bt-shell .col-right { min-width: 0; }

.bt-shell .strategy-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.bt-shell .strategy-row > .panel { margin-bottom: 16px; }

@media (max-width: 1100px) {
  .bt-shell .strategy-row { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .bt-shell .layout { grid-template-columns: 1fr; }
  .bt-shell .col-left, .bt-shell .col-right { grid-column: 1 / -1; }
}

/* ─── Panels ───────────────────────────────────────────────── */
.bt-shell .panel {
  background: var(--bt-panel);
  border: 1px solid var(--bt-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  color: var(--bt-text);
  box-shadow: var(--bt-shadow);
}
.bt-shell .panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bt-mute-2);
  margin: 0 0 12px;
  font-weight: 700;
}

/* ─── Form controls ────────────────────────────────────────── */
.bt-shell label {
  display: block;
  font-size: 12px;
  color: var(--bt-muted);
  margin: 8px 0 4px;
  font-weight: 500;
}
.bt-shell input[type="text"],
.bt-shell input[type="number"],
.bt-shell input[type="date"],
.bt-shell input[type="hidden"],
.bt-shell select,
.bt-shell textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bt-panel);
  border: 1px solid var(--bt-border);
  border-radius: 8px;
  color: var(--bt-text);
  font-size: 13px;
  font-family: inherit;
}
.bt-shell textarea { min-height: 110px; resize: vertical; }
.bt-shell input:focus, .bt-shell select:focus, .bt-shell textarea:focus {
  outline: none;
  border-color: var(--bt-accent);
  box-shadow: 0 0 0 3px rgba(44, 123, 229, 0.12);
}

/* Timeframe segmented toggle */
.bt-shell .tf-toggle {
  display: inline-flex;
  border: 1px solid var(--bt-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bt-panel-2);
}
.bt-shell .tf-toggle button {
  background: transparent;
  color: var(--bt-muted);
  border: none;
  border-radius: 0;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: none;
}
.bt-shell .tf-toggle button.active {
  background: linear-gradient(135deg, var(--bt-accent), var(--bt-accent-2));
  color: #fff;
}

.bt-shell button {
  background: var(--bt-accent);
  color: #ffffff;
  border: none;
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.bt-shell button.secondary { background: var(--bt-green); color: white; }
.bt-shell button.ghost-btn {
  background: transparent;
  color: var(--bt-accent);
  border: 1px solid var(--bt-accent);
  padding: 6px 12px;
  font-weight: 500;
}
.bt-shell button.ghost-btn:hover { background: #e7f0fc; }
.bt-shell button:disabled { opacity: 0.45; cursor: not-allowed; }
.bt-shell .row { display: flex; gap: 8px; }
.bt-shell .row > * { flex: 1; }

.bt-shell button.big-cta {
  width: 100%;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--bt-accent), var(--bt-accent-2));
  box-shadow: 0 4px 12px rgba(44, 123, 229, 0.28);
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.bt-shell button.big-cta:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(44, 123, 229, 0.38);
}
.bt-shell button.big-cta.secondary {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.30);
}
.bt-shell button.big-cta.secondary:not(:disabled):hover {
  box-shadow: 0 6px 18px rgba(22, 163, 74, 0.42);
}

/* ─── Examples chips row ───────────────────────────────────── */
.bt-shell .examples { font-size: 12px; color: var(--bt-muted); margin-top: 8px; line-height: 2; }
.bt-shell .examples a {
  color: var(--bt-accent);
  cursor: pointer;
  text-decoration: none;
  margin-right: 6px;
  border: 1px solid var(--bt-border);
  border-radius: 14px;
  padding: 3px 10px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-block;
}
.bt-shell .examples a:hover { border-color: var(--bt-accent); background: #e7f0fc; }

/* ─── Preview block ────────────────────────────────────────── */
.bt-shell .preview-block {
  background: var(--bt-panel-2);
  border: 1px solid var(--bt-border-soft);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
}
.bt-shell .preview-block pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 12px;
  color: var(--bt-primary);
}
.bt-shell .preview-block .label {
  font-size: 11px;
  color: var(--bt-mute-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  font-weight: 700;
}
.bt-shell .risk-pill {
  display: inline-block;
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 600;
  margin: 2px 6px 2px 0;
}
.bt-shell .tf-pill {
  display: inline-block;
  background: #e7f0fc;
  border: 1px solid #bfdbfe;
  color: var(--bt-accent-2);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 600;
  margin: 2px 6px 2px 0;
}

/* ─── Autocomplete ─────────────────────────────────────────── */
.bt-shell .autocomplete { position: relative; }
.bt-shell .autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 200;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bt-panel);
  border: 1px solid var(--bt-border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.16);
  display: none;
}
.bt-shell .autocomplete-list.open { display: block; }
.bt-shell .autocomplete-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--bt-border-soft);
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--bt-text);
}
.bt-shell .autocomplete-item:last-child { border-bottom: none; }
.bt-shell .autocomplete-item:hover,
.bt-shell .autocomplete-item.active {
  background: var(--bt-accent);
  color: #ffffff;
}
.bt-shell .autocomplete-item .sym { font-weight: 700; }
.bt-shell .autocomplete-item .nm {
  color: var(--bt-muted); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bt-shell .autocomplete-item.active .nm,
.bt-shell .autocomplete-item:hover .nm { color: rgba(255, 255, 255, 0.85); }
.bt-shell .autocomplete-empty { padding: 10px; color: var(--bt-muted); font-size: 12px; text-align: center; }

.bt-shell .selected-chip {
  margin-top: 8px;
  padding: 8px 10px;
  background: #e7f0fc;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: 13px;
  color: var(--bt-text);
}
.bt-shell .selected-chip .muted { color: var(--bt-muted); }
.bt-shell .selected-chip .chip-links { margin-top: 6px; }
.bt-shell .selected-chip .chip-links a {
  color: var(--bt-accent);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  margin-right: 12px;
}
.bt-shell .selected-chip .chip-links a:hover { text-decoration: underline; }

/* ─── Metrics grid ─────────────────────────────────────────── */
.bt-shell .metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.bt-shell .metric {
  background: var(--bt-panel);
  border: 1px solid var(--bt-border);
  border-radius: 9px;
  padding: 10px 12px;
  box-shadow: var(--bt-shadow);
}
.bt-shell .metric .label {
  font-size: 10.5px;
  color: var(--bt-mute-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.bt-shell .metric .value {
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--bt-text);
}
.bt-shell .metric .value.green, .bt-shell .metric .value .green { color: var(--bt-green); }
.bt-shell .metric .value.red, .bt-shell .metric .value .red { color: var(--bt-red); }
.bt-shell .metric .value.yellow { color: var(--bt-yellow); }

/* ─── Trades table ─────────────────────────────────────────── */
.bt-shell .trades-scroll { overflow-x: auto; }
.bt-shell table.trades-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  table-layout: auto;
  color: var(--bt-text);
}
.bt-shell table.trades-table th,
.bt-shell table.trades-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--bt-border-soft);
  text-align: left;
  white-space: nowrap;
}
.bt-shell table.trades-table th {
  color: var(--bt-mute-2);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  background: var(--bt-panel-2);
  position: sticky; top: 0;
}
.bt-shell table.trades-table th.num,
.bt-shell table.trades-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.bt-shell table.trades-table tbody tr:hover { background: #f0f6ff; }
.bt-shell .reason-pill {
  display: inline-block;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 10.5px;
  font-weight: 600;
}
.bt-shell .reason-pill.signal { background: var(--bt-panel-2); color: var(--bt-muted); }
.bt-shell .reason-pill.stop_loss { background: #fee2e2; color: #b91c1c; }
.bt-shell .reason-pill.trailing_stop { background: #ffedd5; color: #c2410c; }
.bt-shell .reason-pill.take_profit { background: #dcfce7; color: #15803d; }

/* ─── Results header ───────────────────────────────────────── */
.bt-shell .results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.bt-shell .results-header h2 { color: var(--bt-primary); font-size: 15px; text-transform: none; letter-spacing: 0; }
.bt-shell .section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bt-mute-2);
  margin: 18px 0 6px;
  font-weight: 700;
}

/* ─── Charts ───────────────────────────────────────────────── */
.bt-shell .chart-wrap {
  background: var(--bt-panel);
  border: 1px solid var(--bt-border);
  border-radius: 9px;
  padding: 12px;
  height: 280px;
  box-shadow: var(--bt-shadow);
}
.bt-shell .chart-wrap.small { height: 220px; }
.bt-shell .charts-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 800px) { .bt-shell .charts-2col { grid-template-columns: 1fr; } }

/* ─── Toasts / spinner ─────────────────────────────────────── */
.bt-shell .toast {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 8px;
  font-size: 13px;
}
.bt-shell .toast.info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--bt-accent-2);
}
.bt-shell .spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: bt-spin 0.8s linear infinite;
  vertical-align: middle;
  margin-left: 8px;
}
@keyframes bt-spin { to { transform: rotate(360deg); } }

/* ─── Heatmap ──────────────────────────────────────────────── */
.bt-shell .heatmap-wrap {
  background: var(--bt-panel);
  border: 1px solid var(--bt-border);
  border-radius: 9px;
  padding: 10px;
  overflow-x: auto;
  box-shadow: var(--bt-shadow);
}
.bt-shell table.heatmap {
  width: 100%;
  border-collapse: separate;
  border-spacing: 3px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--bt-text);
}
.bt-shell table.heatmap th {
  color: var(--bt-mute-2);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  padding: 4px 6px;
}
.bt-shell table.heatmap td {
  text-align: center;
  padding: 6px 8px;
  border-radius: 4px;
  background: var(--bt-panel-2);
  color: var(--bt-text);
  min-width: 46px;
}

/* ─── Placeholder panels ───────────────────────────────────── */
.bt-shell .panel.placeholder {
  border-style: dashed;
  text-align: center;
  padding: 30px 20px;
  background: transparent;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bt-shell .strategy-row .panel.placeholder { min-height: 220px; }

/* ─── Help details (collapsible sections) ─────────────────── */
.bt-shell .help-details {
  margin-top: 10px;
  border-top: 1px solid var(--bt-border-soft);
  padding-top: 10px;
}
.bt-shell .help-details summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--bt-text);
  padding: 4px 0;
  list-style: none;
  user-select: none;
}
.bt-shell .help-details summary::-webkit-details-marker { display: none; }
.bt-shell .help-details summary::before {
  content: "▶ ";
  font-size: 9px;
  color: var(--bt-accent);
  margin-right: 4px;
  transition: transform 0.15s ease;
  display: inline-block;
}
.bt-shell .help-details[open] summary::before { transform: rotate(90deg); }
.bt-shell .help-details[open] summary { color: var(--bt-accent-2); }
.bt-shell .help-section {
  font-size: 12px;
  color: var(--bt-muted);
  line-height: 1.6;
  padding: 6px 4px 4px 14px;
}
.bt-shell .help-section p { margin: 6px 0; }

/* ─── SEO/FAQ block ────────────────────────────────────────── */
.bt-shell .seo-block h2 {
  text-transform: none;
  letter-spacing: 0;
  font-size: 16px;
  color: var(--bt-primary);
  margin: 0 0 12px;
}
.bt-shell .seo-list { margin: 0 0 0 20px; padding: 0; color: var(--bt-text); font-size: 13px; line-height: 1.75; }
.bt-shell .seo-list li { margin: 6px 0; }
.bt-shell .seo-list b { color: var(--bt-accent-2); }
.bt-shell .faq details {
  border: 1px solid var(--bt-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  background: var(--bt-panel-2);
}
.bt-shell .faq summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--bt-text);
  user-select: none;
}
.bt-shell .faq details[open] summary { color: var(--bt-accent-2); margin-bottom: 8px; }
.bt-shell .faq details p { color: var(--bt-muted); font-size: 13px; line-height: 1.6; margin: 0; }

/* ── Robustness test panel (robustness.js) ───────────────────────────── */
.rb-box { margin: 14px 0 6px; padding: 12px 14px; border: 1px dashed #c9d6ea; border-radius: 10px; background: #fbfcfe; }
.rb-hint { font-size: .8rem; color: #6b7280; margin-left: 8px; }
.rb-tablewrap { overflow-x: auto; }
.rb-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin: 4px 0 6px; }
.rb-table th, .rb-table td { padding: 6px 8px; border-bottom: 1px solid #eef1f6; text-align: left; white-space: nowrap; }
.rb-table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: #6b7280; }
.rb-table tr.rb-group td { font-weight: 600; background: #f7f9fc; }
.rb-verdict { margin: 12px 0 8px; padding: 10px 12px; border-radius: 8px; font-size: .9rem; border-left: 4px solid #94a3b8; background: #f1f5f9; }
.rb-verdict.green { border-left-color: #16a34a; background: #dcfce7; color: #166534; }
.rb-verdict.red { border-left-color: #dc2626; background: #fee2e2; color: #991b1b; }
.rb-verdict.amber { border-left-color: #d97706; background: #fef3c7; color: #854d0e; }
.rb-note { font-size: .8rem; color: #6b7280; margin: 4px 0 10px; }
.rb-box .green, .rb-note.green { color: #16a34a; }
.rb-box .red, .rb-note.red { color: #dc2626; }
