/* ── Balance bar ── */
.balance-bar {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,.06);
  gap: 0;
}
.balance-item {
  flex: 1;
  text-align: center;
}
.balance-lbl {
  font-size: 10px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 2px;
}
.balance-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.balance-divider {
  width: 1px;
  height: 28px;
  background: rgba(255,255,255,.08);
  flex-shrink: 0;
}
.balance-refresh {
  background: none;
  border: none;
  color: var(--hint);
  font-size: 18px;
  cursor: pointer;
  padding: 0 0 0 12px;
  line-height: 1;
  transition: color .2s;
  flex-shrink: 0;
}
.balance-refresh:active { color: var(--accent); }

/* ── Bot status bar ── */
.bot-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2, #27272a);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.bot-status-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bot-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--hint, #71717a);
  transition: background .3s;
  flex-shrink: 0;
}
.bot-status-dot.running { background: var(--green, #22c55e); box-shadow: 0 0 6px rgba(34,197,94,.5); }
.bot-status-dot.stopped { background: var(--red, #ef4444); }

.bot-status-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #fafafa);
}

.bot-toggle-btn {
  padding: 6px 18px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  min-width: 80px;
}
.bot-toggle-btn.start {
  background: rgba(34,197,94,.15);
  color: var(--green, #22c55e);
  border: 1px solid rgba(34,197,94,.35);
}
.bot-toggle-btn.stop {
  background: rgba(239,68,68,.15);
  color: var(--red, #ef4444);
  border: 1px solid rgba(239,68,68,.35);
}

/* ── Danger button ── */
.btn-danger {
  width: 100%;
  padding: 14px;
  background: rgba(239,68,68,.12);
  color: var(--red, #ef4444);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius, 14px);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
  transition: background .15s;
}
.btn-danger:active { background: rgba(239,68,68,.22); }

:root {
  --bg: var(--tg-theme-bg-color, #18181b);
  --bg2: var(--tg-theme-secondary-bg-color, #27272a);
  --text: var(--tg-theme-text-color, #fafafa);
  --hint: var(--tg-theme-hint-color, #71717a);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --green: #22c55e;
  --red: #ef4444;
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 24px;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tab {
  flex: 1;
  padding: 14px 0;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color .2s;
}
.tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* ── Tab content ── */
.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* ── Card ── */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

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

/* ── Toggle ── */
.toggle { position: relative; display: inline-block; width: 48px; height: 28px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--hint);
  border-radius: 999px;
  transition: background .2s;
}
.slider:before {
  content: "";
  position: absolute;
  width: 22px; height: 22px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
input:checked + .slider { background: var(--green); }
input:checked + .slider:before { transform: translateX(20px); }

/* ── Segment control ── */
.seg-control {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 16px;
}
.seg {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--hint);
  font-size: 14px;
  cursor: pointer;
  transition: all .2s;
}
.seg.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ── Fields ── */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block;
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .5px;
}
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .2s;
}
input[type="number"]:focus { border-color: var(--accent); }

.field-hint {
  font-size: 11px;
  color: var(--hint);
  margin-top: 5px;
  line-height: 1.4;
}

.hidden { display: none !important; }

/* ── Button ── */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  margin-top: 4px;
}
.btn-primary:active { opacity: .8; }

.save-msg {
  text-align: center;
  color: var(--green);
  font-size: 14px;
  margin-top: 10px;
}

/* ── Trade card ── */
.trade-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}

.trade-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.trade-symbol { font-size: 16px; font-weight: 700; }
.trade-since  { font-size: 12px; color: var(--hint); }

.trade-pnl-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,.04);
  border-radius: 10px;
}
.trade-pnl-usd { font-size: 22px; font-weight: 800; }
.trade-pnl-pct { font-size: 14px; font-weight: 600; opacity: .85; }

.trade-grid4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.trade-field .lbl { font-size: 10px; color: var(--hint); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .4px; }
.trade-field .val { font-size: 13px; font-weight: 600; }

.trade-meta {
  font-size: 11px;
  color: var(--hint);
  margin-bottom: 12px;
}

.pnl-pos { color: var(--green); }
.pnl-neg { color: var(--red); }

.btn-close-trade {
  width: 100%;
  padding: 11px;
  background: rgba(239,68,68,.12);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-close-trade:active { background: rgba(239,68,68,.22); }

/* ── Stats bar ── */
.stats-bar {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.stat {}
.stat .lbl { font-size: 11px; color: var(--hint); margin-bottom: 4px; }
.stat .val { font-size: 16px; font-weight: 700; }

/* ── Status badge ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.badge-tp { background: rgba(34,197,94,.15); color: var(--green); }
.badge-sl { background: rgba(239,68,68,.15); color: var(--red); }
.badge-manual { background: rgba(113,113,122,.15); color: var(--hint); }

.empty {
  text-align: center;
  color: var(--hint);
  font-size: 15px;
  padding: 48px 0;
}

.label { font-size: 15px; font-weight: 500; }
