/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --bg2:      #161b22;
  --bg3:      #21262d;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --primary:  #238636;
  --primary-h:#2ea043;
  --danger:   #da3633;
  --danger-h: #f85149;
  --cyan:     #58a6ff;
  --green:    #3fb950;
  --red:      #f85149;
  --yellow:   #e3b341;
  --radius:   8px;
  --font:     'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono:     'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 100%; max-width: 420px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px 36px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 24px; font-weight: 700; margin-top: 8px; }
.login-logo .logo-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.logo-icon { font-size: 40px; }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 18px; font-size: 13px; }
.alert-error { background: rgba(248,81,73,.12); border: 1px solid rgba(248,81,73,.4); color: var(--red); }
.field { margin-bottom: 20px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select { width: 100%; padding: 10px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; font-family: var(--mono); outline: none; }
.field input:focus, .field select:focus { border-color: var(--cyan); }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.login-footer { margin-top: 24px; text-align: center; font-size: 12px; color: var(--muted); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 18px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; font-family: var(--font); transition: opacity .15s, background .15s; }
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-success  { background: #1a7f37; color: #fff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-h); }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg3); }
.btn-cyan { background: transparent; border: 1px solid var(--cyan); color: var(--cyan); }
.btn-cyan:hover { background: rgba(88,166,255,.1); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-launch { background: linear-gradient(135deg, #1f6feb, #238636); color: #fff; padding: 12px 32px; font-size: 15px; border-radius: 8px; }
.btn-launch:hover { opacity: .9; }

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 0 24px; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-center { display: flex; align-items: center; gap: 8px; }
.addr-label { color: var(--muted); font-size: 12px; }
.addr-value { font-family: var(--mono); font-size: 12px; color: var(--cyan); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.conn-dot.connected { background: var(--green); }
.conn-dot.error { background: var(--red); }

.topbar-bots { display: flex; gap: 6px; margin-left: 16px; }
.tb-bot {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); cursor: pointer; transition: all .2s;
  user-select: none;
}
.tb-bot.stopped { background: var(--bg3); color: var(--muted); }
.tb-bot.stopped .tb-dot { background: var(--muted); }
.tb-bot.running { background: rgba(63,185,80,.12); border-color: var(--green); color: var(--green); }
.tb-bot.running .tb-dot { background: var(--green); animation: pulse 1.5s infinite; }
.tb-bot.running:hover { background: rgba(63,185,80,.22); }
.tb-bot.stopped:hover { background: var(--bg); color: var(--text); }
.tb-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }

/* ── Dashboard body ────────────────────────────────────────────────────── */
.dashboard-body { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Running bot banner ────────────────────────────────────────────────── */
.running-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; background: rgba(63,185,80,.08);
  border-bottom: 1px solid rgba(63,185,80,.3);
}
.rb-left  { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.rb-right { display: flex; gap: 8px; }
.rb-dot   { width: 10px; height: 10px; border-radius: 50%; background: var(--green); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ═══════════════════════════════════════════════════════════════════════
   WIZARD
══════════════════════════════════════════════════════════════════════ */
.wizard-wrap { max-width: 900px; margin: 40px auto; padding: 0 20px; }

/* Progress bar */
.wizard-progress { display: flex; align-items: center; margin-bottom: 40px; }
.progress-step { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.progress-step span { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.progress-step.active { color: var(--text); }
.progress-step.active span { border-color: var(--cyan); color: var(--cyan); }
.progress-step.done span { background: var(--green); border-color: var(--green); color: #000; }
.progress-step.done { color: var(--green); }
.progress-line { flex: 1; height: 2px; background: var(--border); margin: 0 12px; }

/* Step */
.wizard-step { display: none; }
.wizard-step.active { display: block; }
.step-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.step-sub { color: var(--muted); margin-bottom: 28px; }

/* Bot choice cards */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
@media(max-width: 640px) { .choice-grid { grid-template-columns: 1fr; } }

.choice-card { background: var(--bg2); border: 2px solid var(--border); border-radius: var(--radius); padding: 24px; cursor: pointer; transition: border-color .2s, background .2s; }
.choice-card:hover { border-color: var(--cyan); background: rgba(88,166,255,.05); }
.choice-icon { font-size: 36px; margin-bottom: 12px; }
.choice-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.choice-card p { color: var(--muted); font-size: 13px; margin-bottom: 12px; line-height: 1.6; }
.choice-bullets { list-style: none; padding: 0; margin-bottom: 16px; }
.choice-bullets li { font-size: 12px; color: var(--muted); padding: 3px 0; }
.choice-bullets li::before { content: "✓ "; color: var(--green); }
.choice-btn { font-size: 13px; font-weight: 700; color: var(--cyan); }

/* Amount step */
.amount-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; }
.balance-display { display: flex; align-items: baseline; gap: 10px; margin-bottom: 20px; }
.bal-big { font-size: 36px; font-weight: 700; font-family: var(--mono); color: var(--cyan); }
.bal-big-label { font-size: 14px; color: var(--muted); }
.amount-pair-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media(max-width: 500px) { .amount-pair-row { grid-template-columns: 1fr; } }
.amount-field { display: flex; flex-direction: column; gap: 6px; }
.amount-field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.amount-field input, .amount-field select { padding: 10px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 15px; font-family: var(--mono); outline: none; }
.amount-field input:focus, .amount-field select:focus { border-color: var(--cyan); }

/* Risk cards */
.risk-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 24px; }
@media(max-width: 700px) { .risk-grid { grid-template-columns: 1fr; } }
.risk-card { background: var(--bg2); border: 2px solid var(--border); border-radius: var(--radius); padding: 20px; cursor: pointer; transition: border-color .2s; }
.risk-card:hover { border-color: var(--muted); }
.risk-card.selected { border-color: var(--cyan); background: rgba(88,166,255,.06); }
.risk-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; margin-bottom: 10px; }
.risk-badge.low  { background: rgba(63,185,80,.15);  color: var(--green);  border: 1px solid var(--green); }
.risk-badge.med  { background: rgba(227,179,65,.15); color: var(--yellow); border: 1px solid var(--yellow); }
.risk-badge.high { background: rgba(248,81,73,.15);  color: var(--red);    border: 1px solid var(--red); }
.risk-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.risk-card p { font-size: 12px; color: var(--muted); margin-bottom: 14px; line-height: 1.6; }
.rp-row { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 0; border-top: 1px solid var(--border); }
.rp-row span { color: var(--muted); }
.rp-row b { color: var(--text); font-family: var(--mono); }

/* Preview */
.preview-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; }

/* Backtest step */
.backtest-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; }
.bt-summary { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }
.bt-summary b { color: var(--fg); }
.bt-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
.bt-table th { text-align: left; padding: 7px 10px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.bt-table td { padding: 9px 10px; border-bottom: 1px solid rgba(48,54,61,.5); font-family: var(--mono); cursor: pointer; }
.bt-row:hover { background: rgba(88,166,255,.05); }
.bt-row.bt-selected { background: rgba(88,166,255,.10); outline: 1px solid var(--cyan); }
.bt-rec-badge { background: rgba(63,185,80,.15); color: #3fb950; border: 1px solid rgba(63,185,80,.3); border-radius: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; font-family: var(--sans); white-space: nowrap; }
.bt-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.bt-hint b { color: var(--fg); }
.preview-loading { color: var(--muted); text-align: center; padding: 20px; }
.preview-header { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.ph-item { display: flex; flex-direction: column; gap: 3px; }
.ph-item span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.ph-item b { font-size: 15px; font-family: var(--mono); }
.preview-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 13px; }
.preview-table th { text-align: left; padding: 6px 10px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
.preview-table td { padding: 8px 10px; border-bottom: 1px solid rgba(48,54,61,.5); font-family: var(--mono); }
.preview-table tr.total-row td { border-top: 1px solid var(--border); color: var(--cyan); }
.preview-note { font-size: 12px; color: var(--muted); line-height: 1.6; padding: 10px; background: var(--bg3); border-radius: 6px; }

.swap-box { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.swap-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid rgba(48,54,61,.5); font-size: 13px; }
.swap-row:last-child { border-bottom: none; }
.swap-row span { color: var(--muted); }
.swap-action b { color: var(--yellow); }
.swap-ok b { color: var(--green); }
.swap-note { font-size: 12px; color: var(--muted); margin-top: 10px; padding: 8px; background: rgba(227,179,65,.08); border: 1px solid rgba(227,179,65,.25); border-radius: 6px; }

/* Wizard nav */
.wizard-nav { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; }

/* ═══════════════════════════════════════════════════════════════════════
   LIVE DASHBOARD
══════════════════════════════════════════════════════════════════════ */
.live-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: var(--bg2); border-bottom: 1px solid var(--border); }
.live-title { font-size: 18px; font-weight: 700; }
.live-controls { display: flex; align-items: center; gap: 10px; }

.status-badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.status-badge.running { background: rgba(63,185,80,.15); border-color: var(--green); color: var(--green); }

/* Pair panel */
.pair-panel { padding: 16px 24px; border-bottom: 1px solid var(--border); }
.pair-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pair-label  { font-size: 16px; font-weight: 700; }
.pair-price  { font-family: var(--mono); font-size: 20px; font-weight: 700; }
.pair-meta   { display: flex; gap: 18px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.pair-meta span b { color: var(--text); }
.trend-bullish { color: var(--green); }
.trend-bearish { color: var(--red); }
.trend-neutral { color: var(--yellow); }

/* Orders table */
.orders-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 8px; }
.orders-table th { text-align: left; padding: 4px 8px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.orders-table td { padding: 5px 8px; border-bottom: 1px solid rgba(48,54,61,.5); font-family: var(--mono); }
.cell-open   { color: var(--green); font-weight: 700; }
.cell-filled { color: var(--cyan);  font-weight: 700; }
.cell-wait   { color: var(--muted); }
.cell-sell   { color: var(--red);   font-weight: 700; }
.cell-buy    { color: var(--green); font-weight: 700; }

.balance-row { display: flex; gap: 24px; padding: 8px 0; font-size: 13px; }
.bal-item    { display: flex; align-items: center; gap: 6px; }
.bal-label   { color: var(--muted); }
.bal-val     { font-family: var(--mono); font-weight: 700; }
.bal-diff    { font-family: var(--mono); font-size: 11px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* Grid stats */
.grid-stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 1px; background: var(--border); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stat-box { background: var(--bg2); padding: 14px 20px; }
.stat-label { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.stat-value { font-size: 20px; font-weight: 700; font-family: var(--mono); }
.compound-box { background: rgba(88,166,255,.05); }
.compound-val { color: var(--cyan); }

/* Grid tab bar */
.grid-tab-bar { display: flex; border-bottom: 1px solid var(--border); background: var(--bg2); padding: 0 16px; gap: 4px; }
.grid-tab { background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); font-size: 13px; font-weight: 600; padding: 10px 16px; cursor: pointer; transition: color .15s, border-color .15s; }
.grid-tab:hover { color: var(--fg); }
.grid-tab.active { color: var(--fg); border-bottom-color: var(--cyan); }

/* Grid panel stats row (inside tab content) */
.grid-panel-stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.grid-panel-footer { padding: 10px 24px 16px; }

/* Grid table */
.grid-table-wrap { padding: 12px 24px; overflow-x: auto; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.grid-table th { text-align: left; padding: 6px 8px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
.grid-table td { padding: 5px 8px; border-bottom: 1px solid rgba(48,54,61,.4); font-family: var(--mono); white-space: nowrap; }
.grid-table tr.near-price { background: rgba(88,166,255,.07); }
.gain-pos { color: var(--cyan); font-weight: 700; }

/* Log */
.log-box { padding: 12px 24px 16px; }
.log-title { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.log-lines { font-family: var(--mono); font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; max-height: 130px; overflow-y: auto; }
.log-empty { color: var(--border); }
.log-line  { line-height: 1.4; }

/* ── Grid Bot Summary Card ───────────────────────────────────────────────── */
.grid-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 16px 24px;
  overflow: hidden;
}

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

.grid-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.grid-mode-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(88,166,255,.15);
  color: var(--cyan);
  border: 1px solid var(--cyan);
  white-space: nowrap;
}

.pnl-hero {
  text-align: center;
  padding: 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.pnl-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.pnl-amount {
  font-size: 42px;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--green);
  margin: 0;
}

.pnl-percent {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
  font-family: var(--mono);
}

.grid-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

@media (max-width: 1200px) {
  .grid-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

.grid-stat {
  background: var(--bg2);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.grid-stat-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.grid-stat-value {
  font-size: 15px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text);
}

.grid-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.compound-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compound-toggle-input {
  appearance: none;
  width: 44px;
  height: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  outline: none;
}

.compound-toggle-input:checked {
  background: var(--green);
}

.compound-toggle-input::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.2s;
}

.compound-toggle-input:checked::after {
  left: 22px;
}

.compound-toggle-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.withdraw-btn {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.grid-detail-section {
  border-bottom: 1px solid var(--border);
}

.grid-detail-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  background: var(--bg2);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.grid-detail-toggle:hover {
  background: var(--bg3);
}

.grid-detail-arrow {
  display: inline-block;
  transition: transform 0.2s;
}

.grid-detail-arrow.open {
  transform: rotate(90deg);
}

.grid-detail-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.grid-detail-content.open {
  max-height: 1000px;
  transition: max-height 0.3s ease-in;
}

.grid-detail-content .grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.grid-detail-content .grid-table th {
  text-align: left;
  padding: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.grid-detail-content .grid-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(48,54,61,.4);
  font-family: var(--mono);
  white-space: nowrap;
}

.grid-detail-content .grid-table tr.near-price {
  background: rgba(88,166,255,.07);
}

.grid-detail-content .gain-pos {
  color: var(--cyan);
  font-weight: 700;
}
