/* График для Telegram. Цвета — как у терминала и «Радара». Ночная тема —
   обычная, дневная — атрибут data-theme="light" у <html>. */

:root {
  color-scheme: dark;
  --bg: #0b0e11; --panel: #12161c; --raise: #1c222b; --line: #252c36;
  --fg: #eaecef; --dim: #848e9c; --faint: #5e6673;
  --up: #2ebd85; --down: #f6465d; --main: #f0b90b; --on-main: #11150e;
  --legend: rgba(11, 14, 17, 0.72);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
  --right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fff; --panel: #fff; --raise: #f0f2f5; --line: #dfe3e8;
  --fg: #14181d; --dim: #6b7480; --faint: #9aa3af;
  --up: #0c9d6b; --down: #e0364e; --main: #c98f00; --on-main: #fff;
  --legend: rgba(255, 255, 255, 0.78);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); }
body { color: var(--fg); font: 15px/1.35 var(--font); -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; touch-action: manipulation; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
button svg.filled { fill: currentColor; }
h1, h2, p { margin: 0; }
em { font-style: normal; }
.up { color: var(--up); }
.down { color: var(--down); }
:focus-visible { outline: 2px solid var(--main); outline-offset: -2px; }

/* ---- до графика ---- */
.gate { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; background: var(--bg); }
.gate__title { font-size: 20px; font-weight: 650; }
.gate__text { max-width: 320px; color: var(--dim); }
.gate__id { padding: 12px 22px; border-radius: 12px; background: var(--raise); font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: 0.5px; }
.gate__spin { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--main); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.btn { min-height: 46px; padding: 0 20px; border-radius: 12px; background: var(--raise); font-weight: 600; }
.btn--main { background: var(--main); color: var(--on-main); }

/* ---- каркас ---- */
.app { position: fixed; top: 0; left: 0; right: 0; height: var(--tg-viewport-height, 100dvh); display: grid; grid-template: "top" auto "tfs" auto "stage" minmax(0, 1fr) "bar" auto / minmax(0, 1fr); padding: var(--top) var(--right) 0 var(--left); background: var(--bg); }
.top { grid-area: top; display: flex; align-items: center; gap: 4px; height: 50px; padding: 0 12px; }
.top__sym { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; min-height: 44px; justify-content: center; text-align: left; }
.top__name { display: flex; align-items: center; gap: 4px; font-size: 18px; font-weight: 700; line-height: 1.15; }
.top__name svg { width: 13px; height: 13px; color: var(--dim); }
.top__sub { color: var(--dim); font-size: 11px; white-space: nowrap; }
.top__price { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; white-space: nowrap; }
.top__last { font-size: 18px; font-weight: 650; line-height: 1.15; }
.top__chg { font-size: 12px; }
.icon { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; color: var(--dim); flex: none; }
.icon.on { color: var(--main); }

.tfs { grid-area: tfs; display: flex; gap: 2px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tfs::-webkit-scrollbar { display: none; }
.tfs button { flex: none; min-width: 42px; height: 38px; padding: 0 9px; color: var(--dim); font-size: 14px; font-weight: 550; position: relative; }
.tfs button.on { color: var(--fg); }
.tfs button.on::after { content: ""; position: absolute; left: 9px; right: 9px; bottom: 0; height: 2px; border-radius: 2px; background: var(--main); }

.stage { grid-area: stage; position: relative; overflow: hidden; }
.stage__chart { position: absolute; inset: 0; touch-action: none; }
.legends { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.legend { position: absolute; left: 8px; max-width: calc(100% - 84px); display: flex; flex-direction: column; align-items: flex-start; gap: 1px; font-size: 11px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.legend__ohlc { display: flex; flex-wrap: wrap; gap: 0 5px; padding: 1px 4px; border-radius: 4px; background: var(--legend); color: var(--dim); }
.legend__ohlc span { margin-right: -2px; }
.legend__row { pointer-events: auto; display: flex; flex-wrap: wrap; gap: 0 6px; padding: 3px 4px; border-radius: 4px; background: var(--legend); text-align: left; color: var(--dim); }
.legend__row b { font-weight: 550; }
.legend__vals { display: inline-flex; flex-wrap: wrap; gap: 0 6px; }
.legend__fold { pointer-events: auto; padding: 4px 8px; border-radius: 4px; background: var(--legend); color: var(--dim); }
.legend__fold svg { width: 15px; height: 15px; display: block; }
.notice { position: absolute; z-index: 5; left: 50%; bottom: 40px; transform: translateX(-50%); padding: 7px 14px; border-radius: 16px; background: var(--raise); color: var(--fg); font-size: 13px; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
.tolast { position: absolute; z-index: 4; right: 68px; bottom: 34px; width: 40px; height: 40px; border-radius: 50%; background: var(--raise); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.tolast svg { width: 18px; height: 18px; }

.bar { grid-area: bar; display: grid; grid-template-columns: repeat(4, 1fr); padding-bottom: var(--bottom); border-top: 1px solid var(--line); background: var(--panel); }
.bar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 54px; color: var(--dim); font-size: 11px; }
.bar button:active { color: var(--main); }

/* Телефон лёжа: монета и свечи в одну строку, кнопки — столбцом справа. */
@media (orientation: landscape) and (max-height: 520px) {
  .app { grid-template: "top tfs bar" auto "stage stage bar" minmax(0, 1fr) / auto minmax(0, 1fr) auto; }
  .top { height: 40px; border-bottom: 1px solid var(--line); gap: 8px; }
  .top__sub { display: none; }
  .top__name, .top__last { font-size: 15px; }
  .top__price { margin-left: 4px; }
  .bar { grid-template: repeat(4, 1fr) / 54px; border-top: 0; border-left: 1px solid var(--line); padding-bottom: 0; }
  .bar button { height: auto; }
  .bar span { display: none; }
}

/* ---- шторка ---- */
.back { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.5); }
.sheet { position: fixed; z-index: 11; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; max-height: 78%; display: flex; flex-direction: column; border-radius: 16px 16px 0 0; background: var(--panel); border-top: 1px solid var(--line); animation: rise 0.18s ease-out; }
.sheet--tall { height: calc(100% - var(--top) - 24px); max-height: none; }
@keyframes rise { from { transform: translateY(40px); opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .sheet, .gate__spin { animation: none; } }
.sheet__grip { flex: none; touch-action: none; padding-top: 8px; }
.sheet__grip i { display: block; width: 38px; height: 4px; margin: 0 auto; border-radius: 2px; background: var(--line); }
.sheet__head { display: flex; align-items: center; min-height: 48px; padding: 0 4px 0 16px; }
.sheet__head h2 { flex: 1; font-size: 17px; font-weight: 650; }
.sheet__head #sheetPrev { margin-left: -12px; }
.sheet__body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 16px calc(16px + var(--bottom)); }

.search { position: sticky; top: 0; z-index: 2; padding-bottom: 8px; background: var(--panel); }
.search input { width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid transparent; background: var(--raise); font-size: 16px; user-select: text; -webkit-user-select: text; }
.search input:focus { outline: 0; border-color: var(--main); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-top: 8px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 34px; padding: 0 13px; border-radius: 17px; background: var(--raise); color: var(--dim); font-size: 13px; }
.chip.on { background: var(--main); color: var(--on-main); font-weight: 600; }

.coin { display: flex; align-items: center; min-height: 52px; border-bottom: 1px solid var(--line); }
.coin.on .coin__s { color: var(--main); }
.coin__pick { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; min-height: 52px; text-align: left; }
.coin__s { font-weight: 650; }
.coin__v { grid-row: 2; color: var(--dim); font-size: 12px; }
.coin__p { text-align: right; font-variant-numeric: tabular-nums; }
.coin__c { grid-column: 2; grid-row: 2; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }
.coin .icon { margin-left: -8px; }
.empty { padding: 28px 0; text-align: center; color: var(--dim); }

.sect { margin: 16px 0 4px; color: var(--dim); font-size: 12px; font-weight: 600; }
.sect:first-child { margin-top: 0; }
.item { display: flex; align-items: center; min-height: 52px; border-bottom: 1px solid var(--line); }
.item__main { flex: 1; min-width: 0; min-height: 52px; text-align: left; }
.item__main b { display: block; font-weight: 600; }
.item__main span { color: var(--dim); font-size: 12px; }
.item.off .item__main { opacity: 0.45; }
.item .icon { min-width: 40px; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; border-bottom: 1px solid var(--line); }
.step { display: flex; align-items: center; border-radius: 10px; background: var(--raise); }
.step button { width: 44px; height: 42px; font-size: 20px; color: var(--dim); }
.step input { width: 64px; height: 42px; border: 0; background: none; text-align: center; font-size: 16px; font-variant-numeric: tabular-nums; user-select: text; -webkit-user-select: text; }
.step input:focus { outline: 0; color: var(--main); }
.field select { height: 42px; padding: 0 12px; border: 0; border-radius: 10px; background: var(--raise); font-size: 16px; max-width: 60%; }
.plot { padding: 12px 0; border-bottom: 1px solid var(--line); }
.plot__top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sw { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.sw button { aspect-ratio: 1; max-height: 34px; min-height: 28px; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.sw button.on { border-color: var(--fg); }
.widths { display: flex; gap: 4px; }
.widths button { width: 38px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--raise); }
.widths button.on { box-shadow: inset 0 0 0 2px var(--main); }
.widths i { width: 20px; background: var(--fg); border-radius: 2px; }
.row { display: flex; gap: 8px; margin-top: 16px; }
.row .btn { flex: 1; }
.btn--bad { color: var(--down); }
.opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.opts button { min-height: 44px; padding: 4px 6px; border-radius: 10px; background: var(--raise); color: var(--dim); font-size: 13px; line-height: 1.2; }
.opts button.on { box-shadow: inset 0 0 0 2px var(--main); color: var(--fg); font-weight: 600; }
.toast { position: fixed; z-index: 40; left: 50%; bottom: calc(84px + var(--bottom)); transform: translateX(-50%); max-width: 88%; padding: 10px 16px; border-radius: 12px; background: var(--fg); color: var(--bg); font-size: 14px; text-align: center; }
