/* =========================================================================
   app.css — Minimalist Scenario Explorer Design System
   ========================================================================= */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-hover: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-secondary: #475569;
  --ink-muted: #64748b;
  --ink-faint: #94a3b8;
  
  --brand: #4f46e5;
  --brand-light: #eef2ff;
  --brand-hover: #4338ca;
  
  --profit: #10b981;
  --profit-bg: #ecfdf5;
  --profit-border: #a7f3d0;
  --profit-ink: #065f46;
  
  --loss: #ef4444;
  --loss-bg: #fef2f2;
  --loss-border: #fecaca;
  --loss-ink: #991b1b;
  
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 24px 16px 80px;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden-select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
}

/* ---------- Top Navigation ---------- */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-sm);
}
.brand:hover .brand-text { color: var(--brand); }
.brand:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }

.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
}

.logo-mark svg {
  width: 16px;
  height: 16px;
}

.brand-text {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.data-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}

/* ---------- Strategy Header ---------- */
.strategy-header {
  margin-bottom: 24px;
}

.strategy-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.strategy-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand);
  background: var(--brand-light);
  padding: 2px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.strategy-name {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1.15;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* The chevron is the only hint that the title is a dropdown. */
.strategy-caret {
  flex: none;
  color: var(--brand);
  opacity: 0.75;
}

/* The real <select>, laid transparently over the tag + title so the whole
   block is one large tap target. Native list on mobile, no custom menu to
   maintain, and it stays keyboard-focusable. */
.title-left {
  position: relative;
}

.title-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
}

.title-select:focus-visible + .strategy-name,
.title-left:focus-within .strategy-name {
  outline: 2px solid var(--brand);
  outline-offset: 4px;
  border-radius: 6px;
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-pill:hover {
  background: var(--surface-alt);
  border-color: var(--ink-muted);
}

.btn-pill:active {
  transform: scale(0.97);
}

.strategy-desc {
  font-size: 14px;
  color: var(--ink-secondary);
  line-height: 1.5;
  margin-bottom: 14px;
}

/* Rule summary chips */
.rules-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 520px) {
  .rules-strip {
    grid-template-columns: 1fr;
  }
}

.rule-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
}

.rule-chip .badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 4px;
  color: #fff;
  flex-shrink: 0;
}

.rule-chip.buy .badge {
  background: var(--profit);
}

.rule-chip.sell .badge {
  background: var(--loss);
}

/* ---------- Scenario Console ---------- */
.scenario-console {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.console-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.console-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.console-sub {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--ink-muted);
}

.ctrl-group {
  margin-bottom: 16px;
}

.group-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.group-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.group-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-link {
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--brand);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.action-link:hover {
  background: var(--brand-light);
  text-decoration: underline;
}

.dot-sep {
  font-size: 11px;
  color: var(--border-strong);
}

.group-hint {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--ink-faint);
}

/* Checkable pill options */
.pill-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.check-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-pill .check-icon {
  font-size: 11px;
  color: transparent;
  transition: color 0.15s ease;
  font-weight: 800;
}

.check-pill:hover {
  border-color: var(--ink-muted);
  background: var(--surface-alt);
  color: var(--ink);
}

.check-pill:has(input:checked) {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.25);
}

.check-pill:has(input:checked) .check-icon {
  color: #fff;
}

/* Select inputs */
.custom-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.custom-select:focus {
  outline: none;
  border-color: var(--brand);
}

.ctrl-row-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 520px) {
  .ctrl-row-two {
    grid-template-columns: 1fr;
  }
}

/* Checkbox Toggle */
.ctrl-checks-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.toggle-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.toggle-checkbox input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.box-indicator {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.toggle-checkbox input:checked + .box-indicator {
  background: var(--brand);
  border-color: var(--brand);
}

.toggle-checkbox input:checked + .box-indicator::after {
  content: '✓';
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.uses-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.uses-badges span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  color: var(--ink-secondary);
}

.uses-badges span i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

/* More settings drawer */
.more-settings {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.more-settings summary {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  list-style: none;
}

.more-settings summary::-webkit-details-marker {
  display: none;
}

.settings-body {
  padding-top: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.field-item label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.field-item input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
}

.settings-note {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.4;
}

/* =========================================================================
   RESULTS PRESENTATION (HIGH PERFORMANCE & CLARITY)
   ========================================================================= */

.results-area {
  min-height: 200px;
}

.results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

/* Executive Highlights Card */
.insights-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 20px;
}

.insight-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.insight-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.insight-val {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.insight-sub {
  font-size: 12px;
  color: var(--ink-secondary);
  line-height: 1.35;
}

/* Verdict banner */
.verdict-banner {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.verdict-banner.win {
  background: var(--profit-bg);
  border-color: var(--profit-border);
}

.verdict-banner.lose {
  background: var(--loss-bg);
  border-color: var(--loss-border);
}

.verdict-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.verdict-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.verdict-banner.win .verdict-title {
  color: var(--profit-ink);
}

.verdict-banner.lose .verdict-title {
  color: var(--loss-ink);
}

.verdict-detail {
  font-size: 13.5px;
  color: var(--ink-secondary);
  line-height: 1.45;
}

/* Scenario Leaderboard Table */
.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 13px;
  font-weight: 800;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.table-responsive {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
  background: var(--surface);
}

.leaderboard-table th {
  background: var(--surface-alt);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.leaderboard-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}

.leaderboard-table tr:last-child td {
  border-bottom: none;
}

.leaderboard-table tr.row-clickable {
  cursor: pointer;
  transition: background 0.12s ease;
}

.leaderboard-table tr.row-clickable:hover {
  background: var(--brand-light);
}

.leaderboard-table tr.row-active {
  background: rgba(79, 70, 229, 0.08);
  font-weight: 600;
}

.leaderboard-table tr.row-active td {
  border-color: rgba(79, 70, 229, 0.2);
}

.rank-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  width: 40px;
}

.pnl-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 13.5px;
  padding: 2px 6px;
  border-radius: 4px;
}

.pnl-pill.up {
  color: var(--profit-ink);
  background: var(--profit-bg);
}

.pnl-pill.down {
  color: var(--loss-ink);
  background: var(--loss-bg);
}

.btn-inspect {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-inspect:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* Active Scenario Detailed Dashboard */
.drilldown-container {
  border-top: 2px dashed var(--border);
  padding-top: 24px;
  margin-top: 8px;
}

.drilldown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.drilldown-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-light);
  border: 1px solid rgba(79, 70, 229, 0.2);
  color: var(--brand);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}

/* KPI Tiles Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (max-width: 600px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.kpi-tile {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.kpi-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  margin-bottom: 2px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.2;
}

.kpi-value.up {
  color: var(--profit);
}

.kpi-value.down {
  color: var(--loss);
}

.kpi-sub {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--ink-muted);
  margin-top: 4px;
}

/* Result Nav Tabs */
/* Four long labels in a flex row do not shrink below their content, so on a
   375px phone this row was 433px wide and took the WHOLE PAGE sideways with
   it — including the fixed bottom bar, which stretches to the document width.
   Scrolling the strip itself contains it; the labels stay readable by swipe
   rather than being truncated to "(91)". */
.result-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.result-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: none;
  white-space: nowrap;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* Chart Tab */
.chart-container {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

.chartwrap {
  position: relative;
  width: 100%;
  height: 400px;
}

.chartwrap > div:first-child {
  width: 100%;
  height: 100%;
}

/* The OHLC readout. TradingView's signature: the values for the bar under
   the pointer, pinned above the chart and always present, rather than a
   tooltip that has to be summoned. */
.chartreadout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  padding: 9px 12px 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  min-height: 34px;
}
.chartreadout b { color: var(--ink); font-weight: 700; }
.chartreadout b.up, .chartreadout .up { color: var(--profit); }
.chartreadout b.down, .chartreadout .down { color: var(--loss); }
.chartreadout .ro-date { font-weight: 700; color: var(--ink); }
.chartreadout .ro-chg { font-weight: 700; }
.chartreadout .ro-ind { display: inline-flex; align-items: center; gap: 5px; }
.chartreadout .ro-ind i { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.chartreadout .ro-held {
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 700;
}
.chartreadout .ro-held.up { background: var(--profit-bg, #d1fae5); }
.chartreadout .ro-held.down { background: var(--loss-bg, #fee2e2); }
@media (max-width: 620px) {
  .chartreadout { font-size: 10.5px; gap: 3px 10px; }
}

.charttip {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.4;
  pointer-events: none;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.chartzoom {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  z-index: 5;
}

.chartzoom button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.chartzoom button:hover {
  background: var(--surface-alt);
}

/* Range buttons. The chart opens on "All"; one tap gets to a readable slice
   without pinching six years of daily bars. */
.chartranges {
  display: flex;
  gap: 5px;
  padding: 10px 12px 0;
  flex-wrap: wrap;
}
.chartranges button {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.12s ease;
}
.chartranges button:hover { border-color: var(--brand); color: var(--brand); }
.chartranges button.on {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* The legend is the only thing on the page that says what the marks mean, so
   it is a bordered panel rather than a row of grey footnote text. */
.chartlegend {
  display: flex;
  gap: 8px 18px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--ink-secondary);
  padding: 11px 14px;
  margin: 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

.chartlegend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.chartlegend span i { flex: none; }

.chartlegend .ln { width: 16px; height: 3px; border-radius: 2px; }

.chartlegend .tri.up {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid var(--profit);
}

.chartlegend .tri.down {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid var(--loss);
}

/* Matches the exit marker the chart draws: a filled dot, coloured by whether
   that trade ended up or down. */
.chartlegend .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--profit) 0 50%, var(--loss) 50% 100%);
}

.chartlegend .band {
  width: 15px; height: 13px;
  border-radius: 3px;
}
/* Solid fallback first: a browser without color-mix drops those declarations,
   and an invisible swatch defeats the point of the legend. */
.chartlegend .band.win  { background: #d1fae5; border: 1px solid #6ee7b7; }
.chartlegend .band.loss { background: #fee2e2; border: 1px solid #fca5a5; }
.chartlegend .band.win  { background: color-mix(in srgb, var(--profit) 26%, transparent); border: 1px solid color-mix(in srgb, var(--profit) 45%, transparent); }
.chartlegend .band.loss { background: color-mix(in srgb, var(--loss) 26%, transparent); border: 1px solid color-mix(in srgb, var(--loss) 45%, transparent); }

.chartlegend .vol {
  width: 13px; height: 9px;
  background: linear-gradient(to top, var(--ink-muted) 60%, transparent 60%);
  opacity: 0.55;
}

/* Trade log details */
.trades-list {
  display: grid;
  gap: 8px;
}

.trade-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.trade-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  font-size: 13.5px;
}

.trade-item summary::-webkit-details-marker {
  display: none;
}

.trade-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
}

.trade-item .dot.w {
  background: var(--profit);
}

.trade-item .dot.l {
  background: var(--loss);
}

.trade-summary-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

.trade-summary-right {
  font-family: var(--font-mono);
  font-weight: 700;
}

.trade-summary-right.up {
  color: var(--profit);
}

.trade-summary-right.down {
  color: var(--loss);
}

.trade-detail-body {
  padding: 14px;
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.trade-step {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.trade-step .k {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink-muted);
}

.trade-step .v em {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Warnings */
.warn-box {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.45;
  margin-bottom: 16px;
}

.busy-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--ink-muted);
}

/* ---------- output is its own screen ---------- */
body[data-view="results"] .top-nav,
body[data-view="results"] .strategy-header,
body[data-view="results"] .scenario-console{display:none}

.results-bar{display:flex;align-items:center;gap:10px;padding:0 0 14px;margin-bottom:14px;
             border-bottom:1px solid var(--line,#e6e8ec)}
.results-back{width:36px;height:36px;flex:none;border-radius:10px;cursor:pointer;
              border:1px solid var(--line,#e6e8ec);background:var(--card,#fff);color:inherit;
              display:grid;place-items:center}
.results-bar-text{min-width:0;flex:1}
.results-bar-text b{display:block;font-size:15px;letter-spacing:-.01em}
.results-bar-text span{display:block;font-size:12px;opacity:.65;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.results-rerun{flex:none;border-radius:9px;padding:8px 14px;cursor:pointer;font-weight:600;font-size:13px;
               border:1px solid var(--line,#e6e8ec);background:var(--card,#fff);color:inherit}
.results-rerun:hover{border-color:currentColor}

.view-results-bar{position:fixed;left:0;right:0;bottom:0;z-index:40;padding:12px 16px calc(12px + env(safe-area-inset-bottom));
                  background:linear-gradient(to top,var(--bg) 65%,transparent);display:flex;justify-content:center}
.view-results-bar button{display:inline-flex;align-items:center;justify-content:center;gap:9px;
                         width:100%;max-width:728px;background:var(--ink);color:#fff;border:0;
                         border-radius:12px;padding:15px;font-weight:700;font-size:15px;cursor:pointer;
                         box-shadow:var(--shadow-md)}
.view-results-bar button:active{transform:scale(.995)}
body[data-view="results"] .view-results-bar{display:none}

/* live symbol fetch — only visible when tools/serve.py is running */
.live-box{border:1px dashed var(--border-strong);border-radius:var(--radius-md);padding:12px;background:var(--surface-alt)}
.live-row{display:flex;gap:8px}
.live-row input{flex:1;min-width:0;background:var(--surface);border:1px solid var(--border);
                border-radius:var(--radius-sm);padding:9px 11px;font-family:var(--font-mono);font-size:13.5px}
.live-row input:focus{outline:none;border-color:var(--brand)}

/* ---- Trade detail: gap badge, indicator chips ------------------------- */

.gap-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 5px;
  margin-left: 6px;
  white-space: nowrap;
}
/* "Inside" is the trustworthy case, so it stays neutral. A gap is a warning
   that the fill differs from the price the signal was read at. */
.gap-badge.gap-inside { background: var(--surface-alt); color: var(--ink-muted); }
.gap-badge.gap-up     { background: var(--profit-bg); color: var(--profit-ink); }
.gap-badge.gap-down   { background: var(--loss-bg); color: var(--loss-ink); }

.trade-ind .v {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ind-chip {
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--surface-alt);
  border-radius: 5px;
  padding: 1px 6px;
  white-space: nowrap;
}
.ind-chip b {
  font-weight: 600;
  color: var(--brand);
  margin-right: 3px;
}

.why-text {
  font-style: italic;
  color: var(--ink-muted);
}

/* ---- Session rules --------------------------------------------------- */

.session-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.ctrl-group.is-disabled {
  opacity: 0.5;
}
.ctrl-group.is-disabled input,
.ctrl-group.is-disabled select {
  cursor: not-allowed;
}

/* ---- Patterns tab ---------------------------------------------------- */

.pattern-block {
  margin-bottom: 22px;
}

.pattern-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 4px;
}

.pattern-note {
  font-size: 12.5px;
  color: var(--ink-muted);
  line-height: 1.45;
  margin-bottom: 10px;
}

/* Wide tables scroll inside their own box; the page never scrolls sideways. */
.pattern-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.pattern-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 420px;
}

.pattern-table th,
.pattern-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.pattern-table thead th {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  background: var(--surface-alt);
}

.pattern-table tbody tr:last-child td {
  border-bottom: none;
}

.pattern-table .num {
  text-align: right;
}

.pattern-table .up   { color: var(--profit-ink); }
.pattern-table .down { color: var(--loss-ink); }

/* A bucket with too few trades to read anything into. */
.pattern-table .thin-row td {
  color: var(--ink-faint);
}

.thin-flag {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: #92400e;
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 6px;
}

/* ---- Sign-in chip -------------------------------------------------- */

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 4px 6px 4px 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.user-chip img {
  border-radius: 50%;
  display: block;
}
.chip-out {
  border: none;
  background: var(--surface-alt);
  color: var(--ink-muted);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 15px;
  cursor: pointer;
}
.chip-out:hover { background: var(--loss-bg); color: var(--loss-ink); }

.nav-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- Save button on the results bar --------------------------------- */

.results-save {
  background: var(--brand);
  border: 1px solid var(--brand);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.results-save:hover:not(:disabled) { background: var(--brand-hover); }
.results-save:disabled { opacity: 0.6; cursor: default; }

/* ---- Saved results list --------------------------------------------- */

.saved-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-bottom: 6px;
}
.saved-main { min-width: 0; }
.saved-main b {
  display: block;
  font-size: 13.5px;
  letter-spacing: -0.01em;
}
.saved-main span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.saved-num {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}
.saved-num small {
  display: block;
  font-weight: 400;
  font-size: 10.5px;
  color: var(--ink-muted);
}
.saved-num.up { color: var(--profit-ink); }
.saved-num.down { color: var(--loss-ink); }
.saved-when {
  font-size: 11px;
  color: var(--ink-faint);
}
.saved-del {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.saved-del:hover { color: var(--loss); }

/* ---- Winners vs Losers ---------------------------------------------- */

.attrib-head { margin-bottom: 12px; }

.attrib-split {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  font-weight: 600;
}
.a-win, .a-loss {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}
.a-win  { background: var(--profit-bg); color: var(--profit-ink); border: 1px solid var(--profit-border); }
.a-loss { background: var(--loss-bg);   color: var(--loss-ink);   border: 1px solid var(--loss-border); }
.a-base { font-size: 11.5px; font-weight: 400; color: var(--ink-muted); }

/* Verdict pills. "noise" is the common case and is styled to be calm rather
   than alarming - most factors are noise, and that is the normal result. */
.verdict {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 5px;
  white-space: nowrap;
}
.v-strong { background: var(--profit-bg); color: var(--profit-ink); border: 1px solid var(--profit-border); }
.v-maybe  { background: var(--warn-bg);   color: #92400e;          border: 1px solid var(--warn-border); }
.v-weak   { background: var(--surface-alt); color: var(--ink-muted); border: 1px solid var(--border); }
.v-noise  { background: transparent;       color: var(--ink-faint); border: 1px solid var(--border); }

.info-box {
  background: var(--brand-light);
  border: 1px solid #c7d2fe;
  color: var(--ink-secondary);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.info-box b { color: var(--ink); }
