:root {
  --bg: #0a0f1e;
  --bg-2: #0e1526;
  --surface: #121b2f;
  --surface-2: #16213a;
  --border: #22304d;
  --border-soft: #1a2740;
  --text: #e7eefb;
  --muted: #8ba1c4;
  --muted-2: #5f7294;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.12);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 19px; color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--muted-2); letter-spacing: 0.4px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--surface-2); color: var(--text);
  border-color: var(--border);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-ico { width: 18px; text-align: center; font-size: 13px; opacity: 0.9; }

.side-footer { margin-top: auto; border-top: 1px solid var(--border-soft); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.side-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex-shrink: 0; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot.idle { background: var(--muted-2); }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--border-soft);
  background: rgba(14, 21, 38, 0.6); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.clock { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.logout { color: var(--muted); text-decoration: none; font-size: 13px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); transition: all 0.15s; }
.logout:hover { color: var(--red); border-color: var(--red); }

.content { padding: 24px 28px 48px; max-width: 1200px; width: 100%; }

/* ---------- Flash / toast ---------- */
.flash { min-height: 0; margin-bottom: 16px; font-size: 13px; }
.flash:empty { display: none; }
.flash.ok { color: var(--green); }
.flash.err { color: var(--red); }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  position: relative; overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
}
.card:hover { border-color: #2c3d63; transform: translateY(-2px); }
.card .card-ico {
  position: absolute; right: 14px; top: 14px; width: 32px; height: 32px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 15px; background: var(--surface-2); color: var(--accent-2);
}
.card .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }
.card .sub { font-size: 12px; color: var(--muted-2); margin-top: 4px; }
.value.green { color: var(--green); }
.value.red { color: var(--red); }
.value.amber { color: var(--amber); }

/* ---------- Section ---------- */
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ""; width: 4px; height: 16px; border-radius: 2px; background: var(--accent); }

/* ---------- Actions / buttons ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
button, .btn {
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: all 0.15s;
}
button:hover, .btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2f6fe0; border-color: #2f6fe0; }
.btn-danger { background: var(--red-soft); border-color: transparent; color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 11px 14px; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover { background: rgba(59, 130, 246, 0.05); }
.table tbody tr:last-child td { border-bottom: none; }
.table .empty { text-align: center; color: var(--muted-2); padding: 28px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.03em;
}
.badge.paper { background: var(--surface-2); color: var(--accent-2); border: 1px solid var(--border); }
.badge.real { background: var(--red-soft); color: var(--red); border: 1px solid transparent; }
.badge.running { background: var(--green-soft); color: var(--green); }
.badge.stopped { background: var(--muted); color: #0a0f1e; }
.badge.waiting { background: var(--amber-soft); color: var(--amber); }
.badge.triggered { background: var(--green-soft); color: var(--green); }
.badge.open { background: var(--green-soft); color: var(--green); }
.badge.closed { background: var(--surface-2); color: var(--muted); }
.badge.cancelled, .badge.expired { background: var(--red-soft); color: var(--red); }
.badge.skipped { background: var(--amber-soft); color: var(--amber); }
.badge.sl, .badge.SL { background: var(--red-soft); color: var(--red); }
.badge.target, .badge.TARGET { background: var(--green-soft); color: var(--green); }
.badge.trailing_stop, .badge.TRAILING_STOP { background: var(--amber-soft); color: var(--amber); }

.pnl { font-weight: 700; }
.pnl.pos { color: var(--green); }
.pnl.neg { color: var(--red); }

/* ---------- Chart ---------- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.chart-legend { display: flex; gap: 20px; margin-top: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.chart-legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: inherit; }

/* ---------- Grid / misc ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.def-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.def { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.def .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.def .v { font-size: 16px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- Mode selector ---------- */
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.mode-card {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: all 0.15s;
}
.mode-card:hover { border-color: #2c3d63; }
.mode-card.sel-paper { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.mode-card.sel-real { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.mode-card h3 { font-size: 15px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.mode-card p { font-size: 12px; color: var(--muted); }
.mode-card .mode-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.mode-card .mode-tag.t-paper { background: var(--accent-2); color: #0a0f1e; }
.mode-card .mode-tag.t-real { background: var(--red); color: #fff; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.mt { margin-top: 18px; }
.mb { margin-bottom: 16px; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1000px 600px at 20% 0%, #12203c 0%, var(--bg) 55%);
}
.login-card {
  width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 32px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand { padding: 0 0 6px; justify-content: flex-start; }
.login-card h1 { font-size: 20px; font-weight: 700; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.login-card input {
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 14px; outline: none;
  transition: border-color 0.15s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button { padding: 12px; font-size: 14px; }