/* TradeBot Mini App — follows Telegram's theme (--tg-theme-* vars are set by telegram-web-app.js).
   Fallbacks below are used when opened outside Telegram. */

:root {
  --bg: var(--tg-theme-secondary-bg-color, #0e1116);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #171b22));
  --text: var(--tg-theme-text-color, #e9edf2);
  --hint: var(--tg-theme-hint-color, #8b95a3);
  --subtle: var(--tg-theme-subtitle-text-color, var(--hint));
  --section-header: var(--tg-theme-section-header-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #5ea8ff);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --separator: var(--tg-theme-section-separator-color, color-mix(in srgb, var(--hint) 22%, transparent));
  --up: #22b07d;
  --down: #e5484d;
  --warn: #e0a126;
  --up-soft: color-mix(in srgb, var(--up) 15%, transparent);
  --down-soft: color-mix(in srgb, var(--down) 15%, transparent);
  --warn-soft: color-mix(in srgb, var(--warn) 18%, transparent);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 16%), inset 0 0 0 1px color-mix(in srgb, var(--hint) 10%, transparent);
  --shadow-2: 0 12px 40px rgb(0 0 0 / 30%);
  --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --tabs-h: 58px;
  --rail-w: 0px;                  /* side navigation width (desktop only) */
  --content-w: 720px;             /* max width of the page content; grows on wide screens */
  --gutter: 12px;                 /* page side padding */
  --col-gap: 20px;
  --vh: var(--tg-viewport-height, 100vh);   /* Telegram's real viewport height (100vh is wrong in some clients) */
  color-scheme: light dark;
}
html[data-scheme="light"] { --up: #0f8a5f; --down: #d92d3a; --warn: #b07600;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 6%), inset 0 0 0 1px color-mix(in srgb, var(--hint) 10%, transparent);
  --shadow-2: 0 16px 48px rgb(0 0 0 / 22%); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- layout ---------------------------------------------------------------- */
#app { min-height: 100vh; min-height: var(--tg-viewport-stable-height, 100vh); }
.view { padding: 2px var(--gutter) calc(var(--tabs-h) + var(--safe-bottom) + 24px); outline: none; max-width: var(--content-w); margin: 0 auto;
  width: 100%; min-width: 0; }
.view > .block:first-child > .section-title,
.view > .cols:first-child > .col:first-child > .block:first-child > .section-title,
.view > .cols:first-child > .col:first-child > :is(.notice, .card):first-child { margin-top: 10px; }

/* Content blocks (a section title + its cards). Phones stack them in source order; see "wide screens" below. */
.block { min-width: 0; }
.block + .card, .block + .notice, .block + p { margin-top: 12px; }
.col { min-width: 0; }
.list-grid { min-width: 0; }
.filters .field.bare { padding: 6px 0 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid transparent; transition: padding .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.topbar-main { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "eq actions" "stats stats" "chips chips";
  align-items: center; gap: 8px 12px; max-width: calc(var(--content-w) - 2 * var(--gutter)); margin: 0 auto; }
.topbar-equity { grid-area: eq; min-width: 0; }
.topbar-label { font-size: 12px; color: var(--hint); font-weight: 600; letter-spacing: .02em; }
.topbar-updated { font-weight: 500; opacity: .85; }
.topbar-value { font-size: 30px; font-weight: 750; letter-spacing: -.025em; line-height: 1.1; transition: font-size .2s ease; }
.topbar-actions { grid-area: actions; display: flex; gap: 8px; align-self: start; }
.topbar-stats { grid-area: stats; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-pill { display: flex; flex-direction: column; gap: 1px; padding: 8px 12px; border-radius: 12px; background: var(--section);
  box-shadow: var(--shadow-1); }
.stat-pill-label { font-size: 11.5px; color: var(--hint); font-weight: 600; }
.stat-pill-value { font-size: 16px; font-weight: 700; }
.topbar-chips { grid-area: chips; }
.topbar.compact { padding-top: calc(var(--safe-top) + 8px); padding-bottom: 8px; border-bottom-color: var(--separator);
  box-shadow: 0 8px 24px rgb(0 0 0 / 8%); }
.topbar.compact .topbar-value { font-size: 20px; }
.topbar.compact .topbar-stats, .topbar.compact .topbar-chips { display: none; }
.icon-btn { flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 16px; padding: 0;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 14%, transparent);
  transition: transform .12s ease, filter .15s ease; }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--tg-theme-bottom-bar-bg-color, var(--section));
  border-top: 1px solid var(--separator);
}
.tab {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--hint); font-size: 11px; font-weight: 600; cursor: pointer; position: relative;
  transition: color .15s ease;
}
.tab::before { content: ""; position: absolute; top: 5px; left: 50%; width: 46px; height: 27px; border-radius: 9px;
  transform: translateX(-50%); background: transparent; transition: background .15s ease; }
.tab svg { position: relative; z-index: 1; width: 24px; height: 24px; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"]::before { background: var(--accent-soft); }
.tab .dot { position: absolute; z-index: 2; top: 8px; right: calc(50% - 18px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }


/* ---- gate (not in Telegram / session problems) ------------------------------- */
.gate { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 24px; }
.gate h1 { margin: 10px 0 0; font-size: 22px; }
.gate p { margin: 0; color: var(--hint); max-width: 320px; }
.gate-mark { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; font-weight: 800; font-size: 22px;
  background: var(--accent); color: var(--accent-text); }

/* ---- bottom sheet ------------------------------------------------------------ */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: #0007; animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: calc(var(--vh) * .86 - var(--safe-top)); overflow: auto;
  overscroll-behavior: contain; outline: none;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 12px calc(var(--safe-bottom) + 18px);
  max-width: 720px; margin: 0 auto; animation: rise .22s cubic-bezier(.2, .8, .2, 1);
  box-shadow: var(--shadow-2);
}
.sheet.tall { max-height: calc(var(--vh) * .94 - var(--safe-top)); }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--hint); opacity: .4; margin: 2px auto 8px; }
.sheet-head { position: sticky; top: -8px; z-index: 2; display: flex; align-items: center; gap: 12px; margin: 0 -12px; padding: 0 12px;
  background: var(--bg); }
.sheet-title { flex: 1; min-width: 0; margin: 4px 6px 10px; font-size: 18px; overflow-wrap: anywhere; }
.sheet-close { display: none; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-bottom) + 14px); z-index: 30;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: var(--text); color: var(--bg); box-shadow: 0 8px 28px #0005; animation: fade .2s ease;
}
.toast.error { background: var(--down); color: #fff; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (prefers-reduced-transparency: reduce) { .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); } }
