/* ==========================================================================
   FluxBot — dark / light trading theme
   Token-driven: swapping these variables re-skins the whole app, and the
   [data-theme="light"] block below flips them for light mode.
   ========================================================================== */

:root, :root[data-theme="dark"] {
  --bg: #0a0b10;
  --bg-elev: #0f1017;
  --card: #14151d;
  --card-hover: #191b24;
  --card2: #191b24;
  --elev: #1e2130;
  --border: rgba(255, 255, 255, 0.07);
  --border-light: rgba(255, 255, 255, 0.14);
  --text: #eef0f6;
  --text-dim: #c3c7d4;
  --muted: #9ca0b0;
  --faint: #63667a;
  --green: #2ee6a6;
  --green-dim: rgba(46, 230, 166, 0.13);
  --red: #ff5470;
  --red-dim: rgba(255, 84, 112, 0.13);
  --accent: #7b6cff;
  --accent-2: #a390ff;
  --accent-dim: rgba(123, 108, 255, 0.15);
  --amber: #ffb545;
  --amber-dim: rgba(255, 181, 69, 0.14);
  --purple: #a390ff;
  --purple-dim: rgba(163, 144, 255, 0.16);
  --input-bg: #191b24;
  --grad: linear-gradient(135deg, var(--accent), #9b5cf0);
  --grad-glow: 0 10px 26px -12px rgba(123, 108, 255, 0.9);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'Space Grotesk', 'Manrope', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
  --sidebar-w: 236px;
  --topbar-h: 60px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
}

/* ---------- light theme (ported from FluxBot design) ---------- */
:root[data-theme="light"] {
  --bg: #eef0f6;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-hover: #f7f8fc;
  --card2: #f7f8fc;
  --elev: #ffffff;
  --border: rgba(12, 16, 40, 0.09);
  --border-light: rgba(12, 16, 40, 0.18);
  --text: #12141c;
  --text-dim: #3c4152;
  --muted: #565a6b;
  --faint: #8a8ea1;
  --green: #00b37a;
  --green-dim: rgba(0, 179, 122, 0.12);
  --red: #e23a5a;
  --red-dim: rgba(226, 58, 90, 0.10);
  --accent: #5b4be6;
  --accent-2: #6f5cf0;
  --accent-dim: rgba(91, 75, 230, 0.10);
  --amber: #e0930a;
  --amber-dim: rgba(224, 147, 10, 0.12);
  --purple: #6f5cf0;
  --purple-dim: rgba(111, 92, 240, 0.12);
  --input-bg: #f7f8fc;
  --grad: linear-gradient(135deg, var(--accent), #7a5cf0);
  --grad-glow: 0 12px 26px -14px rgba(91, 75, 230, 0.55);
  --shadow: 0 18px 45px -22px rgba(30, 40, 90, 0.28);
}

* { 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: 20px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ---------- 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: 11px;
  height: var(--topbar-h);
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-mark {
  width: 31px;
  height: 31px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-mark svg { width: 31px; height: 31px; display: block; }

.logo-text { font-family: var(--font-display); font-size: 19px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.logo-text b { color: var(--accent-2); font-weight: 700; }

.nav { display: flex; flex-direction: column; gap: 3px; padding: 14px 12px; flex: 1; overflow-y: auto; }

.nav-group {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 14px 12px 8px;
}
.nav-group:first-child { padding-top: 6px; }

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

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-foot .muted { font-family: var(--mono); color: var(--faint); }
.live-pip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--green); }
.live-pip .dot { width: 6px; height: 6px; }

.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: var(--bg);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

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

/* topbar light/dark toggle: bordered box (design) + icon for the theme you'd switch TO */
.theme-toggle {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); color: var(--muted);
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-light); background: var(--card); }
.theme-toggle svg { width: 17px; height: 17px; display: block; }
.theme-toggle .ico-light { display: none; }
:root[data-theme="light"] .theme-toggle .ico-dark { display: none; }
:root[data-theme="light"] .theme-toggle .ico-light { display: block; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--card);
  transition: border-color 150ms ease;
}
.status-badge.on { color: var(--green); border-color: rgba(46, 230, 166, 0.35); }
.status-badge.warn { color: var(--amber); border-color: rgba(255, 181, 69, 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 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: 11.5px;
  color: var(--faint);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
  min-height: 18px;
}
.stat-value { font-size: 27px; font-weight: 600; font-family: var(--mono); letter-spacing: -0.02em; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.stat-sub .dot-sep { color: var(--faint); margin: 0 1px; }

/* Account sync: "as of <relative>" freshness line + manual "Sync now" button */
.sync-as-of { color: var(--muted); }
.sync-as-of.stale { color: var(--amber); }

.icon-btn.sync-now {
  font-size: 0;
  padding: 3px;
  margin: -3px -3px -3px 0;
  color: var(--faint);
  display: inline-flex;
  align-items: center;
}
.icon-btn.sync-now svg { width: 14px; height: 14px; display: block; }
.icon-btn.sync-now:hover:not(:disabled) { color: var(--accent); background: var(--card-hover); }
.icon-btn.sync-now:disabled { cursor: default; opacity: 0.8; }
.icon-btn.sync-now.spinning { color: var(--accent); }
.icon-btn.sync-now.spinning svg { animation: spin 700ms linear infinite; }

/* 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 7px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  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: 2px 7px;
  margin: 1px 2px 1px 0;
  border-radius: 5px;
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--mono);
  white-space: nowrap;
}

/* status dots */

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  flex-shrink: 0;
}
/* status dots carry a soft halo ring in the FluxBot design (bot cards etc.) */
.dot.on, .dot.running { background: var(--green); box-shadow: 0 0 0 4px var(--green-dim); }
.dot.off, .dot.stopped { background: var(--faint); box-shadow: 0 0 0 4px rgba(139, 147, 167, 0.12); }
.dot.warn, .dot.pending { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-dim); }
.dot.error { background: var(--red); box-shadow: 0 0 0 4px var(--red-dim); }
/* compact dots (topbar connection badges, sidebar Live pip) stay small + ringless */
.status-badge .dot, .live-pip .dot { width: 6px; height: 6px; box-shadow: none; }
.dot.pulse { animation: pulse-dot 1.8s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 230, 166, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(46, 230, 166, 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: 600;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease, filter 150ms ease;
  white-space: nowrap;
}
.btn:hover { background: var(--card-hover); color: var(--text); border-color: var(--border-light); }
.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(123, 108, 255, 0.65);
  outline-offset: 2px;
}

.btn-primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: var(--grad-glow); }
.btn-primary:hover { background: var(--grad); border-color: transparent; color: #fff; filter: brightness(1.08); }
.btn-primary:disabled { filter: none; }

.btn-green { background: rgba(46, 230, 166, 0.14); border-color: rgba(46, 230, 166, 0.4); color: var(--green); }
.btn-green:hover { background: rgba(46, 230, 166, 0.24); border-color: var(--green); color: var(--green); }

.btn-danger { background: transparent; border-color: rgba(255, 84, 112, 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: var(--card-hover); color: var(--text); }

/* spinner */

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-light);
  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 var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
table.data tbody tr { transition: background 150ms ease; }
table.data tbody tr:hover { background: var(--card-hover); }
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(255, 181, 69, 0.06); }
tr.overfit:hover { background: rgba(255, 181, 69, 0.1) !important; }
tr.clickable { cursor: pointer; }

/* portfolio total in the per-symbol comparison (multi backtest) */
table.data tr.combined-row td { border-top: 1px solid var(--border-light); background: rgba(123, 108, 255, 0.04); }

.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(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 9px 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 var(--accent-dim);
}
input[type="number"] { font-family: var(--mono); font-size: 12.5px; }
input::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }
:root[data-theme="light"] input::-webkit-calendar-picker-indicator { filter: none; }

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(123, 108, 255, 0.04);
  border: 1px dashed rgba(123, 108, 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: var(--border-light); 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(255, 84, 112, 0.45);
  border-radius: var(--radius-sm);
  color: var(--red);
  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(255, 181, 69, 0.45);
  color: var(--amber);
}
.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: var(--elev);
  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(--card2); 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(--card2);
  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); }

/* cards/minis open the detail view — signal it without overriding the dot
 * cursor (the inner rename input keeps a text caret) */
.bot-card[data-bot-card], .bot-mini[data-bot-card] { cursor: pointer; }
.bot-card[data-bot-card]:focus-visible,
.bot-mini[data-bot-card]:focus-visible {
  outline: 2px solid rgba(123, 108, 255, 0.55);
  outline-offset: 2px;
}

/* ---------- inline rename (pencil + editor) ---------- */

.rename-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, color 150ms ease, background 150ms ease, border-color 150ms ease;
}
.rename-btn svg { width: 13px; height: 13px; display: block; }
.bot-card:hover .rename-btn,
.bot-mini:hover .rename-btn,
.bd-head-main .rename-btn { opacity: 1; }
.rename-btn:hover { color: var(--accent); background: rgba(123, 108, 255, 0.10); }
.rename-btn:focus-visible {
  opacity: 1; outline: none;
  color: var(--accent);
  border-color: rgba(123, 108, 255, 0.55);
}
.rename-btn:active { transform: scale(0.9); }

.rename-form { display: inline-flex; align-items: center; gap: 5px; width: 100%; }
.rename-input {
  flex: 1;
  min-width: 60px;
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text);
  background: var(--card2);
  border: 1px solid var(--accent);
  border-radius: 6px;
}
.rename-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(123, 108, 255, 0.3); }
.rename-ok, .rename-cancel {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: transparent;
  font-size: 13px; line-height: 1;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.rename-ok { color: var(--green); }
.rename-ok:hover { background: var(--green-dim); border-color: var(--green); }
.rename-cancel { color: var(--muted); }
.rename-cancel:hover { color: var(--red); background: var(--red-dim); border-color: var(--red); }
.rename-ok:disabled, .rename-cancel:disabled, .rename-input:disabled { opacity: 0.5; cursor: default; }

/* ---------- bot detail page (#bot/<id>) ---------- */

.bp-topline { display: flex; align-items: center; margin-bottom: var(--sp-4); }
.bp-back { color: var(--text-dim); }
.bp-back:hover { color: var(--text); }

/* header wraps to two rows when cramped (adaptive bots add a badge + button) */
.bp-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-3);
}
.bd-head-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  flex: 1 1 260px;
}
.bd-title {
  font-size: 18px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 60px;
  max-width: 100%;
}
.bd-head-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--sp-2);
  flex: 0 0 auto;
  margin-left: auto;
}
.bd-refresh { font-size: 0; padding: 5px 7px; color: var(--muted); }
.bd-refresh svg { width: 14px; height: 14px; display: block; }
.bd-refresh:hover { color: var(--accent); }
/* keep the inline rename editor usable when it replaces the title */
.bd-title .rename-form { min-width: 220px; }
.bd-title .rename-input { font-size: 15px; }
/* param chips inside the config line */
.bd-sub .chip { vertical-align: middle; }

.bd-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: var(--sp-4);
}
.bd-sub .dot-sep { color: var(--faint); margin: 0 3px; }

.metrics-grid.bd-tiles { margin-bottom: var(--sp-3); }

.bd-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px 12px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-2);
  font-size: 13px;
}
.bd-row-label {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 100px;
}
.bd-row-value { color: var(--text-dim); }
.bd-row-value .muted { font-size: 12px; }
.toggle-inline { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12px; }
.toggle-inline input { cursor: pointer; }
.toggle-inline .good { color: var(--green); }
/* Unrealized PnL: dotted underline hints "still moving"; tooltip carries details */
.upnl { border-bottom: 1px dotted var(--muted); cursor: help; }

.bd-error {
  font-size: 12px;
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid rgba(255, 84, 112, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: var(--sp-2);
}

/* subtle note over the candles when the bot has no trades yet */
.bd-chart-note {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 5px 12px;
  font-size: 11.5px;
  color: var(--muted);
  background: color-mix(in srgb, var(--card) 84%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- 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(--card2);
  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(46, 230, 166, 0.3); }
.metric-tile.good .m-value { color: var(--green); }
.metric-tile.bad { border-color: rgba(255, 84, 112, 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); }

/* "vs Market" group — alpha is the headline number */
.metric-tile.alpha .m-value { font-size: 19px; }

/* equity chart legend (strategy line vs buy & hold benchmark overlay) */
.chart-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11.5px;
  color: var(--muted);
  margin: -6px 0 8px;
}
.chart-legend .lg-item { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend .lg-swatch { width: 18px; height: 0; border-top: 2px solid; border-radius: 1px; }
.chart-legend .lg-swatch.lg-strategy { border-top-style: solid; border-top-color: var(--accent); }
.chart-legend .lg-swatch.lg-benchmark { border-top-style: dashed; border-top-color: rgba(122, 144, 182, 0.8); }

/* ---------- 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(--card2);
  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(123, 108, 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; }
.history-item .hi-del {
  flex-shrink: 0;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 16px; line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, color 150ms ease, border-color 150ms ease, background 150ms ease;
}
.history-item:hover .hi-del { opacity: 1; }
.history-item .hi-del:hover { color: var(--red); border-color: var(--red); background: rgba(255, 84, 112, 0.08); }
.history-item .hi-del:focus-visible { opacity: 1; outline: none; border-color: var(--red); color: var(--red); }

/* ---------- 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(--card2); 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: var(--elev);
  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); }
}

/* ---------- background-analysis banner (top strip) ---------- */

.bg-banner-host {
  position: sticky;
  top: var(--topbar-h);
  z-index: 49;
  display: flex;
  flex-direction: column;
}
.bg-banner-host:empty { display: none; }

.bg-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px var(--sp-5);
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--card2);
  animation: fade-in 200ms ease;
}
.bg-banner b { color: var(--text); font-weight: 600; }
.bg-banner .spinner { color: var(--accent); width: 13px; height: 13px; }
.bg-banner-text { min-width: 0; }
.bg-banner-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.bg-banner-running { border-left: 3px solid var(--accent); }

.bg-banner-done {
  border-left: 3px solid var(--green);
  color: var(--text-dim);
  background: linear-gradient(90deg, var(--green-dim), transparent 60%), var(--card2);
}
.bg-banner-done .bg-banner-icon { background: var(--green-dim); color: var(--green); }

.bg-banner-failed {
  border-left: 3px solid var(--red);
  background: linear-gradient(90deg, var(--red-dim), transparent 60%), var(--card2);
}
.bg-banner-failed .bg-banner-icon { background: var(--red-dim); color: var(--red); }

.bg-banner-link {
  margin-left: auto;
  color: var(--green);
  font-weight: 600;
  white-space: nowrap;
}
.bg-banner-link:hover { text-decoration: underline; }

.bg-banner-x {
  margin-left: 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}
.bg-banner-running .bg-banner-x { margin-left: auto; }
.bg-banner-x:hover { color: var(--text); }

/* ---------- 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, var(--card-hover) 25%, var(--elev) 37%, var(--card-hover) 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; }

/* ---------- Leverage Lab (backtest tab + bot modal hint) ---------- */

.card-title .actions { align-items: center; }

.lev-reco {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 13px;
  margin-bottom: var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(46, 230, 166, 0.35);
  background: var(--green-dim);
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
}
.lev-reco .lev-reco-badge {
  font-family: var(--mono);
  font-weight: 700;
  white-space: nowrap;
  color: var(--green);
}
.lev-reco.warn {
  border-color: rgba(255, 181, 69, 0.45);
  background: var(--amber-dim);
}
.lev-reco.warn .lev-reco-badge { color: var(--amber); }

.lev-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.lev-legend .sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: -1px;
  font-style: normal;
}
.lev-legend .sw.ret { background: var(--green); }
.lev-legend .sw.dd { background: rgba(255, 84, 112, 0.55); width: 5px; }
.lev-legend .sw.liq { background: none; color: var(--red); font-weight: 700; width: auto; }
.lev-legend .sw.dist { background: linear-gradient(90deg, var(--green), transparent); height: 3px; vertical-align: 2px; }

.lev-bars {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin: 2px 0 14px;
  overflow-x: auto;
}
.lev-cell {
  flex: 1 1 0;
  min-width: 52px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 3px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.012);
}
.lev-cell.empty { opacity: 0.6; }
.lev-cell.rec {
  border-color: rgba(46, 230, 166, 0.4);
  background: rgba(46, 230, 166, 0.06);
  box-shadow: 0 0 0 1px rgba(46, 230, 166, 0.18);
}
.lev-cell.rec.warn {
  border-color: rgba(255, 181, 69, 0.45);
  background: var(--amber-dim);
  box-shadow: 0 0 0 1px rgba(255, 181, 69, 0.2);
}
.lev-ret { font-family: var(--mono); font-size: 10.5px; font-weight: 600; }
.lev-ret.pos { color: var(--green); }
.lev-ret.neg { color: var(--red); }
.lev-plot { position: relative; width: 100%; height: 66px; }
.lev-plot-axis {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  border-top: 1px dashed var(--border-light);
}
.lev-bar { position: absolute; display: block; }
.lev-bar.ret { left: calc(50% - 9px); width: 11px; }
.lev-bar.ret.pos { background: var(--green); border-radius: 3px 3px 1px 1px; }
.lev-bar.ret.neg { background: var(--red); border-radius: 1px 1px 3px 3px; }
.lev-bar.dd {
  left: calc(50% + 4px);
  width: 4px;
  background: rgba(255, 84, 112, 0.5);
  border-radius: 0 0 2px 2px;
}
.lev-none {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  font-size: 10px;
  color: var(--faint);
  white-space: nowrap;
}
.lev-liq {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  width: 15px;
  height: 15px;
  line-height: 14px;
  text-align: center;
  border-radius: 50%;
  background: var(--red-dim);
  border: 1px solid rgba(255, 84, 112, 0.5);
  color: var(--red);
  font-size: 9.5px;
  font-weight: 700;
}
.lev-x { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--text-dim); }
.lev-cell.rec .lev-x { color: var(--green); }
.lev-cell.rec.warn .lev-x { color: var(--amber); }
.lev-dist { display: flex; align-items: center; gap: 4px; width: 82%; }
.lev-dist-track {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}
.lev-dist-fill { display: block; height: 100%; border-radius: 2px; }
.lev-dist-fill.ok { background: var(--green); opacity: 0.7; }
.lev-dist-fill.warn { background: var(--amber); opacity: 0.8; }
.lev-dist-fill.bad { background: var(--red); }
.lev-dist > span {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted);
  min-width: 16px;
  text-align: right;
}
table.data tr.lev-rec-row td { background: rgba(46, 230, 166, 0.05); }
table.data tr.lev-rec-row.warn td { background: rgba(255, 181, 69, 0.05); }

/* one-line suggestion under the bot-modal leverage slider */
.lev-hint {
  margin: -6px 0 12px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(46, 230, 166, 0.3);
  background: var(--green-dim);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.45;
}
.lev-hint b { color: var(--green); }
.lev-hint.warn { border-color: rgba(255, 181, 69, 0.4); background: var(--amber-dim); }
.lev-hint.warn b { color: var(--amber); }

/* ---------- 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(--card2);
  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(123, 108, 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(123, 108, 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(123, 108, 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(163, 144, 255, 0.04);
  border: 1px dashed rgba(163, 144, 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(163, 144, 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); }

/* ---------------------------------------------------------------------- */
/* Auto-configure risk/exits (bot modal)                                   */
/* ---------------------------------------------------------------------- */

.risk-auto-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: var(--sp-3);
}
.risk-auto-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
}
#bot-autorisk-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex: none;
}
#bot-autorisk-btn .ico { width: 14px; height: 14px; }
#bot-autorisk-btn:not(:disabled) {
  border-color: rgba(163, 144, 255, 0.45);
  color: var(--purple);
}
#bot-autorisk-btn:not(:disabled):hover {
  background: var(--purple-dim);
  border-color: var(--purple);
}

.autorisk-panel:empty { display: none; }
.autorisk-panel { margin-bottom: var(--sp-3); }
.autorisk-loading { padding: 4px 0 2px; }

.autorisk-reco {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: var(--sp-2);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(163, 144, 255, 0.35);
  background: var(--purple-dim);
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
}
.autorisk-reco-badge {
  font-weight: 700;
  white-space: nowrap;
  color: var(--purple);
}
.autorisk-reco.native {
  border-color: rgba(46, 230, 166, 0.35);
  background: var(--green-dim);
}
.autorisk-reco.native .autorisk-reco-badge { color: var(--green); }

.autorisk-rows { display: flex; flex-direction: column; gap: 7px; }
.autorisk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.autorisk-row-main { min-width: 0; flex: 1; }
.autorisk-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.autorisk-star { color: var(--purple); font-size: 12px; }
.autorisk-hint {
  font-size: 10.5px;
  color: var(--faint);
  margin-top: 1px;
}
.autorisk-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
}
.ar-chip {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.ar-chip b { font-family: var(--mono); font-weight: 600; color: var(--text-dim); }
.ar-chip b.pos { color: var(--green); }
.ar-chip b.neg { color: var(--red); }
.autorisk-act { flex: none; }
.autorisk-row.autorisk-rec {
  border-color: rgba(163, 144, 255, 0.4);
  background: rgba(163, 144, 255, 0.07);
}
.autorisk-row.autorisk-na { opacity: 0.55; }
.autorisk-row.autorisk-na .autorisk-name { font-weight: 500; }
.autorisk-src { font-size: 11px; margin-top: 9px; text-align: right; }

/* ---------------------------------------------------------------------- */
/* 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(255, 181, 69, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(255, 181, 69, 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(--card2);
  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(255, 84, 112, 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(123, 108, 255, 0.18), rgba(163, 144, 255, 0.18));
  border: 1px solid rgba(163, 144, 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(--card2);
  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(--card2);
  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(255, 181, 69, 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(--card2); 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(--card2);
  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: var(--card-hover); }
.expander-btn.open { transform: rotate(90deg); }

.algo-pills { flex-direction: column; align-items: stretch; }
.algo-pills .radio-pill { flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: 11px 13px; }
.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(--card2); }
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(123, 108, 255, 0.09), transparent 65%),
    radial-gradient(700px 420px at 85% 110%, rgba(163, 144, 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: var(--shadow);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  margin-bottom: 6px;
}
.login-logo .logo-mark { width: 44px; height: 44px; border-radius: 0; background: none; }
.login-logo .logo-mark svg { width: 44px; height: 44px; }
.login-logo .logo-text { font-size: 24px; }

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

.login-error {
  color: var(--red);
  font-size: 12.5px;
  min-height: 18px;
  margin: 2px 0 10px;
  text-align: center;
}

.login-switch {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 16px;
}
.login-switch a { color: var(--accent-2); text-decoration: none; font-weight: 600; }
.login-switch a:hover { text-decoration: underline; }

.user-chip { font-weight: 600; color: var(--text-dim); }

/* ---------- strategies overview (ranked leaderboard tab) ---------- */

/* kind badges: distinct muted hues per strategy origin (FluxBot tag palette) */
.badge-kind-builtin { background: rgba(127, 147, 201, 0.14); color: #7f93c9; }
.badge-kind-discovered { background: var(--green-dim); color: var(--green); }
.badge-kind-ml { background: var(--accent-dim); color: var(--accent-2); }

.score-badge {
  display: inline-block;
  min-width: 46px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(139, 147, 167, 0.12);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: help;
}
.score-badge.good { background: var(--green-dim); color: var(--green); }
.score-badge.bad { background: var(--red-dim); color: var(--red); }

/* client-side column sorting */
table.data th.sortable { cursor: pointer; user-select: none; transition: color 150ms ease; }
table.data th.sortable:hover { color: var(--text); }
table.data th .sort-arrow { font-size: 8px; color: var(--accent); margin-left: 3px; vertical-align: 1px; }

#sv-data td.sv-strat { white-space: normal; min-width: 190px; max-width: 320px; }
#sv-data td.sv-strat b { color: var(--text); }
#sv-data td.sv-strat .badge { margin-left: 6px; vertical-align: middle; }

/* strategies without any stored backtest sink to the bottom, muted */
#sv-data tr.sv-untested td { color: var(--faint); }
#sv-data tr.sv-untested td.sv-noresults { font-size: 12px; font-style: italic; letter-spacing: 0.2px; }
#sv-data tr.sv-untested .sv-strat b { color: var(--muted); }
#sv-data tr.sv-untested .badge { opacity: 0.65; }

/* ---------- favourite strategies (star to pin to the top) ---------- */

/* gold accent, distinct from the blue/green theme accents so a starred
 * strategy reads at a glance */
:root { --fav-gold: #f5c451; }

/* leading star column: keep it tight against the expander */
#sv-data th.sv-fav-th { width: 26px; padding-left: 0; padding-right: 0; }
#sv-data td.sv-fav-cell { width: 26px; padding-left: 0; padding-right: 0; text-align: center; }

.fav-star {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  font-size: 16px;
  color: var(--faint);
  border-radius: 5px;
  transition: color 120ms ease, background 120ms ease, transform 120ms ease;
}
.fav-star:hover { color: var(--fav-gold); background: rgba(245, 196, 81, 0.10); }
.fav-star:focus-visible {
  outline: none;
  color: var(--fav-gold);
  box-shadow: 0 0 0 2px rgba(245, 196, 81, 0.45);
}
.fav-star:active { transform: scale(0.88); }
.fav-star.on { color: var(--fav-gold); }
.fav-star.on:hover { color: var(--fav-gold); }

/* pinned favourite rows get a subtle gold edge so the top block reads as a
 * group; the untested-muted styles still apply to favourite-but-untested rows */
#sv-data tr.sv-fav-row > td:first-child { box-shadow: inset 2px 0 0 var(--fav-gold); }

/* ---------- settings tab (per-user Telegram) ---------- */
.settings-wrap { max-width: 620px; }
.settings-card { padding: 22px; display: flex; flex-direction: column; gap: var(--sp-3); }
.settings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.settings-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.btn-ghost { background: transparent; border: 1px solid var(--border-light); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-light); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; background: rgba(139, 147, 167, 0.14); color: var(--text-dim); }
.pill-ok { background: var(--green-dim); color: var(--green); }
.pill-warn { background: var(--amber-dim); color: var(--amber); }
.settings-help { margin-top: var(--sp-1); font-size: 12.5px; color: var(--muted); }
.settings-help summary { cursor: pointer; color: var(--text-dim); user-select: none; }
.settings-help ol { margin: 10px 0 0; padding-left: 20px; line-height: 1.7; }
.settings-help code { background: var(--card2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); }

/* ---------- settings: layout + category nav ---------- */
.settings-layout { display: flex; gap: var(--sp-4); align-items: flex-start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; min-width: 168px; flex-shrink: 0; }
.settings-nav-item {
  text-align: left; padding: 9px 12px; border-radius: var(--radius-sm);
  background: transparent; border: none; color: var(--muted); font-size: 13.5px;
  font-weight: 500; cursor: pointer; transition: all 130ms ease;
}
.settings-nav-item:hover { background: var(--card-hover); color: var(--text-dim); }
.settings-nav-item.active { background: var(--accent-dim); color: var(--accent); }
.settings-content { flex: 1; min-width: 0; max-width: 640px; display: flex; flex-direction: column; gap: var(--sp-3); }
.settings-title { margin: 0; font-size: 15px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.settings-row:last-child { border-bottom: none; }
@media (max-width: 720px) {
  .settings-layout { flex-direction: column; }
  .settings-nav { flex-direction: row; flex-wrap: wrap; min-width: 0; }
}

/* ---------- topbar user menu ---------- */
.user-menu { position: relative; }
.user-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 8px 4px 4px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 13px; font-weight: 500; cursor: pointer;
}
.user-chip:hover { border-color: var(--border-light); color: var(--text); }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #7b6cff, #a855f7);
  color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-caret { opacity: 0.6; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 172px; z-index: 60;
  background: var(--elev); border: 1px solid var(--border-light); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
/* the JS toggles the `hidden` attribute; display:flex above would otherwise
   override the UA [hidden] rule and leave the menu permanently open */
.user-dropdown[hidden] { display: none; }
.user-dd-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-dim); font-size: 13.5px;
  font-weight: 600; cursor: pointer; text-decoration: none; width: 100%; text-align: left;
}
.user-dd-item:hover { background: var(--card-hover); color: var(--text); }

/* ---------- exchanges ---------- */
.exch-logo { display: inline-flex; width: 22px; height: 22px; vertical-align: middle; }
.exch-logo svg { width: 100%; height: 100%; }
.exch-logo.lg { width: 40px; height: 40px; }
.exch-conn-list { display: flex; flex-direction: column; gap: 8px; }
.exch-conn { display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card2); }
.exch-conn-meta { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.exch-conn-meta .muted { font-size: 12px; }
.exch-conn-actions { display: flex; gap: 6px; }
.exch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.exch-card { display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card2); text-align: center; }
.exch-card.soon { opacity: 0.6; }
.exch-card-name { font-weight: 600; font-size: 13.5px; }

/* ---------- 2FA + backup codes + danger ---------- */
.modal-head h3 { font-size: 16px; margin: 0; display: flex; align-items: center; gap: 8px; }
.mfa-qr { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 10px; width: max-content; margin: 8px auto; }
.mfa-qr img { width: 180px; height: 180px; display: block; }
.mfa-secret { text-align: center; font-size: 12.5px; color: var(--muted); }
.mfa-secret code { color: var(--text); font-family: var(--mono); user-select: all; }
.backup-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.backup-codes code { background: var(--card2); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; text-align: center; font-family: var(--mono); font-size: 13px; letter-spacing: 0.5px; user-select: all; }
.danger-card { border-color: rgba(234,57,67,0.35); }

/* ---------------------------------------------------------------------- */
/* billing / subscriptions                                                 */
/* ---------------------------------------------------------------------- */

/* Topbar plan chip */
.plan-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  font: 600 12.5px/1 var(--font); color: var(--text-dim);
  background: var(--card2); border: 1px solid var(--border-light);
  transition: filter .15s, border-color .15s;
}
.plan-pill:hover { filter: brightness(1.05); border-color: var(--accent); }
.plan-pill .plan-pill-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.plan-pill.plan-pill-free { background: var(--accent-dim); border-color: transparent; color: var(--text); }
.plan-pill .plan-pill-cta { color: var(--accent); font-weight: 700; }

/* Plan badge (settings) */
.plan-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font: 700 12px/1.4 var(--font); letter-spacing: .2px;
  background: var(--card2); color: var(--text-dim); border: 1px solid var(--border-light);
}
.plan-badge.plan-starter { background: var(--accent-dim); color: var(--accent); border-color: transparent; }
.plan-badge.plan-pro { background: var(--green-dim); color: var(--green); border-color: transparent; }
.plan-badge.plan-elite { background: var(--purple-dim); color: var(--purple); border-color: transparent; }
.bill-planline { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

/* Usage meters */
.meters { display: flex; flex-direction: column; gap: 14px; }
.meter .meter-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.meter-bar { height: 7px; border-radius: 999px; background: var(--card2); overflow: hidden; border: 1px solid var(--border); }
.meter-fill { height: 100%; border-radius: 999px; background: var(--grad); transition: width .3s ease; }
.meter-warn .meter-fill { background: linear-gradient(90deg, var(--amber), #ffcf7a); }
.meter-full .meter-fill { background: linear-gradient(90deg, var(--red), #ff7a90); }
.meter-off { opacity: .6; }

/* Danger button (cancel) */
.btn-danger { color: var(--red); border-color: rgba(226,57,90,.4); }
.btn-danger:hover { color: #fff; background: var(--red); border-color: transparent; }

/* Pricing modal */
.modal:has(.pricing-body) { max-width: 980px; width: min(980px, 95vw); }
.pricing-body { padding: 18px 20px 22px; }
.pricing-toggle { display: inline-flex; gap: 4px; padding: 4px; margin: 0 auto 18px;
  background: var(--card2); border: 1px solid var(--border); border-radius: 999px; }
.pricing-toggle { display: flex; width: max-content; margin-left: auto; margin-right: auto; }
.pricing-toggle .seg {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 7px 16px; border-radius: 999px; font: 600 13px/1 var(--font);
  display: inline-flex; align-items: center; gap: 6px;
}
.pricing-toggle .seg.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }
.pricing-toggle .save { font-size: 10.5px; font-weight: 700; color: var(--green);
  background: var(--green-dim); padding: 2px 6px; border-radius: 6px; }

.plan-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .plan-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .plan-grid { grid-template-columns: 1fr; } }
.plan-card {
  position: relative; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); padding: 18px 16px 16px;
}
.plan-card.plan-hot { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan-card.plan-current { background: var(--card2); }
.plan-tag { position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--grad); color: #fff; font: 700 10.5px/1 var(--font);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; box-shadow: var(--grad-glow); }
.plan-name { font: 700 15px/1 var(--font-display); color: var(--text); }
.plan-price { font: 800 26px/1 var(--font-display); color: var(--text); margin: 10px 0 2px; }
.plan-price span { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.plan-tagline { font-size: 12px; min-height: 32px; margin-bottom: 10px; }
.plan-features { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.plan-features li { font-size: 12.5px; color: var(--text-dim); padding-left: 20px; position: relative; line-height: 1.35; }
.plan-features li::before { content: "✓"; position: absolute; left: 0; top: 0; color: var(--green); font-weight: 800; }
.plan-cta .btn { width: 100%; justify-content: center; }
.pricing-foot { text-align: center; margin-top: 16px; font-size: 12px; }
