/* Панель DEFIbot. Цвета — тема Telegram (--tg-theme-*), вне Telegram —
   запасные значения по светлой/тёмной схеме. Цвет состояния всегда
   подкреплён текстом или числом, а не только оттенком. */
:root {
  --fb-bg: #eff1f5; --fb-card: #ffffff; --fb-text: #12151a; --fb-hint: #7a828e;
  --fb-accent: #2b72d6;
  --rgb-gain: 22, 128, 61;   --rgb-loss: 200, 45, 45;
  --rgb-sos: 160, 20, 30;    --rgb-stop: 190, 30, 40;  --rgb-red: 205, 55, 50;
  --rgb-orange: 196, 90, 0;  --rgb-yellow: 150, 104, 0; --rgb-green: 22, 128, 61;
  --rgb-blue: 30, 100, 190;
  --tint: .12;
}
:root[data-scheme="dark"] {
  --fb-bg: #0f1419; --fb-card: #1a2129; --fb-text: #eef1f4; --fb-hint: #8a95a1;
  --fb-accent: #64a8f0;
  --rgb-gain: 92, 206, 128;  --rgb-loss: 255, 120, 110;
  --rgb-sos: 255, 105, 115;  --rgb-stop: 255, 110, 105; --rgb-red: 255, 128, 110;
  --rgb-orange: 255, 170, 90; --rgb-yellow: 230, 190, 80; --rgb-green: 92, 206, 128;
  --rgb-blue: 120, 180, 255;
  --tint: .16;
}
:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, var(--fb-accent)));
  --btn: var(--tg-theme-button-color, var(--fb-accent));
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: rgba(128, 136, 148, .2);
  --gain: rgb(var(--rgb-gain)); --loss: rgb(var(--rgb-loss));
  --r: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
        "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

/* ── итог ─────────────────────────────────────────── */
.hero { padding: 6px 4px 14px; }
.eyebrow { display: flex; align-items: center; gap: 8px; color: var(--hint); font-size: 13px; }
.eyebrow .grow { flex: 1; }
.big { font-size: 36px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin-top: 4px; }
.line { font-size: 16px; margin-top: 4px; }
.hint { color: var(--hint); font-size: 13px; margin-top: 2px; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.icon-btn {
  border: 0; background: transparent; padding: 0; width: 44px; height: 44px; margin: -12px -10px -12px 0;
  display: inline-flex; align-items: center; justify-content: center; color: var(--accent); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
                stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--r); padding: 10px 12px; min-height: 64px; display: block; }
.tile .k { color: var(--hint); font-size: 12px; }
.tile .v { font-size: 17px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .s { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── секции и строки ──────────────────────────────── */
.section { margin-bottom: 14px; }
.section > h2 {
  margin: 0 0 6px 16px; font-size: 13px; font-weight: 500; color: var(--sub);
  text-transform: uppercase; letter-spacing: .04em;
}
.card { background: var(--card); border-radius: var(--r); overflow: hidden; }
.card.pad { padding: 12px 14px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 56px;
  position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
a.row:active, .tile:active { opacity: .6; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .num { text-align: right; flex-shrink: 0; }
.row .num .a { font-weight: 600; }
.row .num .b { font-size: 13px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; position: relative; }
.kv + .kv::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
.kv .k { color: var(--text); min-width: 0; }
.kv .v { font-weight: 600; text-align: right; flex-shrink: 0; }
.note { padding: 9px 14px; font-size: 14px; position: relative; }
.note + .note::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }

/* ── HF: число в полосе профиля ───────────────────── */
.hf {
  flex-shrink: 0; min-width: 58px; padding: 5px 0; border-radius: 9px; text-align: center;
  font-weight: 600; font-size: 14px; background: rgba(128, 136, 148, .14); color: var(--hint);
}
.b-sos, .b-stop { --c: var(--rgb-stop); }
.b-sos { --c: var(--rgb-sos); }
.b-red { --c: var(--rgb-red); }
.b-orange { --c: var(--rgb-orange); }
.b-yellow { --c: var(--rgb-yellow); }
.b-green { --c: var(--rgb-green); }
.b-blue { --c: var(--rgb-blue); }
.hf[class*="b-"] { background: rgba(var(--c), var(--tint)); color: rgb(var(--c)); }
.banner {
  border-radius: var(--r); padding: 10px 14px; margin-bottom: 12px; font-weight: 500;
  background: rgba(var(--c, var(--rgb-loss)), var(--tint)); color: rgb(var(--c, var(--rgb-loss)));
}
.warn { border-radius: var(--r); padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
        background: rgba(var(--rgb-orange), var(--tint)); }
.warn div + div { margin-top: 4px; }

/* ── фильтры и переключатели ──────────────────────── */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -12px; padding-left: 12px;
         scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: 0; border-radius: 18px; padding: 0 14px; height: 36px; cursor: pointer;
  background: var(--card); color: var(--text); font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }
.seg { display: flex; background: rgba(128, 136, 148, .16); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: transparent; border-radius: 8px; height: 34px; font-size: 13px;
  cursor: pointer; color: var(--text);
}
.seg button[aria-pressed="true"] { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.toolbar { margin-bottom: 10px; }

/* ── позиция ──────────────────────────────────────── */
.head h1 { font-size: 22px; line-height: 1.2; margin: 4px 4px 2px; }
.head .sub { color: var(--hint); font-size: 14px; margin: 0 4px 12px; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.kpis .tile .v { font-size: 20px; }
.leg .amt { font-weight: 500; }
.leg .rate { color: var(--hint); font-size: 13px; }
.facts { color: var(--hint); font-size: 13px; padding: 0 4px 14px; }
.addr { display: flex; align-items: center; gap: 10px; }
.addr code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 13px; color: var(--hint); }
.btn {
  border: 0; border-radius: 10px; height: 40px; padding: 0 16px; cursor: pointer;
  background: var(--btn); color: var(--btn-text); font-weight: 500;
}
.btn.quiet { background: rgba(128, 136, 148, .16); color: var(--text); }

/* ── график ───────────────────────────────────────── */
.chart { padding: 12px 14px 10px; }
.chart .cap { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; min-height: 22px; }
.chart .cap .v { font-weight: 600; font-size: 17px; }
.chart .cap .t { color: var(--hint); font-size: 13px; }
.chart .plot { height: 180px; margin: 6px 0 8px; touch-action: pan-y; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--sep); stroke-width: 1; }
.chart .axis { fill: var(--hint); font-size: 11px; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ar { fill: var(--accent); opacity: .08; }
.chart .guide { stroke: var(--hint); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .zero { stroke: var(--hint); stroke-width: 1; stroke-dasharray: 2 4; opacity: .7; }
.chart .empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--hint); font-size: 14px; }
.chart .seg + .seg { margin-top: 6px; }

/* ── состояния ────────────────────────────────────── */
.sk { background: rgba(128, 136, 148, .16); border-radius: 8px; height: 14px; margin: 8px 0; animation: pulse 1.2s ease-in-out infinite; }
.sk.big { height: 36px; width: 60%; }
.sk.card { height: 160px; border-radius: var(--r); }
@keyframes pulse { 50% { opacity: .5; } }
.state { text-align: center; padding: 48px 20px; color: var(--hint); }
.state b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.state .btn { margin-top: 16px; }

/* ── нижние вкладки ───────────────────────────────── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; font-size: 11px; color: var(--hint); min-height: 52px;
}
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
            stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { .sk, .icon-btn.spin svg { animation: none; } }
