/* ── Telegram theme variables (injected by client) ──────── */
:root {
  --bg:         var(--tg-theme-bg-color,          #18222d);
  --bg2:        var(--tg-theme-secondary-bg-color, #1e2c3a);
  --fg:         var(--tg-theme-text-color,         #e8edf2);
  --fg-hint:    var(--tg-theme-hint-color,         #8899a6);
  --accent:     var(--tg-theme-button-color,       #2b95d6);
  --accent-fg:  var(--tg-theme-button-text-color,  #ffffff);
  --link:       var(--tg-theme-link-color,         #5db8f5);
  --danger:     #e05252;
  --success:    #4caf7d;
  --warn:       #e8a838;
  --radius:     12px;
  --nav-h:      64px;
  --top-h:      52px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--top-h);
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--fg);
}
.topbar-status {
  font-size: 20px;
  transition: color .3s;
}
.topbar-status.idle     { color: var(--fg-hint); }
.topbar-status.scanning { color: var(--warn);    animation: pulse 1s infinite; }
.topbar-status.paused   { color: var(--danger);  }
.topbar-status.ok       { color: var(--success); }

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

/* ── Screens ─────────────────────────────────────────────── */
main {
  position: fixed;
  top: var(--top-h);
  bottom: var(--nav-h);
  left: 0; right: 0;
  overflow-y: auto;
  padding: 16px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.screen { display: none; }
.screen.active { display: block; }

/* ── Section titles ──────────────────────────────────────── */
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-hint);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ── Cards ───────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
}
.card-wide { grid-column: span 2; }
.card-label { font-size: 12px; color: var(--fg-hint); margin-bottom: 4px; }
.card-value { font-size: 22px; font-weight: 700; }
.card-value.small { font-size: 14px; font-weight: 500; }
.card-sub   { font-size: 13px; margin-top: 2px; }
.positive   { color: var(--success); }
.negative   { color: var(--danger); }

/* ── Status row ──────────────────────────────────────────── */
.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.status-chip {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg2);
}
.status-chip.idle     { color: var(--fg-hint); }
.status-chip.scanning { color: var(--warn);    background: rgba(232,168,56,.15); }
.status-chip.paused   { color: var(--danger);  background: rgba(224,82,82,.15);  }
.status-chip.ok       { color: var(--success); background: rgba(76,175,125,.15); }
.muted-label { font-size: 13px; color: var(--fg-hint); }

/* ── Action row ──────────────────────────────────────────── */
.action-row { display: flex; gap: 10px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .75; transform: scale(.97); }
.btn.full-width { width: 100%; margin-top: 8px; }
.btn-primary   { background: var(--accent);  color: var(--accent-fg); }
.btn-secondary { background: var(--bg2);     color: var(--fg);        }
.btn-danger    { background: var(--danger);  color: #fff;              }
.btn-sm        { padding: 6px 14px; font-size: 13px; }

/* ── Position list ───────────────────────────────────────── */
.pos-list { display: flex; flex-direction: column; gap: 10px; }

.pos-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
}
.pos-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.pos-sym {
  font-size: 16px;
  font-weight: 700;
}
.pos-dir {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}
.pos-dir.long  { background: rgba(76,175,125,.2); color: var(--success); }
.pos-dir.short { background: rgba(224,82,82,.2);  color: var(--danger);  }

.pos-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--fg-hint);
  margin-top: 3px;
}
.pos-row span:last-child { color: var(--fg); font-weight: 500; }

.pos-pnl {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pnl-val {
  font-size: 18px;
  font-weight: 700;
}

/* ── Signal card ─────────────────────────────────────────── */
.sig-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
}
.sig-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sig-rank { font-size: 12px; color: var(--fg-hint); }
.sig-scores { font-size: 12px; color: var(--fg-hint); margin-top: 6px; }
.sig-reasons { margin-top: 8px; }
.sig-reason-item {
  font-size: 12px;
  color: var(--fg-hint);
  padding: 2px 0;
}
.sig-trade {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.sig-trade-row { font-size: 12px; color: var(--fg-hint); }
.sig-trade-row span { color: var(--fg); }
.sig-actions { display: flex; gap: 8px; margin-top: 10px; }

.news-chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 600;
}
.news-low    { background: rgba(76,175,125,.2);  color: var(--success); }
.news-medium { background: rgba(232,168,56,.2);  color: var(--warn);    }
.news-high   { background: rgba(224,82,82,.2);   color: var(--danger);  }

/* ── Stat grid ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat-item {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-label { font-size: 12px; color: var(--fg-hint); margin-bottom: 4px; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-item.wide { grid-column: span 2; }

/* ── Chart ───────────────────────────────────────────────── */
.chart-wrap {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-wrap canvas { max-height: 168px; }

/* ── Settings form ───────────────────────────────────────── */
.settings-form { display: flex; flex-direction: column; gap: 14px; }
.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
}
.settings-form select,
.settings-form input {
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.settings-form select:focus,
.settings-form input:focus {
  border-color: var(--accent);
}

/* ── Balance row ─────────────────────────────────────────── */
.balance-row {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.balance-val { font-size: 20px; font-weight: 700; }

/* ── About ───────────────────────────────────────────────── */
.about-text {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 14px;
  line-height: 1.7;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--fg-hint);
  padding: 32px 0;
  font-size: 14px;
}

/* ── Bottom nav ──────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg2);
  display: flex;
  border-top: 1px solid rgba(255,255,255,.07);
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--fg-hint);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn .nav-icon { font-size: 20px; line-height: 1; }
.nav-btn.active { color: var(--accent); }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30,44,58,.96);
  border: 1px solid rgba(255,255,255,.12);
  color: var(--fg);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  white-space: nowrap;
  transition: opacity .25s;
  backdrop-filter: blur(8px);
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  z-index: 50;
  backdrop-filter: blur(4px);
  padding-bottom: env(safe-area-inset-bottom);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 28px;
  width: 100%;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-sub   { font-size: 14px; color: var(--fg-hint); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
