/* ── design tokens ────────────────────────────────────────────────────── */
:root {
  --bg: #0A0A0F;
  --bg-elevated: #0F0F16;
  --surface: #13131A;
  --surface-2: #191922;
  --border: #23232E;
  --border-soft: #1A1A22;

  --text: #F2F2F7;
  --text-dim: #8A8A9E;
  --text-faint: #55556A;

  --accent: #7C5CFF;
  --accent-soft: rgba(124, 92, 255, 0.14);
  --accent-glow: rgba(124, 92, 255, 0.35);

  --pos: #00E5A0;
  --pos-soft: rgba(0, 229, 160, 0.12);
  --pos-glow: rgba(0, 229, 160, 0.45);

  --neg: #FF4D6D;
  --neg-soft: rgba(255, 77, 109, 0.12);
  --neg-glow: rgba(255, 77, 109, 0.45);

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
  --topbar-h: 52px;
}

/* Light-theme fallback: still dark by design intent (crypto-native), but
   respect a Telegram-forced light theme by lifting surfaces slightly. */
:root[data-theme="light"] {
  --bg: #101014;
  --surface: #17171F;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(ellipse 800px 400px at 15% -10%, rgba(124, 92, 255, 0.10), transparent 60%),
    radial-gradient(ellipse 600px 400px at 100% 0%, rgba(0, 229, 160, 0.05), transparent 55%);
  background-attachment: fixed;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── topbar ────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 10, 15, 0.72);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-mark {
  color: var(--accent);
  font-size: 16px;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

.mode-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.mode-chip.live {
  color: var(--pos);
  border-color: rgba(0, 229, 160, 0.3);
  background: var(--pos-soft);
}
.mode-chip.dry {
  color: #FFB74D;
  border-color: rgba(255, 183, 77, 0.3);
  background: rgba(255, 183, 77, 0.1);
}

/* ── tabbar (bottom nav) ───────────────────────────────────────────────── */
.tabbar {
  height: var(--tabbar-h);
  display: flex;
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(10, 10, 15, 0.82);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-top: 1px solid var(--border-soft);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease;
}
.tab-icon { font-size: 17px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ── content shell ─────────────────────────────────────────────────────── */
#content {
  flex: 1;
  padding: 14px 14px 20px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* ── cards ─────────────────────────────────────────────────────────────── */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 12px 0;
}

/* ── hero balance card ─────────────────────────────────────────────────── */
.hero-card {
  background: radial-gradient(ellipse 400px 200px at 0% 0%, var(--accent-soft), transparent 70%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
}
.hero-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  margin-bottom: 6px;
}
.hero-value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.hero-value .unit {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
  font-family: var(--font-body);
}
.hero-sub {
  display: flex;
  gap: 18px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.hero-sub-item .k {
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}
.hero-sub-item .v {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
}

.sparkline-wrap {
  margin-top: 14px;
  height: 44px;
}
.sparkline-wrap svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ── stat grid ─────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
}
.stat-tile .k {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.stat-tile .v {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.stat-tile .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 3px;
}

.pos { color: var(--pos); text-shadow: 0 0 12px var(--pos-glow); }
.neg { color: var(--neg); text-shadow: 0 0 12px var(--neg-glow); }
.neutral { color: var(--text); }

/* ── rows / lists ──────────────────────────────────────────────────────── */
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
}
.row:last-child { border-bottom: none; }
.row .label { color: var(--text-dim); }
.row .value { font-family: var(--font-mono); font-weight: 500; }

/* ── strategy chips row ────────────────────────────────────────────────── */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.chip {
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 100px;
  background: var(--pos-soft);
  color: var(--pos);
  border: 1px solid rgba(0, 229, 160, 0.25);
}
.chip.empty {
  background: transparent;
  color: var(--text-faint);
  border: 1px dashed var(--border);
}

/* ── strategy toggle rows ─────────────────────────────────────────────── */
.strategy-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
}
.strategy-row:last-child { border-bottom: none; }

.strategy-name-block { display: flex; align-items: center; gap: 9px; }
.strategy-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.strategy-dot.on {
  background: var(--pos);
  box-shadow: 0 0 8px var(--pos-glow);
}
.strategy-name { font-size: 14px; font-weight: 500; }
.strategy-status { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

button.toggle-btn {
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent-soft);
  color: var(--accent);
  transition: transform 0.1s ease, opacity 0.15s ease;
}
button.toggle-btn:active { transform: scale(0.96); }
button.toggle-btn:disabled { opacity: 0.5; }
button.toggle-btn.stop {
  border-color: var(--neg);
  background: var(--neg-soft);
  color: var(--neg);
}

/* ── settings ──────────────────────────────────────────────────────────── */
.settings-group-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 18px 0 8px 0;
}
.settings-group-title:first-child { margin-top: 0; }

.settings-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  gap: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.settings-field:last-child { border-bottom: none; }
.settings-field label {
  font-size: 13px;
  color: var(--text-dim);
  flex: 1;
  line-height: 1.3;
}
.settings-field input {
  width: 108px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
  transition: border-color 0.15s ease;
}
.settings-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.save-btn {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  margin-top: 16px;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.save-btn:active { transform: scale(0.98); }
.save-btn:disabled { opacity: 0.6; box-shadow: none; }

/* ── history / trades ──────────────────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 13px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
}
.filter-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.trade-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  gap: 10px;
}
.trade-item:last-child { border-bottom: none; }
.trade-left { min-width: 0; flex: 1; }
.trade-question {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trade-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 3px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.trade-strategy-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.trade-right { text-align: right; flex-shrink: 0; }
.trade-pnl {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
}
.trade-price {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

/* ── chart canvas ──────────────────────────────────────────────────────── */
.chart-wrap { height: 160px; margin-top: 4px; }
.chart-wrap svg { width: 100%; height: 100%; display: block; overflow: visible; }

.bar-chart-wrap { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .bar-label {
  width: 84px; flex-shrink: 0;
  font-size: 12px; color: var(--text-dim);
}
.bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
}
.bar-fill.pos-fill { background: linear-gradient(90deg, var(--pos), rgba(0,229,160,0.6)); }
.bar-fill.neg-fill { background: linear-gradient(90deg, var(--neg), rgba(255,77,109,0.6)); }
.bar-row .bar-val {
  font-family: var(--font-mono);
  font-size: 12px;
  width: 62px;
  text-align: right;
  flex-shrink: 0;
}

/* ── profile ───────────────────────────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}
.profile-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #4A2FD8);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.profile-name { font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.profile-username { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }

/* ── toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  max-width: 88%;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── empty / loading / error states ───────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 36px 16px;
  font-size: 13.5px;
}
.empty-state .icon { font-size: 26px; display: block; margin-bottom: 8px; opacity: 0.5; }

.spinner-wrap { display: flex; justify-content: center; padding: 48px 0; }
.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  text-align: center;
  color: var(--neg);
  padding: 24px 16px;
  font-size: 13.5px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
