:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --card: #1a1d24;
  --text: #e8e8ea;
  --muted: #9a9ea8;
  --accent: #3d8bfd;
  --green: #3ecf6d;
  --red: #ef4444;
  --warn: #f59e0b;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1a1d24;
    --muted: #6b7280;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#auth-screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 32px;
}

/* Flex-column layout instead of `position: fixed` for the bottom nav — some
   Telegram in-app WebViews mishandle fixed positioning during scroll (the bar
   drifted with the page instead of staying pinned), confirmed live 2026-09-14.
   A flex container filling the viewport with an internally-scrolling content
   area keeps the nav truly pinned regardless of WebView quirks. */
#main-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

.screen-content {
  flex: 1;
  min-height: 0; /* flexbox gotcha: without this the item refuses to shrink
    below its content's natural height, so it grows past 100dvh and the WHOLE
    page (nav included) scrolls instead of just this pane — confirmed live
    2026-09-14, the bottom nav "didn't move at all" was this, not a WebView bug. */
  overflow-y: auto;
  padding: 16px;
}

#auth-screen h2 { text-align: center; }

input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--muted);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 10px;
}

button {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}

button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--muted); }
button#token-save { background: var(--accent); color: white; }
button.warn { background: var(--warn); color: #1a1d24; }
button.danger { background: var(--red); color: white; }
button.accent { background: var(--accent); color: white; }
button.success { background: var(--green); color: #0f1115; }

.error { color: var(--red); min-height: 18px; font-size: 13px; }

.tabs {
  flex-shrink: 0;
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 8px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid rgba(154,158,168,0.2);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 4px 2px;
  margin-bottom: 0;
  font-size: 11px;
  font-weight: 500;
}
.tab-icon { font-size: 22px; line-height: 1; }
.tab-label { line-height: 1; }
.tab-btn.active { color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* "Сегодня" is the number people actually open this app to check — it gets
   the hero treatment (bigger, its own row) instead of matching the other
   three periods 1-for-1, per the app's real content hierarchy rather than a
   uniform SaaS-card grid. */
.hero-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border-radius: 16px;
  border: 2px solid transparent;
  padding: 18px;
  margin-bottom: 14px;
  cursor: pointer;
}
.hero-card.active { border-color: var(--accent); }
.hero-value { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hero-value.positive { color: var(--green); }
.hero-value.negative { color: var(--red); }

.cards { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; margin-bottom: 16px; }
.card {
  flex: 1 1 calc(33.333% - 7px);
  min-width: 110px;
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
}
button.card {
  text-align: left;
  border: 2px solid transparent;
  margin-bottom: 0;
  cursor: pointer;
}
button.card.active { border-color: var(--accent); }
.card-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.card-value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }

.danger-row { display: flex; gap: 8px; }
.danger-row button { flex: 1; }

.bot-row {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.bot-row-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.bot-ticker { font-weight: 700; }
.bot-status { font-size: 12px; padding: 2px 8px; border-radius: 8px; }
.bot-status.run { background: rgba(62,207,109,0.15); color: var(--green); }
.bot-status.paused { background: rgba(245,158,11,0.15); color: var(--warn); }
.bot-status.stopped { background: rgba(154,158,168,0.15); color: var(--muted); }
.bot-status.error { background: rgba(239,68,68,0.15); color: var(--red); }
.bot-error { font-size: 12px; color: var(--red); margin-bottom: 8px; }
.bot-actions { display: flex; gap: 6px; }
.bot-actions button { margin-bottom: 0; padding: 8px; font-size: 13px; }

#pnl-chart { width: 100%; margin-bottom: 12px; }

.candidates-updated { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.candidate-row {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.candidate-symbol { font-weight: 700; }
.candidate-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }
.candidate-mult { font-size: 16px; font-weight: 700; color: var(--warn); }
.candidates-empty { color: var(--muted); text-align: center; padding: 24px 0; }
