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

:root {
  --bg: #0a0e14;
  --surface: #111820;
  --surface-alt: #0d1219;
  --border: #1e2730;
  --border-accent: #2a3440;
  --text: #d4dce6;
  --text-bright: #e8eef4;
  --text-muted: #6b7a8d;
  --green: #00d26a;
  --green-dim: rgba(0, 210, 106, 0.12);
  --red: #ff4757;
  --red-dim: rgba(255, 71, 87, 0.12);
  --yellow: #ffbe0b;
  --blue: #58a6ff;
  --accent: #4a9eff;
  --accent-gradient: linear-gradient(90deg, #3a7bd5, #4a9eff);
  --mono: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Helvetica, Arial, sans-serif;
}

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

/* --- Top accent bar --- */
.top-bar {
  height: 3px;
  background: var(--accent-gradient);
  width: 100%;
}

/* --- Header --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 107, 0, 0.04) 0%, transparent 100%);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-bright);
}

h1 .title-accent {
  color: var(--accent);
}

.header-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status {
  font-size: 0.7rem;
  padding: 0.2rem 0.65rem;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--mono);
}

.status.connected {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(0, 210, 106, 0.25);
}

.status.disconnected {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(255, 71, 87, 0.25);
}

#last-refresh {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.total-nav {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-bright);
  padding: 0.25rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  letter-spacing: 0.02em;
  cursor: help;
  white-space: nowrap;
}

.total-nav.loading {
  color: var(--text-muted);
  font-weight: 500;
}

.total-nav.error {
  color: var(--red);
  border-color: rgba(255, 71, 87, 0.4);
}

.total-nav.stale {
  border-color: rgba(255, 165, 0, 0.4);
  color: #ffa500;
}

#btn-refresh {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.3rem 0.85rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--mono);
  transition: background 0.15s, color 0.15s;
}

#btn-refresh:hover {
  background: var(--accent);
  color: #000;
}

/* --- Main content wrapper --- */
.main-content {
  padding: 0 1.5rem 2rem;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  background: var(--surface);
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--mono);
}

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

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

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

/* --- Strategy sub-tabs --- */
.sub-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.sub-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.45rem 1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.sub-tab:hover {
  color: var(--text);
}

.sub-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Filters --- */
.filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.filters label {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.filters select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-family: var(--mono);
}

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

.filters input[type="range"] {
  width: 100px;
  accent-color: var(--accent);
  cursor: pointer;
}

#filter-tvl-label {
  font-family: var(--mono);
  color: var(--text);
  min-width: 40px;
}

/* --- Tables --- */
.table-section {
  margin-bottom: 1.5rem;
}

.table-section h2 {
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-left: 0.2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

thead th {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border-accent);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  font-family: var(--mono);
}

thead th[data-sort] {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 1.3rem;
}

thead th[data-sort]:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

thead th[data-sort]::after {
  content: "\2195";
  position: absolute;
  right: 0.3rem;
  opacity: 0.25;
  font-size: 0.65rem;
}

thead th.sort-asc::after {
  content: "\2191";
  opacity: 1;
  color: var(--accent);
}

thead th.sort-desc::after {
  content: "\2193";
  opacity: 1;
  color: var(--accent);
}

/* Right-align numeric columns */
thead th[data-sort="tvl"],
thead th[data-sort="volume_24h"] {
  text-align: right;
}

tbody td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* Alternating row backgrounds */
tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.012);
}

tbody tr:hover {
  background: rgba(255, 107, 0, 0.04);
}

/* Right-align TVL and Volume cells */
tbody td.td-right {
  text-align: right;
}

/* --- Token icon + text --- */
.token-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.token-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
}

.token-initials {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  font-family: var(--sans);
  text-transform: uppercase;
}

/* --- Inline icons for chains + DEXes (logo only, hover tooltip for name) --- */
.badge-logo {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  vertical-align: middle;
  object-fit: cover;
  cursor: default;
  opacity: 0.85;
  transition: opacity 0.15s;
  position: relative;
}

.badge-logo:hover {
  opacity: 1;
}

.badge-fallback {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-family: var(--mono);
  cursor: default;
  text-transform: uppercase;
}

/* Tooltip on hover */
.icon-wrap {
  position: relative;
  display: inline-block;
}

.icon-wrap .icon-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e2430;
  color: var(--text);
  font-size: 0.65rem;
  font-family: var(--mono);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  border: 1px solid var(--border);
}

.icon-wrap:hover .icon-tooltip {
  display: block;
}

.fee-info {
  cursor: help;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: 2px;
}

/* --- Spread coloring --- */
.spread-positive {
  color: var(--green);
}

.spread-negative {
  color: var(--red);
}

/* Spread bar indicator */
.spread-cell {
  position: relative;
}

.spread-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  border-radius: 1px;
  max-width: 100%;
}

.spread-bar-positive {
  background: var(--green);
}

.spread-bar-negative {
  background: var(--red);
}

/* Highlight rows with |spread| > 5 bps */
.spread-highlight {
  /* disabled — no visual highlight on high-spread rows */
}

.direction-cell {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pool-link a {
  color: var(--blue);
  text-decoration: none;
}

.pool-link a:hover {
  text-decoration: underline;
  color: #7db8ff;
}

/* --- Errors --- */
.hidden {
  display: none;
}

#errors-list {
  list-style: none;
  padding: 0;
}

#errors-list li {
  background: var(--red-dim);
  color: var(--red);
  padding: 0.4rem 0.8rem;
  border-radius: 3px;
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  border: 1px solid rgba(255, 71, 87, 0.2);
}

/* --- Execution Panel --- */
.exec-section {
  margin-top: 0;
  padding-top: 0;
}

.exec-wallet {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.exec-wallet span:first-child {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 0.75rem;
}

.exec-balance {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.exec-balance strong {
  color: var(--text-bright);
  font-family: var(--mono);
}

/* --- NAV bar --- */
.exec-nav-header {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-bright);
  margin-bottom: 0.5rem;
  letter-spacing: 0.02em;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 165, 0, 0.06);
  border-left: 2px solid rgba(255, 165, 0, 0.5);
  border-radius: 2px;
}

.exec-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.nav-cell {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.nav-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-value {
  color: var(--text-bright);
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 600;
}

.nav-unit {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-family: var(--mono);
  margin-left: -0.4rem;
}

.nav-cell .nav-value + .nav-unit {
  display: inline;
  margin-left: 0;
  position: relative;
  top: -2px;
}

.nav-bps {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.nav-positive {
  color: var(--green, #4ade80);
}

.nav-negative {
  color: var(--red, #f87171);
}

.nav-missing {
  margin: -0.5rem 0 1rem 0;
  padding: 0.4rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.nav-missing.hidden {
  display: none;
}

@media (max-width: 720px) {
  .exec-nav {
    grid-template-columns: 1fr;
  }
}

.btn-small {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.7rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: border-color 0.15s, color 0.15s;
}

.btn-small:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.exec-positions {
  margin-bottom: 1.5rem;
}

.exec-positions h3 {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.exec-forms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.exec-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
}

.exec-form-card h3 {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.8rem;
  color: var(--text-bright);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-row {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  flex: 1;
  min-width: 100px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.form-row select,
.form-row input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: var(--mono);
}

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

.form-actions {
  display: flex;
  gap: 0.6rem;
}

.btn-action {
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--mono);
  transition: opacity 0.15s;
}

.btn-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-dry {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--blue);
}

.btn-dry:hover:not(:disabled) {
  background: rgba(88, 166, 255, 0.1);
}

.btn-live {
  background: var(--green);
  color: #000;
}

.btn-live:hover:not(:disabled) {
  opacity: 0.85;
}

.exec-result {
  margin-top: 0.8rem;
  padding: 0.6rem 0.8rem;
  border-radius: 3px;
  font-size: 0.78rem;
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
}

.exec-result.success {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(0, 210, 106, 0.25);
}

.exec-result.error {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(255, 71, 87, 0.25);
}

.exec-result.info {
  background: rgba(88, 166, 255, 0.1);
  color: var(--blue);
  border: 1px solid rgba(88, 166, 255, 0.25);
}

.exec-disabled-msg {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.exec-disabled-msg code {
  background: var(--surface);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--accent);
}

/* --- Responsive --- */
@media (max-width: 900px) {
  table {
    display: block;
    overflow-x: auto;
  }
  .exec-forms {
    grid-template-columns: 1fr;
  }
  header {
    padding: 0.8rem 1rem;
  }
  .main-content {
    padding: 0 1rem 2rem;
  }
  .tabs {
    padding: 0 1rem;
  }
}

/* --- History tab --- */
.history-filters {
  align-items: center;
}

.range-buttons {
  display: inline-flex;
  gap: 2px;
  margin-left: auto;
}

.range-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.range-btn:hover {
  color: var(--text);
}

.range-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.hist-status {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.chart-section {
  margin-bottom: 1.5rem;
}

.chart-wrap {
  position: relative;
  height: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.8rem;
}

/* Sub-chart (spread_bps under the on-chain-vs-dex overlay): shorter so the
   pair fits one screen without scrolling. */
.chart-wrap-sub {
  height: 200px;
  margin-top: 0.8rem;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.table-header h2 {
  margin: 0;
}

.pagination {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.page-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.78rem;
  width: 1.8rem;
  height: 1.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.page-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.page-info {
  min-width: 14rem;
  text-align: center;
  color: var(--text);
}

/* --- Clerk multi-tenant gate --------------------------------------------- */
/* While the bootstrap decides auth state, hide the app to avoid a flash of the
   dashboard before the sign-in gate appears. Removed once auth is resolved. */
body.clerk-init .main-content,
body.clerk-init header .header-right,
body.clerk-init .tabs {
  visibility: hidden;
}

.clerk-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.clerk-gate.hidden {
  display: none;
}

.clerk-gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2.5rem;
  text-align: center;
}

.clerk-gate-card h1 {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text-bright);
}

.clerk-gate-sub {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.clerk-gate-err {
  color: var(--red);
  max-width: 22rem;
}

/* Mounted Clerk widgets sit inline in the header. */
#clerk-org-switcher,
#clerk-user-button {
  display: flex;
  align-items: center;
}
