:root {
  --bg: #0a0b0d;
  --surface: #111318;
  --surface-hi: #161923;
  --border: #1f232c;
  --border-hi: #2a2f3a;
  --text: #e7e9ef;
  --text-dim: #9096a3;
  --text-muted: #5e6573;
  --accent: #7aa2ff;

  --int: #22c55e;
  --int-bg: rgba(34, 197, 94, 0.1);
  --int-border: rgba(34, 197, 94, 0.35);
  --watch: #fbbf24;
  --watch-bg: rgba(251, 191, 36, 0.1);
  --watch-border: rgba(251, 191, 36, 0.35);
  --risky: #f97316;
  --risky-bg: rgba(249, 115, 22, 0.1);
  --risky-border: rgba(249, 115, 22, 0.35);
  --avoid: #ef4444;
  --avoid-bg: rgba(239, 68, 68, 0.1);
  --avoid-border: rgba(239, 68, 68, 0.35);

  --mono: ui-monospace, "JetBrains Mono", "Menlo", "Consolas", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.view[hidden] { display: none !important; }

/* ── Tabs ────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin-left: 24px;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab:hover { background: var(--surface-hi); color: var(--text); }
.tab.active { background: var(--surface-hi); color: var(--text); border-color: var(--border-hi); }

.tab-badge {
  background: var(--border-hi);
  color: var(--text-dim);
  padding: 1px 6px;
  border-radius: 9px;
  font-size: 10.5px;
  font-family: var(--mono);
  min-width: 18px;
  text-align: center;
}

.tab.active .tab-badge { background: var(--accent); color: #000; }

/* ── Panels (for wallets / positions views) ─────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin: 16px 22px;
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
}

.panel-help {
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
  margin: 4px 0 14px;
}

.panel-subtitle {
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 8px;
  font-size: 12px;
}

.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.row-form input {
  flex: 1 1 140px;
  min-width: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12.5px;
  transition: border-color 0.12s;
}

.row-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.row-form input::placeholder { color: var(--text-muted); }

.row-form input[type="number"] { flex: 0 0 100px; }

.row-form button,
.btn {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 8px 18px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: filter 0.12s;
  font-family: inherit;
}

.row-form button:hover, .btn:hover { filter: brightness(1.1); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-hi); filter: none; }

.btn-danger { background: var(--avoid); color: white; }

.btn-small { padding: 4px 10px; font-size: 11.5px; }

/* ── Generic data table (wallets, positions) ────────── */
table.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  margin-top: 8px;
}

table.data-table thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

table.data-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.data-table tbody tr:hover { background: var(--bg); }

table.data-table .col-num { text-align: right; }
table.data-table .addr { color: var(--text-dim); }
table.data-table .label { font-weight: 600; color: var(--text); }

.pnl-pos { color: var(--int); }
.pnl-neg { color: var(--avoid); }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
  background: var(--surface-hi);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.buy { background: var(--int-bg); color: var(--int); border-color: var(--int-border); }
.badge.sell { background: var(--avoid-bg); color: var(--avoid); border-color: var(--avoid-border); }
.badge.open { background: rgba(122, 162, 255, 0.12); color: var(--accent); border-color: rgba(122, 162, 255, 0.35); }
.badge.closed { background: var(--surface-hi); color: var(--text-muted); }

.toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  gap: 6px;
  user-select: none;
}
.toggle input { appearance: none; width: 28px; height: 16px; background: var(--border); border-radius: 8px; position: relative; cursor: pointer; transition: background 0.15s; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; background: var(--text-dim); border-radius: 50%; transition: all 0.15s; }
.toggle input:checked { background: rgba(34, 197, 94, 0.4); }
.toggle input:checked::after { left: 14px; background: var(--int); }

/* W column badge indicator */
.col-badge { width: 30px; text-align: center; }
.watched-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.col-actions { width: 100px; }

.mint-mini {
  color: var(--text-muted);
  font-size: 11.5px;
  cursor: pointer;
}
.mint-mini:hover { color: var(--accent); }

/* Sparkline in detail panel */
.sparkline {
  width: 100%;
  height: 80px;
  margin: 8px 0 12px;
}

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.support-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(34, 197, 94, 0.09);
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 6px;
  color: #e5e7eb;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--mono);
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.support-badge:hover {
  background: rgba(34, 197, 94, 0.16);
  border-color: rgba(34, 197, 94, 0.55);
}
.support-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: support-pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}
.support-logo {
  height: 18px;
  width: auto;
  border-radius: 3px;
  display: block;
}
.support-ticker {
  color: #22c55e;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.support-text {
  color: #9ca3af;
  font-weight: 500;
}
@keyframes support-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  50%      { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
}

/* Hide support text on narrow screens so the badge doesn't overlap the sides */
@media (max-width: 960px) {
  .support-text { display: none; }
}
@media (max-width: 640px) {
  .support-badge { display: none; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.status .divider { color: var(--text-muted); }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.live-dot.on {
  background: var(--int);
  box-shadow: 0 0 8px var(--int);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Stats strip ─────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 16px 22px;
  background: var(--bg);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color 0.15s;
}

.stat-card:hover { border-color: var(--border-hi); }

.stat-card.avoid { border-left: 3px solid var(--avoid); }
.stat-card.risky { border-left: 3px solid var(--risky); }
.stat-card.watch { border-left: 3px solid var(--watch); }
.stat-card.interesting { border-left: 3px solid var(--int); }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ── Controls ────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.chip-group {
  display: flex;
  gap: 6px;
}

.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
}

.chip:hover { background: var(--surface-hi); color: var(--text); }

.chip.active { background: var(--surface-hi); color: var(--text); border-color: var(--border-hi); }

.chip.interesting.active { background: var(--int-bg); color: var(--int); border-color: var(--int-border); }
.chip.watch.active { background: var(--watch-bg); color: var(--watch); border-color: var(--watch-border); }
.chip.risky.active { background: var(--risky-bg); color: var(--risky); border-color: var(--risky-border); }
.chip.avoid.active { background: var(--avoid-bg); color: var(--avoid); border-color: var(--avoid-border); }

.score-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
}

.score-filter input[type="range"] {
  width: 140px;
  accent-color: var(--accent);
}

#min-score-value {
  min-width: 20px;
  color: var(--text);
  font-weight: 600;
}

.search {
  flex: 1;
  min-width: 220px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  transition: border-color 0.12s;
}

.search:focus {
  outline: none;
  border-color: var(--accent);
}

.search::placeholder { color: var(--text-muted); }

/* ── Table ───────────────────────────────────────────── */
.table-wrap {
  padding: 0 22px 22px;
  overflow: auto;
  position: relative;
}

table.tokens {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--mono);
  font-size: 12.5px;
}

table.tokens thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  padding: 10px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.12s;
}

thead th.sortable:hover { color: var(--text); }

thead th.sort-active { color: var(--accent); }

thead th.sortable::after {
  content: "";
  display: inline-block;
  margin-left: 4px;
  opacity: 0.35;
  font-size: 9px;
}

thead th.sortable.sort-active.sort-desc::after { content: "▼"; opacity: 1; }
thead th.sortable.sort-active.sort-asc::after { content: "▲"; opacity: 1; }

table.tokens tbody tr {
  transition: background 0.1s;
  cursor: pointer;
}

table.tokens tbody tr:hover { background: var(--surface); }

table.tokens td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.tokens tbody tr.new {
  animation: flash-in 1.2s ease-out;
}

@keyframes flash-in {
  0% { background: rgba(122, 162, 255, 0.18); }
  100% { background: transparent; }
}

/* Cell flash on live price updates */
.flash-buy {
  animation: flash-buy 0.9s ease-out;
}
.flash-sell {
  animation: flash-sell 0.9s ease-out;
}

@keyframes flash-buy {
  0% { background: rgba(34, 197, 94, 0.35); color: var(--int); }
  100% { background: transparent; }
}
@keyframes flash-sell {
  0% { background: rgba(239, 68, 68, 0.35); color: var(--avoid); }
  100% { background: transparent; }
}

.col-time { width: 70px; color: var(--text-muted); }
.col-symbol { font-weight: 600; color: var(--text); }
.mayhem-icon {
  height: 16px;
  width: 16px;
  vertical-align: middle;
  margin-left: 4px;
  border-radius: 2px;
}

/* Live-mode badge in topbar — impossible to miss */
.live-mode-badge {
  margin-left: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: help;
}
.live-mode-badge.dry-run {
  background: rgba(250, 204, 21, 0.18);
  color: #facc15;
  border: 1px solid rgba(250, 204, 21, 0.4);
}
.live-mode-badge.live {
  background: rgba(239, 68, 68, 0.22);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.5);
  animation: live-pulse 1.5s ease-in-out infinite;
}

/* Quick-buy action buttons in token list */
.qb-live {
  background: rgba(239, 68, 68, 0.18);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.5);
  font-weight: 700;
}
.qb-live:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
}
.qb-dryrun {
  background: rgba(250, 204, 21, 0.15);
  color: #facc15;
  border: 1px solid rgba(250, 204, 21, 0.4);
  font-weight: 600;
}
.qb-dryrun:hover:not(:disabled) {
  background: rgba(250, 204, 21, 0.25);
}
@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}
.col-name { color: var(--text-dim); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.col-score { width: 60px; font-weight: 600; text-align: right; }
.col-verdict { width: 110px; }
.col-pct { width: 70px; text-align: right; color: var(--text-dim); }
.col-num { width: 80px; text-align: right; color: var(--text-dim); }

.verdict-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.verdict-tag.AVOID { background: var(--avoid-bg); color: var(--avoid); border-color: var(--avoid-border); }
.verdict-tag.RISKY { background: var(--risky-bg); color: var(--risky); border-color: var(--risky-border); }
.verdict-tag.WATCH { background: var(--watch-bg); color: var(--watch); border-color: var(--watch-border); }
.verdict-tag.INTERESTING { background: var(--int-bg); color: var(--int); border-color: var(--int-border); }

.score-cell.high { color: var(--int); }
.score-cell.mid { color: var(--watch); }
.score-cell.low { color: var(--risky); }
.score-cell.bad { color: var(--avoid); }

.score-delta {
  font-size: 10px;
  font-weight: 500;
  margin-left: 2px;
  opacity: 0.9;
}

.pct-warn { color: var(--risky) !important; }
.pct-bad { color: var(--avoid) !important; }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 13px;
}

/* ── Detail panel ───────────────────────────────────── */
.detail {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(480px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.22s ease-out;
  z-index: 20;
  overflow: auto;
}

.detail.open { transform: translateX(0); box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5); }

.detail-inner { padding: 20px 22px; }

.detail-close {
  position: sticky;
  top: 0;
  float: right;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 10px;
  margin-bottom: 8px;
}

.detail-close:hover { color: var(--text); }

.detail h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}

.detail .subtitle {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  margin-bottom: 18px;
}

.detail-live-mc {
  display: flex;
  align-items: baseline;
  gap: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.detail-live-mc .k {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.detail-live-mc .v {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
}

.detail-grid .k { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-grid .v { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.detail h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 18px 0 8px;
  font-weight: 600;
}

.signals { list-style: none; padding: 0; margin: 0; }
.signals li {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  margin-bottom: 6px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.addr {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 5px;
  word-break: break-all;
  margin-bottom: 8px;
  display: block;
  color: var(--text-dim);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.links a {
  display: inline-block;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  transition: all 0.12s;
}

.links a:hover { border-color: var(--accent); background: var(--surface-hi); }

/* ── Toast ─────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s;
  pointer-events: none;
  z-index: 30;
  max-width: 320px;
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .col-name { display: none; }
  .col-pct:nth-of-type(7), .col-num:nth-of-type(10) { display: none; }
}

@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .controls { padding: 10px 14px; }
  .table-wrap { padding: 0 14px 14px; }
}
