/* ── Global Reset & Variables ───────────────────────────────────── */
:root {
  --bg-primary: #0b0e14;
  --bg-secondary: #12161f;
  --bg-card: #171c28;
  --bg-card-hover: #1d2333;
  --border: #252d3d;
  --border-glow: rgba(99, 102, 241, 0.25);

  --text-primary: #e2e8f0;
  --text-secondary: #8892a6;
  --text-muted: #5a6478;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.1);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --cyan: #06b6d4;
  --cyan-bg: rgba(6, 182, 212, 0.1);

  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Header ────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.logo-sub {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-badge.live {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.status-badge.paused {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-badge.paused .status-dot {
  background: var(--amber);
  animation: none;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  font-family: var(--font);
  outline: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn svg {
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--accent); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.2); border-color: var(--red); }

.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.2);
}
.btn-success:hover { background: rgba(34, 197, 94, 0.2); border-color: var(--green); }


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

/* ── Layout ────────────────────────────────────────────────────── */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ── Stats Cards ───────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  transition: border-color 0.2s, transform 0.15s;
}

.stat-card:hover {
  border-color: var(--border-glow);
  transform: translateY(-2px);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-value.red { color: var(--red); }
.stat-value.amber { color: var(--amber); }
.stat-value.green { color: var(--green); }
.stat-value.cyan { color: var(--cyan); }
.stat-value.accent { color: var(--accent); }

/* ── Main Grid ─────────────────────────────────────────────────── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
}

@media (max-width: 1024px) {
  .main-grid { grid-template-columns: 1fr; }
}

/* ── Panel (shared) ────────────────────────────────────────────── */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Search Bar ────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-bar input {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 13px;
  width: 260px;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--accent);
}

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

/* ── Table ─────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

th:hover { color: var(--text-secondary); }

td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(37, 45, 61, 0.5);
  white-space: nowrap;
}

tr {
  transition: background 0.15s;
  cursor: pointer;
}

tr:hover {
  background: var(--bg-card-hover);
}

.addr {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

/* ── Score Badges ──────────────────────────────────────────────── */
.score {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
}

.score.high {
  background: var(--red-bg);
  color: var(--red);
}

.score.medium {
  background: var(--amber-bg);
  color: var(--amber);
}

.score.low {
  background: var(--green-bg);
  color: var(--green);
}

.score.na {
  color: var(--text-muted);
}

/* ── Pagination ────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination button {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.pagination button:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Alert Feed ────────────────────────────────────────────────── */
.alert-feed {
  max-height: calc(100vh - 350px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.alert-feed::-webkit-scrollbar { width: 5px; }
.alert-feed::-webkit-scrollbar-track { background: transparent; }
.alert-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.alert-item {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(37, 45, 61, 0.4);
  animation: slideIn 0.3s ease-out;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alert-item:hover {
  background: var(--bg-card-hover);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

.alert-time {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--mono);
  letter-spacing: 0.5px;
}

.alert-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
  word-break: break-word;
}

.alert-text .tag {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-right: 6px;
  display: inline-block;
  vertical-align: middle;
}

.alert-addr {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--bg-secondary);
  padding: 1px 4px;
  border-radius: 4px;
}

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

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
  overflow-y: auto;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 780px;
  margin-bottom: 60px;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.15s;
}

.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.modal-addr {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  word-break: break-all;
  margin-bottom: 20px;
}

.wallet-stats-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.w-stat {
  background: var(--bg-secondary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.w-stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.w-stat-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Verdict Box ────────────────────────────────────────────────── */
.verdict-box {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-primary);
  border-left: 4px solid var(--accent);
  line-height: 1.5;
}

.verdict-box.high {
  border-left-color: var(--red);
  background: var(--red-bg);
}

/* ── Final Score Banner ─────────────────────────────────────────── */
.final-score-banner {
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.final-score-banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(99, 102, 241, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

.final-score-banner .score-title {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.final-score-banner .score-number {
  font-size: 48px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1;
  margin-bottom: 8px;
}

.final-score-banner .score-formula {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Accordion & Score UI ────────────────────────────────────── */
.score-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow: hidden;
}

.score-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.score-header:hover {
  background: var(--bg-card-hover);
}

.score-header.active {
  border-bottom: 1px solid var(--border);
}

.score-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-header-label {
  font-weight: 600;
  font-size: 14px;
}

.score-header-sublabel {
  font-size: 11px;
  color: var(--text-muted);
}

.score-content {
  display: none;
  padding: 16px;
  background: var(--bg-primary);
}

.score-content.active {
  display: block;
}

.chevron {
  width: 14px;
  height: 14px;
  transition: transform 0.2s;
  color: var(--text-muted);
  flex-shrink: 0;
}

.score-header.active .chevron {
  transform: rotate(180deg);
}

/* ── Score Breakdown ───────────────────────────────────────────── */
.breakdown-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.breakdown-item {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.breakdown-item:hover {
  border-color: var(--border-glow);
}

.breakdown-label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.breakdown-label-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.breakdown-label-left .weight-tag {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 1px 6px;
  border-radius: 4px;
}

.breakdown-value {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--mono);
}

.breakdown-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.breakdown-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ── Info Tooltip (click-triggered) ──────────────────────────── */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  flex-shrink: 0;
  position: relative;
}

.info-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.info-btn svg {
  width: 12px;
  height: 12px;
}

.info-popover {
  display: none;
  position: absolute;
  z-index: 1000;
  bottom: calc(100% + 10px);
  right: -8px;
  width: 280px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 11px;
  line-height: 1.6;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  text-transform: none;
  letter-spacing: normal;
  /* JS will override position/z-index to fixed to escape stacking contexts */
}

.info-popover.active {
  display: block;
  animation: popoverIn 0.2s ease-out;
}

@keyframes popoverIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.info-popover::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: var(--accent) transparent transparent transparent;
}

.info-popover strong {
  color: var(--accent);
}

/* ── ML Stats Grid ───────────────────────────────────────────── */
.ml-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.ml-stat-item {
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.ml-stat-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.ml-stat-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.ml-explanation {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
}

.ml-feature-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.ml-feature-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
}

.ml-feature-row .feature-name {
  color: var(--text-secondary);
}

.ml-feature-row .feature-value {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Trade List in Modal ───────────────────────────────────────── */
.trade-list-header {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  margin-top: 8px;
  color: var(--text-secondary);
}

.modal table td {
  font-size: 12px;
}

/* ── Tags ──────────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag.rules {
  background: var(--red-bg);
  color: var(--red);
}

.tag.ml {
  background: var(--cyan-bg);
  color: var(--cyan);
}

.tag.green {
  background: var(--green-bg);
  color: var(--green);
}

.tag.cyan {
  background: var(--cyan-bg);
  color: var(--cyan);
}

.tag.both {
  background: linear-gradient(135deg, var(--red-bg), var(--cyan-bg));
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.feed-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (max-width: 1024px) {
  .trades-row {
    grid-template-columns: 1fr !important;
  }
}

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Loading State ─────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Responsive Header ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .header-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .container {
    padding: 16px;
  }
  .search-bar input {
    width: 180px;
  }
}
