/* Цвета и размеры: docs/telegram_design.md, раздел «Цвета». Серии графиков проверены на различимость при дальтонизме. */
:root {
  --bg: #EEF1ED; --card: #FFFFFF; --inner: #F4F6F3; --ink: #16201B; --muted: #56635B; --line: #D5DCD6; --grid: #E3E8E3; --kb-line: #C3CFC6;
  --accent: #1F6F54; --accent-ink: #FFFFFF; --mark: #D3EBDC; --mark-ink: #1F6F54;
  --pos: #1F6F54; --neg: #9A3B26; --warn-bg: #FBF3E2; --warn-ink: #7A5310;
  --danger: #8A3B12; --danger-bg: #FBF4EF; --danger-line: #D9B9A6;
  --s-bot: #13875E; --s-mkt: #4A3AA7; --s-bot-fill: rgba(19,135,94,.12);
  --s-c1: #2A78D6; --s-c2: #EB6834; --s-c3: #1BAF7A; --s-cash: #A3AEA6;
  --s-pos: #13875E; --s-neg: #C4452F; --s-dd: rgba(196,69,47,.18);
  --font: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121A17; --card: #1C2622; --inner: #232F2A; --ink: #E3EAE5; --muted: #93A39A; --line: #26312C; --grid: #222C28; --kb-line: #33433B;
  --accent: #5CC29A; --accent-ink: #0E1412; --mark: #1E4537; --mark-ink: #8FE0BC;
  --pos: #6FD3A8; --neg: #F0907A; --warn-bg: #2B2416; --warn-ink: #E8C27A;
  --danger: #F0A07E; --danger-bg: #2A1D17; --danger-line: #5A3A2C;
  --s-bot: #2FA477; --s-mkt: #9085E9; --s-bot-fill: rgba(47,164,119,.18);
  --s-c1: #3987E5; --s-c2: #D95926; --s-c3: #199E70; --s-cash: #56635D;
  --s-pos: #2FA477; --s-neg: #E66767; --s-dd: rgba(230,103,103,.22);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14.5px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
#view { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 14px 12px 20px; }
#view h1 { margin: 0; font-size: 20px; line-height: 1.2; text-wrap: balance; }
#view h2 { margin: 0; font-size: 15px; line-height: 1.3; }
#view p { margin: 0; }
.backlink { align-self: flex-start; background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; cursor: pointer; }

.sub { color: var(--muted); font-size: 13px; }
.card { background: var(--card); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card.mark { background: var(--mark); }
.card.warn { background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; }
.card.err { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-line); font-size: 13.5px; }
.row2 { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.big { font-size: 28px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.chip { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 3px 8px; border-radius: 6px; background: var(--mark); color: var(--mark-ink); white-space: nowrap; }
.chip.off { background: var(--inner); color: var(--muted); }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.ex { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--warn-ink); background: var(--warn-bg); padding: 2px 6px; border-radius: 5px; vertical-align: 2px; white-space: nowrap; }

.seg { display: flex; background: var(--inner); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; text-align: center; padding: 6px 4px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); background: transparent; border: 0; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); }
.seg button:disabled { cursor: default; opacity: .6; }
.seg button:focus-visible, .btn:focus-visible, .li:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--card); border-radius: 12px; padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile.in { background: var(--inner); }
.tile b { font-size: 17px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile span { font-size: 11.5px; color: var(--muted); line-height: 1.25; }

.list { display: flex; flex-direction: column; }
.list > .li { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 13.5px; font-variant-numeric: tabular-nums; background: none; border: 0; text-align: left; width: 100%; cursor: pointer; }
.list > .li + .li { border-top: 1px solid var(--line); }
.coin { width: 30px; height: 30px; border-radius: 50%; background: var(--inner); display: grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .grow small, .li .end small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.li .end { text-align: right; }
.spark { width: 64px; height: 24px; flex-shrink: 0; }

.kv { display: flex; flex-direction: column; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.kv > div + div { border-top: 1px solid var(--line); }
.kv > div > span:first-child { color: var(--muted); }
.kv > div > span:last-child { text-align: right; }

.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13.5px; }
details.more > div { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; font-size: 13.5px; }

.btn { display: block; width: 100%; min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; cursor: pointer; padding: 10px; color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-line); }
.btn.link { border: 0; background: none; color: var(--accent); min-height: 0; padding: 4px 0; text-align: left; }
.btn:disabled { opacity: .55; cursor: default; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btns .wide { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field .inrow { display: flex; gap: 6px; }
.field input, .field select { flex: 1; min-width: 0; background: var(--inner); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 15px; font-variant-numeric: tabular-nums; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .paste { flex: none; width: auto; min-height: 0; padding: 0 12px; font-size: 13px; }

.chartbox { position: relative; }
.chartbox svg { display: block; width: 100%; height: auto; overflow: visible; }
.chartbox text { fill: var(--muted); font-family: var(--font); font-size: 10px; font-variant-numeric: tabular-nums; }
.chartbox .gl { stroke: var(--grid); stroke-width: 1; }
.chartbox .zl { stroke: var(--kb-line); stroke-width: 1; }
.chartbox .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; line-height: 1.35; color: var(--ink); box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 2; font-variant-numeric: tabular-nums; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.tip .h { color: var(--muted); font-size: 11.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); align-items: center; }
.legend span, .legend label { display: inline-flex; align-items: center; gap: 5px; }
.legend label { cursor: pointer; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.ln { height: 3px; border-radius: 2px; width: 14px; }
.stack { display: flex; gap: 2px; height: 14px; border-radius: 5px; overflow: hidden; }
.stack div { height: 100%; }
.stackleg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.stackleg span { display: flex; align-items: center; gap: 6px; }
.stackleg i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.stackleg b { margin-left: auto; font-weight: 600; }
.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dim { opacity: .55; }
table.t { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 5px 2px; text-align: right; border-top: 1px solid var(--line); vertical-align: top; }
table.t th { border-top: 0; color: var(--muted); font-weight: 600; font-size: 11px; line-height: 1.2; }
table.t td:first-child, table.t th:first-child { text-align: left; }
table.t td small { display: block; color: var(--muted); font-size: 10.5px; font-weight: 400; }
table.t td.me { background: var(--mark); }

.strat { gap: 10px; }
.strat.off { opacity: .6; }
.strat .kv > div { font-size: 12.5px; }

.settings { background: var(--card); border-radius: 14px; overflow: hidden; }
.settings h3 { margin: 0; padding: 10px 14px 4px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.settings .li { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 11px 14px; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; cursor: pointer; font-size: 14px; }
.settings .li:first-of-type { border-top: 0; }
.settings .li span:last-child { color: var(--muted); font-size: 13px; }
.settings .li.danger, .settings .li.danger span:last-child { color: var(--danger); }
.settings .li.static { cursor: default; }
.switch { appearance: none; width: 40px; height: 24px; border-radius: 12px; background: var(--kb-line); position: relative; cursor: pointer; flex-shrink: 0; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 19px; }
.switch:disabled { opacity: .6; cursor: default; }

.plan { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; width: 100%; text-align: left; }
.plan.on { border-color: var(--accent); background: var(--mark); }
.plan .grow { flex: 1; }
.plan small { display: block; color: var(--muted); font-size: 12px; }

/* Главная кнопка вне Telegram (в Telegram — системная MainButton) */
.mainwrap { position: sticky; bottom: 0; padding: 8px 12px 10px; background: var(--bg); }
.mainwrap[hidden] { display: none; }
.mainbtn { width: 100%; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px; padding: 13px; border-radius: 12px; border: 0; cursor: pointer; }
.mainbtn:disabled { opacity: .6; }

.tabs { position: sticky; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs[hidden] { display: none; }
.tabs button { flex: 1; background: none; border: 0; font-size: 11.5px; padding: 8px 2px 10px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; }
.tabs button svg { width: 22px; height: 22px; }
.tabs button.on { color: var(--accent); font-weight: 600; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet h2 { margin: 0; font-size: 17px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 13.5px; max-width: calc(100% - 32px); z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.center { text-align: center; color: var(--muted); padding: 40px 0; }

/* Переключатель языка на первом экране */
.langsw { align-self: flex-end; width: auto; }
.langsw button { flex: none; padding: 5px 12px; }
