/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ────────────────────────────────────────────────────────── */
:root {
  --bg: #080b0f;
  --bg-2: #0d1117;
  --bg-3: #111820;
  --bg-hover: #151e2a;
  --border: #1a2a3a;
  --border-hi: #1e3a52;

  --text: #c9d1d9;
  --text-dim: #4a5568;
  --text-dimmer: #2d3748;

  --green: #00ff85;
  --green-dim: #00c467;
  --green-glow: rgba(0, 255, 133, 0.12);
  --green-bg: rgba(0, 255, 133, 0.04);

  --red: #ff4d6a;
  --red-dim: #c73552;
  --red-glow: rgba(255, 77, 106, 0.12);

  --yellow: #ffd166;
  --yellow-dim: #b8942f;

  --cyan: #38bdf8;
  --cyan-dim: #1e7ba8;
  --purple: #a78bfa;

  --nado-color: #00d4ff;
  --ostium-color: #ff9f47;

  --font: 'JetBrains Mono', 'Courier New', monospace;
  --radius: 4px;
}

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle scanline overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent 2px,
      rgba(0, 0, 0, 0.04) 2px,
      rgba(0, 0, 0, 0.04) 4px);
  pointer-events: none;
  z-index: 9999;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-img {
  height: 24px;
  width: 24px;
  border-radius: 4px;
  /* Optional, softens the square edges slightly */
  box-shadow: 0 0 10px rgba(0, 114, 255, 0.4);
  /* Slight blue glow to match the A8 theme */
}

.header-brand .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
  text-shadow: 0 0 16px var(--green);
  letter-spacing: 0.08em;
}

.header-brand .tagline {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.header-exchanges {
  display: flex;
  align-items: center;
  gap: 24px;
}

.exchange-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.exchange-badge .name {
  color: var(--text);
}

.exchange-badge .latency {
  color: var(--text-dim);
  font-size: 10px;
}

.exchange-badge.nado .name {
  color: var(--nado-color);
}

.exchange-badge.ostium .name {
  color: var(--ostium-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.status-dot.loading {
  background: var(--yellow);
  animation: blink 0.8s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.2;
  }
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.last-updated-label {
  font-size: 10px;
  color: var(--text-dimmer);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.last-updated-value {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Refresh progress bar ─────────────────────────────────────────────────── */
.refresh-bar-track {
  height: 2px;
  background: var(--border);
  width: 100%;
  position: relative;
  overflow: hidden;
}

.refresh-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green-dim), var(--green));
  transition: width 0.05s linear;
  box-shadow: 0 0 8px var(--green);
}

/* ── Sub-header / Stats bar ───────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.stat-label {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  color: var(--text);
  font-weight: 600;
}

.badge {
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.badge-arb {
  background: var(--green-glow);
  color: var(--green);
  border: 1px solid var(--green-dim);
}

.badge-noarb {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

/* ── Error banner ─────────────────────────────────────────────────────────── */
#error-banner {
  display: none;
  background: var(--red-glow);
  border-bottom: 1px solid var(--red-dim);
  color: var(--red);
  padding: 6px 20px;
  font-size: 11px;
}

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 16px 20px;
  overflow-x: auto;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

.arb-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

/* Column widths */
.arb-table .col-rank {
  width: 40px;
  text-align: center;
}

.arb-table .col-pair {
  width: 140px;
}

.arb-table .col-price {
  width: 110px;
  text-align: right;
}

.arb-table .col-directions {
  width: 480px;
}

.arb-table .col-oi {
  width: 90px;
  text-align: right;
}

/* Header row */
.arb-table thead tr {
  background: var(--bg-3);
  border-bottom: 2px solid var(--border-hi);
}

.arb-table thead th {
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Header group separators */
.arb-table thead .th-nado {
  color: var(--nado-color);
  border-left: 2px solid rgba(0, 212, 255, 0.2);
}

.arb-table thead .th-ostium {
  color: var(--ostium-color);
  border-left: 2px solid rgba(255, 159, 71, 0.2);
}

.arb-table thead .th-arb {
  color: var(--purple);
  border-left: 2px solid rgba(167, 139, 250, 0.2);
}

/* Body rows */
.arb-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.arb-table tbody tr:hover {
  background: var(--bg-hover);
}

.arb-table tbody td {
  padding: 9px 10px;
  font-size: 12px;
  white-space: nowrap;
}

/* Row states */
.row-arb-a {
  background: rgba(0, 255, 133, 0.03);
  border-left: 2px solid var(--green-dim) !important;
}

.row-arb-b {
  background: rgba(56, 189, 248, 0.03);
  border-left: 2px solid var(--cyan-dim) !important;
}

.row-near {
  border-left: 2px solid var(--yellow-dim) !important;
}

.row-default {
  border-left: 2px solid transparent;
}

/* Glow on arb row */
@keyframes arb-row-glow {
  0% {
    box-shadow: inset 0 0 0 0 rgba(0, 255, 133, 0);
  }

  30% {
    box-shadow: inset 0 0 20px 0 rgba(0, 255, 133, 0.1);
  }

  100% {
    box-shadow: inset 0 0 0 0 rgba(0, 255, 133, 0);
  }
}

.arb-glow {
  animation: arb-row-glow 1.2s ease-out;
}

/* Price cell colors */
.nado-bid,
.nado-ask {
  color: var(--nado-color);
  font-variant-numeric: tabular-nums;
}

.ostium-bid,
.ostium-ask {
  color: var(--ostium-color);
  font-variant-numeric: tabular-nums;
}

/* Flash on price change */
@keyframes flash-green {
  0% {
    background: rgba(0, 255, 133, 0.35);
  }

  100% {
    background: transparent;
  }
}

.flash {
  animation: flash-green 0.7s ease-out;
}

/* ── Dual-direction spread cell ──────────────────────────────────────────── */
.col-directions {
  padding: 4px 10px !important;
  border-left: 2px solid rgba(167, 139, 250, 0.12);
}

.dir-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0.5;
  /* dim both by default */
  transition: opacity 0.2s;
}

/* Profit line is always at full opacity */
.dir-row-profit {
  opacity: 0.75;
}

.dir-row-loss {
  opacity: 0.4;
}

/* The winning direction is fully highlighted */
.dir-row-active {
  opacity: 1 !important;
}

.dir-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-dimmer);
  min-width: 26px;
}

.dir-spread {
  font-size: 12px;
  font-weight: 600;
  min-width: 80px;
  text-align: right;
}

.dir-pct {
  font-size: 11px;
  min-width: 90px;
  color: var(--text-dim);
}

.dir-action {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-left: 4px;
}

.dir-net {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 2px;
  cursor: help;
  /* tooltip on hover */
}

.net-positive {
  color: var(--green-dim);
}

.net-negative {
  color: var(--text-dimmer);
}

/* N→O row colors: profit = nado-color (buy), loss = dim */
.dir-row:first-child .dir-spread {
  color: var(--nado-color);
}

.dir-row:first-child.dir-row-profit .dir-spread {
  color: var(--green);
}

.dir-row:first-child.dir-row-active .dir-action {
  color: var(--green);
}

/* O→N row colors: profit = ostium-color (buy), loss = dim */
.dir-row:last-child .dir-spread {
  color: var(--ostium-color);
}

.dir-row:last-child.dir-row-profit .dir-spread {
  color: var(--green);
}

.dir-row:last-child.dir-row-active .dir-action {
  color: var(--cyan);
}

/* Profit pct turns green */
.dir-row-profit .dir-pct {
  color: var(--green-dim);
}

.dir-row-active .dir-pct {
  color: var(--text);
}

/* Status badges for trading status */
.status-badge {
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.status-live {
  background: var(--green-glow);
  color: var(--green);
}

.status-post_only {
  background: rgba(255, 209, 102, 0.15);
  color: var(--yellow);
}

.status-reduce_only {
  background: rgba(255, 77, 106, 0.15);
  color: var(--red);
}

.status-not_tradable {
  background: var(--bg-3);
  color: var(--text-dimmer);
}

.mkt-closed {
  color: var(--yellow-dim);
  font-size: 11px;
}

/* Rank column */
.col-rank {
  color: var(--text-dimmer);
  font-weight: 600;
}

/* OI column */
.col-oi {
  color: var(--text-dim);
  font-size: 11px;
}

/* ── Loading skeleton ─────────────────────────────────────────────────────── */
.skeleton-row td {
  padding: 9px 10px;
}

.skeleton {
  display: inline-block;
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-hover) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}


/* ── Strategy B Panel ─────────────────────────────────────────────────────── */
.strategy-panel {
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  padding: 0;
}

.strategy-header {
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.strategy-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--purple);
  letter-spacing: 0.12em;
}

.strategy-subtitle {
  font-size: 10px;
  color: var(--text-dim);
}

.strategy-table .col-pair {
  width: 140px;
}

.strategy-table .col-direction {
  width: 180px;
}

.strategy-table .col-price {
  width: 130px;
}

.strategy-table .col-pct {
  width: 100px;
}

.strategy-table .col-profit {
  width: 120px;
  font-weight: 600;
}

.strategy-table .col-friction {
  width: 120px;
  color: var(--text-dim);
}

.text-right {
  text-align: right !important;
}

/* ── Execution Panel ──────────────────────────────────────────────────────── */
.execution-panel {
  display: flex;
  gap: 32px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}

/* ── Fee Settings Panel ───────────────────────────────────────────────────── */
.fee-panel {
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding: 14px 20px 16px;
}

.fee-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.fee-panel-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--purple);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.fee-panel-sub {
  font-size: 10px;
  color: var(--text-dimmer);
  letter-spacing: 0.04em;
  flex: 1;
}

.fee-link {
  color: var(--text-dim) !important;
  text-decoration: none;
}

.fee-link:hover {
  color: var(--text) !important;
}

.fee-reset-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.fee-reset-btn:hover {
  border-color: var(--purple);
  color: var(--purple);
}

@keyframes btn-flash-anim {
  0% {
    background: rgba(167, 139, 250, 0.25);
  }

  100% {
    background: transparent;
  }
}

.btn-flash {
  animation: btn-flash-anim 0.5s ease-out;
}

.fee-controls {
  display: flex;
  gap: 24px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.fee-control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  flex: 1;
}

.fee-control-label {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.fee-exchange-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 1px 5px;
  border-radius: 3px;
}

.nado-tag {
  background: rgba(0, 212, 255, 0.12);
  color: var(--nado-color);
  border: 1px solid rgba(0, 212, 255, 0.2);
}

.ostium-tag {
  background: rgba(255, 159, 71, 0.12);
  color: var(--ostium-color);
  border: 1px solid rgba(255, 159, 71, 0.2);
}

.fee-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.fee-hint {
  font-size: 9px;
  color: var(--text-dimmer);
  letter-spacing: 0.03em;
}

.fee-control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fee-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--border-hi);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.fee-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--purple);
  box-shadow: 0 0 6px rgba(167, 139, 250, 0.5);
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.fee-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.8);
}

.fee-value-display {
  font-size: 12px;
  font-weight: 600;
  color: var(--purple);
  font-variant-numeric: tabular-nums;
  min-width: 55px;
  text-align: right;
}

/* Total summary box */
.fee-total-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--bg-3);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 10px 18px;
  min-width: 140px;
  text-align: center;
}

.fee-total-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dimmer);
  text-transform: uppercase;
}

.fee-total-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

.fee-total-low {
  color: var(--green);
}

.fee-total-mid {
  color: var(--yellow);
}

.fee-total-high {
  color: var(--red);
}

.fee-total-pct {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.fee-total-formula {
  font-size: 10px;
  color: var(--text-dimmer);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
.footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dimmer);
}

.footer a {
  color: var(--text-dim);
  text-decoration: none;
}

.footer a:hover {
  color: var(--text);
}

.footer-sources {
  display: flex;
  gap: 16px;
}

.source-nado {
  color: var(--nado-color) !important;
  opacity: 0.7;
}

.source-ostium {
  color: var(--ostium-color) !important;
  opacity: 0.7;
}

/* ── Divider between DEX columns ─────────────────────────────────────────── */
.arb-table .border-nado {
  border-left: 2px solid rgba(0, 212, 255, 0.12);
}

.arb-table .border-ostium {
  border-left: 2px solid rgba(255, 159, 71, 0.12);
}

.arb-table .border-arb {
  border-left: 2px solid rgba(167, 139, 250, 0.12);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .arb-table .col-oi {
    display: none;
  }
}

@media (max-width: 768px) {
  .header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .stats-bar {
    flex-wrap: wrap;
    gap: 12px;
  }

  body {
    font-size: 11px;
  }

  .arb-table .col-rank {
    display: none;
  }
}