/* ==========================================================================
   BingX Bot — dark fintech theme
   ========================================================================== */

:root {
  --bg: #0b0e14;
  --bg-elev: #0e121a;
  --card: #11151f;
  --card-hover: #141927;
  --border: #1f2531;
  --border-light: #2a3245;
  --text: #e6e9f0;
  --text-dim: #aeb6c8;
  --muted: #8b93a7;
  --faint: #5d6577;
  --green: #16c784;
  --green-dim: rgba(22, 199, 132, 0.12);
  --red: #ea3943;
  --red-dim: rgba(234, 57, 67, 0.12);
  --accent: #4f8cff;
  --accent-dim: rgba(79, 140, 255, 0.14);
  --amber: #f0a93b;
  --amber-dim: rgba(240, 169, 59, 0.12);
  --purple: #9b6dff;
  --purple-dim: rgba(155, 109, 255, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --sidebar-w: 200px;
  --topbar-h: 58px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #38415a; }

/* ---------- layout ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4f8cff 0%, #9b6dff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.logo-mark svg { width: 16px; height: 16px; }

.logo-text { font-size: 15px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.logo-text b { color: var(--accent); font-weight: 700; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 150ms ease, color 150ms ease;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text-dim); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-foot { padding: 14px 16px; border-top: 1px solid var(--border); font-size: 11.5px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; }

.topbar-badges { display: flex; gap: var(--sp-2); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--card);
  transition: border-color 150ms ease;
}
.status-badge.on { color: var(--green); border-color: rgba(22, 199, 132, 0.35); }
.status-badge.warn { color: var(--amber); border-color: rgba(240, 169, 59, 0.35); }
.status-badge.off { color: var(--muted); }

.content { padding: var(--sp-5); max-width: 1600px; width: 100%; margin: 0 auto; }

.tab { display: none; animation: fade-in 200ms ease; }
.tab.active { display: block; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--sp-4);
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: var(--sp-3);
}
.card-title .actions { display: flex; gap: var(--sp-2); text-transform: none; letter-spacing: 0; }

/* stat cards */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 150ms ease, transform 150ms ease;
}
.stat-card:hover { border-color: var(--border-light); transform: translateY(-1px); }

.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: 0.3px; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; font-family: var(--mono); letter-spacing: -0.3px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* two-column areas */

.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: var(--sp-4); margin-bottom: 0; }
.grid-2 > .card { margin-bottom: var(--sp-4); }

.split { display: grid; grid-template-columns: 340px 1fr; gap: var(--sp-4); align-items: start; }
.split > * { min-width: 0; } /* let .table-wrap scroll instead of stretching the page */
.split .panel-left { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); }

/* ---------- pnl colors ---------- */

.pos { color: var(--green); }
.neg { color: var(--red); }
.amber { color: var(--amber); }

/* ---------- badges & chips ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-long { background: var(--green-dim); color: var(--green); }
.badge-short { background: var(--red-dim); color: var(--red); }
.badge-paper { background: var(--accent-dim); color: var(--accent); }
.badge-live { background: var(--red-dim); color: var(--red); }
.badge-neutral { background: rgba(139, 147, 167, 0.12); color: var(--muted); }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-amber { background: var(--amber-dim); color: var(--amber); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-blue { background: var(--accent-dim); color: var(--accent); }

.chip {
  display: inline-block;
  padding: 1px 7px;
  margin: 1px 2px 1px 0;
  border-radius: 6px;
  background: rgba(79, 140, 255, 0.08);
  border: 1px solid rgba(79, 140, 255, 0.18);
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--mono);
  white-space: nowrap;
}

/* status dots */

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  flex-shrink: 0;
}
.dot.on, .dot.running { background: var(--green); }
.dot.off, .dot.stopped { background: #4a5266; }
.dot.warn { background: var(--amber); }
.dot.error { background: var(--red); }
.dot.pulse { animation: pulse-dot 1.8s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 199, 132, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(22, 199, 132, 0); }
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); border-color: #38415a; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* shared keyboard focus ring */
.btn:focus-visible,
.icon-btn:focus-visible,
.nav-item:focus-visible,
.btn-group button:focus-visible,
.history-item:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(79, 140, 255, 0.65);
  outline-offset: 2px;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3d7df5; border-color: #3d7df5; color: #fff; }

.btn-green { background: rgba(22, 199, 132, 0.14); border-color: rgba(22, 199, 132, 0.4); color: var(--green); }
.btn-green:hover { background: rgba(22, 199, 132, 0.24); border-color: var(--green); color: var(--green); }

.btn-danger { background: transparent; border-color: rgba(234, 57, 67, 0.4); color: var(--red); }
.btn-danger:hover { background: var(--red-dim); border-color: var(--red); color: var(--red); }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 6px; }

.btn-group { display: inline-flex; border: 1px solid var(--border-light); border-radius: var(--radius-sm); overflow: hidden; }
.btn-group button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.btn-group button:hover { color: var(--text); }
.btn-group button.active { background: var(--accent-dim); color: var(--accent); }
.btn-group button + button { border-left: 1px solid var(--border-light); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 150ms ease, color 150ms ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }

/* spinner */

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  border-radius: 50%;
  display: inline-block;
  animation: spin 700ms linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(31, 37, 49, 0.55);
  white-space: nowrap;
  vertical-align: middle;
}
table.data tbody tr { transition: background 150ms ease; }
table.data tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.num { font-family: var(--mono); font-size: 12.5px; }

tr.overfit { background: rgba(240, 169, 59, 0.06); }
tr.overfit:hover { background: rgba(240, 169, 59, 0.1) !important; }
tr.clickable { cursor: pointer; }

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding-top: var(--sp-3);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--sp-3); }
.field > span {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field output { color: var(--accent); font-family: var(--mono); text-transform: none; }

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], select, textarea {
  background: var(--bg-elev);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 11px;
  width: 100%;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.15);
}
input[type="number"] { font-family: var(--mono); font-size: 12.5px; }
input::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b93a7' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
  cursor: pointer;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-light);
  border-radius: 4px;
  outline: none;
  padding: 0;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff2;
  cursor: grab;
  transition: transform 150ms ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: none; cursor: grab;
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; margin-bottom: var(--sp-2); }
.check-row input { margin: 0; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-3); }

.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3);
  background: rgba(79, 140, 255, 0.04);
  border: 1px dashed rgba(79, 140, 255, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-3);
}
.param-grid .field { margin-bottom: 0; }
.param-grid .field > span { text-transform: none; font-family: var(--mono); font-size: 11px; }
.param-grid .empty-note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; text-align: center; padding: 4px; }

details.advanced { margin-bottom: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius-sm); }
details.advanced summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: color 150ms ease;
}
details.advanced summary:hover { color: var(--text-dim); }
details.advanced summary::before { content: '▸'; transition: transform 150ms ease; font-size: 10px; }
details.advanced[open] summary::before { transform: rotate(90deg); }
details.advanced .advanced-body { padding: var(--sp-3); padding-top: 0; }

.radio-pills { display: flex; gap: var(--sp-2); }
.radio-pill {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 150ms ease;
  user-select: none;
}
.radio-pill input { position: absolute; opacity: 0; pointer-events: none; }
.radio-pill:hover { border-color: #38415a; color: var(--text-dim); }
.radio-pill.checked { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.radio-pill.checked.danger { border-color: var(--red); background: var(--red-dim); color: var(--red); }

.warning-box {
  background: var(--red-dim);
  border: 1px solid rgba(234, 57, 67, 0.45);
  border-radius: var(--radius-sm);
  color: #ff8d94;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 11px 13px;
  margin-bottom: var(--sp-3);
}
.warning-box b { color: var(--red); }

.warning-box.amber {
  background: var(--amber-dim);
  border-color: rgba(240, 169, 59, 0.45);
  color: #ffd9a0;
}
.warning-box.amber b { color: var(--amber); }

/* tooltip */

.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--border-light);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  text-transform: none;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(3px);
  background: #1c2230;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-transform: none;
  padding: 8px 11px;
  border-radius: 8px;
  width: 230px;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 200;
  box-shadow: var(--shadow);
}
.tip:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- bots ---------- */

.bots-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: var(--sp-4); }

.bot-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  transition: border-color 150ms ease, transform 150ms ease;
}
.bot-card:hover { border-color: var(--border-light); }

.bot-card-head { display: flex; align-items: center; gap: 9px; }
.bot-card-head .name { font-weight: 600; font-size: 14.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bot-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.bot-meta b { color: var(--text-dim); font-weight: 500; }

.bot-stats { display: flex; gap: var(--sp-4); padding: 10px 12px; background: var(--bg-elev); border-radius: var(--radius-sm); }
.bot-stats .bs { flex: 1; }
.bot-stats .bs-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.bot-stats .bs-value { font-size: 15px; font-weight: 600; font-family: var(--mono); margin-top: 2px; }
.bot-stats .bs-value .badge { vertical-align: middle; }

.bot-error {
  font-size: 11.5px;
  color: var(--red);
  background: var(--red-dim);
  border-radius: 6px;
  padding: 5px 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

.bot-actions { display: flex; gap: var(--sp-2); margin-top: auto; }
.bot-actions .btn { flex: 1; }
.bot-actions .btn-danger { flex: 0 0 auto; }

/* bots strip on dashboard */

.bots-strip { display: flex; gap: var(--sp-3); overflow-x: auto; padding-bottom: 4px; }
.bot-mini {
  min-width: 230px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  transition: border-color 150ms ease;
}
.bot-mini:hover { border-color: var(--border-light); }
.bot-mini .row1 { display: flex; align-items: center; gap: 8px; }
.bot-mini .row1 .name { font-weight: 600; font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-mini .row2 { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }

/* ---------- charts ---------- */

.chart-box { position: relative; width: 100%; }
.chart-box .lw-attribution,
.chart-box #tv-attr-logo { display: none !important; }

.range-toggle { display: flex; justify-content: flex-end; }

/* ---------- metrics grid (backtest) ---------- */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.metric-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  transition: border-color 150ms ease;
}
.metric-tile:hover { border-color: var(--border-light); }
.metric-tile .m-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.metric-tile .m-value { font-size: 17px; font-weight: 700; font-family: var(--mono); margin-top: 4px; letter-spacing: -0.3px; }
.metric-tile.good { border-color: rgba(22, 199, 132, 0.3); }
.metric-tile.good .m-value { color: var(--green); }
.metric-tile.bad { border-color: rgba(234, 57, 67, 0.3); }
.metric-tile.bad .m-value { color: var(--red); }

.metrics-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.metrics-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- history lists (prev backtests / jobs) ---------- */

.history-list { display: flex; flex-direction: column; gap: var(--sp-2); max-height: 420px; overflow-y: auto; }
.history-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  transition: border-color 150ms ease, background 150ms ease;
}
.history-item:hover { border-color: var(--accent); background: rgba(79, 140, 255, 0.05); }
.history-item .hi-main { flex: 1; min-width: 0; }
.history-item .hi-title { font-weight: 600; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .hi-sub { color: var(--muted); font-size: 11px; margin-top: 1px; }
.history-item .hi-right { font-family: var(--mono); font-size: 12px; text-align: right; flex-shrink: 0; }

/* ---------- progress ---------- */

.progress-wrap { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-3) 0; }
.progress-track { flex: 1; height: 8px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 999px;
  transition: width 400ms ease;
}
.progress-label { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 90px; text-align: right; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: #161c29;
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text-dim);
  box-shadow: var(--shadow);
  animation: toast-in 200ms ease;
  word-break: break-word;
}
.toast-success { border-left-color: var(--green); }
.toast-error { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateX(20px); transition: opacity 250ms ease, transform 250ms ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh var(--sp-4) var(--sp-4);
  z-index: 500;
  overflow-y: auto;
  animation: fade-in 150ms ease;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
  animation: modal-in 200ms ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  margin-top: var(--sp-3);
}

/* ---------- skeleton / empty / loading ---------- */

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #141927 25%, #1a2030 37%, #141927 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  min-height: 18px;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

.skeleton-rows { display: flex; flex-direction: column; gap: 10px; }

.empty {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--muted);
}
.empty .empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(139, 147, 167, 0.08);
  border: 1px solid var(--border);
  color: var(--faint);
  margin-bottom: 12px;
}
.empty .empty-icon svg { width: 20px; height: 20px; }
.empty .empty-title { font-weight: 600; color: var(--text-dim); font-size: 13.5px; }
.empty .empty-hint { font-size: 12.5px; margin-top: 4px; max-width: 360px; margin-left: auto; margin-right: auto; }

/* ---------- responsive ---------- */

@media (max-width: 1280px) {
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .split .panel-left { position: static; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 880px) {
  .sidebar { width: 60px; }
  .sidebar .logo-text, .nav-item span, .sidebar-foot { display: none; }
  .logo { justify-content: center; padding: 0; }
  .nav-item { justify-content: center; padding: 11px 0; }
  .content { padding: var(--sp-3); }
  .topbar h1 { font-size: 15px; }
  .metrics-grid,
  .metrics-grid.cols-3,
  .metrics-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .fi-row { grid-template-columns: 110px 1fr 56px; }
}

@media (max-width: 640px) {
  /* compact connection badges to status dots so the topbar never overflows */
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .topbar-badges { gap: 6px; }
  .status-badge { padding: 7px; }
  .status-badge .badge-label { display: none; }
}

/* ---------------------------------------------------------------------- */
/* tag-style multi-symbol input                                            */
/* ---------------------------------------------------------------------- */

.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  background: var(--bg-elev);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
  min-height: 36px;
  cursor: text;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.tag-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.15);
}
.tag-input input {
  flex: 1;
  min-width: 90px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 3px 4px !important;
  font-family: var(--mono);
  font-size: 12.5px;
  width: auto;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px 2px 9px;
  border-radius: 6px;
  background: var(--accent-dim);
  border: 1px solid rgba(79, 140, 255, 0.3);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--mono);
  white-space: nowrap;
  animation: fade-in 120ms ease;
}
.tag .tag-x {
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0.6;
  font-size: 13px;
  line-height: 1;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 150ms ease, background 150ms ease;
}
.tag .tag-x:hover { opacity: 1; background: rgba(79, 140, 255, 0.18); }

.tag-hint { font-size: 11px; color: var(--faint); margin: -8px 0 10px; }

/* ---------------------------------------------------------------------- */
/* risk & exits panel (backtest advanced + bot modal)                      */
/* ---------------------------------------------------------------------- */

.risk-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-3);
  background: rgba(155, 109, 255, 0.04);
  border: 1px dashed rgba(155, 109, 255, 0.22);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-3);
}
.risk-panel .form-row { margin-bottom: 0; }
.risk-panel .check-row { margin: 6px 0; }

.risk-sub {
  margin: 2px 0 8px 23px;
  padding-left: 12px;
  border-left: 2px solid rgba(155, 109, 255, 0.25);
  animation: fade-in 150ms ease;
}
.risk-sub .form-row .field { margin-bottom: var(--sp-2); }

.risk-head {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 10px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.risk-head:first-child { margin-top: 0; }
.risk-head::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------------------------------------------------------------------- */
/* adaptive mode (self-improving bots)                                     */
/* ---------------------------------------------------------------------- */

.dot.pending { background: var(--amber); animation: pulse-amber 1.6s ease-in-out infinite; }

@keyframes pulse-amber {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 169, 59, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(240, 169, 59, 0); }
}

.insights-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.insight {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--purple);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.diff-old { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(234, 57, 67, 0.6); }
.diff-new { color: var(--green); font-weight: 600; }
.diff-arrow { color: var(--faint); padding: 0 6px; }

.improve-modal { max-width: 680px; }

/* ---------------------------------------------------------------------- */
/* creator result cards                                                    */
/* ---------------------------------------------------------------------- */

.gen-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: var(--sp-3);
  transition: border-color 150ms ease;
}
.gen-card:hover { border-color: var(--border-light); }

.gen-card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: 9px;
}
.gen-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 5px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(79, 140, 255, 0.18), rgba(155, 109, 255, 0.18));
  border: 1px solid rgba(155, 109, 255, 0.3);
  color: var(--purple);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.gen-card-head .name { font-weight: 600; font-size: 13.5px; flex: 1; min-width: 160px; }
.gen-score { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.gen-score b { color: var(--text); font-size: 13px; }

.gen-rules {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.mchips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.mchips .set-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-right: 2px;
}
.mchip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.mchip b { font-family: var(--mono); font-size: 11.5px; font-weight: 600; color: var(--text-dim); }
.mchip b.pos { color: var(--green); }
.mchip b.neg { color: var(--red); }
.mchip.warn { border-color: rgba(240, 169, 59, 0.4); background: var(--amber-dim); color: var(--amber); }
.mchip.warn b { color: var(--amber); }
.mchips .sep { width: 1px; height: 16px; background: var(--border-light); margin: 0 4px; }

.gen-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ---------------------------------------------------------------------- */
/* ML lab — feature importance bars + expandable table rows                */
/* ---------------------------------------------------------------------- */

.fi-rows { display: flex; flex-direction: column; gap: 6px; max-width: 560px; }
.fi-row { display: grid; grid-template-columns: 150px 1fr 64px; align-items: center; gap: 10px; }
.fi-name {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}
.fi-track { height: 8px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.fi-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 999px;
  min-width: 2px;
}
.fi-val { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: right; }

tr.detail-row > td {
  background: var(--bg-elev);
  padding: 14px 16px;
  white-space: normal;
}
tr.detail-row:hover { background: transparent !important; }

.expander-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 5px;
  transition: transform 150ms ease, color 150ms ease, background 150ms ease;
}
.expander-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.expander-btn.open { transform: rotate(90deg); }

.algo-pills .radio-pill { flex-direction: column; gap: 2px; padding: 9px 8px; }
.algo-pills .radio-pill small { font-size: 10px; color: var(--faint); font-weight: 400; }
.algo-pills .radio-pill.checked small { color: inherit; opacity: 0.75; }

/* per-symbol expanders inside multi-backtest results */

details.sym-expander { margin-bottom: var(--sp-2); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); }
details.sym-expander summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
details.sym-expander summary::before { content: '▸'; color: var(--muted); transition: transform 150ms ease; font-size: 10px; }
details.sym-expander[open] summary::before { transform: rotate(90deg); }
details.sym-expander summary .sum-right { margin-left: auto; display: flex; gap: 14px; font-family: var(--mono); font-size: 12px; font-weight: 500; }
details.sym-expander .sym-body { padding: 4px 14px 14px; }

/* ---------------------------------------------------------------------- */
/* login overlay (shown when ADMIN_USER/ADMIN_PASSWORD auth is enabled)    */
/* ---------------------------------------------------------------------- */

.login-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 480px at 50% -8%, rgba(79, 140, 255, 0.09), transparent 65%),
    radial-gradient(700px 420px at 85% 110%, rgba(155, 109, 255, 0.05), transparent 60%),
    var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  animation: fade-in 150ms ease;
}

.login-card {
  width: min(380px, calc(100vw - 32px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 26px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}
.login-logo .logo-mark { width: 34px; height: 34px; border-radius: 9px; }
.login-logo .logo-mark svg { width: 18px; height: 18px; }
.login-logo .logo-text { font-size: 17px; }

.login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 24px;
}

.login-error {
  color: #ea3943;
  font-size: 12.5px;
  min-height: 18px;
  margin: 2px 0 10px;
  text-align: center;
}
