:root {
  --bg-app: #1c1c1c;
  --bg-sidebar: #1a1a1a;
  --bg-surface: #232323;
  --bg-hover: #262626;
  --border: #2a2a2a;
  --border-strong: #333333;
  --text: #e6e6e6;
  --text-muted: #9a9a9a;
  --text-faint: #6e6e6e;
  --icon: #b0b0b0;
  --accent: #2f6b47;
  --accent-text: #8fc7a3;
  --danger-bg: #3a1d20;
  --danger-border: #5a2a2e;
  --danger-text: #f0b0b5;
  --warn-text: #d9c27a;
  --r-sm: 4px;
  --r-md: 6px;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s6: 24px;
  --t-fast: 100ms ease-out;
  --t-med: 160ms ease-out;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --sidebar-w: 200px;
  --statusbar-h: 28px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-app);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--text-muted); }
code, .mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.pos { color: var(--accent-text); }
.neg { color: var(--danger-text); }
.warn { color: var(--warn-text); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 15px; }
h2 { font-size: 13px; }
h3 { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }

/* Layout */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--statusbar-h) 1fr; height: 100vh; }
.statusbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s3);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow-x: auto;
}
.statusbar .item { display: flex; align-items: center; gap: var(--s1); }
.statusbar .sep { width: 1px; height: 14px; background: var(--border-strong); }
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: var(--s2) 0;
  overflow-y: auto;
}
.main { overflow: auto; padding: var(--s4) var(--s6) var(--s6); }

.nav-section { padding: var(--s2) var(--s3) var(--s1); font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.nav-item {
  display: flex; align-items: center; gap: var(--s2);
  margin: 0 var(--s2); padding: 5px var(--s2);
  border-radius: var(--r-sm);
  color: var(--text-muted); text-decoration: none;
  cursor: pointer; transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item:focus-visible { outline: 1px solid var(--border-strong); outline-offset: 0; }
.nav-item.active { background: var(--bg-surface); color: var(--text); }
.nav-item svg { width: 16px; height: 16px; fill: var(--icon); flex: none; }
.nav-item .tag { margin-left: auto; }
.sidebar .spacer { flex: 1; }

/* Icons */
.icon { width: 16px; height: 16px; fill: var(--icon); vertical-align: -3px; }

/* Badges and chips */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 6px; height: 18px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge.live { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.badge.paper { color: var(--text-muted); }
.badge.ok { color: var(--accent-text); border-color: var(--accent); }
.badge.bad { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.badge.warn { color: var(--warn-text); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); display: inline-block; }
.dot.ok { background: var(--accent-text); }
.dot.bad { background: var(--danger-text); }
.dot.warn { background: var(--warn-text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 26px; padding: 0 10px;
  background: var(--bg-surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font: inherit; font-size: 12px; cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { background: var(--bg-hover); border-color: #3d3d3d; }
.btn:active { background: var(--bg-app); }
.btn:focus-visible { outline: 1px solid var(--text-muted); outline-offset: 1px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: #357a51; }
.btn.danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.btn.danger:hover { background: #45222a; }
.btn.icon-only { width: 26px; padding: 0; }
.btn.loading { color: transparent; position: relative; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; width: 10px; height: 10px;
  border: 1.5px solid var(--text-muted); border-top-color: transparent; border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }

/* Tooltip for icon-only buttons */
[data-tip] { position: relative; }
[data-tip]:hover::before, [data-tip]:focus-visible::before {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  padding: 3px 6px; background: #111; border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  color: var(--text); font-size: 11px; white-space: nowrap; z-index: 20; pointer-events: none;
}

/* Page structure */
.page-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; }
.page-head .grow { flex: 1; }
.section { border-top: 1px solid var(--border); padding: var(--s3) 0; }
.section > h3 { margin-bottom: var(--s2); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s6); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--s6); }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--s4); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.stats { display: flex; gap: var(--s6); flex-wrap: wrap; padding: var(--s2) 0; }
.stat .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 15px; font-variant-numeric: tabular-nums; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 5px var(--s2); border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-weight: 500; color: var(--text-muted); font-size: 12px; white-space: nowrap; position: sticky; top: 0; background: var(--bg-app); }
th.num, td.num { text-align: right; }
tbody tr { transition: background var(--t-fast); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr.clickable { cursor: pointer; }
tr.live-row td:first-child { box-shadow: inset 2px 0 0 var(--danger-border); }
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }
.empty { color: var(--text-faint); padding: var(--s3) var(--s2); }

/* Forms */
input, select {
  height: 26px; padding: 0 var(--s2);
  background: var(--bg-surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font: inherit; font-size: 12px;
  transition: border-color var(--t-fast);
}
input:hover, select:hover { border-color: #3d3d3d; }
input:focus, select:focus { outline: none; border-color: var(--text-muted); }
input:disabled { opacity: 0.5; }
input.num { width: 110px; }
input.invalid { border-color: var(--danger-border); }
label.field { display: grid; grid-template-columns: 200px 120px 1fr; align-items: center; gap: var(--s2); padding: 2px 0; }
label.field .help { color: var(--text-faint); font-size: 12px; }
.form-actions { margin-top: var(--s3); }

/* Banners */
.banner { padding: var(--s2) var(--s3); border: 1px solid var(--border-strong); border-radius: var(--r-sm); margin-bottom: var(--s3); }
.banner.error, .banner.danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.banner.warn { color: var(--warn-text); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

/* Charts */
.chart { width: 100%; height: 220px; display: block; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-app); }
.chart.tall { height: 280px; }
.legend { display: flex; gap: var(--s4); font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 4px; }
.legend i.l-buy { background: var(--accent-text); }
.legend i.l-sell { background: var(--danger-text); }
.legend i.l-faint { background: var(--text-faint); }
.plain { text-decoration: none; }
.table-wrap.full { max-height: none; }

/* Dialog */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  animation: fade var(--t-med);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  width: 460px; max-width: calc(100vw - 32px);
  background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: var(--s4);
}
.dialog.danger { border-color: var(--danger-border); }
.dialog h2 { margin-bottom: var(--s2); }
.dialog p { margin: 0 0 var(--s3); color: var(--text-muted); }
.dialog .phrase { font-family: var(--mono); background: var(--bg-app); padding: 4px 6px; border-radius: var(--r-sm); color: var(--danger-text); user-select: all; }
.dialog input { width: 100%; margin-bottom: var(--s2); }
.dialog .btn-row { justify-content: flex-end; margin-top: var(--s2); }

/* Login */
.login { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login form { width: 300px; display: flex; flex-direction: column; gap: var(--s2); }
.login h1 { margin-bottom: var(--s2); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: var(--s2) 0 var(--s3); }
.tab { padding: 6px var(--s3); color: var(--text-muted); cursor: pointer; border-bottom: 1px solid transparent; margin-bottom: -1px; background: none; border-top: 0; border-left: 0; border-right: 0; font: inherit; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text-muted); }
.tab:focus-visible { outline: 1px solid var(--border-strong); }

.loading-text { color: var(--text-faint); padding: var(--s3) 0; }
.toast {
  position: fixed; bottom: 16px; right: 16px; z-index: 60;
  padding: var(--s2) var(--s3); background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  animation: fade var(--t-med);
}
.toast.error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.addr { font-family: var(--mono); font-size: 12px; }
.wrap-anywhere { overflow-wrap: anywhere; }

/* Live page */
.market-strip { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--r-sm); margin-bottom: var(--s3); overflow-x: auto; }
.market {
  flex: 1; min-width: 220px; text-align: left;
  padding: var(--s2) var(--s3);
  background: none; color: var(--text); font: inherit;
  border: 0; border-right: 1px solid var(--border);
  cursor: pointer; transition: background var(--t-fast);
}
.market:last-child { border-right: 0; }
.market:hover { background: var(--bg-hover); }
.market:focus-visible { outline: 1px solid var(--text-muted); outline-offset: -1px; }
.market.active { background: var(--bg-surface); box-shadow: inset 0 -2px 0 var(--text-muted); }
.m-head { display: flex; gap: var(--s2); align-items: baseline; }
.m-price { font-size: 20px; font-variant-numeric: tabular-nums; transition: color var(--t-med); }
.m-price.up { color: var(--accent-text); }
.m-price.down { color: var(--danger-text); }
.m-row { display: flex; gap: var(--s3); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart.xl { height: 380px; }
.chart-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s2); flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; }
.seg-btn { background: var(--bg-surface); color: var(--text-muted); border: 0; border-right: 1px solid var(--border-strong); padding: 0 10px; height: 24px; font: inherit; font-size: 12px; cursor: pointer; transition: background var(--t-fast), color var(--t-fast); }
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--bg-hover); color: var(--text); }
.seg-btn.active { background: var(--bg-app); color: var(--text); }
.seg-btn:focus-visible { outline: 1px solid var(--text-muted); outline-offset: -1px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; background: none; color: var(--text-faint); border: 1px solid var(--border); border-radius: var(--r-sm); font: inherit; font-size: 12px; cursor: pointer; transition: color var(--t-fast), border-color var(--t-fast); }
.chip.on { color: var(--text); border-color: var(--border-strong); }
.chip:hover { color: var(--text); }
.chip:focus-visible { outline: 1px solid var(--text-muted); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; vertical-align: 0; }
.swatch.b1 { background: #8fc7a3; }
.swatch.b2 { background: #9db7e0; }
.swatch.b3 { background: #d9c27a; }
.swatch.b4 { background: #c9a0dc; }
.swatch.b5 { background: #e0a37a; }
tr.dim td { color: var(--text-muted); }
td.wrap, div.wrap { white-space: normal; max-width: 380px; min-width: 220px; }
.nowrap { white-space: nowrap; }

/* Bot "now" panel */
.now { display: flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: var(--r-sm); margin-bottom: var(--s3); }
.now-item { padding: var(--s2) var(--s3); border-right: 1px solid var(--border); min-width: 140px; }
.now-item:last-child { border-right: 0; }
.now-item.wide { flex: 1; min-width: 260px; }
.now-item .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
