:root {
  color-scheme: dark;
  --bg: #0a0d13;
  --bg-gradient: radial-gradient(1200px 600px at 20% -10%, rgba(79, 140, 255, 0.10), transparent),
                 radial-gradient(1000px 500px at 100% 0%, rgba(53, 192, 122, 0.06), transparent);
  --panel: #121722;
  --panel-2: #1a2130;
  --panel-3: #202940;
  --border: #262f42;
  --text: #e6e9ef;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent-2: #7aa8ff;
  --green: #35c07a;
  --red: #ef5762;
  --yellow: #e0a63d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg) var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent-2); }

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 23, 34, 0.85);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

header.topbar h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
header.topbar h1::before {
  content: "◆";
  color: var(--accent);
}

header.topbar a.back { font-size: 13px; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
/* The wallet detail page's pair cards benefit from real width (the sell ladder needs room to
   breathe) — a wider container just for that page, not the wallets list or login. */
main.wide { max-width: 1680px; }

.card {
  background: linear-gradient(180deg, var(--panel), rgba(18, 23, 34, 0.6));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 14px;
  font-weight: 700;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background 0.15s; }
tr.clickable:hover { background: var(--panel-2); }
tr.entry-row td { padding: 5px 12px 5px 24px; border-bottom: 1px dashed var(--border); background: var(--panel-2); }
tr.entry-row:last-child td { border-bottom: 1px dashed var(--border); }
tfoot td { border-top: 2px solid var(--border); border-bottom: none; padding-top: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.dry { background: rgba(224, 166, 61, 0.15); color: var(--yellow); }
.badge.live { background: rgba(239, 87, 98, 0.15); color: var(--red); }
.badge.running { background: rgba(53, 192, 122, 0.15); color: var(--green); }
.badge.running::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 1.6s infinite; }
.badge.stopped { background: rgba(139, 148, 167, 0.15); color: var(--muted); }
.badge.paused { background: rgba(239, 87, 98, 0.15); color: var(--red); }
.badge.buying { background: rgba(79, 140, 255, 0.15); color: var(--accent-2); }
.badge.selling { background: rgba(53, 192, 122, 0.15); color: var(--green); }
.badge.warn { background: rgba(224, 166, 61, 0.18); color: var(--yellow); }

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

button, input, select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 600;
}
button:hover { opacity: 0.9; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--red); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.muted { color: var(--muted); }
.mono { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }

.error-box {
  background: rgba(239, 87, 98, 0.1);
  border: 1px solid rgba(239, 87, 98, 0.4);
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  white-space: pre-line;
}

.notice-box {
  background: rgba(79, 140, 255, 0.1);
  border: 1px solid rgba(79, 140, 255, 0.4);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

.warn-box {
  background: rgba(224, 166, 61, 0.1);
  border: 1px solid rgba(224, 166, 61, 0.4);
  color: var(--yellow);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

#balances { font-size: 13px; }
#balances b { color: var(--text); font-weight: 700; }

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card { width: 320px; }
.login-card .field input { width: 100%; }

.pairs-grid {
  display: grid;
  /* One card per row, full width — deliberately not a multi-column grid. With how much each
     card now shows (campaign summary, live P&L, the sell-ladder visualization, warnings), a
     narrow multi-column card was too cramped to read at a glance; a single wide column trades
     vertical space for legibility. */
  grid-template-columns: 1fr;
  gap: 26px;
  align-items: start;
}

.pair-card {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  padding: 28px 34px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.pair-card:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.pair-card.phase-selling { border-left-color: var(--green); }
.pair-card.disabled { opacity: 0.55; }
.pair-card.liq-warn { border-left-color: var(--yellow); box-shadow: 0 0 0 1px rgba(224, 166, 61, 0.3); }
.pair-card.size-mismatch { border-left-color: var(--yellow); }

.pair-card .pc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.pair-card h3 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: 0.01em; }

.pair-card .pc-price {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 36px;
  font-weight: 600;
  margin: 10px 0 16px;
}
.pair-card .pc-price .pc-price-label { font-family: inherit; font-size: 13px; color: var(--muted); font-weight: 500; display: block; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }

.pair-card .pc-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 20px;
  font-size: 14px;
  color: var(--muted);
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.pair-card .pc-stats b { color: var(--text); font-weight: 600; }
@media (max-width: 900px) {
  .pair-card { padding: 22px 24px; }
  .pair-card .pc-stats { grid-template-columns: 1fr 1fr; }
}

.pair-card .pc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}
.pair-card .pc-actions button {
  flex: 1 1 calc(33.33% - 5px);
  min-width: 100px;
  padding: 7px 9px;
  font-size: 12px;
}

/* Sell ladder — a horizontal price strip showing the current position (average entry, live
   price) and the projected rungs where the campaign would partially sell as price climbs. */
.sell-ladder {
  margin: 12px 0 6px;
  padding: 10px 12px 14px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
}
.sell-ladder-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.sell-ladder-title .sell-ladder-extra { text-transform: none; letter-spacing: 0; font-size: 11px; }
.sell-ladder-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(53, 192, 122, 0.12), rgba(53, 192, 122, 0.35));
  /* The rung labels below the bar (and the "Próximo" badge above it) are position:absolute, so
     they don't push surrounding in-flow siblings out of the way on their own — track needs real
     margin on both sides to reserve that space, otherwise the context line/legend render right
     against the 6px bar and their text collides with the floating labels/badge. */
  margin: 26px 4px 76px;
}
.sell-ladder-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--panel-3);
  z-index: 2;
}
.sell-ladder-marker.current {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.25);
}
.sell-ladder-marker.current::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  animation: sellLadderPulse 1.8s ease-out infinite;
}
.sell-ladder-marker.entry {
  width: 2px;
  height: 16px;
  border-radius: 1px;
  border: none;
  background: repeating-linear-gradient(180deg, var(--muted) 0 3px, transparent 3px 6px);
  top: -2px;
  transform: translateX(-50%);
}
.sell-ladder-rung {
  position: absolute;
  top: -1px;
  transform: translateX(-50%);
  width: 2px;
  height: 8px;
  background: var(--green);
  border-radius: 1px;
}
/* The resting order right now — the one that actually fires next — gets its own bigger, glowing
   marker instead of just a longer label, so it reads as "this one" at a glance rather than
   fighting for space inside the text. */
.sell-ladder-rung.next {
  width: 3px;
  height: 12px;
  top: -3px;
  background: var(--accent-2);
  box-shadow: 0 0 8px rgba(122, 168, 255, 0.7);
}
.sell-ladder-rung.next .sell-ladder-next-badge {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-2);
  color: #0a0d13;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}
.sell-ladder-rung .sell-ladder-label {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  line-height: 1.35;
  white-space: nowrap;
  color: var(--muted);
  text-align: center;
}
/* Two fixed rows (not alternating up/down off the same anchor — that fought CSS's auto-height
   resolution and every label ended up at the same spot) so adjacent close-together rungs never
   collide, regardless of how tightly sellRisePercentage packs them. */
.sell-ladder-rung.row-b .sell-ladder-label { top: 46px; }
.sell-ladder-rung .sell-ladder-label b { display: block; color: var(--green); font-size: 11px; }
.sell-ladder-rung.next .sell-ladder-label b { color: var(--accent-2); }
.sell-ladder-context {
  font-size: 11px;
  color: var(--muted);
  margin: -6px 0 16px;
}
.sell-ladder-context b { color: var(--text); font-weight: 600; }
.sell-ladder-legend {
  display: flex;
  gap: 14px;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}
.sell-ladder-legend span { display: inline-flex; align-items: center; gap: 4px; }
.sell-ladder-legend .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

@keyframes sellLadderPulse {
  0% { opacity: 0.9; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.6); }
}

/* Manual trading ladder — tab strip to switch between open positions, a big flashing price, and
   a two-column grid of one-click limit-order buttons (buy below current price, sell above). */
.ladder-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 16px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.ladder-tab.active { background: var(--accent); color: white; border-color: var(--accent); }
.ladder-tab-pl { font-size: 11px; font-weight: 700; }
.ladder-tab-pl.pos { color: var(--green); }
.ladder-tab-pl.neg { color: var(--red); }
/* Inside the active (highlighted) tab, a colored P&L figure is hard to read against the accent
   background — fall back to a translucent white instead of green/red there. */
.ladder-tab.active .ladder-tab-pl { color: rgba(255, 255, 255, 0.85); }

.ladder-summary {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  min-width: 220px;
}
.ladder-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  padding: 2px 0;
}
.ladder-summary-row span:first-child { color: var(--muted); }
.ladder-summary-prices {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}
.ladder-summary-prices span {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 11px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
}

.ladder-price-block {
  text-align: center;
  padding: 18px 0 22px;
}
.ladder-price-symbol { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.ladder-price-value {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 40px;
  font-weight: 700;
  display: inline-block;
  padding: 4px 18px;
  border-radius: 10px;
  transition: background-color 0.15s, color 0.15s;
}
.ladder-price-value.flash-up { background: rgba(53, 192, 122, 0.22); color: var(--green); }
.ladder-price-value.flash-down { background: rgba(239, 87, 98, 0.22); color: var(--red); }

.ladder-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.ladder-column-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}
.ladder-column-title.buy { color: var(--green); }
.ladder-column-title.sell { color: var(--red); }
.ladder-buttons { display: flex; flex-direction: column; gap: 5px; }
.ladder-buttons button {
  width: 100%;
  padding: 8px 10px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  position: relative;
}
.ladder-buttons button.buy { background: rgba(53, 192, 122, 0.14); color: var(--green); border: 1px solid rgba(53, 192, 122, 0.35); }
.ladder-buttons button.buy:hover { background: rgba(53, 192, 122, 0.28); }
.ladder-buttons button.sell { background: rgba(239, 87, 98, 0.14); color: var(--red); border: 1px solid rgba(239, 87, 98, 0.35); }
.ladder-buttons button.sell:hover { background: rgba(239, 87, 98, 0.28); }
.ladder-buttons button .ladder-btn-count {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
}

.ladder-open-orders { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.ladder-open-orders h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 8px; }
.ladder-order-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--panel-2);
  margin-bottom: 5px;
}
.ladder-order-row .tag {
  font-size: 10px;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  margin-right: 8px;
}
.ladder-order-row .tag.buy { background: rgba(53, 192, 122, 0.18); color: var(--green); }
.ladder-order-row .tag.sell { background: rgba(239, 87, 98, 0.18); color: var(--red); }
.ladder-order-row .tag.manual { background: rgba(79, 140, 255, 0.18); color: var(--accent-2); margin-right: 4px; }
.ladder-order-row .time { color: var(--muted); font-size: 10px; margin-left: 6px; }
.ladder-order-row button { padding: 2px 8px; font-size: 11px; }
/* Manual clicks get a distinct left border + tint on the whole row, not just the small tag —
   easier to spot at a glance among a long list of automatic rungs. */
.ladder-order-row.manual { background: rgba(79, 140, 255, 0.1); border-left: 3px solid var(--accent-2); padding-left: 7px; }

/* History — one compact card per campaign, collapsed by default. A campaign that scaled in/out
   over dozens of rungs used to mean dozens of near-empty table rows on screen at once; now that
   detail only shows up once you actually ask for it by clicking. */
.history-item {
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}
.history-item.closed.profit { border-left-color: var(--green); }
.history-item.closed.loss { border-left-color: var(--red); }
.history-item.is-open { border-left-color: var(--accent-2); }

.history-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  cursor: pointer;
  background: var(--panel-2);
  user-select: none;
}
.history-item-header:hover { background: var(--panel); }
.history-item-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.history-item-symbol { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 9px; }
.history-item-meta { font-size: 12px; color: var(--muted); }
.history-item-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.history-item-profit { font-size: 19px; font-weight: 700; font-family: "SF Mono", Consolas, monospace; white-space: nowrap; }
.history-item-chevron { color: var(--muted); font-size: 13px; transition: transform 0.15s; display: inline-block; }
.history-item.expanded .history-item-chevron { transform: rotate(180deg); }

.history-entries { display: none; padding: 6px 18px 14px; background: var(--panel-2); }
.history-item.expanded .history-entries { display: block; }
.history-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
}
.history-entry:nth-child(odd) { background: var(--panel); }
.history-entry .tag { font-size: 10px; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; flex-shrink: 0; }
.history-entry .tag.buy { background: rgba(53, 192, 122, 0.18); color: var(--green); }
.history-entry .tag.sell { background: rgba(239, 87, 98, 0.18); color: var(--red); }
.history-entry-time { color: var(--muted); font-size: 11px; width: 130px; flex-shrink: 0; }
.history-entry-detail { flex: 1; color: var(--text); }
.history-entry-profit { font-weight: 600; text-align: right; width: 90px; flex-shrink: 0; }
