/* MEV Terminal — Bloomberg-style */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0a0c0f;
  --bg-2: #0c0f13;
  --panel: #0f1216;
  --panel-2: #13171d;
  --panel-hi: #181d24;
  --border: #1c2128;
  --border-2: #2a313a;
  --text: #d4dae0;
  --text-2: #a0a8b2;
  --muted: #5b6470;
  --muted-2: #3d444d;
  --green: #7ee787;
  --green-bg: rgba(126, 231, 135, 0.08);
  --red: #ff6b6b;
  --red-bg: rgba(255, 107, 107, 0.08);
  --amber: #f0b429;
  --amber-bg: rgba(240, 180, 41, 0.08);
  --cyan: #56d4ff;
  --cyan-bg: rgba(86, 212, 255, 0.08);
  --magenta: #d2a8ff;
  --blue: #79b8ff;
  --sol: #9945ff;
  --base: #0052ff;
  --grid: rgba(255,255,255,0.03);
  --selection: rgba(86, 212, 255, 0.18);
}

[data-theme="light"] {
  --bg: #f4f4ef;
  --bg-2: #ecebe4;
  --panel: #fbfaf6;
  --panel-2: #f4f3ed;
  --panel-hi: #ecebe4;
  --border: #d9d6cc;
  --border-2: #c4c0b3;
  --text: #1a1a1a;
  --text-2: #2a2a2a;
  --muted: #6b6b66;
  --muted-2: #9a978d;
  --green: #1a7f3a;
  --green-bg: rgba(26, 127, 58, 0.08);
  --red: #c43a3a;
  --red-bg: rgba(196, 58, 58, 0.08);
  --amber: #a87600;
  --amber-bg: rgba(168, 118, 0, 0.08);
  --cyan: #006b8a;
  --cyan-bg: rgba(0, 107, 138, 0.08);
  --magenta: #6f3aa8;
  --blue: #1a4f9e;
  --sol: #6b1fcc;
  --base: #003ec4;
  --grid: rgba(0,0,0,0.04);
  --selection: rgba(0, 107, 138, 0.15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
  font-feature-settings: "tnum" 1, "zero" 1;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

#root { height: 100vh; }

::selection { background: var(--selection); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-2); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

button, input, select { font: inherit; color: inherit; }

/* ============ APP SHELL ============ */
.app {
  display: grid;
  grid-template-rows: 36px 1fr 22px;
  height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: 240px 1fr auto;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  height: 36px;
  font-size: 11px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-right: 1px solid var(--border);
  height: 100%;
}
.brand-mark {
  width: 18px; height: 18px;
  background: var(--amber);
  display: grid;
  place-items: center;
  color: #0a0c0f;
  font-weight: 700;
  font-size: 10px;
}
.brand-name {
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
}
.brand-sub {
  color: var(--muted);
  font-size: 10px;
}

.ticker {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 16px;
  overflow: hidden;
  white-space: nowrap;
}
.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.ticker-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
}
.ticker-val { font-weight: 600; }
.ticker-delta { font-size: 10px; }

.topbar-actions {
  display: flex;
  align-items: center;
  height: 100%;
}
.tb-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  height: 100%;
  padding: 0 12px;
  border-left: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: var(--mono);
}
.tb-btn:hover { background: var(--panel-hi); color: var(--text); }
.tb-btn.active { color: var(--amber); }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  padding: 0 4px;
  height: 14px;
  border: 1px solid var(--border-2);
  border-radius: 2px;
  font-size: 9px;
  color: var(--muted);
  background: var(--bg);
}

/* ============ MAIN ============ */
.main {
  display: grid;
  grid-template-columns: 220px 1fr;
  overflow: hidden;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sb-section {
  border-bottom: 1px solid var(--border);
  padding: 6px 0;
}
.sb-title {
  padding: 6px 14px 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}
.sb-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  cursor: pointer;
  border-left: 2px solid transparent;
  color: var(--text-2);
  font-size: 11px;
  user-select: none;
}
.sb-item:hover { background: var(--panel-hi); color: var(--text); }
.sb-item.active {
  background: var(--panel-hi);
  color: var(--text);
  border-left-color: var(--amber);
}
.sb-item-icon { color: var(--muted); display: grid; place-items: center; }
.sb-item.active .sb-item-icon { color: var(--amber); }
.sb-badge {
  font-size: 9px;
  padding: 1px 5px;
  background: var(--border);
  color: var(--muted);
  font-weight: 600;
}
.sb-badge.live { background: var(--green-bg); color: var(--green); }
.sb-badge.hot { background: var(--amber-bg); color: var(--amber); }

.sb-chain {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  font-size: 11px;
  color: var(--text-2);
  cursor: pointer;
}
.sb-chain:hover { background: var(--panel-hi); }
.sb-chain-dot { width: 8px; height: 8px; }
.sb-chain-stat { color: var(--muted); font-size: 10px; }

.workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ============ TABS ============ */
.tabs {
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  height: 30px;
  overflow-x: auto;
  overflow-y: hidden;
}
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-right: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
  position: relative;
}
.tab:hover { background: var(--panel-hi); color: var(--text-2); }
.tab.active {
  color: var(--text);
  background: var(--bg);
  border-bottom: 1px solid var(--bg);
  margin-bottom: -1px;
}
.tab.active::after {
  content: '';
  position: absolute;
  inset: auto 0 -1px 0;
  height: 1px;
  background: var(--amber);
  top: 0;
  bottom: auto;
  height: 2px;
}
.tab-close {
  width: 12px; height: 12px;
  display: grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
  color: var(--muted-2);
  border-radius: 2px;
}
.tab-close:hover { color: var(--text); background: var(--border); }

.tab-add {
  padding: 0 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.tab-add:hover { color: var(--text); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  height: 36px;
  flex-wrap: wrap;
}
.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--border);
  margin-right: 4px;
  height: 22px;
}
.tb-group:last-child { border-right: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 10px;
  cursor: pointer;
  height: 22px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.chip:hover { border-color: var(--border-2); color: var(--text); }
.chip.active { color: var(--amber); border-color: var(--amber); background: var(--amber-bg); }
.chip.sol.active { color: var(--sol); border-color: var(--sol); background: rgba(153,69,255,0.08); }
.chip.base.active { color: var(--base); border-color: var(--base); background: rgba(0,82,255,0.08); }

.chip-dot { width: 6px; height: 6px; border-radius: 50%; }

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  height: 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  flex: 1;
  max-width: 360px;
  font-family: var(--mono);
}
.search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text);
}
.search input::placeholder { color: var(--muted-2); }
.search-prefix { color: var(--muted); }

/* ============ TABLES ============ */
.tbl-wrap {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  position: relative;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.tbl thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  color: var(--muted);
  text-align: left;
  font-weight: 500;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
}
.tbl thead th.sortable { cursor: pointer; }
.tbl thead th.sortable:hover { color: var(--text); }
.tbl thead th .sort-arrow { color: var(--amber); margin-left: 4px; }
.tbl tbody td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl tbody tr { transition: background 80ms; }
.tbl tbody tr:hover { background: var(--panel); }
.tbl tbody tr.selected { background: var(--selection); }
.tbl tbody tr.fresh { animation: flash 1.6s ease-out; }
.tbl-num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-mono { font-family: var(--mono); }

@keyframes flash {
  0% { background: var(--amber-bg); }
  100% { background: transparent; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.live-dot {
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  animation: pulse 1.4s infinite;
}

/* ============ COMMON ============ */
.pos { color: var(--green); }
.neg { color: var(--red); }
.warn { color: var(--amber); }
.info { color: var(--cyan); }
.muted { color: var(--muted); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  background: transparent;
  font-family: var(--mono);
}
.tag.green { color: var(--green); background: var(--green-bg); }
.tag.red { color: var(--red); background: var(--red-bg); }
.tag.amber { color: var(--amber); background: var(--amber-bg); }
.tag.cyan { color: var(--cyan); background: var(--cyan-bg); }
.tag.magenta { color: var(--magenta); border-color: var(--magenta); }
.tag.solid { background: currentColor; }
.tag.solid > * { color: var(--bg); }

.chain-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.chain-pill::before {
  content: '';
  width: 6px; height: 6px;
}
.chain-pill.sol::before { background: var(--sol); }
.chain-pill.base::before { background: var(--base); }
.chain-pill.sol { color: var(--sol); }
.chain-pill.base { color: var(--base); }

.venue {
  font-size: 11px;
  letter-spacing: 0.02em;
}

/* ============ PANELS / CARDS ============ */
.split {
  display: grid;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  height: 28px;
  flex-shrink: 0;
}
.panel-head .panel-title { color: var(--text-2); font-weight: 600; }
.panel-head-actions { display: flex; gap: 6px; align-items: center; }
.panel-body { flex: 1; overflow: auto; min-height: 0; }
.panel-body.pad { padding: 12px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0;
  background: var(--border);
}
.kpi {
  background: var(--panel);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kpi-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.kpi-val {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: -0.01em;
}
.kpi-sub {
  font-size: 10px;
  color: var(--muted);
}

/* ============ STATUS BAR ============ */
.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 12px;
  height: 22px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--muted);
}
.statusbar .sep { width: 1px; height: 12px; background: var(--border); }
.statusbar-item { display: inline-flex; align-items: center; gap: 5px; }
.statusbar-item.ok { color: var(--green); }
.statusbar-spacer { flex: 1; }

/* ============ DETAIL DRAWER ============ */
.detail {
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.detail-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.detail-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.detail-body { flex: 1; overflow: auto; }
.detail-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 11px;
}
.detail-row .k { color: var(--muted); }
.detail-row .v { font-weight: 500; text-align: right; }

.path {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 11px;
}
.path-node {
  padding: 2px 6px;
  background: var(--panel-hi);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10px;
}
.path-arrow { color: var(--muted); }

/* ============ SPARK ============ */
.spark {
  display: inline-block;
  vertical-align: middle;
}

/* ============ MEMPOOL TICKER ============ */
.mempool-row {
  display: grid;
  grid-template-columns: 80px 80px 1fr 80px 100px 80px;
  gap: 8px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  align-items: center;
}
.mempool-row.fresh { animation: flash 1.6s ease-out; }
.mempool-row:hover { background: var(--panel-hi); }

/* ============ BUTTON ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  height: 24px;
  letter-spacing: 0.02em;
}
.btn:hover { background: var(--panel-hi); border-color: var(--border-2); }
.btn.primary { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
.btn.primary:hover { background: var(--amber); color: var(--bg); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.icon { padding: 4px 6px; min-width: 24px; justify-content: center; }
.btn.sm { height: 20px; font-size: 10px; padding: 2px 8px; }

/* ============ HEATMAP / BARS ============ */
.bar {
  position: relative;
  height: 14px;
  background: var(--panel-hi);
  font-family: var(--mono);
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--cyan);
  opacity: 0.35;
}
.bar-fill.green { background: var(--green); }
.bar-fill.red { background: var(--red); }
.bar-fill.amber { background: var(--amber); }
.bar-text {
  position: relative;
  padding: 0 6px;
  font-size: 10px;
  line-height: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ============ ASCII / CODE ============ */
.code {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 8px 10px;
  white-space: pre-wrap;
  color: var(--text-2);
  overflow: auto;
}

/* ============ MISC ============ */
.divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}
.col { display: flex; flex-direction: column; }
.row { display: flex; flex-direction: row; }
.grow { flex: 1; min-width: 0; min-height: 0; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-10 { gap: 10px; } .gap-12 { gap: 12px; }
.center { display: flex; align-items: center; }
.between { display: flex; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.upper { text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px; }
.tiny { font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* density tweaks */
[data-density="compact"] .tbl tbody td { padding: 2px 8px; }
[data-density="compact"] .tbl thead th { padding: 4px 8px; }
[data-density="compact"] .sb-item { padding: 3px 14px; }

[data-density="comfortable"] .tbl tbody td { padding: 7px 10px; }
[data-density="comfortable"] .tbl thead th { padding: 8px 10px; }
[data-density="comfortable"] .sb-item { padding: 6px 14px; }

/* Right rail */
.rightrail {
  width: 380px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* small heatmap cell */
.hm-cell {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin: 1px;
}

/* loading shimmer not needed; data is generated */

/* tweaks panel positioning override */
.tw-host { font-family: var(--mono); }

/* ============ VIEW HEADER ============ */
.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.view-header-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.view-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
}
.view-subtitle {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.view-header-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ============ SOURCE PILL ============ */
.source-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 9px;
  letter-spacing: 0.04em;
  user-select: none;
}
.source-pill .tag { font-weight: 700; }
.source-pill .tag .live-dot { width: 4px; height: 4px; }

/* ============ HINT ICON ============ */
.hint {
  opacity: 0.7;
  transition: opacity 120ms;
}
.hint:hover { opacity: 1; color: var(--cyan); }

th .th-hint {
  color: var(--muted-2);
  margin-left: 3px;
  font-size: 10px;
  opacity: 0.5;
}
.tbl thead th[title] { cursor: help; }

/* ============ KPI HINT ICON ============ */
.kpi-label .hint { color: var(--muted-2); }
.kpi-label .hint:hover { color: var(--cyan); }

/* ============ STATUSBAR EXTENDED ============ */
.statusbar-item .info { color: var(--cyan); font-weight: 500; }

/* ============ BADGE LIVE/HOT/NEAR-RT ============ */
.sb-badge.hot { background: var(--amber-bg); color: var(--amber); }
.sb-badge.live { background: var(--green-bg); color: var(--green); }

/* ============ LIGHT THEME — denser hover state for header ============ */
[data-theme="light"] .view-header { background: #fbfaf6; }
[data-theme="light"] .view-title { color: #1a1a1a; }
[data-theme="light"] .view-subtitle { color: #6b6b66; }

/* ============ FOCUS RING ============ */
.btn:focus-visible, .chip:focus-visible, .tb-btn:focus-visible {
  outline: 1px solid var(--amber);
  outline-offset: 1px;
}

/* ============ SOURCE-PILL REFRESH BUTTON OVERRIDES ============ */
.source-pill .btn.sm {
  border: 1px solid var(--border);
  background: var(--panel-hi);
}
.source-pill .btn.sm:hover { border-color: var(--amber); color: var(--amber); }

/* ============ HELP DOT (next to view title) ============ */
.view-title .hint { font-size: 10px; }
