/* Цвета берутся из темы Telegram; запасные значения — для открытия в обычном браузере. */
:root {
  --bg: var(--tg-theme-bg-color, #0e1014);
  --surface: var(--tg-theme-secondary-bg-color, #171a21);
  --text: var(--tg-theme-text-color, #eceef2);
  --hint: var(--tg-theme-hint-color, #8d95a3);
  --accent: var(--tg-theme-button-color, #3d8bff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --fill: color-mix(in srgb, var(--text) 7%, var(--surface));
  --up: #3ccf91;
  --down: #ff6369;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: dark light;
}
:root[data-scheme="light"] { --up: #11805a; --down: #d3263a; --bg: var(--tg-theme-bg-color, #ffffff); --surface: var(--tg-theme-secondary-bg-color, #f2f3f6); --text: var(--tg-theme-text-color, #14171c); --hint: var(--tg-theme-hint-color, #6b7280); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 var(--font); }
body { min-height: 100vh; }
#app { max-width: 560px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--hint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ----- верхняя панель ----- */
.top { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.top h1 { font-size: 22px; font-weight: 700; flex: 1; letter-spacing: -0.01em; }
.top .sub { font-size: 13px; color: var(--hint); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--hint); }
.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

/* ----- добавление ----- */
.add { display: flex; gap: 8px; margin: 8px 0 4px; }
.add input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-transform: uppercase; }
.add input::placeholder { text-transform: none; color: var(--hint); }
.add input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.btn { height: 44px; padding: 0 18px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn[disabled] { opacity: .55; }
.btn.ghost { background: var(--fill); color: var(--text); }
.btn.danger { background: transparent; color: var(--down); border: 1px solid color-mix(in srgb, var(--down) 45%, transparent); width: 100%; }
.form-msg { min-height: 20px; font-size: 13px; color: var(--hint); margin: 2px 2px 8px; }
.form-msg.err { color: var(--down); }

/* ----- список ----- */
.list { display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; min-height: 64px; padding: 10px 14px; background: var(--surface); border-radius: var(--radius); }
.row:active { background: var(--fill); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.who { min-width: 0; display: grid; }
.who b { font-size: 16px; }
.who small { color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.px { display: grid; justify-items: end; gap: 2px; }
.px b { font-size: 16px; }
.pill { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill.up { color: var(--up); } .pill.down { color: var(--down); } .pill.flat { color: var(--hint); }

/* ----- состояния ----- */
.state { text-align: center; padding: 40px 12px; color: var(--hint); display: grid; gap: 12px; justify-items: center; }
.state h2 { color: var(--text); font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; min-width: 52px; padding: 0 14px; border-radius: 12px; background: var(--fill); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.skel { height: 64px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--fill) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sh 1.4s linear infinite; }
@keyframes sh { to { background-position: -200% 0; } }

/* ----- детальный экран ----- */
.head { padding: 4px 2px 12px; }
.head .ticker { display: flex; align-items: baseline; gap: 8px; color: var(--hint); font-size: 14px; }
.head .ticker b { color: var(--text); font-size: 15px; }
.price { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.chg { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface); border-radius: 12px; margin: 4px 0 8px; }
.tab { flex: 1; min-height: 40px; border-radius: 9px; color: var(--hint); font-weight: 600; }
.tab[aria-selected="true"] { background: var(--fill); color: var(--text); box-shadow: 0 0 0 1px var(--line) inset; }
.ohlc { display: flex; gap: 12px; flex-wrap: wrap; min-height: 20px; font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; padding: 0 2px 4px; }
.ohlc span b { color: var(--text); font-weight: 600; }
.chart-wrap { position: relative; height: clamp(260px, 44vh, 400px); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
#chart { position: absolute; inset: 0; }
.chart-state { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; color: var(--hint); gap: 10px; background: var(--surface); }

.section { margin-top: 20px; }
.section > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--hint); font-weight: 600; margin-bottom: 8px; padding: 0 2px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 14px; display: grid; gap: 14px; }
.panel .lbl { font-size: 14px; }
.panel .help { font-size: 13px; color: var(--hint); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; width: 100%; text-align: left; }
.switch-row .t { display: grid; }
.switch-row .t small { color: var(--hint); font-size: 13px; }
.switch { flex: none; width: 50px; height: 30px; border-radius: 15px; background: var(--fill); position: relative; transition: background .15s; box-shadow: 0 0 0 1px var(--line) inset; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch-row[aria-checked="true"] .switch { background: var(--accent); box-shadow: none; }
.switch-row[aria-checked="true"] .switch::after { transform: translateX(20px); background: var(--accent-text); }

/* лесенка эскалации порога */
.ladder { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ladder li { display: grid; grid-template-columns: 92px 1fr 52px; gap: 10px; align-items: center; font-size: 13px; }
.ladder .bar { height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.ladder .bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width .2s; }
.ladder li:nth-child(n+2) .bar i { opacity: .85; }
.ladder b { text-align: right; font-variant-numeric: tabular-nums; }

/* новости */
.news { display: grid; gap: 2px; }
.news a { display: grid; gap: 4px; padding: 12px 2px; color: inherit; text-decoration: none; border-top: 1px solid var(--line); }
.news a:first-child { border-top: 0; }
.news .meta { font-size: 12px; color: var(--hint); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.news .t { font-size: 15px; line-height: 1.35; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 900px) { #app { padding-top: 28px; } }
