/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1e2530;
  --bg4: #252d3a;
  --border: #2a3441;
  --text: #e2e8f0;
  --muted: #8892a4;
  --green: #00E5A0;
  --cyan: #00c8e0;
  --orange: #ff9a3c;
  --red: #ff4d6d;
  --yellow: #ffd166;
  --radius: 12px;
  --sidebar-w: 220px;
  --font-mono: 'Space Mono', monospace;
  --font-sans: 'DM Sans', sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-sans); font-size: 14px; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }
input, select { font-family: inherit; outline: none; }
a { cursor: pointer; text-decoration: none; color: inherit; }
canvas { display: block; }

/* ── Login Screen ───────────────────────────────────────────────────────── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(0,229,160,0.08) 0%, transparent 70%), var(--bg);
}
.login-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 20px;
  padding: 48px 40px; text-align: center; max-width: 360px; width: 90%;
}
.login-logo { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { color: var(--muted); margin-bottom: 32px; font-size: 13px; }
.login-note { color: var(--muted); font-size: 11px; margin-top: 20px; }

/* ── App Shell ──────────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px 24px; border-bottom: 1px solid var(--border);
}
.sidebar-title { font-weight: 700; font-size: 13px; line-height: 1.3; }
.nav-links { flex: 1; padding: 16px 0; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--muted); font-size: 13px; font-weight: 500;
  border-radius: 0; transition: all 0.15s; position: relative;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active {
  color: var(--green);
  background: rgba(0,229,160,0.08);
}
.nav-link.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--green); border-radius: 0 2px 2px 0;
}
.sidebar-footer {
  padding: 16px 20px 0; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.user-pill { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.user-pill img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--bg3); }
#user-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }

/* ── Main Content ───────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; padding: 32px; }
.page { display: none; }
.page.active { display: block; }

/* ── Page Header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.subtitle { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 6px; }

/* ── KPI Grid ───────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 28px; }
.kpi-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px;
}
.kpi-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-family: var(--font-mono); font-size: 24px; font-weight: 700; }
.kpi-value.cyan { color: var(--cyan); }
.kpi-value.green { color: var(--green); }
.kpi-value.orange { color: var(--orange); }
.kpi-value.red { color: var(--red); }

/* ── Equity Hero ────────────────────────────────────────────────────────── */
.equity-hero {
  background: linear-gradient(135deg, var(--bg2) 0%, var(--bg3) 100%);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 28px; margin-bottom: 20px;
  display: flex; align-items: flex-end; justify-content: space-between;
}
.label-xs { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 6px; }
.equity-value { font-family: var(--font-mono); font-size: 36px; font-weight: 700; color: var(--text); }
.equity-sub { display: flex; gap: 32px; }
.val-green { font-family: var(--font-mono); font-size: 16px; font-weight: 700; color: var(--green); }
.val-red { font-family: var(--font-mono); font-size: 16px; font-weight: 700; color: var(--red); }
.val-orange { font-family: var(--font-mono); font-size: 15px; font-weight: 700; color: var(--orange); }

/* ── Section Title ──────────────────────────────────────────────────────── */
.section-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; color: var(--muted);
  margin-bottom: 12px; margin-top: 24px; display: flex; align-items: center; justify-content: space-between;
}
.mt { margin-top: 32px; }
.see-all { color: var(--cyan); font-size: 11px; cursor: pointer; }
.see-all:hover { text-decoration: underline; }

/* ── Charts ─────────────────────────────────────────────────────────────── */
.chart-wrap {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; overflow: hidden;
}
.chart-wrap-lg {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; overflow: hidden;
}
.period-pills { display: flex; gap: 6px; }

/* ── Equity Stats Row ───────────────────────────────────────────────────── */
.equity-stats-row {
  display: flex; gap: 32px; padding: 16px 20px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
}
.equity-stat-val { font-family: var(--font-mono); font-size: 18px; font-weight: 700; margin-top: 4px; }
.equity-stat-val.cyan { color: var(--cyan); }
.equity-stat-val.green { color: var(--green); }
.equity-stat-val.red { color: var(--red); }

/* ── Alert Cards ────────────────────────────────────────────────────────── */
.alert-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.alert-card {
  background: rgba(255,154,60,0.06); border: 1px solid rgba(255,154,60,0.3);
  border-radius: var(--radius); padding: 12px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
}
.dd-info { text-align: right; }
.dd-bar-wrap {
  grid-column: 1 / -1; height: 4px; background: var(--bg4); border-radius: 2px; overflow: hidden;
}
.dd-bar { height: 100%; border-radius: 2px; transition: width 0.4s; }

/* ── Mini Bot Cards (dashboard) ─────────────────────────────────────────── */
.mini-bot-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s; margin-bottom: 8px;
}
.mini-bot-card:hover { border-color: var(--cyan); background: var(--bg3); }
.mini-bot-name { font-weight: 600; font-size: 13px; }
.mini-bot-sub { color: var(--muted); font-size: 11px; }
.mini-bot-right { margin-left: auto; text-align: right; }
.dd-badge {
  display: inline-block; background: rgba(0,229,160,0.12); color: var(--green);
  border-radius: 6px; font-size: 11px; font-family: var(--font-mono); font-weight: 700;
  padding: 2px 8px; margin-left: 8px;
}
.dd-badge.dd-warn { background: rgba(255,77,109,0.12); color: var(--red); }

/* ── Bot Cards ──────────────────────────────────────────────────────────── */
.filter-pills { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.pill {
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
  padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600;
  transition: all 0.15s;
}
.pill:hover { border-color: var(--cyan); color: var(--cyan); }
.pill.active { background: rgba(0,229,160,0.12); border-color: var(--green); color: var(--green); }

.bot-list { display: flex; flex-direction: column; gap: 12px; }
.bot-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.bot-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.bot-card-name { font-size: 16px; font-weight: 700; margin-top: 6px; }
.bot-card-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bot-card-pl { text-align: right; }

.status-badge {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  padding: 2px 8px; border-radius: 4px;
}
.status-running { background: rgba(0,229,160,0.15); color: var(--green); }
.status-stopped { background: rgba(136,146,164,0.15); color: var(--muted); }
.status-locked { background: rgba(255,154,60,0.15); color: var(--orange); }

.bot-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.stat { }
.stat-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 4px; }
.stat-val { font-family: var(--font-mono); font-size: 15px; font-weight: 700; }
.stat-val.red { color: var(--red); }
.stat-val.orange { color: var(--orange); }

.bot-card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--green); color: #0d1117; font-weight: 700; font-size: 13px;
  padding: 9px 18px; border-radius: 8px; transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  font-weight: 600; font-size: 13px; padding: 9px 18px; border-radius: 8px; transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--text); color: var(--text); }

.btn-danger {
  background: var(--red); color: #fff; font-weight: 700; font-size: 13px;
  padding: 9px 18px; border-radius: 8px; transition: opacity 0.15s;
}
.btn-danger:hover { opacity: 0.85; }

.btn-kill {
  background: rgba(255,77,109,0.12); border: 1px solid rgba(255,77,109,0.4);
  color: var(--red); font-weight: 700; font-size: 13px; padding: 10px 20px;
  border-radius: 8px; display: flex; align-items: center; gap: 8px; transition: all 0.15s;
  letter-spacing: 0.04em;
}
.btn-kill:hover { background: rgba(255,77,109,0.2); border-color: var(--red); }

.btn-stop {
  background: rgba(255,77,109,0.1); border: 1px solid rgba(255,77,109,0.35);
  color: var(--red); font-weight: 600; font-size: 12px; padding: 7px 14px; border-radius: 7px;
  transition: all 0.15s;
}
.btn-stop:hover { background: rgba(255,77,109,0.2); }

.btn-start {
  background: rgba(0,229,160,0.1); border: 1px solid rgba(0,229,160,0.35);
  color: var(--green); font-weight: 600; font-size: 12px; padding: 7px 14px; border-radius: 7px;
  transition: all 0.15s;
}
.btn-start:hover { background: rgba(0,229,160,0.2); }

.btn-lock {
  background: rgba(255,154,60,0.1); border: 1px solid rgba(255,154,60,0.35);
  color: var(--orange); font-weight: 600; font-size: 12px; padding: 7px 14px; border-radius: 7px;
  transition: all 0.15s;
}
.btn-lock:hover { background: rgba(255,154,60,0.2); }
.btn-lock.locked { opacity: 0.5; cursor: not-allowed; }

.btn-settings {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--muted); font-weight: 600; font-size: 12px; padding: 7px 14px; border-radius: 7px;
  transition: all 0.15s;
}
.btn-settings:hover { border-color: var(--cyan); color: var(--cyan); }

.btn-icon {
  background: transparent; color: var(--muted); padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }

.btn-icon-sm {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 5px; font-size: 11px; transition: all 0.15s;
}
.btn-icon-sm:hover { border-color: var(--red); color: var(--red); }

/* ── Table ──────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 12px 16px; text-align: left; font-size: 10px; font-weight: 700;
  letter-spacing: 0.08em; color: var(--muted); border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.muted { color: var(--muted); }
.badge {
  background: var(--bg3); border: 1px solid var(--border); color: var(--cyan);
  font-size: 11px; font-family: var(--font-mono); font-weight: 700;
  padding: 2px 8px; border-radius: 5px;
}

/* ── Accounts Grid ──────────────────────────────────────────────────────── */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.account-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
}
.account-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.account-login { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }
.account-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.account-equity { font-family: var(--font-mono); font-size: 15px; font-weight: 700; margin-top: 4px; }

/* ── Status dots ────────────────────────────────────────────────────────── */
.dot-green { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; box-shadow: 0 0 6px var(--green); }
.dot-gray  { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }

/* ── Inline Form ────────────────────────────────────────────────────────── */
.inline-form {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 20px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.inline-form input, .inline-form select {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 8px 12px; border-radius: 7px; font-size: 13px; flex: 1; min-width: 140px;
}
.inline-form input:focus, .inline-form select:focus { border-color: var(--cyan); }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 32px; max-width: 400px; width: 90%; text-align: center;
}
.modal-wide { max-width: 480px; text-align: left; }
.modal-icon { font-size: 36px; margin-bottom: 12px; }
.modal-box h3 { font-size: 18px; font-weight: 700; margin-bottom: 10px; letter-spacing: 0.04em; }
.modal-box p { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { margin: 0; }

/* Risk Form */
.risk-form { display: flex; flex-direction: column; gap: 12px; }
.risk-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px;
}
.risk-row label { font-size: 13px; font-weight: 500; }
.risk-input-wrap { display: flex; align-items: center; gap: 8px; }
.risk-input-wrap input {
  background: var(--bg4); border: 1px solid var(--border); color: var(--cyan);
  padding: 5px 10px; border-radius: 6px; font-family: var(--font-mono); font-size: 14px; font-weight: 700;
  width: 80px; text-align: right;
}
.risk-input-wrap input:focus { border-color: var(--cyan); }
.risk-unit { color: var(--muted); font-size: 12px; min-width: 28px; }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  padding: 12px 20px; border-radius: 10px; font-size: 13px; font-weight: 600;
  animation: slideUp 0.25s ease;
}
.toast-success { background: rgba(0,229,160,0.15); border: 1px solid rgba(0,229,160,0.4); color: var(--green); }
.toast-error   { background: rgba(255,77,109,0.15); border: 1px solid rgba(255,77,109,0.4); color: var(--red); }
.toast-warning { background: rgba(255,154,60,0.15); border: 1px solid rgba(255,154,60,0.4); color: var(--orange); }

@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.loading { padding: 32px; text-align: center; color: var(--muted); font-size: 13px; }
.empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

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

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 16px; }
  .equity-hero { flex-direction: column; gap: 16px; }
  .bot-stats { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
