:root {
  --bg: #0b0e11;
  --bg-elev: #101419;
  --bg-pane: #0d1116;
  --bg-hover: #151a22;
  --bg-active: #1b222c;
  --border: #1e242c;
  --border-soft: #151a21;
  --fg: #eaecef;
  --fg-2: #b7bdc6;
  --muted: #76808f;
  --muted-2: #545d6a;
  --pos: #0ecb81;
  --pos-bg: rgba(14, 203, 129, 0.13);
  --neg: #f6465d;
  --neg-bg: rgba(246, 70, 93, 0.14);
  --gold: #f0b90b;
  --gold-bg: rgba(240, 185, 11, 0.13);
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.13);
  --blue: #38bdf8;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.gold { color: var(--gold); }
.purple { color: var(--purple); }
.muted-xs { color: var(--muted); font-size: 11px; }
.num { text-align: right !important; }
.border-top { border-top: 1px solid var(--border); }

/* ==================== AUTH OVERLAY ==================== */
.login-overlay {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}
.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 20px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.login-sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.login-box input {
  width: 100%;
  height: 34px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  margin-bottom: 10px;
}
.login-box input:focus { outline: none; border-color: var(--gold); }
.t-btn-primary {
  height: 34px;
  background: var(--gold);
  color: #0b0e11;
  border: 0;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.t-btn-primary.full { width: 100%; }
.login-error { color: var(--neg); font-size: 11px; margin-top: 8px; min-height: 16px; }

/* ==================== TOPBAR (38px) ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 38px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 10px;
  flex-wrap: wrap;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--fg);
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 6px rgba(14, 203, 129, 0.7);
  flex-shrink: 0;
}
.v-div {
  width: 1px;
  height: 16px;
  background: var(--border);
}

/* Chain switcher in topbar */
.chain-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chain-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.chain-tab:hover { background: var(--bg-hover); color: var(--fg); }
.chain-tab.active {
  background: var(--bg-active);
  border-color: #2b3340;
  color: var(--fg);
}
.chain-tab.active .ct-sym-bsc { color: var(--gold); }
.chain-tab.active .ct-sym-sol { color: var(--purple); }
.ct-px { color: var(--muted); font-weight: 400; font-size: 10.5px; }

/* Main Nav Tabs */
.nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.nav-tab {
  position: relative;
  height: 38px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 120ms;
}
.nav-tab:hover { color: var(--fg); }
.nav-tab.active {
  color: var(--fg);
  font-weight: 600;
}
.nav-tab.active::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 2px;
  background: var(--gold);
}
.tab-cnt {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 2px;
  background: var(--bg-active);
  color: var(--fg-2);
}

/* Segmented Controls */
.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.seg button {
  height: 24px;
  padding: 0 8px;
  border: 0;
  border-right: 1px solid var(--border-soft);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--fg); background: var(--bg-hover); }
.seg button.active {
  background: var(--bg-active);
  color: var(--gold);
  font-weight: 600;
}

.status-pill {
  height: 24px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 3px;
  background: var(--gold-bg);
  color: var(--gold);
}
.status-pill.is-auto { background: var(--pos-bg); color: var(--pos); }
.status-pill.is-paused { background: var(--neg-bg); color: var(--neg); }

.meta-clock { font-size: 11px; color: var(--muted); }

.icon-btn {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  cursor: pointer;
  transition: color 120ms, border-color 120ms;
}
.icon-btn:hover { color: var(--fg); border-color: #364152; }
.icon-btn svg { width: 13px; height: 13px; }

.global-error {
  padding: 6px 12px;
  background: rgba(246, 70, 93, 0.14);
  border-bottom: 1px solid rgba(246, 70, 93, 0.35);
  color: #fda4af;
  font-size: 11.5px;
}

/* ==================== WORKSPACE & VIEWS ==================== */
.workspace { width: 100%; }
.view { display: none; }
.view.active { display: block; }

/* ==================== KPI RIBBON ==================== */
.kpi-ribbon {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  background: var(--bg-pane);
  border-bottom: 1px solid var(--border);
}
.kpi-cell {
  padding: 9px 12px;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.kpi-cell:last-child { border-right: 0; }
.kpi-k {
  font-family: var(--font-sans);
  font-size: 10.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.kpi-v {
  margin-top: 3px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.kpi-usd {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.92;
}
.kpi-usd-muted {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--fg-2);
}
.kpi-s {
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================== COCKPIT MIDDLE (CHART + SIDE) ==================== */
.cockpit-mid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr);
  border-bottom: 1px solid var(--border);
}
.cockpit-mid.compare-mode {
  grid-template-columns: 1fr;
}
.cockpit-mid.compare-mode .side-pane {
  border-left: 0;
  border-top: 1px solid var(--border);
}

.chart-pane {
  background: var(--bg);
  min-width: 0;
}
.chart-pane.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.chart-pane.compare-grid .chart-block:first-child {
  border-right: 1px solid var(--border);
}

.chart-block {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Polymarket-inspired clean scrubbable PnL hero header inside dark terminal */
.poly-pnl-head {
  padding: 14px 18px 4px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.poly-pnl-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.poly-pnl-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.poly-tri {
  font-size: 9px;
  line-height: 1;
}
.poly-pnl-value-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.poly-pnl-big {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--fg);
}
.poly-pnl-native {
  font-size: 14px;
  font-weight: 600;
  opacity: 0.9;
}
.poly-pnl-sub {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 17px;
}
.poly-pnl-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.poly-pills {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.poly-pills button {
  height: 24px;
  padding: 0 9px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.poly-pills button:hover { color: var(--fg); }
.poly-pills button.active {
  background: var(--bg-active);
  color: var(--fg);
}

.pane-head {
  height: 32px;
  padding: 0 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.pane-head-left, .pane-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.pane-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}

.echarts-box {
  width: 100%;
  height: 256px;
}
.chart-pane.compare-grid .echarts-box {
  height: 224px;
}
.chart-empty {
  height: 256px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  padding: 16px;
  text-align: center;
}
.chart-empty code {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 1px 5px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Side Pane */
.side-pane {
  background: var(--bg-pane);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pane-tabs {
  display: flex;
  gap: 12px;
  height: 100%;
}
.pane-tab {
  position: relative;
  height: 100%;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}
.pane-tab:hover { color: var(--fg); }
.pane-tab.active { color: var(--fg); font-weight: 600; }
.pane-tab.active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--gold);
}
.pane-body {
  height: 312px;
  overflow-y: auto;
}

/* Attribution Rows (Ultra-Compact) */
.attr-row {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.attr-row:hover { background: var(--bg-hover); }
.attr-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.attr-name {
  font-size: 11.5px;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attr-vals {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  flex-shrink: 0;
  font-size: 11.5px;
}
.attr-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 3px;
  gap: 8px;
}
.attr-track {
  flex: 1;
  height: 3px;
  background: #1a2029;
  overflow: hidden;
}
.attr-fill { height: 100%; }
.attr-fill.pos { background: var(--pos); }
.attr-fill.neg { background: var(--neg); }

/* Side AI Feed */
.side-ai-row {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.side-ai-row:hover { background: var(--bg-hover); }
.side-ai-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}
.side-ai-diff { font-size: 11px; color: var(--purple); font-weight: 600; }
.side-ai-reason { font-size: 11px; color: var(--fg-2); margin-top: 2px; }

/* ==================== TABLES (HIGH DENSITY) ==================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.t-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.t-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 28px;
  padding: 0 10px;
  text-align: left;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg-pane);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.t-table td {
  height: 29px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  color: var(--fg-2);
  vertical-align: middle;
}
.t-table tbody tr:hover td { background: var(--bg-hover); }

.tok-link {
  color: var(--fg);
  font-weight: 600;
  text-decoration: none;
}
.tok-link:hover { color: var(--gold); text-decoration: underline; }

.copy-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 3px;
  background: transparent;
  border: 0;
  color: var(--muted-2);
  cursor: pointer;
  vertical-align: middle;
}
.copy-mini:hover { color: var(--fg); }
.copy-mini svg { width: 11px; height: 11px; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 5px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-active);
  color: var(--fg-2);
  white-space: nowrap;
}
.tag-pos { background: var(--pos-bg); color: var(--pos); }
.tag-neg { background: var(--neg-bg); color: var(--neg); }
.tag-warn { background: var(--gold-bg); color: var(--gold); }
.tag-purple { background: var(--purple-bg); color: var(--purple); }
.tag-info { background: rgba(56, 189, 248, 0.13); color: var(--blue); }

.link-btn {
  background: transparent;
  border: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }

/* ==================== SUBBARS & INPUTS ==================== */
.subbar {
  min-height: 36px;
  padding: 4px 12px;
  background: var(--bg-pane);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.subbar-thin { background: var(--bg); min-height: 34px; }
.subbar-left, .subbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.t-input {
  height: 24px;
  width: 210px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg);
  font-size: 11px;
}
.t-input:focus { outline: none; border-color: var(--gold); }
.t-input::placeholder { color: var(--muted-2); }

/* ==================== DECISIONS SPLIT ==================== */
.decisions-split {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
}
.split-left { border-right: 1px solid var(--border); min-width: 0; }
.split-right { background: var(--bg-pane); min-width: 0; }

.run-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.run-row:hover { background: var(--bg-pane); }
.run-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--muted);
}
.run-head-group { display: inline-flex; align-items: center; gap: 6px; }
.run-summary {
  font-size: 12px;
  color: var(--fg);
  line-height: 1.5;
}
.run-diffs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.run-verify {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}
.run-details {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}
.run-details summary {
  cursor: pointer;
  color: var(--gold);
  user-select: none;
}
.run-details ul {
  margin-top: 5px;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--fg-2);
}

.compact-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.compact-item:hover { background: var(--bg-hover); }
.compact-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

/* ==================== OPS / SCANNER / HEALTH ==================== */
.ops-panel { display: none; }
.ops-panel.active { display: block; }

.terminal-pre {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  color: var(--fg-2);
  font-size: 11.5px;
  line-height: 1.55;
  overflow-x: auto;
  max-height: 70vh;
  white-space: pre;
}

.health-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.split-col { min-width: 0; }
.split-col:first-child { border-right: 1px solid var(--border); }

.ops-lines {
  max-height: 360px;
  overflow-y: auto;
  padding: 6px 0;
}
.ops-line {
  padding: 3px 12px;
  font-size: 11px;
  color: var(--fg-2);
  border-bottom: 1px solid var(--border-soft);
  word-break: break-all;
}
.run-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.run-chip {
  height: 22px;
  padding: 0 7px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--fg-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  cursor: pointer;
}
.run-chip:hover { border-color: var(--gold); color: var(--fg); }
.run-chip.active { background: var(--gold-bg); border-color: var(--gold); color: var(--gold); }

/* ==================== EMPTY & TOAST ==================== */
.empty-msg, .empty-cell {
  padding: 20px 12px !important;
  text-align: center !important;
  color: var(--muted);
  font-size: 11.5px;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  padding: 7px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--gold);
  color: var(--fg);
  font-size: 11.5px;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #262e3a; }
::-webkit-scrollbar-thumb:hover { background: #374354; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1180px) {
  .kpi-ribbon { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-cell { border-bottom: 1px solid var(--border); }
  .cockpit-mid, .decisions-split, .health-split, .chart-pane.compare-grid {
    grid-template-columns: 1fr;
  }
  .side-pane, .split-left, .split-col:first-child, .chart-pane.compare-grid .chart-block:first-child {
    border-left: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .kpi-ribbon { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .meta-clock, .v-div { display: none; }
  .t-input { width: 100%; }
}
