:root {
  --bg:        #0b0d12;
  --surface:   #12151e;
  --surface2:  #181c28;
  --surface3:  #1e2333;
  --border:    #252a3a;
  --border2:   #2e3449;
  --text:      #dde3f0;
  --text-muted:#5a6380;
  --text-dim:  #3d4560;
  --green:     #22c55e;
  --red:       #ef4444;
  --blue:      #3b82f6;
  --yellow:    #f59e0b;
  --accent:    #6366f1;
  --accent2:   #818cf8;

  --sidebar-w: 52px;
  --sidebar-expanded: 180px;
  --header-h:  44px;
  --status-h:  24px;
}

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

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr var(--status-h);
  grid-template-areas:
    "sidebar app"
    "sidebar statusbar";
}

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

/* ── Sidebar ── */
#sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  overflow: hidden;
  transition: width 0.2s ease;
  z-index: 50;
}
#sidebar:hover { width: var(--sidebar-expanded); }

.sidebar-logo {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
  padding: 0 14px;
}
.sidebar-logo span { color: var(--accent); }

.nav-items { list-style: none; flex: 1; padding: 8px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  border-left: 2px solid transparent;
}
.nav-item svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-item span { font-size: 12px; font-weight: 500; opacity: 0; transition: opacity 0.15s; }
#sidebar:hover .nav-item span { opacity: 1; }

.nav-item:hover { color: var(--text); background: var(--surface2); }
.nav-item.active {
  color: var(--accent2);
  background: rgba(99,102,241,0.1);
  border-left-color: var(--accent);
}

.sidebar-bottom {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.bot-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.status-dot.idle    { background: var(--text-dim); }
.status-dot.training{ background: var(--blue); box-shadow: 0 0 6px var(--blue); }
.status-dot.testing { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.status-dot.live    { background: var(--green); box-shadow: 0 0 6px var(--green); }

/* ── App area ── */
#app {
  grid-area: app;
  position: relative;
  overflow: hidden;
}

/* ── Pages ── */
.page {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}
.page.active { display: flex; }

.page-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-header h1 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text);
}
.header-actions { display: flex; align-items: center; gap: 8px; }

.page-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.page-body.p0 { padding: 0; }

/* ── Stat cards ── */
.stat-row, .three-col {
  display: grid;
  gap: 10px;
}
.stat-row { grid-template-columns: repeat(6, 1fr); }
.three-col { grid-template-columns: repeat(3, 1fr); }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
}
.stat-card.accent { border-color: rgba(99,102,241,0.4); }
.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.stat-value { font-size: 20px; font-weight: 700; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Layout helpers ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ── Panels ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-body {
  padding: 14px;
  flex: 1;
}
.panel-body.p0 { padding: 0; }
.chart-sm { height: 180px; }

/* ── Progress ── */
.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}
.progress-track {
  height: 4px;
  background: var(--surface3);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.6s ease;
  width: 0%;
}

/* ── Controls ── */
.ctrl-select, .ctrl-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.ctrl-select:focus, .ctrl-input:focus { border-color: var(--accent); }
.ctrl-select.full-width, .ctrl-input { width: 100%; }

.tf-group { display: flex; gap: 2px; }
.tf-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
}
.tf-btn:hover { color: var(--text); border-color: var(--border2); }
.tf-btn.active { color: var(--accent2); border-color: var(--accent); background: rgba(99,102,241,0.12); }

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-danger {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.4);
  color: var(--red);
  padding: 7px 16px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
  width: 100%;
}
.btn-danger:hover { background: rgba(239,68,68,0.2); border-color: var(--red); }

/* ── Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table.full { display: block; overflow-y: auto; height: 100%; }

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  padding: 9px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface2); }
.empty { text-align: center; color: var(--text-muted); padding: 32px !important; }

/* ── Form grid ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  align-items: center;
}
.form-grid label { font-size: 11px; color: var(--text-muted); }

/* ── Danger zone ── */
.danger-zone {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid rgba(239,68,68,0.2);
}
.danger-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(239,68,68,0.6);
  margin-bottom: 10px;
}

/* ── KV grid (backtest results) ── */
.kv-grid { display: flex; flex-direction: column; gap: 6px; }
.kv-row { display: flex; justify-content: space-between; align-items: center; }
.kv-key { color: var(--text-muted); font-size: 11px; }
.kv-val { font-size: 12px; font-weight: 600; }

/* ── Log view ── */
.log-view {
  height: 160px;
  overflow-y: auto;
  padding: 10px 14px;
  background: var(--bg);
  font-size: 11px;
  line-height: 1.8;
}
.log-line { color: var(--text-muted); }
.log-line.info  { color: var(--text); }
.log-line.warn  { color: var(--yellow); }
.log-line.error { color: var(--red); }
.log-line.good  { color: var(--green); }

/* ── Misc ── */
.tag { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 3px; letter-spacing: 0.5px; }
.tag-blue { background: rgba(59,130,246,0.15); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.tag-green { background: rgba(34,197,94,0.12); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 11px; }
.pnl-pos { color: var(--green); }
.pnl-neg { color: var(--red); }
.side-buy { color: var(--green); font-weight: 600; }
.side-sell { color: var(--red); font-weight: 600; }

/* ── Statusbar ── */
#statusbar {
  grid-area: statusbar;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}
.sb-left, .sb-right { display: flex; align-items: center; gap: 8px; }
.sb-sep { color: var(--text-dim); }
.sb-item { white-space: nowrap; }
#sb-mode.idle     { color: var(--text-muted); }
#sb-mode.training { color: var(--blue); }
#sb-mode.testing  { color: var(--yellow); }
#sb-mode.live     { color: var(--green); }
#sb-ws.connected  { color: var(--green); }
#sb-ws.error      { color: var(--red); }
