/* ─── Reset & base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d2e;
  --surface2:    #222537;
  --border:      #2e3150;
  --text:        #e2e4f0;
  --muted:       #7a7d9a;
  --green:       #00d68f;
  --red:         #ff3d71;
  --yellow:      #ffaa00;
  --blue:        #4c6ef5;
  --radius:      8px;
  --gap:         16px;
}

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ─── Layout ─────────────────────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: var(--gap); }

/* ─── Header ─────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-left h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--red);
  transition: background 0.3s;
}
.status-dot.online { background: var(--green); animation: pulse 2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.dry-run-badge {
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255,170,0,0.15);
  color: var(--yellow);
  border: 1px solid rgba(255,170,0,0.3);
  font-size: 11px;
  font-weight: 600;
  display: none;
}
.dry-run-badge.visible { display: inline-block; }

/* ─── Stat Cards ─────────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  margin: var(--gap) 0;
}

@media (max-width: 900px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .cards { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}
.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }
.card-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* ─── Sections ───────────────────────────────────────────────────────── */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--gap);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

.section-header .badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--muted);
}

/* ─── Chart ──────────────────────────────────────────────────────────── */
.chart-wrapper {
  padding: 16px;
  height: 200px;
  position: relative;
}

/* ─── Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid rgba(46,49,80,0.6);
  transition: background 0.15s;
}
tbody tr:hover { background: var(--surface2); }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 10px 14px;
  font-size: 13px;
  white-space: nowrap;
}

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

/* ─── Row colouring for open positions ──────────────────────────────── */
tr.profit td:first-child { border-left: 3px solid var(--green); }
tr.loss   td:first-child { border-left: 3px solid var(--red); }

/* ─── Pill badges ────────────────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.pill-back  { background: rgba(76,110,245,0.2); color: var(--blue); }
.pill-lay   { background: rgba(255,61,113,0.2); color: var(--red); }
.pill-win   { background: rgba(0,214,143,0.2);  color: var(--green); }
.pill-loss  { background: rgba(255,61,113,0.2); color: var(--red); }


/* ─── Edge colouring ─────────────────────────────────────────────────── */
.edge-pos { color: var(--green); font-weight: 600; }
.edge-neg { color: var(--muted); }
.edge-nil { color: var(--muted); }

/* ─── Score display ──────────────────────────────────────────────────── */
.score { font-variant-numeric: tabular-nums; }
.score .serving::after { content: ' ●'; color: var(--yellow); font-size: 8px; }

/* ─── P&L colouring ──────────────────────────────────────────────────── */
.pos { color: var(--green); }
.neg { color: var(--red); }
.status-finished { color: var(--muted); font-size: 11px; }

/* ─── Settled table — scrollable ────────────────────────────────────── */
#settled-wrap { max-height: 320px; overflow-y: auto; }

/* ─── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Match filter bar ───────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.filter-btn:hover  { color: var(--text); border-color: var(--blue); }
.filter-btn.active { color: var(--text); background: rgba(76,110,245,0.15); border-color: var(--blue); }

.pill-system { background: rgba(0,214,143,0.12); color: var(--green); }

/* ─── Tab bar ────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 8px var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;   /* below header */
  z-index: 90;
}

.tab {
  padding: 7px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover  { color: var(--text); background: var(--surface2); }
.tab.active { color: var(--text); background: var(--surface2); border-color: var(--border); }

/* ─── Tab panels ─────────────────────────────────────────────────────── */
.tab-panel.hidden { display: none; }

/* ─── Config grid ────────────────────────────────────────────────────── */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 16px;
}

.config-field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 5px;
}

.config-field input {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
}
.config-field input:focus {
  outline: none;
  border-color: var(--blue);
}

/* ─── System cards ───────────────────────────────────────────────────── */
.system-card {
  border-bottom: 1px solid var(--border);
  padding: 16px;
}
.system-card:last-child { border-bottom: none; }
.system-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.system-card-title { flex: 1; min-width: 0; }
.system-name  { font-weight: 700; font-size: 15px; margin-right: 8px; }
.system-desc  { font-size: 12px; color: var(--muted); }
.system-card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.toggle-label { font-size: 11px; font-weight: 600; color: var(--muted); min-width: 52px; }
.toggle-label.on { color: var(--green); }

.system-card-body { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.system-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.pill-surface { background: rgba(76,110,245,0.15); color: var(--blue); }
.pill-edge    { background: rgba(0,214,143,0.12);  color: var(--green); }
.pill-warn    { background: rgba(255,170,0,0.12);  color: var(--yellow); }
.pill-neutral { background: var(--surface2); color: var(--muted); }

.system-staking {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  background: var(--surface2);
  border-radius: 6px;
}

/* ─── Save notice ────────────────────────────────────────────────────── */
.save-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(255,170,0,0.08);
  border: 1px solid rgba(255,170,0,0.25);
  border-radius: var(--radius);
  margin: var(--gap) 0 0;
  font-size: 13px;
  color: var(--yellow);
}
.save-notice.hidden { display: none; }
.save-status { font-size: 12px; color: var(--muted); }

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-sm   { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--blue);    color: #fff; border-color: var(--blue); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-ghost   { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-danger  { background: rgba(255,61,113,0.15); color: var(--red); border-color: rgba(255,61,113,0.3); }
.btn-danger:hover { background: rgba(255,61,113,0.3); }

/* ─── Toggle switch ──────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 38px; height: 20px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: rgba(0,214,143,0.2); border-color: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: var(--green); }

/* ─── Modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 520px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.modal-header h2 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ─── Form inside modal ──────────────────────────────────────────────── */
.form-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin: 16px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.form-section-title:first-child { margin-top: 0; }

.form-group {
  margin-bottom: 12px;
}
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group textarea {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
}
.form-group textarea { resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.form-row.checkboxes { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.form-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.check-label input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--blue); }

.surface-checks {
  grid-template-columns: repeat(4, auto);
  justify-content: start;
}

/* ─── Backtest table specifics ───────────────────────────────────────── */
.bt-pnl-pos { color: var(--green); font-weight: 600; }
.bt-pnl-neg { color: var(--red);   font-weight: 600; }

/* Selected run row highlight */
.bt-row-selected td { background: rgba(76,110,245,0.08) !important; }
.bt-run-row:hover td { background: var(--surface2); }

/* Detail panel: slide in smoothly */
#bt-detail-panel { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Small hint text under section headers */
.section-hint {
  font-size: 12px;
  color: var(--muted);
  margin: -8px 0 12px 0;
  padding: 0 2px;
}

.muted-text { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ── Backtest progress strip ──────────────────────────────────────────── */
#bt-progress-strip {
  margin: 8px 0 12px;
  padding: 10px 14px;
  background: rgba(76,110,245,0.08);
  border: 1px solid rgba(76,110,245,0.25);
  border-radius: var(--radius);
  overflow: hidden;
}

.bt-progress-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

#bt-progress-line {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: monospace;
  color: var(--text);
}

.bt-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(76,110,245,0.3);
  border-top-color: var(--blue);
  border-radius: 50%;
  flex-shrink: 0;
  animation: btSpin 0.8s linear infinite;
}

@keyframes btSpin { to { transform: rotate(360deg); } }

/* ─── Match Analytics Panel ─────────────────────────────────────────────── */
.match-detail-panel {
  border-top: 2px solid var(--blue);
  background: var(--bg);
  padding: 0;
  animation: fadeIn 0.15s ease;
}
.match-detail-panel.hidden { display: none; }

.mda-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.mda-title { display: flex; flex-direction: column; gap: 3px; }
.mda-match { font-weight: 700; font-size: 15px; }
.mda-meta  { font-size: 12px; color: var(--muted); }

.mda-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 16px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.mda-charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
}
.mda-charts-grid-2 { grid-template-columns: repeat(2, 1fr); }

.mda-chart-cell {
  background: var(--surface);
  padding: 12px;
}
.mda-chart-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.mda-chart-wrap {
  position: relative;
  height: 160px;
}
.mda-chart-wrap-tall { height: 210px; }

/* Stats snapshot table inside the 6th chart cell */
.mda-stats-snap { height: 160px; overflow-y: auto; }
.snap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.snap-table th {
  padding: 4px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.snap-table td { padding: 5px 8px; border-bottom: 1px solid rgba(46,49,80,0.4); }
.snap-table td.snap-label { color: var(--muted); font-size: 11px; }
.snap-table tr:last-child td { border-bottom: none; }

/* Expand button in match row */
.expand-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 4px;
  transition: all 0.15s;
  white-space: nowrap;
}
.expand-btn:hover { color: var(--text); border-color: var(--blue); }
.expand-btn.active { color: var(--blue); border-color: var(--blue); background: rgba(76,110,245,0.1); }

/* ─── Sticky first column ────────────────────────────────────────────────── */
#matches-table th:first-child,
#matches-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface);
  min-width: 180px;
  max-width: 280px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#matches-table th:first-child { z-index: 4; }
#matches-table tbody tr:hover td:first-child { background: var(--surface2); }
#matches-table td:first-child::after,
#matches-table th:first-child::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
  box-shadow: 2px 0 6px rgba(0,0,0,0.25);
}

/* ─── Column hide rules (CSS class on table toggles cols via data-col) ────── */
#matches-table.hide-col-tourn [data-col="col-tourn"] { display: none; }
#matches-table.hide-col-surf  [data-col="col-surf"]  { display: none; }
#matches-table.hide-col-vol   [data-col="col-vol"]   { display: none; }
#matches-table.hide-col-backA [data-col="col-backA"] { display: none; }
#matches-table.hide-col-layA  [data-col="col-layA"]  { display: none; }
#matches-table.hide-col-backB [data-col="col-backB"] { display: none; }
#matches-table.hide-col-layB  [data-col="col-layB"]  { display: none; }
#matches-table.hide-col-probA [data-col="col-probA"] { display: none; }
#matches-table.hide-col-probB [data-col="col-probB"] { display: none; }
#matches-table.hide-col-edgeA [data-col="col-edgeA"] { display: none; }
#matches-table.hide-col-edgeB [data-col="col-edgeB"] { display: none; }
#matches-table.hide-col-mom   [data-col="col-mom"]   { display: none; }
#matches-table.hide-col-fs1A  [data-col="col-fs1A"]  { display: none; }
#matches-table.hide-col-fs1B  [data-col="col-fs1B"]  { display: none; }
#matches-table.hide-col-fsWA  [data-col="col-fsWA"]  { display: none; }
#matches-table.hide-col-fsWB  [data-col="col-fsWB"]  { display: none; }
#matches-table.hide-col-ss2A  [data-col="col-ss2A"]  { display: none; }
#matches-table.hide-col-ss2B  [data-col="col-ss2B"]  { display: none; }
#matches-table.hide-col-aceA  [data-col="col-aceA"]  { display: none; }
#matches-table.hide-col-aceB  [data-col="col-aceB"]  { display: none; }
#matches-table.hide-col-dfA   [data-col="col-dfA"]   { display: none; }
#matches-table.hide-col-dfB   [data-col="col-dfB"]   { display: none; }
#matches-table.hide-col-bpA   [data-col="col-bpA"]   { display: none; }
#matches-table.hide-col-bpB   [data-col="col-bpB"]   { display: none; }
#matches-table.hide-col-sys   [data-col="col-sys"]   { display: none; }
#matches-table.hide-col-stat  [data-col="col-stat"]  { display: none; }

/* ─── Column picker dropdown ─────────────────────────────────────────────── */
.col-picker-wrap { position: relative; display: inline-block; }

.col-picker {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 150;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 280px;
  max-height: 480px;
  overflow-y: auto;
}
.col-picker.hidden { display: none; }

.col-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.col-group-label {
  padding: 8px 14px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  font-weight: 600;
}

.col-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 13px;
}
.col-check-row:hover { background: var(--surface2); }
.col-check-row input[type="checkbox"] { width: 13px; height: 13px; accent-color: var(--blue); flex-shrink: 0; }
.col-check-row label { cursor: pointer; flex: 1; user-select: none; }

/* ─── Backtest detail stat cards ─────────────────────────────────────────── */
.bt-stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.bt-stat-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}
.bt-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 4px;
}
.bt-stat-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}
.bt-stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── Backtest charts grid ────────────────────────────────────────────────── */
.bt-charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
}
.bt-chart-cell {
  background: var(--surface);
  padding: 12px;
}
.bt-chart-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.bt-chart-wrap { position: relative; height: 200px; }

/* Collapse/expand for charts panel */
#bt-charts-panel.collapsed { display: none; }

/* ─── Backtest strategy cards ─────────────────────────────────────────────── */
.bt-strat-card {
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}
.bt-strat-card:last-child { border-bottom: none; }
.bt-strat-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.bt-strat-name { font-weight: 700; font-size: 14px; margin-right: 8px; }
.bt-strat-desc { font-size: 12px; color: var(--muted); }
.bt-strat-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

/* ─── Bet records filter bar ─────────────────────────────────────────────── */
.bt-filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 13px;
}
.bt-filter-bar label { color: var(--muted); font-size: 12px; }
.bt-filter-bar select {
  padding: 4px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
}
.bt-filter-bar select:focus { outline: none; border-color: var(--blue); }
.bt-filter-stats {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
}
.bt-filter-stats span { white-space: nowrap; }

/* ─── Backtest save notice (reuse live-trading style) ───────────────────── */
#bt-strat-save-notice { margin: 12px 16px; }

/* ─── System card backtest stats row ──────────────────────────────────── */
.system-bt-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.system-bt-label {
  font-weight: 600;
  color: var(--text-sub);
  margin-right: 2px;
}
.system-bt-item strong { color: var(--text); }

/* ── Smart Filter Panel ───────────────────────────────────────────────── */
.smart-filter-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.smart-filter-panel.hidden { display: none; }

.sf-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.sf-group { display: flex; flex-direction: column; gap: 5px; }
.sf-group-actions { align-self: flex-end; }

.sf-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sf-checks { display: flex; flex-wrap: wrap; gap: 8px; }
.sf-checks label {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap;
}

.sf-range { display: flex; align-items: center; gap: 6px; }
.sf-range input { width: 72px; }
.sf-range span { color: var(--muted); }

.sf-group input[type="number"] {
  width: 90px;
  padding: 5px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
}
.sf-group input[type="number"]::placeholder { color: var(--muted); }
.sf-group input[type="number"]:focus {
  outline: none;
  border-color: var(--blue);
}

/* ── Advanced Filters Collapsible ────────────────────────────────────── */
#adv-filters-body { transition: max-height 0.2s ease, opacity 0.2s ease; overflow: hidden; }
#adv-filters-body.collapsed { max-height: 0 !important; opacity: 0; margin: 0; padding: 0; }

/* ── Chart dismiss button ─────────────────────────────────────────────── */
.mda-chart-dismiss {
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}
.mda-chart-dismiss:hover { color: var(--red); }

/* ── Custom Chart Builder Form ────────────────────────────────────────── */
.acf-form {
  background: var(--surface2);
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  grid-column: 1 / -1;   /* span full width of the charts grid */
}

.acf-form-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.acf-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.acf-input {
  width: 100%;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  margin-top: 5px;
}
.acf-input:focus { outline: none; border-color: var(--blue); }

.acf-metrics-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}

/* ─── Telegram settings ──────────────────────────────────────────────── */
.tg-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
  padding: 16px;
}
.tg-group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.tg-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.tg-toggle-row:last-child { border-bottom: none; }
.tg-toggle-label {
  font-size: 13px;
  color: var(--text);
}

.acf-metric-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  padding: 4px 0;
}
.acf-metric-label input[type="checkbox"] { cursor: pointer; }

/* ── Backtest Custom Chart Form ───────────────────────────────────────── */
.acf-bt-form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.acf-bt-form-grid .form-group { flex: 1; min-width: 160px; }
.acf-bt-form-grid .form-group label { display: block; margin-bottom: 5px; }

/* ─── Performance Tab ────────────────────────────────────────────────────── */
.perf-system-selector {
  margin: 12px 16px;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.perf-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.perf-selector-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 600;
  color: var(--muted);
}

.perf-checks-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.perf-check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.perf-check-label:hover {
  border-color: var(--blue);
  background: rgba(76,110,245,0.08);
}

.perf-check-label input[type="checkbox"] {
  accent-color: var(--blue);
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.perf-stat-section-title {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}

.perf-cards-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.perf-sys-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 160px;
  flex: 0 0 auto;
}

.perf-sys-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.perf-sys-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.perf-sys-stat {
  font-size: 12px;
  font-weight: 600;
}

.perf-sys-label {
  color: var(--muted);
  font-weight: 400;
}

.perf-sys-no-data {
  font-size: 11px;
  color: var(--muted);
}

.perf-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
}

/* ── Pre-match snapshot section ─────────────────────────────────── */
.mda-prematch-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 4px;
}
@media (max-width: 640px) { .mda-prematch-grid { grid-template-columns: 1fr; } }

.prematch-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.prematch-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 10px;
}

.prematch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.prematch-table th {
  text-align: right;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.prematch-table th.pm-col-a { color: #4c6ef5; }
.prematch-table th.pm-col-b { color: #00d68f; }
.prematch-table td {
  padding: 4px 6px;
  border-bottom: 1px solid rgba(46,49,80,0.4);
  text-align: right;
}
.prematch-table td.pm-label {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.prematch-table tr:last-child td { border-bottom: none; }

.drift-up   { color: var(--yellow); font-weight: 600; }
.drift-down { color: var(--green);  font-weight: 600; }
