/* ── QS Design System — Dark Trading Theme ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #030712;
  --surface: #0a1628;
  --surface-2: #111827;
  --surface-3: #1f2937;
  --border: #1f2937;
  --border-light: #374151;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --accent-soft: #1e3a8a;
  --green: #10b981;
  --green-dim: #059669;
  --red: #ef4444;
  --gold: #eab308;
  --cyan: #06b6d4;
  --purple: #818cf8;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Nav ───────────────────────────────────────────────────────────────── */
.nav {
  background: rgba(10, 22, 40, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 2.5rem;
  padding: 0 1.5rem;
  height: 60px;
}
.logo {
  display: inline-flex;
  align-items: center;
  align-self: stretch;
  text-decoration: none;
}
.logo img {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
}
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface-2); }
.nav-links a.active { color: var(--accent); background: var(--accent-soft); }

/* ── Main ───────────────────────────────────────────────────────────────── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Report Header ──────────────────────────────────────────────────────── */
.report-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.report-header h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }
.report-meta { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.badge {
  font-size: 0.78rem;
  padding: 0.2rem 0.75rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-weight: 500;
}
.badge.outline { background: transparent; border: 1px solid var(--border-light); color: var(--text-muted); }
.badge.small { font-size: 0.68rem; padding: 0.1rem 0.5rem; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-light); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Markdown Content ───────────────────────────────────────────────────── */
.md-content { max-width: 100%; overflow-x: auto; }
.md-content h1, .md-content h2, .md-content h3 {
  margin: 2rem 0 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.md-content h1 { font-size: 1.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.6rem; }
.md-content h2 { font-size: 1.15rem; color: var(--accent); }
.md-content h3 { font-size: 1rem; color: var(--cyan); }
.md-content p { margin: 0.75rem 0; color: var(--text); }
.md-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.825rem;
  border-radius: var(--radius);
  overflow: hidden;
}
.md-content th, .md-content td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}
.md-content th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}
.md-content td { color: var(--text-muted); }
.md-content tr:nth-child(even) td { background: rgba(255,255,255,0.015); }
.md-content code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--cyan);
  font-family: "JetBrains Mono", "Fira Code", monospace;
}
.md-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  margin: 0.75rem 0;
  border: 1px solid var(--border);
}
.md-content details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin: 1.25rem 0;
}
.md-content summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.95rem;
  padding: 0.25rem 0;
}
.md-content summary:hover { color: var(--accent-hover); }
.md-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}
.md-content strong {
  color: var(--text);
  font-weight: 600;
}
.md-content a {
  color: var(--accent);
  text-decoration: none;
}
.md-content a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
}
.empty-state h1 { margin-bottom: 0.75rem; font-size: 1.5rem; }
.empty-state p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ── Report List ────────────────────────────────────────────────────────── */
.report-list { display: flex; flex-direction: column; gap: 0.75rem; }
.report-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s;
}
.report-card:hover { border-color: var(--accent); background: var(--surface-2); }
.report-card-title { font-weight: 600; }
.report-card-meta { color: var(--text-muted); font-size: 0.85rem; display: flex; gap: 1rem; }

/* ── Run Output ─────────────────────────────────────────────────────────── */
.run-list { display: flex; flex-direction: column; gap: 0.75rem; }
.run-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.run-card:hover { border-color: var(--accent); background: var(--surface-2); }
.run-title { font-weight: 650; }
.run-meta, .run-stats { display: flex; flex-wrap: wrap; gap: 0.8rem; color: var(--text-muted); font-size: 0.82rem; }
.stat-buy, .dir-buy { color: var(--green); }
.stat-sell, .dir-sell { color: var(--red); }
.dir-neutral { color: var(--text-muted); }
.return-positive { color: var(--green) !important; }
.return-negative { color: var(--red) !important; }
.return-neutral { color: var(--text-muted) !important; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.metric-card span { display: block; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-card strong { display: block; margin-top: 0.3rem; font-size: 1.35rem; color: var(--text); }
.metric-card.buy strong { color: var(--green); }
.metric-card.sell strong { color: var(--red); }

.run-config { margin-bottom: 1.25rem; }
.config-grid {
  display: grid;
  grid-template-columns: repeat(3, auto minmax(0, 1fr));
  gap: 0.35rem 0.75rem;
  font-size: 0.85rem;
}
.config-grid span { color: var(--text-muted); }
.config-grid b { color: var(--text); font-weight: 600; }

.signal-table-wrap { overflow-x: auto; }
.signal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.signal-table th, .signal-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}
.signal-table th { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.signal-table a { color: var(--accent); text-decoration: none; }

.signal-page-header { margin-bottom: 1rem; }
.bt-confidence {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.bt-confidence-score { display: flex; align-items: baseline; gap: 0.75rem; }
.bt-confidence-score span {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bt-confidence-score strong { color: var(--green); font-size: 1.65rem; line-height: 1; }
.bt-confidence-detail { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; color: var(--text); font-size: 0.82rem; }
.bt-confidence-detail small { width: 100%; color: var(--text-dim); font-size: 0.72rem; }
.signal-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.signal-search-field {
  position: relative;
  width: min(100%, 440px);
}
.signal-search-field input {
  width: 100%;
  height: 42px;
  padding: 0 2.75rem 0 0.85rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  outline: none;
}
.signal-search-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.signal-search-field input::placeholder { color: var(--text-dim); }
.signal-search-field button {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  width: 30px;
  height: 30px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.signal-search-field button:hover { color: var(--text); }
.signal-filter-group, .signal-sort-field { display: flex; align-items: center; gap: 0.45rem; }
.signal-filter-label, .signal-sort-field > span {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
}
.signal-segment {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.signal-segment button {
  min-width: 42px;
  height: 30px;
  padding: 0 0.6rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.signal-segment button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.signal-segment button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }
.signal-sort-field { margin-left: auto; }
.signal-sort-field select {
  height: 36px;
  padding: 0 2rem 0 0.65rem;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
}
.signal-history { padding-bottom: 0.75rem; }
.signal-scroll-sentinel { height: 1px; }
.signal-list-status {
  min-height: 1.5rem;
  padding-top: 0.65rem;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-align: center;
}
.signal-history.is-loading .signal-list-status { color: var(--text-muted); }
.empty-state.compact { padding: 3rem 1rem 2.25rem; }
.empty-state.compact a { color: var(--accent); }
.bt-result { font-weight: 600; }
.bt-result.hit { color: var(--green); }
.bt-result.miss { color: var(--red); }
.ticker-win-rate { color: var(--text); font-size: 0.82rem; }
.ticker-win-count { margin-left: 0.35rem; color: var(--text-dim); font-size: 0.7rem; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.symbol-grid { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.25rem; }
.symbol-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.symbol-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.symbol-panel-header h2 { font-size: 1rem; }
.symbol-panel img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.metric-card small { display: block; margin-top: 0.25rem; color: var(--text-dim); font-size: 0.7rem; }
.ticker-history { margin-top: 1.25rem; padding-top: 1rem; }
.ticker-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.ticker-history-header h2 { margin: 0; color: var(--text); }
.ticker-history-header span { color: var(--text-dim); font-size: 0.75rem; }
.badge.direction.buy { background: rgba(16, 185, 129, 0.16); color: var(--green); }
.badge.direction.sell { background: rgba(239, 68, 68, 0.16); color: var(--red); }
.badge.direction.neutral { background: var(--surface-3); color: var(--text-muted); }

/* ── Runner ─────────────────────────────────────────────────────────────── */
.runner-header { margin-bottom: 1.25rem; }
.runner-header h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: 0; }
.runner-grid { display: flex; flex-direction: column; gap: 1.5rem; }
.runner-grid .card { border-radius: var(--radius); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.card h2 { font-size: 1.05rem; margin-bottom: 1rem; color: var(--accent); }

.signal-form { display: flex; flex-direction: column; }
.runner-form-section { padding: 0 0 1.5rem; }
.runner-form-section + .runner-form-section {
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.runner-form-section h2 {
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label, .form-group legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-group legend { margin-bottom: 0.45rem; }
.mode-fieldset { border: 0; margin-bottom: 1.25rem; }
.mode-segment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 520px);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.mode-segment label { cursor: pointer; }
.mode-segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-segment span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
}
.mode-segment input:checked + span { background: var(--accent); color: #fff; }
.mode-segment input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 1px; }
.runner-scope-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(180px, 1fr);
  gap: 1rem;
}
.parameter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.9rem;
}
.field-label { display: flex; align-items: center; gap: 0.35rem; min-height: 20px; }
.field-meta, .field-unit { color: var(--text-dim); font-size: 0.72rem; }
.info-tip { position: relative; display: inline-flex; }
.info-tip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: help;
}
.info-tip-trigger:hover, .info-tip-trigger:focus-visible { color: var(--text); outline: none; }
.info-tip-trigger svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.info-tip-content {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 20;
  width: 250px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.45;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 4px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
  pointer-events: none;
}
.info-tip:hover .info-tip-content, .info-tip:focus-within .info-tip-content {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.form-group input, .form-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  height: 42px;
  padding: 0 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.form-actions .btn { min-width: 132px; }

/* ── Status ─────────────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
}
.status-indicator.running { background: var(--gold); animation: pulse 1.2s infinite; }
.status-indicator.completed { background: var(--green); }
.status-indicator.error { background: var(--red); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.progress-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}
.status-detail {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Gradient accents ───────────────────────────────────────────────────── */
.gradient-line {
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--cyan), transparent);
  margin-bottom: 1.5rem;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .form-row { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .config-grid { grid-template-columns: auto 1fr; }
  .run-card { flex-direction: column; align-items: flex-start; }
  .report-header { flex-direction: column; align-items: stretch; }
  .report-meta { width: 100%; }
  .report-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .symbol-panel-header { align-items: flex-start; flex-direction: column; gap: 0.25rem; }
  .symbol-panel-header .run-meta { overflow-wrap: anywhere; }
  .nav-inner { gap: 0.5rem; padding: 0 0.75rem; }
  .nav-links a { padding: 0.45rem 0.65rem; white-space: nowrap; }
  .signal-search-field { width: 100%; }
  .signal-filter-group { flex: 1 1 auto; align-items: flex-start; flex-direction: column; }
  .signal-filter-label { min-height: 1rem; }
  .signal-sort-field { width: 100%; margin-left: 0; justify-content: space-between; }
  .signal-sort-field select { flex: 1; max-width: 260px; }
  .bt-confidence { align-items: flex-start; flex-direction: column; gap: 0.5rem; }
  .runner-scope-grid, .parameter-grid { grid-template-columns: 1fr; }
  .mode-segment { width: 100%; }
  .form-actions .btn { width: 100%; }
  .info-tip-content { left: 0; transform: translate(0, 4px); }
  .info-tip:hover .info-tip-content, .info-tip:focus-within .info-tip-content { transform: translate(0, 0); }
}

@media (min-width: 769px) and (max-width: 1040px) {
  .parameter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
