:root {
  --bg: var(--tg-theme-secondary-bg-color, #eff1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #858a94);
  --link: var(--tg-theme-link-color, #2b78d0);
  --accent: var(--tg-theme-button-color, #2b78d0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --profit: #1f9d5b;
  --loss: #d9443c;
  --long: #3478c6;
  --short: #d68a1f;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #0f1216);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1a1e24));
    --text: var(--tg-theme-text-color, #eceef1);
    --hint: var(--tg-theme-hint-color, #8b919b);
  }
}
:root[data-theme="dark"] { --profit: #35c27a; --loss: #f0625a; --long: #5a9be6; --short: #e9a340; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 12px calc(84px + env(safe-area-inset-bottom));
}

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--profit); }
.neg { color: var(--loss); }
.muted { color: var(--hint); }

/* ---------- шапка ---------- */
.head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 4px 2px;
}
.head h1 { flex: 1; margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.stamp { margin: 0 4px 12px; color: var(--hint); font-size: 13px; }
.icon-btn {
  border: 0;
  background: var(--card);
  color: var(--link);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:disabled { opacity: .5; }
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- главный блок ---------- */
.hero {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
}
.hero-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hero-label { color: var(--hint); font-size: 13px; }
.hero-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.hero-side { text-align: right; }
.hero-side .num { font-size: 17px; font-weight: 600; }

.ladder { margin-top: 14px; display: grid; gap: 3px; }
.rung {
  display: grid;
  grid-template-columns: 58px 1fr 72px;
  align-items: center;
  gap: 8px;
  border: 0; background: none; color: inherit; font: inherit;
  padding: 3px 0; cursor: pointer; text-align: left;
}
.rung-coin { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 5px; min-width: 0; }
.rung-coin span { overflow: hidden; text-overflow: ellipsis; }
.side-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.side-dot.long { background: var(--long); }
.side-dot.short { background: var(--short); }
.rung-track { position: relative; height: 14px; }
.rung-track::before {
  content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px;
  width: 1px; background: var(--sep);
}
.rung-bar { position: absolute; top: 2px; height: 10px; border-radius: 3px; min-width: 2px; }
.rung-bar.pos { background: var(--profit); left: 50%; }
.rung-bar.neg { background: var(--loss); right: 50%; }
.rung-val { text-align: right; font-size: 13px; }
.ladder-legend { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--hint); }

/* ---------- секции и списки ---------- */
.section-title { margin: 22px 6px 8px; font-size: 13px; color: var(--hint); font-weight: 500; }
.panel { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.panel.pad { padding: 12px 14px; }

.row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; width: 100%;
  background: none; border: 0; color: inherit; font: inherit; text-align: left;
}
.row + .row, .row + .detail, .detail + .row { border-top: 1px solid var(--sep); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-sub { color: var(--hint); font-size: 13px; }
.row-end { text-align: right; }
.row-end .num:first-child { font-weight: 600; }
button.row { cursor: pointer; }
button.row:active { background: color-mix(in srgb, var(--hint) 12%, transparent); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.kv + .kv { border-top: 1px solid var(--sep); }
.kv .k { color: var(--hint); }
.kv .v { text-align: right; }

.badge {
  font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--hint);
}
.badge.long { background: color-mix(in srgb, var(--long) 16%, transparent); color: var(--long); }
.badge.short { background: color-mix(in srgb, var(--short) 18%, transparent); color: var(--short); }

/* ---------- метрики ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--sep); }
.cell { background: var(--card); padding: 10px 14px; }
.cell .k { color: var(--hint); font-size: 12px; }
.cell .v { font-size: 17px; font-weight: 600; }
.cell .s { color: var(--hint); font-size: 12px; }

/* ---------- экспозиция ---------- */
.split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 8px 0 6px; background: var(--sep); }
.split .l { background: var(--long); }
.split .s { background: var(--short); }
.split-legend { display: flex; justify-content: space-between; font-size: 13px; }

/* ---------- переключатели ---------- */
.chips { display: flex; gap: 6px; margin: 0 2px 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 16px; padding: 6px 12px;
  background: var(--card); color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-text); }

/* ---------- графики ---------- */
.chart-box { position: relative; height: 190px; }
.chart-box.small { height: 120px; }
.chart-box.tall { height: 240px; }
.chart-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart-title b { font-size: 14px; }
.empty-chart { height: 100%; display: grid; place-items: center; color: var(--hint); font-size: 13px; text-align: center; }

/* ---------- таблица ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { color: var(--hint); font-weight: 500; font-size: 12px; text-align: right; padding: 8px 14px 4px; }
td { text-align: right; padding: 7px 14px; border-top: 1px solid var(--sep); }
th:first-child, td:first-child { text-align: left; }

/* ---------- позиция ---------- */
.detail { padding: 4px 14px 14px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; margin: 6px 0 10px; }
.facts .k { color: var(--hint); font-size: 11px; }
.facts .v { font-size: 14px; }
.range { position: relative; height: 6px; border-radius: 3px; background: var(--sep); margin: 14px 0 4px; }
.range .mark { position: absolute; top: -4px; width: 3px; height: 14px; border-radius: 2px; background: var(--text); }
.range .zero { position: absolute; top: -2px; width: 1px; height: 10px; background: var(--hint); }
.range-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--hint); }

/* ---------- состояния ---------- */
.notice { background: var(--card); border-radius: var(--radius); padding: 22px 18px; text-align: center; margin-top: 30px; }
.notice h2 { margin: 0 0 6px; font-size: 18px; }
.notice p { margin: 4px 0; color: var(--hint); }
.skeleton { height: 120px; border-radius: var(--radius); background: var(--card); margin-bottom: 10px; opacity: .6; }
.info { margin: 0 6px 10px; font-size: 13px; color: var(--hint); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status-dot.ok { background: var(--profit); }
.status-dot.warn { background: var(--short); }
.status-dot.none { background: var(--hint); }

/* ---------- нижние вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tab {
  flex: 1; max-width: 170px;
  border: 0; background: none; color: var(--hint); font: inherit; font-size: 11px;
  padding: 8px 4px 9px; cursor: pointer; display: grid; justify-items: center; gap: 2px;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 10;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--card);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; max-width: 90vw;
}

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .icon-btn.spin { animation: none; }
}
.tab-icon { display: block; line-height: 0; }
.kv.stack { flex-direction: column; gap: 2px; }
.kv.stack .v { text-align: left; }
