/* Атрибут hidden всегда прячет элемент. Без этого правила любой класс
   с display: flex или grid перебивает hidden и оставляет пустую плашку. */
[hidden] {
    display: none !important;
}

/* ===== Design Tokens ===== */
:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2128;
    --surface-3: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-faint: #6e7681;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --green: #26a69a;
    --red: #ef5350;
    --orange: rgba(255, 165, 0, 0.15);
    --zone-line: rgba(226, 232, 240, 0.82);
    --radius-sm: 6px;
    --radius-md: 8px;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', 'Roboto Mono', Consolas, monospace;
    --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --surface-3: #e8eaed;
    --border: #d0d7de;
    --text: #1f2328;
    --text-muted: #59636e;
    --text-faint: #818b98;
    --zone-line: rgba(51, 65, 85, 0.95);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* Кнопка меню — только на узких экранах */
.menu-toggle {
    display: none;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
}

.sidebar-backdrop {
    display: none;
}

.header {
    background: linear-gradient(135deg, #1e293b 0%, #312e81 100%);
    color: #fff;
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h1 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.header p {
    font-size: 11px;
    opacity: 0.7;
    line-height: 1.2;
}

.logo {
    flex-shrink: 0;
}

.theme-toggle {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.2);
}

/* Ссылка на страницу справки — выглядит так же, как кнопка темы */
.help-link {
    text-decoration: none;
}

.main {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ===== Sidebar ===== */
.sidebar {
    /* Шире, чтобы тексты оповещений и названия инструментов не ломались по слогам */
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 14px;
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ===== Разделы левого меню ===== */
/* Настройки собраны в четыре сворачиваемых раздела: одним столбиком до нижних
   пунктов приходилось долго прокручивать. Шапка — обычная кнопка, чтобы
   работали клавиатура и озвучка. */
.side-sec {
    /* Панель — колонка flex, и без запрета на сжатие разделы ужимаются по
       высоте: содержимое обрезается краем скруглённой рамки. */
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-elevated, var(--bg-secondary));
}
.side-sec-head {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 11px;
    background: none;
    border: 0;
    cursor: pointer;
    color: var(--text-primary);
    font: inherit;
    text-align: left;
}
.side-sec-head:hover { background: var(--bg-hover, rgba(127, 127, 127, 0.08)); }
.side-sec-head:focus-visible { outline: 2px solid var(--accent, #22c55e); outline-offset: -2px; }
.side-sec-name { font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }
.side-sec-caret {
    font-size: 11px;
    color: var(--text-secondary);
    transition: transform 0.15s ease;
}
.side-sec.open .side-sec-caret { transform: rotate(180deg); }
.side-sec-body {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 2px 11px 12px;
}

.control-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

select {
    width: 100%;
    padding: 7px 10px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-body);
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

select:hover, select:focus {
    border-color: var(--primary);
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 400 !important;
    color: var(--text) !important;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    margin: 0;
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
    cursor: pointer;
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-body);
    transition: all var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-3);
    color: var(--text);
}

/* ===== Status ===== */
.status {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    line-height: 1.4;
    display: none;
}

.status.show {
    display: block;
}

.status.success {
    background: rgba(38, 166, 154, 0.1);
    color: #26a69a;
    border: 1px solid rgba(38, 166, 154, 0.2);
}

.status.error {
    background: rgba(239, 83, 80, 0.1);
    color: #ef5350;
    border: 1px solid rgba(239, 83, 80, 0.2);
}

.status.loading {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

/* ===== Info Box ===== */
.info-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-top: 8px;
}

.zone-swatch {
    flex-shrink: 0;
    width: 14px;
    height: 4px;
    border-radius: 2px;
    background: var(--zone-line);
}

.info-box p {
    font-size: 11px;
    color: var(--text-muted);
    margin: 3px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===== Chart Area ===== */
.chart-area {
    flex: 1;
    min-width: 0;
    position: relative;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

/* Полоса над графиками с переключателем 1 / 2 / 4 */
.chart-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    /* Значки переносим на вторую строку, а не выпускаем за край полосы.
       Без переноса при открытых панелях справа («Карта рынка сейчас»,
       «Карта зон 8levels») область графика сужается, и последние значки —
       в том числе «Карта зон 8levels» и карандаш — уезжали за границу
       полосы: они оставались в разметке видимыми, но нажать их было
       нельзя, и это читалось как «кнопка не работает». Перенос включается
       сам и только когда места действительно не хватает. */
    flex-wrap: wrap;
    row-gap: 6px;
    gap: 10px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.multi-switch {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border-radius: 6px;
    background: var(--surface-alt, rgba(127, 127, 127, 0.10));
}

.multi-btn {
    min-width: 26px;
    height: 22px;
    padding: 0 6px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.multi-btn:hover:not(:disabled) {
    background: var(--surface);
    color: var(--text);
}

.multi-btn.active {
    background: var(--primary);
    color: #fff;
}

.multi-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Кнопка «свернуть настройки»: колонка слева уходит, графику достаётся её ширина */
.topbar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 120ms ease, border-color 120ms ease;
}

.topbar-icon svg {
    width: 15px;
    height: 15px;
}

/* Кнопку прячет код: без разрешённой биржевой цены панелей с расстояниями
   нет, а карта уровней есть только у платных тарифов. Правило с !important
   нужно потому, что display у .topbar-icon задан жёстко, и одного атрибута
   hidden не хватает — в узкой полосе тоже. */
.topbar-icon[hidden] { display: none !important; }

/* Свёрнутая панель рисования: видна только первая кнопка, остальное раскрывается
   при наведении мыши. Так панель не закрывает свечи в тесной сетке четырёх графиков. */
body.draw-folded .draw-panel {
    opacity: 0.85;
    max-width: none;
    overflow: visible;
}

body.draw-folded .draw-panel > *:not(:first-child) {
    display: none;
}

body.draw-folded .draw-panel:hover {
    opacity: 1;
}

body.draw-folded .draw-panel:hover > * {
    display: flex;
}

/* Кнопка «во весь экран» прижата к правому краю полосы */
.topbar-icon-right {
    margin-left: auto;
}

/* Режим «во весь экран»: шапка и подвал уходят, вся высота — свечам */
body.chart-full .header,
body.chart-full .site-legal {
    display: none;
}

/* Полный экран браузера (F11): подвал с реквизитами тоже убираем — он там лишний,
   а высота нужна свечам. Шапку не трогаем: без неё не выйти в кабинет и к справке. */
body.browser-full .site-legal {
    display: none;
}

@media all and (display-mode: fullscreen) {
    .site-legal { display: none; }
}

.topbar-icon:hover {
    color: var(--text);
    border-color: var(--primary);
}

.main.no-sidebar > .sidebar {
    display: none;
}

/* Со свёрнутыми настройками бумагу видно и меняют прямо в верхней полосе */
.topbar-instrument-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-body);
    white-space: nowrap;
}

.topbar-instrument-btn[hidden] {
    display: none;
}

.topbar-instrument {
    max-width: 240px;
    height: 22px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

/* Таймфрейм в полосе над графиком: тот же вид, что у выбора бумаги рядом,
   и такой же, как у селекта таймфрейма в шапке мини-панелей раскладок 2 и 4 */
.topbar-timeframe {
    /* Ширина по содержимому: растянутый на всю полосу селект оставлял пустое
       поле справа от «1 час» и выглядел как поле ввода, а не как выбор */
    width: auto;
    max-width: 108px;
    height: 22px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.main.no-sidebar #sidebar-collapse svg {
    transform: scaleX(-1);
}

/* Скрепка: четыре графика одной бумаги с разными таймфреймами */
.multi-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.multi-link svg {
    width: 14px;
    height: 14px;
}

.multi-link:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--primary);
}

.multi-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.multi-link:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.multi-note {
    font-size: 11px;
    color: var(--text-muted);
}

/* Сетка графиков: одна, две рядом или четыре квадратом */
/* ===== Строка «график + ключевые уровни» =====
   В режиме официального виджета TradingView линии уровней внутрь чужого окна
   не попадают, поэтому уровни 8levels стоят рядом отдельным блоком: на
   большом экране — колонкой справа, на телефоне и в Telegram — под графиком
   (переворот делает медиа-правило ниже). Блок появляется только когда график
   рисует виджет: в своём окне уровни и так линиями на свечах. */
.chart-row {
    flex: 1;
    min-height: 0;
    display: flex;
    /* Точка отсчёта для незакреплённой боковой панели уровней: без булавки она
       лежит поверх графика и цепляется за правый край именно этой строки. */
    position: relative;
    align-items: stretch;
    gap: 1px;
    background: var(--border);
    /* Страховка от вылезания: строка графика сжимается вместе с областью, а
       блок ключевых уровней своей высоты не отдаёт. Без обрезки его содержимое
       рисовалось поверх складок под графиком. */
    overflow: hidden;
}
.key-levels {
    flex: 0 0 320px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border);
    background: var(--surface);
}
.key-levels[hidden] { display: none; }
/* Справа помещается одна панель. Когда открыта «Карта рынка сейчас», блок
   ключевых уровней уходит: две панели рядом оставляли графику меньше
   половины экрана. Уровни при этом не теряются — они в складках под
   графиком, а блок вернётся, как только карту рынка закроют. */
.chart-area.mn-open .key-levels { display: none; }
.kl-head {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.kl-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kl-title b { font-size: 0.9rem; }
.kl-sub { font-size: 0.78rem; color: var(--text-muted); }
.kl-warn {
    flex: 0 0 auto;
    margin: 8px 12px 0;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.74rem;
    color: var(--text-muted);
    background: var(--surface-2);
}
.kl-warn[hidden] { display: none; }
/* Пояснение про собственную кнопку «без значений». Рамку ему не даём:
   это не предупреждение о проблеме, а напоминание о своём же выборе. */
.kl-note {
    flex: 0 0 auto;
    margin: 6px 12px 0;
    font-size: 0.72rem;
    line-height: 1.35;
    color: var(--text-muted);
}
.kl-note[hidden] { display: none; }
.kl-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px 4px; }
.kl-foot {
    flex: 0 0 auto;
    padding: 6px 12px 10px;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--text-muted);
}

/* Карточка уровня: цифра зоны крупная, признаки — строками «название/значение».
   Тип различается цветной полосой слева, как линия того же уровня на графике. */
.kl-card {
    margin-bottom: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: 10px;
    background: var(--surface-2);
}
.kl-card.sup { border-left-color: var(--green); }
.kl-card.res { border-left-color: var(--red); }
.kl-chead {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 0.76rem;
    color: var(--text-muted);
}
.kl-ctf { font-size: 0.72rem; }
.kl-cprice {
    margin: 2px 0 4px;
    font-size: 1.02rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.kl-crow {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.76rem;
    line-height: 1.5;
}
.kl-crow > span:first-child { color: var(--text-muted); }
.kl-note {
    margin-top: 4px;
    font-size: 0.74rem;
    line-height: 1.45;
    color: var(--text-muted);
}
.kl-empty { padding: 10px 0; font-size: 0.8rem; color: var(--text-muted); }

/* ===== Складки под графиком ===== */
.chart-folds {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    background: var(--surface);
    max-height: 46vh;
    overflow-y: auto;
}
.chart-folds[hidden] { display: none; }
.chart-fold { border-bottom: 1px solid var(--border); }
.chart-fold > summary {
    padding: 8px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}
.chart-fold > summary::marker { color: var(--text-muted); }
.chart-fold-body { padding: 0 12px 10px; }

/* Панель, переехавшая в складку, перестаёт быть плавающей: ни своего угла,
   ни тени, ни кнопок стыковки — местом теперь распоряжается складка */
.levels-panel.dock-fold {
    position: static;
    width: auto;
    max-width: none;
    height: auto;
    max-height: 42vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
}
.levels-panel.dock-fold .lp-head { display: none; }
/* Маркера текущей цены и карточек ключевых уровней в складке нет: и цену, и
   ключевые уровни показывает главный блок рядом с графиком, а второй такой
   же набор рядом читался бы как расхождение данных */
.levels-panel.dock-fold .lp-key { display: none; }
.levels-panel.dock-fold .lp-all > summary { display: none; }
.levels-panel.dock-fold .lp-list { max-height: 34vh; overflow-y: auto; }

/* ===== Боковая полоса значков и панель уровней (режим виджета, большой экран) =====
   Складки под графиком отнимали у свечей высоту, а высота графику дороже
   ширины: на ноутбуке раскрытая карта уровней съедала почти половину окна.
   Поэтому справа стоит узкая полоса из трёх значков, а панель открывается
   по нажатию. Булавка решает, сдвигать график (панель колонкой) или лечь
   поверх свечей (панель плавающая) — второе не отнимает у графика ничего. */
.dock-rail {
    /* 52 px: в более узкую полосу подпись «Ключевые» не влезала и выходила
       за края кнопки на полпикселя — читалось как обрезанный текст. */
    flex: 0 0 52px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 0;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: 41;
}
.dock-rail[hidden] { display: none; }
.dock-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 50px;
    padding: 6px 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}
.dock-tab svg { width: 18px; height: 18px; }
.dock-tab:hover { background: var(--surface-2, rgba(127, 127, 127, .12)); color: var(--text); }
/* Подпись под значком короткая в одно слово: без неё человек угадывает
   назначение по рисунку, а всплывающую подсказку на планшете не видно. */
.dock-tab-name {
    font-size: 9px;
    line-height: 1.1;
    letter-spacing: .2px;
    white-space: nowrap;
}
.dock-tab.active {
    background: var(--accent-soft, rgba(56, 132, 255, .16));
    color: var(--accent, #3884ff);
}
.dock-pane {
    flex: 0 0 340px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border-left: 1px solid var(--border);
}
.dock-pane[hidden] { display: none; }
/* Панель без булавки лежит поверх графика у самой полосы значков: график
   остаётся во всю ширину, а числа уровней всё равно перед глазами. */
.dock-pane.dock-float {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 52px;
    width: 360px;
    z-index: 40;
    box-shadow: -10px 0 24px rgba(0, 0, 0, .28);
}
.dock-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 8px 7px 12px;
    border-bottom: 1px solid var(--border);
}
.dock-title { font-size: 13px; }
/* Пометка «значения скрыты вами»: лежит между шапкой и телом панели, чтобы
   попадалась на глаза до самих точек, но не спорила с заголовком по весу. */
.dock-note {
    margin: 0;
    padding: 6px 10px;
    font-size: 0.72rem;
    line-height: 1.35;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.dock-head-btns { display: flex; align-items: center; gap: 2px; }
.dock-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}
.dock-btn svg { width: 15px; height: 15px; }
.dock-btn:hover { background: var(--surface-2, rgba(127, 127, 127, .12)); color: var(--text); }
/* Булавка нажата — панель закреплена колонкой. Отличать состояния нужно
   на глаз: иначе непонятно, почему панель то сдвигает график, то нет. */
.dock-btn[aria-pressed="true"] { color: var(--accent, #3884ff); }
.dock-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
/* Блоки внутри панели: своя рамка, фон и заголовок им уже не нужны —
   местом и подписью распоряжается сама панель. */
.key-levels.kl-in-dock,
.levels-panel.dock-side {
    position: static;
    flex: 1 1 auto;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
}
.key-levels.kl-in-dock .kl-head { display: none; }
.levels-panel.dock-side .lp-head { display: none; }
.levels-panel.dock-side .lp-all > summary { display: none; }
.levels-panel.dock-side .lp-list { max-height: none; }
/* Карта рынка сейчас открывается тем же правым краем. Двум панелям рядом
   графику остаётся меньше половины окна, поэтому закреплённая панель
   уровней на это время уходит — значки остаются, вернуть её одно нажатие. */
.chart-area.mn-open .dock-pane { display: none; }
@media (max-width: 1100px) {
    /* Узкий экран: полоса значков не нужна, там уровни живут складками
       под графиком — колонка рядом не влезает в принципе. */
    .dock-rail, .dock-pane { display: none; }
}

@media (max-width: 1100px) {
    /* Места на колонку рядом с графиком нет: блок уровней уходит под график.
       Своя прокрутка у блока остаётся, а высоту делим с графиком. */
    .chart-row { flex-direction: column; }
    .key-levels {
        flex: 0 0 auto;
        max-height: 44vh;
        border-left: 0;
        border-top: 1px solid var(--border);
    }
    .chart-folds { max-height: 46vh; }
    /* Блок ключевых уровней переехал в складку: своей рамки, фона и
       потолка высоты ему больше не нужно — местом распоряжается складка,
       а собственный заголовок дублировал бы её подпись. */
    .key-levels.kl-in-fold {
        flex: none;
        max-height: none;
        border: 0;
        background: transparent;
        overflow: visible;
    }
    .key-levels.kl-in-fold .kl-head { display: none; }
    .key-levels.kl-in-fold .kl-warn { margin-left: 0; margin-right: 0; }
    .key-levels.kl-in-fold .kl-body { padding-left: 0; padding-right: 0; }
    .key-levels.kl-in-fold .kl-foot { padding-left: 0; padding-right: 0; }
    /* Правило «рядом с графиком помещается одна панель» к складке не
       относится: она под графиком и ничего не занимает у свечей. */
    .chart-area.mn-open .key-levels.kl-in-fold { display: flex; }
    /* В складке панель уровней живёт в потоке: потолок задаёт сама складка,
       а список внутри прокручивается. Своей высоты панель здесь не считает. */
    .levels-panel.dock-fold { max-height: none; }
    .levels-panel.dock-fold .lp-list { max-height: 30vh; }
}

.chart-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    gap: 1px;
    background: var(--border);
}

.chart-grid[data-layout="2"] {
    grid-template-columns: 1fr 1fr;
}

.chart-grid[data-layout="4"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

#chart {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    position: relative;
    background: var(--bg);
}

/* Подписи «где смотреть уровни» в углу графика больше нет: её закрывала
   панель «Уровни рядом», и найти подпись было нельзя. Про виджет говорит
   значок «График: TradingView» в верхней полосе (см. «Свежесть данных»). */

/* ===== Официальный виджет TradingView ===== */
/* Блок из двух частей: само окно и подпись со ссылкой под ним. Подпись
   обязательна и стоит непосредственно под графиком — в браузере, на телефоне
   и в Телеграме одинаково, потому что это часть того же блока. Высоту задаём
   явно: виджет с autosize внутри блока нулевой высоты остаётся белым. */
.tv-embed {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    /* В ячейках раскладок высоту задаёт сама сетка, и свой минимум здесь
       ломал бы четырёхоконную раскладку: блок вылезал бы за ячейку. */
    min-height: 0;
    position: relative;
}

/* Главное окно одно на всю ширину — ему нужен явный минимум: виджет с
   autosize в блоке почти нулевой высоты остаётся белым прямоугольником. */
.chart-grid[data-layout="1"] #chart > .tv-embed {
    min-height: 360px;
}

/* Гнездо для окна: скрипт TradingView распоряжается его содержимым сам, и
   ничего своего внутрь класть нельзя — он это вычистит. */
.tv-embed-host {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
}

.tv-embed-host .tradingview-widget-container,
.tv-embed-host .tradingview-widget-container__widget {
    width: 100%;
    height: 100%;
}

.tv-embed-host iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Подпись с логотипом. Убирать её нельзя ни в какой раскладке: это условие
   использования виджета, а не украшение. Поэтому у неё фиксированная высота
   и она никогда не прячется — сжимается сам график. */
.tv-copyright {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg);
    font-size: 11px;
    line-height: 1.2;
}

.tv-copyright a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary, var(--text-muted));
    text-decoration: none;
}

.tv-copyright a:hover { text-decoration: underline; }

.tv-logo {
    display: block;
    height: 14px;
    width: auto;
}

/* В тесных ячейках раскладки на четыре графика словам места нет, а логотип и
   ссылка остаются: сокращать можно пояснение, но не саму атрибуцию. */
.chart-grid[data-layout="4"] .tv-copyright-text { display: none; }

/* Заглушка: показывается, когда окно виджета так и не открылось. Лежит
   поверх гнезда, а подпись со ссылкой при этом остаётся на месте. */
.tv-fallback {
    position: absolute;
    inset: 0;
    bottom: 26px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    text-align: center;
    background: var(--bg);
    /* Содержимое не должно вылезать за окно графика: на телефоне
       график низкий, и длинное пояснение закрывало собой подпись
       с логотипом и обрезало саму кнопку. */
    overflow: hidden;
}

.tv-fallback[hidden] { display: none; }

.tv-fallback-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.tv-fallback-text,
.tv-fallback-hint {
    margin: 0;
    max-width: 460px;
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-secondary, var(--text-muted));
}

.tv-fallback-hint { font-size: 11px; }

/* Короткая строка вместо полного пояснения. На широком экране она лишняя —
   там целиком виден обычный текст, — а на телефоне и в Телеграме наоборот:
   полное пояснение скрыто, и без этой строки оставался голый заголовок про
   недоступный график, из которого человек делал вывод, что сломался сервис. */
.tv-fallback-short {
    display: none;
    margin: 0;
    max-width: 460px;
    font-size: 11px;
    line-height: 1.35;
    color: var(--text-secondary, var(--text-muted));
}

.tv-fallback-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

/* В тесных ячейках оставляем только заголовок и кнопки: длинные объяснения
   там всё равно не читаются, а кнопка со ссылкой нужна. */
.chart-grid[data-layout="4"] .tv-fallback-text,
.chart-grid[data-layout="4"] .tv-fallback-hint { display: none; }

/* Телефон и Телеграм: окно графика низкое, и важно сохранить главное —
   заголовок, кнопки и подпись с логотипом. Подробное пояснение про домен
   и блокировщик там не влезает и вытесняет кнопку за край окна. */
@media (max-width: 900px) {
    /* На телефоне высоту окна графика считает сама страница под лист, и
       свой минимум в 360 точек выталкивал подпись с логотипом за край
       экрана — а её видно быть обязано всегда. */
    .chart-grid[data-layout="1"] #chart > .tv-embed { min-height: 0; }
    /* На телефоне строка атрибуции не влезала в ширину и уезжала за правый
       край — на снимках от подписчиков конец слов был обрезан. Логотип и
       ссылку мы обязаны показывать целиком, поэтому строку выравниваем по
       центру, разрешаем ей сжиматься и чуть уменьшаем шрифт. */
    .tv-copyright {
        padding: 2px 6px;
        font-size: 9px;
        justify-content: center;
    }
    .tv-copyright a { min-width: 0; }
    .tv-copyright-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .tv-logo { height: 12px; }
    .tv-fallback {
        gap: 6px;
        padding: 8px;
        bottom: 20px;
    }
    .tv-fallback-title { font-size: 13px; }
    .tv-fallback-text,
    .tv-fallback-hint { display: none; }
    .tv-fallback-short { display: block; }
    .tv-fallback-actions { gap: 6px; }
}

/* В тесных ячейках на четыре графика места нет даже под короткую строку. */
.chart-grid[data-layout="4"] .tv-fallback-short { display: none; }

.tg-app .tv-fallback-text,
.tg-app .tv-fallback-hint { display: none; }
.tg-app .tv-fallback-short { display: block; }

/* ===== Активный график (при двух и четырёх панелях) ===== */
/* Обводим внутренней тенью, а не рамкой: рамка сдвинула бы содержимое
   панели и график пересчитывал бы размер при каждом переключении. */
.pane-active {
    box-shadow: inset 0 0 0 2px var(--accent, #22c55e);
    border-radius: 4px;
}
.pane-tag {
    position: absolute;
    left: 8px;
    bottom: 6px;
    z-index: 6;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--accent, #22c55e);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
}
.pane-tag.is-mini { background: #f59e0b; }
.pane-tag[hidden] { display: none; }
/* Строка в шапке меню: чем именно управляют настройки слева */
.side-active-hint {
    margin: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent, #22c55e);
    border-radius: 8px;
    background: var(--bg-secondary, rgba(127, 127, 127, 0.06));
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary, var(--text-muted));
}
/* Выбрана дополнительная панель — предупреждаем жёлтым, что левое меню
   меняет не её, а главный график. */
.side-active-hint.is-warn {
    border-left-color: #f59e0b;
    color: #b45309;
}
.side-active-hint[hidden] { display: none; }

/* Дополнительный график: своя шапка с выбором бумаги и таймфрейма */
.mini-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
}

.mini-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 5px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.mini-head select {
    min-height: 24px;
    height: 24px;
    padding: 0 4px;
    font-size: 11px;
    border-radius: 4px;
}

.mini-head .mini-instrument {
    flex: 1 1 auto;
    min-width: 0;
}

.mini-head .mini-timeframe {
    flex: 0 0 auto;
    width: 84px;
}

.mini-body {
    flex: 1;
    min-height: 0;
    position: relative;
}

.mini-status {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.mini-title {
    position: absolute;
    top: 4px;
    left: 8px;
    z-index: 5;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
}

/* ===== Chart Overlays ===== */
.chart-title-bar {
    position: absolute;
    top: 8px;
    left: 12px;
    z-index: 5;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chart-title-main {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-shadow: 0 0 4px var(--bg);
}

.chart-title-meta {
    font-size: 10px;
    color: var(--text-muted);
    text-shadow: 0 0 4px var(--bg);
}

.chart-toolbar {
    position: absolute;
    top: 8px;
    right: 60px;
    z-index: 5;
    display: flex;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.toolbar-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font-body);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition);
}

.toolbar-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.toolbar-btn.active {
    background: var(--primary);
    color: #fff;
}

.chart-legend {
    position: absolute;
    bottom: 30px;
    left: 12px;
    z-index: 9;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    color: var(--text-muted);
}

.legend-dot {
    display: inline-block;
    width: 8px;
    height: 2px;
    border-radius: 1px;
    flex-shrink: 0;
}

/* Короткая подпись показывается только в тесной сетке 2 и 4 графиков */
.legend-short {
    display: none;
}

/* Заголовок легенды — как в колонке настроек */
.legend-head {
    font-size: 10px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1px;
}

/* Период выбран, но уровней в кадре нет — показываем бледнее */
.legend-item.legend-empty {
    opacity: 0.42;
}

/* Полоска зоны: закраска внутри и контрастные границы сверху и снизу */
.legend-band {
    display: inline-block;
    width: 10px;
    height: 8px;
    flex-shrink: 0;
    border-top: 2px solid;
    border-bottom: 2px solid;
}

.chart-legend .legend-zone {
    max-width: 190px;
    align-items: flex-start;
    line-height: 1.25;
    margin-top: 2px;
}

/* ===== Легенда в дополнительном графике ===== */
.mini-legend {
    position: absolute;
    bottom: 22px;
    left: 8px;
    z-index: 9;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 7px;
    max-width: calc(100% - 100px);
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    opacity: 0.85;
    pointer-events: none;
    transition: opacity var(--transition);
}

.mini-panel:hover .mini-legend {
    opacity: 1;
}

.mini-legend .legend-item {
    gap: 4px;
    font-size: 10px;
    white-space: nowrap;
}

.mini-legend .legend-band {
    width: 9px;
    height: 7px;
}

.chart-grid[data-layout="4"] .mini-legend {
    gap: 1px 5px;
    padding: 1px 4px;
}

.chart-grid[data-layout="4"] .mini-legend .legend-item {
    font-size: 9px;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 17, 23, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
}

.loading-overlay.show {
    display: flex;
}

[data-theme="light"] .loading-overlay {
    background: rgba(246, 248, 250, 0.7);
}

.loading-overlay p {
    color: var(--text-muted);
    font-size: 13px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) and (min-width: 861px) {
    .sidebar {
        width: 270px;
        padding: 10px;
    }
    .header p { display: none; }
}

/* ===== Телефоны и планшеты ===== */
.sidebar-head { display: none; }

@media (max-width: 860px) {
    .menu-toggle {
        display: inline-flex;
    }

    /* На телефоне настройки открываются кнопкой меню — свёрнутость с большого экрана не применяем */
    .main.no-sidebar > .sidebar {
        display: flex;
    }

    .sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 4px;
        font-size: 15px;
        font-weight: 600;
        color: var(--text);
    }

    /* На телефоне настройки применяются сразу, кнопка не нужна */
    #build-btn {
        display: none;
    }

    .sidebar-close {
        border: 1px solid var(--border);
        background: var(--surface-2, var(--surface));
        color: var(--text);
        border-radius: var(--radius-sm);
        padding: 8px 12px;
        min-height: 40px;
        font-size: 14px;
        cursor: pointer;
    }

    .header {
        padding: 8px 12px;
        height: 56px;
    }

    /* Название целиком, в две строки. Одной строкой «Динамические уровни» на
       узком экране не влезало и обрезалось троеточием — оставалось «Динамические …».
       Двумя строками по 11,5 px оно занимает ту же высоту, что кнопки справа,
       и читается полностью. */
    .header h1 {
        font-size: 11.5px;
        line-height: 1.15;
        white-space: normal;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 2;      /* третьей строке взяться неоткуда, но страхуемся */
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .header p { display: none; }
    .logo { width: 20px; height: 20px; }
    .header-left { gap: 8px; min-width: 0; }

    /* Название сервиса уступает место тикеру: на телефоне важнее видеть,
       какая бумага и какой таймфрейм сейчас на экране. */
    .header-name { display: none; }

    .head-ticker {
        display: inline-flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 1px;
        min-width: 0;
        max-width: 46vw;
        padding: 4px 8px;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--surface-2, var(--surface));
        color: var(--text);
        cursor: pointer;
        text-align: left;
    }
    .head-ticker-name {
        max-width: 100%;
        font-size: 12.5px;
        font-weight: 700;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .head-ticker-tf {
        font-size: 9.5px;
        line-height: 1.1;
        color: var(--text-muted);
        white-space: nowrap;
    }

    /* На телефоне значки чуть крупнее: палец должен попадать по ним без
       прицеливания, а места в узкой полосе для этого хватает. */
    .data-fresh .df-chip {
        padding: 5px 8px;
        gap: 5px;
    }
    .data-fresh .df-chip .df-dot { width: 7px; height: 7px; }
    .data-fresh .df-tip { font-size: 0.74rem; }

    .topbar-icon-draw { display: inline-flex; }

    /* Боковая панель — выдвижное меню поверх графика */
    .sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        width: 92%;
        max-width: 380px;
        z-index: 40;
        padding: 14px;
        transform: translateX(-102%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 35;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }

    .chart-area {
        width: 100%;
    }

    /* Удобные для пальца элементы управления */
    select,
    input[type="text"],
    input[type="number"] {
        font-size: 16px;
        min-height: 42px;
    }

    .btn {
        min-height: 44px;
        font-size: 14px;
    }

    .checkbox-group label,
    .radio-group label {
        min-height: 32px;
    }

    /* Подписи над графиком: переключатель масштаба сверху, название под ним */
    .chart-toolbar {
        top: 6px;
        left: 8px;
        right: 8px;
        justify-content: space-between;
        overflow-x: auto;
    }

    .toolbar-btn {
        font-size: 12px;
        padding: 7px 9px;
        flex: 1 1 auto;
    }

    /* Полоса таймфреймов на телефоне: все периоды в один ряд,
       лишнее уезжает вбок пальцем — без полосы прокрутки на экране */
    .chart-tf-strip {
        justify-content: flex-start;
        gap: 2px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    .chart-tf-strip::-webkit-scrollbar {
        display: none;
    }

    .chart-tf-strip .tf-btn {
        flex: 0 0 auto;
        min-width: 40px;
        padding: 7px 10px;
        font-weight: 600;
        white-space: nowrap;
    }

    .chart-title-bar {
        top: 48px;
        left: 8px;
        right: auto;
        max-width: calc(100% - 76px);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 4px 8px;
    }

    .chart-title-main { font-size: 12px; }
    .chart-title-meta { font-size: 10px; line-height: 1.35; }

    /* На телефоне легенда занимает нужное место на графике, а расшифровка цветов
       и так есть в настройках («Периоды уровней» и «Цвета уровней») */
    .chart-legend,
    .mini-legend {
        display: none;
    }
}

/* Сообщение, когда данные не загрузились */
.chart-fatal {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    height: 100%;
    min-height: 240px;
    padding: 24px;
    text-align: center;
    font-family: var(--font-body);
    color: var(--text);
}

.chart-fatal p {
    margin: 0;
    max-width: 30ch;
    font-size: 15px;
    line-height: 1.5;
}

.chart-fatal button {
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

/* ===== Alerts ===== */
.hint {
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-faint);
    margin-top: 2px;
}

.hint:empty {
    display: none;
}

.hint.warn {
    color: #e0a030;
}

.alert-log-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.alert-log-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.alert-log-title svg {
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    transition: transform 140ms ease;
}

.alert-log-title:hover {
    color: var(--text);
}

/* Свёрнутый список оповещений: остаётся только заголовок */
.alert-log-box.collapsed .alert-log-legend,
.alert-log-box.collapsed #alert-log,
.alert-log-box.collapsed .alert-log-clear {
    display: none;
}

.alert-log-box.collapsed .alert-log-title svg {
    transform: rotate(-90deg);
}

/* Компактные действия вместо больших кнопок «Построить» и «Обновить список» */
.mini-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--primary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border-bottom: 1px dashed currentColor;
}

.link-btn:hover {
    color: var(--text);
}

.link-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

#alert-log {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 168px;
    overflow-y: auto;
}

.alert-item {
    display: flex;
    gap: 6px;
    align-items: baseline;
    font-size: 11px;
    line-height: 1.35;
    color: var(--text);
    border-left: 2px solid var(--border);
    padding-left: 6px;
}

.alert-item .alert-time {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.alert-log-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin: 0 0 4px;
    font-size: 10px;
    color: var(--text-faint);
}

.alert-legend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.alert-legend::before {
    content: "";
    width: 8px;
    height: 2px;
    border-radius: 1px;
    background: var(--border);
}

.alert-legend.touch::before { background: #e0a030; }
.alert-legend.cross::before { background: var(--primary); }
.alert-legend.zone::before { background: var(--green); }

.alert-item .alert-ticker {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted, var(--text));
    background: var(--surface-2, rgba(127, 127, 127, 0.12));
    border-radius: 3px;
    padding: 0 4px;
}

.alert-item.cross {
    border-left-color: var(--primary);
}

.alert-item.touch {
    border-left-color: #e0a030;
}

.alert-item.zone {
    border-left-color: var(--green);
}

.alert-log-clear {
    align-self: flex-start;
    background: transparent;
    border: none;
    padding: 0;
    font-family: inherit;
    font-size: 10px;
    color: var(--text-faint);
    cursor: pointer;
    text-decoration: underline;
}

.alert-log-clear:hover {
    color: var(--text);
}

.alert-banner {
    position: absolute;
    top: 44px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    max-width: min(440px, calc(100% - 24px));
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--primary);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    animation: alert-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.alert-banner[hidden] {
    display: none;
}

.alert-banner.touch {
    border-color: #e0a030;
}

.alert-banner.zone {
    border-color: var(--green);
}

.alert-banner-text {
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
}

.alert-banner-text .alert-extra {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.alert-banner-close {
    background: transparent;
    border: none;
    color: var(--text-faint);
    font-size: 13px;
    line-height: 1;
    padding: 2px 0 2px 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.alert-banner-close:hover {
    color: var(--text);
}

@keyframes alert-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (max-width: 860px) {
    .alert-banner {
        top: auto;
        bottom: 130px;
        max-width: calc(100% - 16px);
        padding: 12px;
    }

    .alert-banner-text { font-size: 14px; }

    .alert-banner-close {
        font-size: 16px;
        padding: 4px 0 4px 8px;
    }
}

/* Панель рисования появляется только по кнопке-карандашу в полосе над графиком.
   Раньше правило стояло в мобильном медиа-блоке, и в браузере полоса кнопок
   всегда занимала левый край полотна: она отнимала место у свечей и закрывала
   логотип TradingView в углу. Теперь одинаково на всех ширинах. */
body.draw-off .draw-panel { display: none; }

/* Карандаш нужен на всех ширинах: без него спрятанную панель не достать */
.topbar-icon-draw { display: inline-flex; }

/* Отступ слева под боковую панель рисования: её кнопки стоят в этой полосе,
   а свечи, линии уровней и подписи цен начинаются правее и уже не перекрываются. */
body.draw-gutter { --draw-gutter: 52px; }
body.draw-gutter .mini-body { --draw-gutter: 38px; }

body.draw-gutter #chart,
body.draw-gutter .mini-body { padding-left: var(--draw-gutter, 0px); }

/* Полотно рисования и подписи должны совпадать с областью свечей, а не с полосой панели */
body.draw-gutter #chart > .draw-canvas,
body.draw-gutter .mini-body > .draw-canvas { left: var(--draw-gutter, 0px); }

body.draw-gutter #chart > .chart-legend,
body.draw-gutter #chart > .chart-title-bar,
body.draw-gutter .mini-body > .mini-legend,
body.draw-gutter .mini-body > .mini-title { margin-left: var(--draw-gutter, 0px); }

/* На узком экране панель уезжает вниз, полоса слева там не нужна — место дороже */
@media (max-width: 860px) {
    body.draw-gutter { --draw-gutter: 0px; }
    body.draw-gutter .mini-body { --draw-gutter: 0px; }
}

/* ===== Панель рисования ===== */
.draw-canvas {
    position: absolute;
    inset: 0;
    z-index: 8;
    pointer-events: none;
    touch-action: none;
}

.draw-panel {
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    z-index: 12;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.draw-tool {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.draw-tool svg {
    width: 18px;
    height: 18px;
}

.draw-tool:hover {
    background: var(--surface-alt, rgba(127, 127, 127, 0.12));
    color: var(--text);
}

.draw-tool.active {
    background: var(--primary);
    color: #fff;
}

.draw-sep {
    height: 1px;
    margin: 3px 4px;
    background: var(--border);
}

.draw-swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* Где держать панель рисования — задаётся в кабинете: сбоку, сверху или снизу.
   Без класса панель стоит слева (как раньше). */
.draw-panel.pos-top,
.draw-panel.pos-bottom {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    flex-direction: row;
    flex-wrap: nowrap;
    max-width: calc(100% - 16px);
    overflow-x: auto;
    scrollbar-width: none;
}

.draw-panel.pos-top { top: 52px; bottom: auto; }
.draw-panel.pos-bottom { top: auto; bottom: 34px; }

.draw-panel.pos-top::-webkit-scrollbar,
.draw-panel.pos-bottom::-webkit-scrollbar { display: none; }

.draw-panel.pos-top .draw-tool,
.draw-panel.pos-bottom .draw-tool { flex: 0 0 auto; }

.draw-panel.pos-top .draw-sep,
.draw-panel.pos-bottom .draw-sep {
    width: 1px;
    height: auto;
    margin: 4px 3px;
}

@media (max-width: 860px) {
    .draw-panel {
        top: auto;
        bottom: 6px;
        left: 6px;
        right: 6px;
        transform: none;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        scrollbar-width: none;
        padding: 3px 4px;
    }

    /* На телефоне место панели не выбирается: всегда полоса внизу */
    .draw-panel.pos-top,
    .draw-panel.pos-bottom {
        top: auto;
        bottom: 6px;
        left: 6px;
        right: 6px;
        transform: none;
        max-width: none;
    }

    .draw-panel::-webkit-scrollbar { display: none; }

    .draw-tool { flex: 0 0 auto; }

    .draw-tool {
        width: 34px;
        height: 34px;
    }

    .draw-sep {
        width: 1px;
        height: auto;
        margin: 4px 3px;
    }
}

/* ===== Настройки каждого способа оповещения ===== */
.channel {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.channel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

/* Подсказка о тарифе занимает всю строку под названием канала */
.channel-head .lock-tip {
    flex: 1 0 100%;
    order: 10;
    margin: 0;
}

.channel-gear {
    flex: 0 0 auto;
    padding: 2px 6px;
    font-size: 10px;
    font-family: inherit;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color 120ms ease, border-color 120ms ease;
}

.channel-gear:hover {
    color: var(--text);
    border-color: var(--primary);
}

.channel-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 2px 0 6px 20px;
    padding: 8px;
    border-left: 2px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface-2);
}

.channel-body[hidden] {
    display: none;
}

.channel-sub {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    margin: 2px 0 0;
}

.channel-kinds {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.channel-test {
    align-self: flex-start;
    margin-top: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-family: inherit;
    color: var(--primary);
    background: transparent;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.channel-test:hover {
    background: var(--primary);
    color: #fff;
}

/* Фильтр по времени торговых сессий */
.session-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
}

.session-custom {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.session-custom[hidden] {
    display: none;
}

.session-time-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.session-time-row input[type="time"] {
    width: auto;
    min-width: 96px;
}

.session-tz {
    font-size: 10px;
    color: var(--text-muted);
}

.session-days {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}

.session-days label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
}

/* Инструменты для оповещений в телеграме (серверное слежение) */
.tg-watch-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
}

.tg-watch-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tg-watch-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px 3px 10px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.tg-watch-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    font-size: 11px;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.tg-watch-chip-remove:hover {
    color: #fff;
    background: var(--danger, #d64545);
}

.tg-watch-add-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tg-watch-add-row select {
    flex: 1;
    min-width: 160px;
}

#tg-watch-limit-hint {
    margin: 0;
}

/* Плашка снизу графика */
.alert-banner.pos-bottom {
    top: auto;
    bottom: 16px;
}

@media (max-width: 860px) {
    .alert-banner.pos-top {
        top: 110px;
        bottom: auto;
    }

    .alert-banner.pos-bottom {
        top: auto;
        bottom: 130px;
    }

    .channel-body {
        margin-left: 12px;
    }

    .channel-gear,
    .channel-test {
        padding: 5px 10px;
        font-size: 11px;
    }
}

/* Поле ввода надписи на графике */
.draw-text-input {
    position: absolute;
    z-index: 14;
    width: 186px;
    padding: 5px 8px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    outline: none;
}

.draw-text-input::placeholder {
    color: var(--text-faint);
    font-size: 11px;
}

/* Файл оповещений */
.alert-file-row {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.alert-file-row .btn-small {
    flex: 1;
    padding: 7px 8px;
    font-size: 12px;
    margin: 0;
}

#alert-file-list {
    margin-top: 6px;
}

/* Подсказка по свече */
.candle-tip {
    position: absolute;
    z-index: 26;
    pointer-events: none;
    min-width: 168px;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
    font-size: 12px;
    line-height: 1.35;
    color: var(--text);
}

/* В дополнительной панели места меньше — подсказку делаем компактнее */
.mini-tip {
    min-width: 132px;
    padding: 6px 8px;
    font-size: 11px;
    z-index: 28;
}

.mini-tip .candle-tip-head {
    margin-bottom: 4px;
    padding-bottom: 4px;
}

.mini-tip .candle-tip-grid {
    gap: 1px 8px;
}

.candle-tip[hidden] {
    display: none;
}

.candle-tip-head {
    font-weight: 600;
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border);
}

.candle-tip-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 2px 12px;
}

.candle-tip-grid span {
    color: var(--text-muted);
}

.candle-tip-grid b {
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.candle-tip-grid b.up {
    color: #26a69a;
}

.candle-tip-grid b.down {
    color: #ef5350;
}

@media (max-width: 900px) {
    .candle-tip {
        min-width: 150px;
        font-size: 11px;
        padding: 7px 8px;
    }
}


/* Плашка источника котировок */
.source-badge {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-muted);
    display: none;
}
.source-badge.visible { display: block; }
.source-badge .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    background: var(--text-faint);
}
.source-badge.live .dot { background: #22c55e; }
.source-badge.warn .dot { background: #f59e0b; }
.source-badge.off .dot { background: #ef4444; }

/* ===== Cabinet UI (merged from cabinet.css) ===== */
/* ===== Кабинет, вход, тарифы ===== */

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-account {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-account:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
}

.btn-account.is-logged {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

/* Значок нужен только там, где почта не влезает: на телефоне и в Телеграме */
.btn-account-icon {
    display: none;
    flex-shrink: 0;
}

/* Название сервиса не должно выдавливать кнопки справа */
.header-left {
    min-width: 0;
}

/* Блок с названием и подписью тоже должен уметь сжиматься: без этого он держит
   свою ширину и заголовок налезает на кнопки аккаунта на узком экране. */
.header-left > div {
    min-width: 0;
    overflow: hidden;
}

.header p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* На большом экране название влезает в одну строку, поэтому там прежнее
   поведение с троеточием. Перенос в две строки включается ниже, для телефона. */
.header h1 { overflow: hidden; }

@media (min-width: 861px) {
    .header h1 { text-overflow: ellipsis; white-space: nowrap; }
}

.header-right > * {
    flex-shrink: 0;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: #22c55e;
    font-size: 12px;
    font-family: var(--font-body);
    cursor: pointer;
    text-decoration: underline;
    text-align: left;
}

.link-btn:hover {
    color: #4ade80;
}

/* ===== Модалка (общая для входа и др.) ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 380px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.modal-head h2 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}

/* Окно «Pine-код уровней». Поле с кодом делаем моноширинным и с прокруткой:
   код читают глазами перед вставкой, а на узком экране он иначе расползается
   переносами и понять, где кончается строка, невозможно. */
.pine-box {
    max-width: 720px;
    width: min(92vw, 720px);
}

.pine-code {
    width: 100%;
    min-height: 240px;
    max-height: 46vh;
    margin: 6px 0 4px;
    padding: 10px 12px;
    box-sizing: border-box;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.45;
    white-space: pre;
    overflow: auto;
    resize: vertical;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.pine-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 10px;
}

.modal-close:hover {
    color: var(--text);
    background: var(--surface-3);
}

/* ===== Вкладки входа ===== */
.auth-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 14px;
}

.auth-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-body);
    padding: 8px 4px;
    border-radius: 5px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.auth-tab.active {
    background: var(--surface);
    color: #22c55e;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.auth-panel[hidden] {
    display: none;
}

.auth-step[hidden] {
    display: none;
}

.auth-step {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-step label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.auth-step input[type="email"],
.auth-step input[type="tel"],
.auth-step input[type="text"],
.account-link-box input {
    width: 100%;
    padding: 9px 10px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-body);
    outline: none;
}

.auth-step input:focus,
.account-link-box input:focus {
    border-color: #22c55e;
}

.auth-error {
    color: #ef5350;
    font-size: 12px;
    margin-top: 8px;
    line-height: 1.4;
}

.auth-error:empty {
    display: none;
}

.auth-telegram-code {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 4px;
    text-align: center;
    color: #22c55e;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
}

.auth-panel .btn,
.auth-step .btn {
    width: 100%;
}

/* ===== Кабинет ===== */
.cabinet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
    padding: 16px;
}

.cabinet-overlay[hidden] {
    display: none;
}

.cabinet-box {
    --cab-pad: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 620px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: var(--cab-pad);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

/* Заголовок прилипает к верху окна: крестик виден на любой прокрутке */
.cabinet-head {
    position: sticky;
    top: 0;
    /* Ниже в кабинете есть карточки и плашки со своим z-index: при прокрутке на
       телефоне они пролезали над шапкой. Поднимаем шапку выше всего кабинета. */
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface);
    margin: calc(-1 * var(--cab-pad)) calc(-1 * var(--cab-pad)) 12px;
    padding: var(--cab-pad) var(--cab-pad) 10px;
    border-bottom: 1px solid var(--border);
    /* Тень отделяет шапку от уезжающего под неё текста */
    box-shadow: 0 6px 12px -8px rgba(0, 0, 0, 0.55);
}

.cabinet-head h2 {
    font-size: 18px;
    font-weight: 600;
}

.cabinet-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 16px;
}

.cabinet-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-body);
    padding: 9px 6px;
    border-radius: 5px;
    cursor: pointer;
    transition: all var(--transition);
}

.cabinet-tab.active {
    background: var(--surface);
    color: #22c55e;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.cabinet-panel[hidden] {
    display: none;
}

.cabinet-guest-note {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 14px;
    font-size: 12px;
    color: var(--text);
}

.account-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}

.account-row:last-child {
    border-bottom: none;
}

.account-row-label {
    width: 76px;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.account-row-value {
    flex: 1 1 auto;
    min-width: 120px;
    font-size: 13px;
    color: var(--text);
    overflow-wrap: anywhere;
}

/* Кнопка «Привязать» не должна сжимать значение до одной буквы в строке
   и не должна вылезать за край окна кабинета */
.account-row .btn-small {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
}

.account-link-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.account-link-box[hidden] {
    display: none;
}

.account-link-box .btn {
    width: auto;
}

.cabinet-section {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.cabinet-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.session-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.session-row:last-child {
    border-bottom: none;
}

/* ===== набор инструментов (слоты) ===== */
.slot-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.slot-row:last-child {
    border-bottom: none;
}

.slot-num {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--bg-elevated, rgba(127, 127, 127, .15));
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

.slot-ticker {
    font-weight: 600;
    color: var(--text);
}

.slot-ticker.is-empty {
    font-weight: 400;
    color: var(--text-muted);
}

.slot-state {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 12px;
    text-align: right;
}

.slot-row .btn-small {
    width: auto;
    flex: 0 0 auto;
}

/* ===== вкладка «Администратор» ===== */
.admin-section .btn-small {
    width: auto;
}

.admin-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.admin-field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.admin-field input {
    width: 100%;
    padding: 9px 10px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-body);
    outline: none;
}

.admin-field input:focus {
    border-color: #22c55e;
}

.admin-stats {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* Таблицы платежей и входов бывают длинными — прокручиваем их внутри блока,
   чтобы остальные разделы вкладки «Администратор» оставались под рукой. */
.admin-scroll-tall {
    max-height: 320px;
    overflow: auto;
}

.admin-users-table-wrap {
    overflow-x: auto;
}

.admin-users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.admin-users-table th,
.admin-users-table td {
    padding: 6px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.admin-users-table th {
    color: var(--text-muted);
    font-weight: 500;
}

.admin-users-table select {
    width: auto;
    padding: 5px 8px;
    padding-right: 22px;
    font-size: 12px;
}

.admin-users-table input[type="number"] {
    padding: 5px 6px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: var(--font-body);
}

@media (max-width: 640px) {
    .admin-users-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .admin-users-table {
        min-width: 560px;
    }
}

.session-row .session-current {
    color: #22c55e;
    font-weight: 600;
}

#account-logout-btn {
    margin-top: 16px;
}

/* ===== Тарифы ===== */
.billing-period-toggle {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 14px;
    max-width: 360px;
}

.billing-period {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-body);
    padding: 7px 6px;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
}

.billing-period.active {
    background: #22c55e;
    color: #06210f;
}

/* Процент скидки на кнопке срока. */
.billing-period-save {
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    background: rgba(34, 197, 94, 0.16);
    color: #22c55e;
}

.billing-period.active .billing-period-save {
    background: rgba(6, 33, 15, 0.16);
    color: #06210f;
}

@media (max-width: 560px) {
    .billing-period-toggle {
        max-width: none;
    }

    .billing-period {
        flex-direction: column;
        gap: 2px;
        padding: 6px 4px;
        font-size: 11px;
    }
}

/* Старая цена без скидки и цена за месяц в карточке тарифа. */
.plan-price-was {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

.plan-price-was s {
    opacity: 0.75;
}

.plan-price-save {
    color: #22c55e;
    font-weight: 600;
}

.billing-plans {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 14px;
}

@media (max-width: 640px) {
    .billing-plans {
        grid-template-columns: 1fr;
    }
}

.plan-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

.plan-card.current {
    border-color: #22c55e;
    box-shadow: 0 0 0 1px #22c55e inset;
}

.plan-current-badge {
    position: absolute;
    top: -9px;
    right: 10px;
    background: #22c55e;
    color: #06210f;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

.plan-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.plan-price {
    font-size: 20px;
    font-weight: 700;
    color: #22c55e;
}

.plan-price span {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

.plan-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
    flex: 1;
}

.plan-features li {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    line-height: 1.35;
}

.plan-features li::before {
    content: "✓";
    color: #22c55e;
    flex-shrink: 0;
}

.plan-card .btn {
    margin-top: auto;
}

.history-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.history-row:last-child {
    border-bottom: none;
}

.history-status {
    font-weight: 600;
}

.history-status.paid { color: #22c55e; }
.history-status.pending { color: #e0a030; }
.history-status.failed { color: #ef5350; }

/* На узком экране четыре ячейки в один ряд не влезают и слова рвутся:
   раскладываем их в две строки — сверху тариф и состояние, снизу сумма и дата. */
@media (max-width: 560px) {
    .history-row {
        display: grid;
        grid-template-columns: 1fr auto;
        row-gap: 2px;
        padding: 8px 0;
    }

    .history-row span:nth-child(3),
    .history-row span:nth-child(4) {
        color: var(--text-muted);
    }

    .history-row span:nth-child(2),
    .history-row span:nth-child(4) {
        text-align: right;
    }
}

/* ===== Настройки: перенесённые блоки в кабинете ===== */
#cabinet-settings-mount .control-group {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-bottom: 10px;
}

#cabinet-settings-mount .channel {
    background: var(--surface);
}

.settings-notes {
    background: rgba(224, 160, 48, 0.12);
    border: 1px solid rgba(224, 160, 48, 0.3);
    color: #e0a030;
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 12px;
    margin-bottom: 12px;
}

.settings-notes:empty {
    display: none;
}

/* ===== Замки по тарифу ===== */
.locked-control {
    opacity: 0.6;
    position: relative;
}

.lock-icon {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #e0a030;
    font-size: 11px;
    cursor: help;
}

.lock-tip {
    display: block;
    width: 100%;
    font-size: 11px;
    color: #e0a030;
    margin: 3px 0 8px 0;
    line-height: 1.4;
}

.lock-tip a,
.lock-tip button.link-btn {
    color: #e0a030;
    font-size: 11px;
}

/* ===== Скрытые в панели графика блоки — теперь только в кабинете ===== */
.cabinet-only {
    display: none;
}

/* ===== Мобильная адаптация ===== */
@media (max-width: 860px) {
    .header-right {
        gap: 6px;
    }

    .btn-account {
        padding: 6px 10px;
        font-size: 12px;
    }

    /* Вошли — вместо длинной почты круглая кнопка кабинета: справка и тема
       больше не уезжают за край, а название сервиса не перекрывается */
    .btn-account.is-logged {
        width: 36px;
        height: 36px;
        padding: 0;
        border-radius: 50%;
        /* В один вид со справкой и темой: три круглых кнопки на синей шапке */
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.25);
        color: #fff;
    }

    .btn-account.is-logged .btn-account-text {
        display: none;
    }

    .btn-account.is-logged .btn-account-icon {
        display: block;
    }

    /* Пальцем в маленькие значки не попасть — увеличиваем */
    .theme-toggle,
    .help-link {
        width: 36px;
        height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    .modal-box,
    .cabinet-box {
        max-width: 100%;
        width: 100%;
        max-height: calc(100dvh - 16px);
        padding: 14px;
    }

    .cabinet-box {
        --cab-pad: 14px;
    }

    .cabinet-overlay,
    .modal-overlay {
        padding: 8px;
    }

    .billing-plans {
        grid-template-columns: 1fr;
    }

    .cabinet-tab,
    .auth-tab {
        font-size: 11px;
        padding: 8px 4px;
    }

    .account-row {
        flex-wrap: wrap;
    }

    .account-row-value {
        width: 100%;
        order: 2;
    }

    /* Кнопка «Привязать» уходит под значение, а не над ним */
    .account-row .btn-small {
        order: 3;
        width: 100%;
    }
}

/* ===== Cabinet UI: green accent override for primary buttons ===== */
#auth-modal .btn-primary,
#cabinet-screen .btn-primary,
.header-right .btn-primary {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: #fff;
}

#auth-modal .btn-primary:hover,
#cabinet-screen .btn-primary:hover,
.header-right .btn-primary:hover {
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
}

#auth-modal .btn-primary:disabled,
#cabinet-screen .btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}


/* ===== Дополнительный блок в окне входа ===== */
.auth-extra {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.auth-svc-box {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Блок ввода ключа и строки кабинета скрываются атрибутом hidden,
   а display: flex его перебивает — поэтому скрываем явно */
.auth-svc-box[hidden],
.account-row[hidden],
.slot-row[hidden] {
    display: none;
}


/* Таблица пользователей: компактные поля, чтобы кнопка «Выдать» была видна */
.admin-users-table input[type="number"],
.admin-users-table input[type="text"] {
    width: 52px;
    padding: 5px 6px;
    font-size: 12px;
}

.admin-users-table select {
    max-width: 118px;
}

.admin-users-table td:first-child {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-users-table {
    font-size: 11px;
}

.admin-users-table td:last-child,
.admin-users-table th:last-child {
    padding-right: 0;
}

/* ===== Режим мини-приложения Telegram (.tg-app на <body>) =====
   В Телеграме уже есть своя панель сверху (аватар, крестик закрытия), поэтому
   шапку сайта делаем компактнее, а график занимает максимум высоты экрана. */
.tg-app .header {
    padding: 4px 10px;
    height: 40px;
}

/* В мини-приложении экран маленький — легенду с графика тоже убираем */
.tg-app .chart-legend,
.tg-app .mini-legend {
    display: none;
}

.tg-app .header h1 {
    font-size: 11.5px;
    line-height: 1.15;
}

.tg-app .header p {
    display: none;
}

.tg-app .logo {
    width: 20px;
    height: 20px;
}

.tg-app .header-left {
    gap: 8px;
}

/* Кнопка входа скрыта до входа (скрипт ставит hidden), а после входа она становится
   входом в кабинет: настройки, подписка и список инструментов для оповещений. */
.tg-app #account-btn[hidden] {
    display: none;
}

.tg-app #account-btn.tg-cabinet-btn {
    display: inline-flex;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
}

.tg-app #account-btn.tg-cabinet-btn .btn-account-text {
    display: none;
}

.tg-app #account-btn.tg-cabinet-btn .btn-account-icon {
    display: block;
}

.tg-app #build-btn {
    display: none;
}

.tg-app .sidebar {
    padding: 8px;
}

.tg-app .control-group {
    margin-bottom: 8px;
}

.tg-app .chart-container,
.tg-app #chart {
    min-height: 0;
}

/* Узкие экраны Telegram (проверено на ширине 390px) — убираем отступы вокруг графика */
@media (max-width: 360px) {
    .header h1 { font-size: 11px; }
    .header-left { gap: 6px; }
    .header { padding: 8px 10px; }
}

@media (max-width: 480px) {
    .tg-app .main {
        gap: 0;
    }

    .tg-app .header {
        height: auto;
        min-height: 36px;
        padding: 3px 8px;
    }

    /* Две строки названия: высоту шапке добавляем ровно под них, поэтому
       height заменён на min-height — иначе вторая строка обрезалась. */
    .tg-app .header h1 {
        font-size: 11.5px;
        line-height: 1.15;
    }
}

/* ---------- Экран оплаты подписки ---------- */
.billing-pay-box {
    margin: 14px 0;
    padding: 14px 16px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 12px;
    background: rgba(34, 197, 94, 0.06);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.billing-pay-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-weight: 600;
}

.billing-pay-amount {
    font-size: 1.15rem;
    white-space: nowrap;
}

.billing-pay-box .btn {
    align-self: flex-start;
    text-decoration: none;
}

.billing-autopay,
.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.admin-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    font-size: 0.92rem;
    cursor: pointer;
}

/* Готовый текст письма в служебной вкладке: показываем ровно так, как
   он уйдёт людям — с переносами строк и без вольной вёрстки браузера. */
.admin-pre {
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.admin-pre[hidden] {
    display: none;
}

.billing-autopay input,
.admin-check input {
    width: 16px;
    height: 16px;
    flex: none;
}

.billing-pay-box[hidden],
.billing-autopay[hidden] {
    display: none;
}

/* Скидка на первый месяц в кабинете */
.billing-promo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 10px 0;
    padding: 12px 14px;
    border: 1px solid var(--accent, #2dd4bf);
    border-radius: 10px;
    background: rgba(45, 212, 191, 0.08);
}
.billing-promo[hidden] { display: none; }
.billing-promo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.billing-promo .btn { flex: 0 0 auto; }
#billing-trial-note[hidden] { display: none; }

/* Таблица пробных периодов: переносим текст, чтобы кнопка отзыва была видна */
#admin-trials-table { width: 100%; table-layout: fixed; }
#admin-trials-table th,
#admin-trials-table td {
    white-space: normal;
    word-break: break-word;
    font-size: 12px;
    vertical-align: top;
}
#admin-trials-table th:nth-child(1), #admin-trials-table td:nth-child(1) { width: 12%; }
#admin-trials-table th:nth-child(2), #admin-trials-table td:nth-child(2) { width: 16%; }
#admin-trials-table th:nth-child(3), #admin-trials-table td:nth-child(3) { width: 20%; }
#admin-trials-table th:nth-child(4), #admin-trials-table td:nth-child(4) { width: 14%; }
#admin-trials-table th:nth-child(5), #admin-trials-table td:nth-child(5) { width: 20%; }
#admin-trials-table th:nth-child(6), #admin-trials-table td:nth-child(6) { width: 18%; }
#admin-trials-table td:nth-child(6) .btn { white-space: nowrap; padding: 6px 10px; }

/* ===== Инструкция в служебной вкладке ===== */
.owner-guide {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.owner-guide > summary {
    cursor: pointer;
    padding: 12px 14px;
    font-weight: 600;
    font-size: 14px;
    list-style: none;
}

.owner-guide > summary::-webkit-details-marker { display: none; }

.owner-guide > summary::before {
    content: "▸ ";
    color: var(--text-muted);
}

.owner-guide[open] > summary::before { content: "▾ "; }

.owner-guide-body {
    padding: 0 14px 14px;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text);
}

.owner-guide-body .lead { color: var(--text-muted); margin-bottom: 12px; }
.owner-guide-body h3 { font-size: 13.5px; margin: 16px 0 6px; }
.owner-guide-body p { margin-bottom: 10px; }
.owner-guide-body ul,
.owner-guide-body ol { margin: 0 0 12px 20px; }
.owner-guide-body li { margin-bottom: 5px; }
.owner-guide-body .tw { overflow-x: auto; margin-bottom: 12px; }
.owner-guide-body table { border-collapse: collapse; width: 100%; font-size: 13px; }
.owner-guide-body th,
.owner-guide-body td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.owner-guide-body th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.owner-guide-body tbody tr:last-child td { border-bottom: 0; }
.owner-guide-body td:first-child { font-weight: 560; }
.owner-guide-body .note {
    padding: 10px 12px;
    border-left: 3px solid var(--green);
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ===== Плашка о сроке подписки в кабинете ===== */
.sub-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 13px;
    line-height: 1.45;
}

.sub-notice-text {
    flex: 1;
    min-width: 0;
    color: var(--text);
}

/* .btn задаёт ширину 100% — внутри плашки кнопка должна быть по тексту,
   иначе она отжимает надпись и та ломается по одному слову на строку. */
.sub-notice .btn-small {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 6px 14px;
    font-size: 12px;
}

/* Спокойное напоминание — просто факт, без тревоги */
.sub-notice[data-level="info"] {
    border-color: rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.08);
}

/* Срок подходит к концу — нужно внимание */
.sub-notice[data-level="warn"] {
    border-color: rgba(255, 165, 0, 0.45);
    background: rgba(255, 165, 0, 0.1);
}

/* Уже закончилась — самое заметное состояние */
.sub-notice[data-level="alert"] {
    border-color: rgba(239, 83, 80, 0.45);
    background: rgba(239, 83, 80, 0.1);
}

@media (max-width: 560px) {
    .sub-notice {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .sub-notice .btn-small {
        width: 100%;
        flex: 0 0 auto;
    }
}

/* ===== Подвал с реквизитами =====
   Требование платёжного сервиса: реквизиты продавца, контакты и ссылки на
   оферту видны на сайте и не спрятаны. Полоса тонкая, чтобы не отнимать
   место у графика; на узком экране переносится в две строки. */
.site-legal {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
    padding: 7px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 11.5px;
    line-height: 1.5;
}
.site-legal-links,
.site-legal-contacts {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}
.site-legal a {
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dotted var(--border);
}
.site-legal a:hover { color: var(--text); border-bottom-color: var(--text-faint); }
.site-legal-req { color: var(--text); }

/* Обёртка нужна только телефону, где подвал сворачивается. На большом экране
   display: contents делает её прозрачной — раскладка подвала прежняя. */
.site-legal-body { display: contents; }
/* Две строки свежести данных в окне «Откуда котировки» */
.csp-fresh {
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-muted);
}
.csp-fresh[hidden] { display: none; }
.site-legal-toggle { display: none; }

/* ===== Телефон: тикер в шапке вместо названия сервиса =====
   Скрываем только на широком экране: правила для телефона стоят выше по файлу,
   и глобальное display: none их перебивало бы. */
@media (min-width: 861px) {
    .head-ticker { display: none; }
    /* Карандаш прежде прятали на широком экране: панель рисования там стояла
       сбоку всегда, и кнопка была не нужна. Теперь панель спрятана и в
       браузере, поэтому кнопка нужна на любой ширине. */
}

@media (max-width: 720px) {
    /* На телефоне подвал сжат до трёх коротких строк мелким кеглем: реквизиты
       и контакты обязаны остаться видимыми, но графику нужно место. */
    .site-legal {
        gap: 0 8px;
        padding: 4px 10px 5px;
        font-size: 9.5px;
        line-height: 1.35;
    }
    .site-legal a { border-bottom: none; text-decoration: underline; text-decoration-style: dotted; }
    .site-legal-links { order: 1; width: 100%; }
    .site-legal-contacts { order: 2; width: 100%; }
    .site-legal-req { order: 3; width: 100%; }

    /* Свёрнутый подвал: одна строка вместо десяти ссылок и реквизитов */
    .site-legal { flex-direction: column; align-items: stretch; }
    .site-legal-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        width: 100%;
        padding: 3px 0;
        border: none;
        background: none;
        color: var(--text-muted);
        font-size: 10.5px;
        cursor: pointer;
    }
    .site-legal-caret { transition: transform 150ms ease; }
    .site-legal-toggle[aria-expanded="true"] .site-legal-caret { transform: rotate(180deg); }
    .site-legal-body {
        display: flex;
        flex-direction: column;
        gap: 3px;
        padding-top: 3px;
    }
    .site-legal-body[hidden] { display: none; }
}

/* Строка условий над кнопкой оплаты */
.billing-legal { margin-top: 10px; line-height: 1.6; }
.billing-legal a { color: var(--primary); text-decoration: none; border-bottom: 1px dotted currentColor; }

/* Уровни инструментов на вкладке «Администратор» */
.admin-details {
    margin-top: 12px;
}

.admin-details > summary {
    cursor: pointer;
    font-weight: 600;
    padding: 6px 0;
}

/* Свёрнутый служебный блок: заголовок выглядит как <h3> раздела, но у него
   есть галочка открытия и закрытия — иначе вкладка растягивается на экраны. */
.admin-fold {
    margin-top: 0;
}

.admin-fold > summary {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0;
    margin-bottom: 8px;
}

.admin-fold[open] > summary {
    color: var(--text);
}

.admin-levels-versions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    font-size: 13px;
}

.admin-levels-version {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border: 1px solid var(--border, #2a3140);
    border-radius: 8px;
}

.admin-levels-table {
    margin-top: 8px;
    font-size: 13px;
}

.admin-levels-table td {
    white-space: nowrap;
}

.levels-ticker {
    opacity: 0.65;
}

/* Редактор уровней инструментов (служебная вкладка) */
.admin-levels-form {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin: 10px 0 14px;
    background: var(--surface-2, rgba(127, 127, 127, .06));
}
.admin-levels-period { margin: 10px 0; }
.admin-levels-period > label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}
.admin-levels-cells {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 6px;
}
.admin-levels-cell {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}
.admin-levels-editor-list { margin-top: 8px; }
.admin-levels-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.admin-levels-row:last-of-type { border-bottom: 0; }
@media (max-width: 640px) {
    .admin-levels-cells { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .admin-levels-row { flex-wrap: wrap; }
}

/* ---- Оповещения от сервера: общий список бумаг и свои алерты ---- */
.watch-block {
    margin-top: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2, rgba(255, 255, 255, 0.02));
}
.watch-title {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
}
.custom-alert-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 10px 0;
}
.custom-alert-form select,
.custom-alert-form input[type="number"],
.custom-alert-form input[type="text"] {
    flex: 1 1 140px;
    min-width: 110px;
}
.custom-alert-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.custom-alert-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}
.custom-alert-row.off { opacity: 0.6; }
/* Кнопки строки не должны растягиваться на всю ширину: текст алерта важнее */
.custom-alert-row .btn,
.custom-alert-form .btn {
    flex: 0 0 auto;
    width: auto;
}
.custom-alert-row span { flex: 1 1 200px; }
.admin-watch-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    max-height: 260px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.admin-watch-list .checkbox-label { flex: 0 1 220px; font-size: 13px; }
@media (max-width: 640px) {
    .custom-alert-form select,
    .custom-alert-form input { flex: 1 1 100%; }
    .admin-watch-list .checkbox-label { flex: 1 1 100%; }
}


/* Несколько графиков рядом — только браузер на большом экране */
@media (max-width: 860px) {
    .chart-grid { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; }
}

.tg-app .chart-grid { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; }

/* В тесной сетке легенда остаётся, но становится короткой строкой:
   вместо «Часовые» — «1ч», заголовок и длинный текст про зоны убираются */
.chart-grid[data-layout="2"] #chart > .chart-legend,
.chart-grid[data-layout="4"] #chart > .chart-legend {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px 7px;
    bottom: 24px;
    left: 8px;
    padding: 2px 6px;
    max-width: calc(100% - 100px);
    opacity: 0.9;
}

.chart-grid[data-layout="2"] .chart-legend .legend-head,
.chart-grid[data-layout="4"] .chart-legend .legend-head,
.chart-grid[data-layout="2"] .chart-legend .legend-full,
.chart-grid[data-layout="4"] .chart-legend .legend-full {
    display: none;
}

.chart-grid[data-layout="2"] .chart-legend .legend-short,
.chart-grid[data-layout="4"] .chart-legend .legend-short {
    display: inline;
}

.chart-grid[data-layout="2"] .chart-legend .legend-zone,
.chart-grid[data-layout="4"] .chart-legend .legend-zone {
    max-width: none;
    margin-top: 0;
    align-items: center;
}

.chart-grid[data-layout="4"] #chart > .chart-legend .legend-item {
    font-size: 9px;
}

/* В сетке 2 и 4 графиков подробная строка под названием не влезает — прячем,
   всё это видно в боковой панели */
.chart-grid[data-layout="2"] .chart-title-meta,
.chart-grid[data-layout="4"] .chart-title-meta {
    display: none;
}

/* ===== Дополнительный график: свои настройки и рисование ===== */
.mini-head .mini-btn {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
}

.mini-head .mini-btn svg {
    width: 14px;
    height: 14px;
}

.mini-head .mini-btn:hover {
    color: var(--text);
}

.mini-head .mini-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Окошко настроек панели */
.mini-opts {
    position: absolute;
    top: 32px;
    right: 6px;
    z-index: 20;
    width: 226px;
    max-height: calc(100% - 44px);
    overflow-y: auto;
    padding: 8px 9px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    font-size: 11px;
    color: var(--text);
}

.mini-opts-own {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 6px;
}

.mini-opts-body.off {
    opacity: 0.5;
}

.mini-opts-label {
    color: var(--text-muted);
}

.mini-opts-periods {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 3px 0 7px;
}

.mini-opts-check {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.mini-opts-check input {
    margin: 0;
}

/* Пояснение в окошке настроек панели, когда включена «скрепка» */
.mini-opts-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
    margin-bottom: 6px;
}

/* Галочка индикатора объёма стоит отдельной строкой под остальными настройками */
.mini-opts-volume {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.mini-opts-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.mini-opts-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 5px;
}

.mini-opts-select {
    flex: 0 0 auto;
    width: 104px;
    height: 24px;
    min-height: 24px;
    padding: 0 4px;
    font-size: 11px;
    border-radius: 4px;
}

.mini-opts-close {
    width: 100%;
    margin-top: 3px;
    padding: 5px 0;
    font-size: 11px;
    border: none;
    border-radius: 5px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}

/* Панель рисования внутри дополнительного графика — компактнее главной */
.draw-panel.mini-draw {
    padding: 3px;
    gap: 1px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

/* Сбоку панель прижимаем к левому краю, сверху и снизу — оставляем по центру */
.draw-panel.mini-draw.pos-side {
    left: 6px;
}

.draw-panel.mini-draw .draw-tool {
    width: 22px;
    height: 22px;
    border-radius: 5px;
}

.draw-panel.mini-draw .draw-tool svg {
    width: 13px;
    height: 13px;
}

.draw-panel.mini-draw .draw-swatch {
    width: 11px;
    height: 11px;
}

.draw-panel.mini-draw.pos-top { top: 24px; }
.draw-panel.mini-draw.pos-bottom { bottom: 26px; }

/* Кнопка перехода на график из отчёта о правке уровней */
.levels-show-btn {
    display: block;
    margin-top: 6px;
}

/* Проверка автоматического расчёта: подсветка расхождений с таблицей */
.levels-diff-bad {
    background: rgba(214, 69, 69, 0.14);
    color: var(--text);
    font-weight: 600;
}
.levels-diff-row td:first-child {
    border-left: 3px solid rgba(214, 69, 69, 0.75);
}
.admin-diff-cell {
    max-width: 17rem;
    white-space: normal;
    word-break: break-word;
    vertical-align: top;
}
.admin-diff-cell .hint { display: block; line-height: 1.35; }
.admin-step-digits,
.admin-step-value {
    width: 7rem;
    max-width: 100%;
}

/* Кнопка быстрого создания своего алерта — поверх графика, видна и на телефоне */
.quick-alert-btn {
    position: absolute;
    right: 14px;
    bottom: 16px;
    z-index: 6;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 0.86rem;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.quick-alert-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.quick-alert-btn svg { width: 17px; height: 17px; }
.quick-alert-btn[hidden] { display: none; }
@media (max-width: 760px) {
    .quick-alert-btn {
        right: 10px;
        /* поднимаем над панелью рисования, иначе она закрывает кнопку */
        bottom: 76px;
        padding: 9px 14px;
    }
    .quick-alert-btn span { display: none; }
}
/* Подсветка формы, когда её открыли кнопкой у графика */
.custom-alert-highlight {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
    border-radius: 8px;
}

/* Уровни из терминала MetaTrader в служебной вкладке. */
.admin-tas-row {
    margin: 10px 0 14px;
    padding: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.admin-tas-row p {
    margin: 0 0 4px;
    font-size: 13px;
}

/* Правка выгрузки: добавить, изменить или убрать инструмент. */
.admin-tas-editor {
    margin: 12px 0;
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
}

.admin-tas-editor h4 {
    margin: 0 0 6px;
    font-size: 14px;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin: 8px 0;
}

.admin-grid label,
.admin-tas-level label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}

.admin-tas-level {
    margin: 6px 0;
}

.admin-tas-off {
    opacity: 0.6;
}

.admin-tas-row .admin-actions {
    margin-top: 6px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 6px;
}

.admin-table th,
.admin-table td {
    padding: 4px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.admin-table th {
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.admin-table td:last-child {
    font-variant-numeric: tabular-nums;
    word-break: break-word;
}

@media (max-width: 640px) {
    .admin-table {
        font-size: 11px;
    }
}

/* ===== Обозреватель бумаг ===== */
/* Родной список остаётся в разметке хранителем значения, но не виден */
.inst-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.inst-open {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    padding: 9px 10px;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition);
}

.inst-open:hover {
    border-color: #22c55e;
}

.inst-open-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inst-open-caret {
    color: var(--text-muted);
    font-size: 11px;
}

.inst-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 95;
    padding: 16px;
}

.inst-overlay[hidden] {
    display: none;
}

.inst-box {
    --inst-pad: 14px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 520px;
    max-height: min(80vh, 640px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.inst-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: var(--inst-pad);
    border-bottom: 1px solid var(--border);
}

.inst-search {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 9px 11px;
}

.inst-search:focus {
    outline: none;
    border-color: #22c55e;
}

.inst-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px var(--inst-pad) 0;
}

.inst-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 12px;
    padding: 5px 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
}

.inst-chip:hover {
    color: var(--text);
}

.inst-chip.active {
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.5);
    color: #22c55e;
}

.inst-chip-num {
    opacity: 0.65;
    margin-left: 4px;
}

.inst-toolrow {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px var(--inst-pad);
}

.inst-count {
    flex: 1;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}

.inst-sort-label {
    color: var(--text-muted);
    font-size: 12px;
}

.inst-sort {
    flex: none;
    max-width: 190px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 12px;
    padding: 5px 7px;
}

.inst-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--inst-pad) 4px;
    -webkit-overflow-scrolling: touch;
}

.inst-group {
    position: sticky;
    top: 0;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 8px 2px 4px;
    z-index: 1;
}

.inst-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 6px;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    font-family: var(--font-body);
}

.inst-row:hover,
.inst-row.is-cursor {
    background: var(--surface-2);
}

.inst-row.is-current {
    background: rgba(34, 197, 94, 0.12);
}

.inst-star {
    flex: none;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 0;
}

.inst-star:hover {
    color: #eab308;
    background: var(--surface-2);
}

.inst-star.is-on {
    color: #eab308;
}

.inst-main {
    flex: 1;
    min-width: 0;
}

.inst-name {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inst-sub {
    color: var(--text-muted);
    font-size: 11px;
    display: flex;
    gap: 6px;
    align-items: center;
}

.inst-lock {
    flex: none;
    color: var(--text-muted);
    font-size: 12px;
}

.inst-alerts {
    flex: none;
    color: #22c55e;
    font-size: 11px;
}

.inst-more {
    flex: none;
    width: 26px;
    height: 26px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 0;
}

.inst-more:hover {
    color: var(--text);
    background: var(--surface-2);
}

.inst-picker {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 2px 6px 8px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inst-picker-title {
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.inst-picker label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    cursor: pointer;
}

.inst-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 18px 6px;
    text-align: center;
}

.inst-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding: 10px var(--inst-pad);
    color: var(--text-muted);
    font-size: 12px;
}

.inst-foot-note {
    flex: 1;
    min-width: 140px;
}

.inst-foot .btn-small {
    flex: none;
    font-size: 12px;
    padding: 6px 10px;
}

.inst-picker .hint {
    font-size: 12px;
    margin: 0;
}

@media (max-width: 640px) {
    .inst-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .inst-box {
        max-width: 100%;
        max-height: 92dvh;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        border-bottom: none;
    }

    .inst-row {
        padding: 11px 6px;
    }

    .inst-star,
    .inst-more {
        width: 32px;
        height: 32px;
    }
}

/* ===== Быстрый алерт поверх графика ===== */
.qa-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 96;
    padding: 16px;
}

.qa-overlay[hidden] {
    display: none;
}

.qa-box {
    --qa-pad: 16px;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 400px;
    max-height: min(86vh, 700px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.qa-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px var(--qa-pad);
    border-bottom: 1px solid var(--border);
}

.qa-tabs {
    display: flex;
    gap: 6px;
    flex: 1;
}

.qa-tab {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 13px;
    padding: 6px 12px;
    cursor: pointer;
}

.qa-tab.active {
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.5);
    color: #22c55e;
}

.qa-panel {
    padding: var(--qa-pad);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.qa-panel[hidden] {
    display: none;
}

.qa-field {
    margin-bottom: 12px;
}

.qa-field > label {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 5px;
}

.qa-field select,
.qa-field input[type="text"] {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 9px 10px;
}

.qa-price-row {
    display: flex;
    gap: 6px;
}

.qa-price-row input {
    flex: 1;
    text-align: center;
    font-size: 17px !important;
    font-weight: 600;
}

.qa-step {
    flex: none;
    width: 42px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
}

.qa-step:hover {
    border-color: #22c55e;
    color: #22c55e;
}

.qa-hint {
    color: var(--text-muted);
    font-size: 11px;
    margin: 5px 0 0;
}

.qa-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 10px;
}

.qa-msg {
    font-size: 12px;
    margin: 0 0 10px;
    color: var(--text-muted);
    min-height: 16px;
}

.qa-msg.is-bad {
    color: #ef4444;
}

.qa-msg.is-good {
    color: #22c55e;
}

.qa-submit {
    width: 100%;
}

.qa-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding: 9px 0;
}

.qa-row:last-child {
    border-bottom: none;
}

.qa-row.off {
    opacity: 0.55;
}

.qa-row-main {
    flex: 1;
    min-width: 0;
}

.qa-row-title {
    font-size: 13px;
}

.qa-row-sub {
    color: var(--text-muted);
    font-size: 11px;
}

.qa-row-btn {
    flex: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    padding: 5px 8px;
    cursor: pointer;
}

.qa-row-btn:hover {
    color: var(--text);
    border-color: #22c55e;
}

@media (max-width: 640px) {
    .qa-overlay {
        align-items: flex-end;
        padding: 0;
        /* Окно алертов не доходит до самого низа: полоса с реквизитами и
           ссылками на тарифы должна оставаться видимой */
        bottom: calc(var(--legal-h, 0px) + env(safe-area-inset-bottom, 0px));
    }

    .qa-box {
        max-width: 100%;
        max-height: 84dvh;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        border-bottom: none;
    }

    .qa-step {
        width: 48px;
        height: 44px;
    }
}

/* ===== Полоса рабочего списка ===== */
/* Перебор бумаг своего списка — частое действие, поэтому оно вынесено из
   обозревателя: полоса всегда над графиком, одно нажатие меняет бумагу. */
.list-strip {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    min-width: 0;
}

.strip-list {
    flex: 0 0 auto;
    max-width: 190px;
    height: 26px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

.strip-arrow,
.strip-more {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition);
}

.strip-arrow:hover,
.strip-more:hover {
    color: var(--text);
    border-color: var(--primary);
}

.strip-arrow:disabled {
    opacity: 0.4;
    cursor: default;
}

.strip-items {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
}

.strip-items::-webkit-scrollbar {
    display: none;
}

.strip-chip {
    flex: 0 0 auto;
    height: 26px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-mono);
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.strip-chip:hover {
    color: var(--text);
    border-color: var(--primary);
}

.strip-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.strip-chip .strip-chip-mark {
    margin-left: 4px;
    font-family: var(--font-body);
    font-size: 10px;
}

.strip-empty {
    color: var(--text-faint);
    font-size: 12px;
    white-space: nowrap;
}

/* Столбик списка в левой панели: там есть место на названия бумаг */
.side-strip {
    margin-top: 6px;
    max-height: 216px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.side-strip:empty {
    display: none;
}

.side-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    width: 100%;
    padding: 5px 8px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.side-row:last-child {
    border-bottom: none;
}

.side-row:hover {
    background: var(--surface-3);
}

.side-row.active {
    background: var(--primary);
    color: #fff;
}

.side-row-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-row-ticker {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-muted);
}

.side-row.active .side-row-ticker {
    color: rgba(255, 255, 255, 0.85);
}

@media (max-width: 640px) {
    .list-strip {
        padding: 4px 6px;
        gap: 4px;
    }

    .strip-list {
        max-width: 120px;
        font-size: 11px;
    }

    /* На узком экране стрелки лишние: полоса и так прокручивается пальцем */
    .strip-arrow {
        display: none;
    }
}

/* ===== Панель масштаба в дополнительном графике ===== */
/* Та же полоса, что на главном графике, только компактнее: в панели мало места,
   поэтому кнопки мельче и стоят в правом верхнем углу. */
.mini-toolbar {
    position: absolute;
    top: 3px;
    right: 46px;
    z-index: 9;
    display: flex;
    gap: 1px;
    padding: 1px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    opacity: 0.85;
    transition: opacity var(--transition);
}

.mini-panel:hover .mini-toolbar,
.mini-toolbar:focus-within {
    opacity: 1;
}

.mini-toolbar-btn {
    padding: 2px 5px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    font-size: 10px;
    font-family: var(--font-body);
    line-height: 1.2;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.mini-toolbar-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.mini-toolbar-btn.active {
    background: var(--primary);
    color: #fff;
}

/* Четыре графика: панель ещё компактнее, чтобы не наезжать на название */
.chart-grid[data-layout="4"] .mini-toolbar {
    right: 40px;
    opacity: 0.8;
}

.chart-grid[data-layout="4"] .mini-toolbar-btn {
    padding: 2px 4px;
    font-size: 10px;
}

@media (max-width: 640px) {
    .mini-toolbar {
        opacity: 1;
        right: 40px;
    }
}

/* ===== Окно «Скрепка — своя раскладка» ===== */
.link-box {
    max-width: 620px;
}

.link-use {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    margin-bottom: 6px;
}

.link-use input {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.link-tabs {
    display: flex;
    gap: 6px;
    margin: 10px 0;
}

.link-tab {
    flex: 1;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.link-tab:hover {
    color: var(--text);
}

.link-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.link-slot {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px 10px;
    margin-bottom: 8px;
    background: var(--surface-2);
}

.link-slot-head {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.link-slot-head span {
    font-weight: 400;
    color: var(--text-muted);
}

.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 6px 10px;
}

.link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.link-row select {
    flex: 1;
    min-width: 0;
    max-width: 96px;
    padding: 3px 4px;
    font-size: 11px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.link-periods {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 7px;
}

.link-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
}

.link-check input {
    width: 13px;
    height: 13px;
    accent-color: var(--primary);
}

.link-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

#link-slots.off {
    opacity: 0.45;
    pointer-events: none;
}

.link-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

@media (max-width: 640px) {
    .link-actions {
        flex-wrap: wrap;
    }
}

/* Выбор режима: по каким бумагам сервер шлёт оповещения */
#watch-mode {
    width: 100%;
    margin-bottom: 4px;
}

#watch-mode-hint {
    margin-bottom: 4px;
}

/* Кнопки «Добавить» и «Из избранного» — одной строкой */
.tg-watch-add-row .btn-small {
    flex: 1 1 auto;
    min-width: 120px;
}

/* ===== Статусы своих алертов: активен, сработал, на паузе, истёк, отменён ===== */
.alert-badge {
    display: inline-block;
    flex: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 11px;
    line-height: 17px;
    white-space: nowrap;
    color: var(--text-muted);
    background: var(--surface-2);
}

.alert-badge-active {
    color: var(--green);
    border-color: color-mix(in srgb, var(--green) 45%, transparent);
    background: color-mix(in srgb, var(--green) 12%, transparent);
}

.alert-badge-triggered {
    color: var(--primary);
    border-color: color-mix(in srgb, var(--primary) 45%, transparent);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.alert-badge-expired,
.alert-badge-cancelled {
    color: var(--text-faint);
}

.qa-row-status {
    display: block;
    margin: 2px 0;
}

.qa-row-fired {
    font-size: 11px;
    color: var(--text-muted);
}

.qa-row-link {
    background: none;
    border: none;
    padding: 0;
    font-size: 11px;
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}

.qa-row-hist .qa-row-main {
    padding-right: 4px;
}

.qa-row-mark {
    background: color-mix(in srgb, var(--primary) 8%, transparent);
}

/* Короткая форма алерта: тонкие настройки спрятаны под «Дополнительно» */
.qa-more {
    border-top: 1px solid var(--border);
    margin-top: 10px;
    padding-top: 8px;
}

.qa-more > summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    list-style: none;
    padding: 4px 0;
}

.qa-more > summary::-webkit-details-marker {
    display: none;
}

.qa-more > summary::before {
    content: '▸ ';
}

.qa-more[open] > summary::before {
    content: '▾ ';
}

/* Строка алерта в кабинете: плашка статуса слева от текста */
.custom-alert-row .alert-badge {
    margin-right: 6px;
}

/* ===== Панель ближайших уровней =====
   Список уровней вокруг текущей цены: сколько до уровня, какой таймфрейм,
   сколько уровней рядом. По нажатию открывается карточка уровня с кнопкой
   «Поставить алерт сюда». Панель лежит поверх графика справа и закрывается
   крестиком, поэтому не отнимает место у свечей. */
.levels-panel-btn {
    position: absolute;
    right: 14px;
    bottom: 60px;
    /* выше слоя рисования (z-index: 8), иначе подписи цен видны сквозь панель */
    z-index: 12;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 0.86rem;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.levels-panel-btn:hover { border-color: var(--primary); color: var(--primary); }
.levels-panel-btn svg { width: 17px; height: 17px; }
.levels-panel-btn[hidden] { display: none; }
.levels-panel-btn[aria-expanded="true"] { border-color: var(--primary); color: var(--primary); }

.levels-panel {
    position: absolute;
    right: 14px;
    /* Отсчёт от низа полосы значков, а не от верха области графика. Панель
       лежит внутри той же области, что и полоса, и с фиксированным top: 14px
       накрывала её правый край: значки «Карта зон 8levels» и карандаш
       оставались видимыми, но нажатие уходило в панель — со стороны это
       выглядело как мёртвая кнопка. Высоту полосы пишет в --topbar-h код
       (она меняется от ширины окна: значки переносятся на вторую строку). */
    top: calc(var(--topbar-h, 0px) + 14px);
    bottom: 100px;
    width: 290px;
    max-width: calc(100% - 28px);
    z-index: 12;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
    overflow: hidden;
}
.levels-panel[hidden] { display: none; }
.lp-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: 11px 12px 8px;
    border-bottom: 1px solid var(--border);
}
.lp-title b { display: block; font-size: 0.94rem; }
.lp-sub { display: block; margin-top: 2px; font-size: 0.76rem; color: var(--text-muted); }
/* Короткая пометка про скрытые значения в шапке панели «Уровни рядом».
   Курсор-подсказка несёт полный текст: в узкой шапке телефона длинная
   строка переносилась бы на три ряда и съедала первый экран списка. */
.lp-hidden-note {
    display: block;
    margin-top: 2px;
    font-size: 0.72rem;
    color: var(--warn, var(--text-muted));
    cursor: help;
}
.lp-close {
    border: 0; background: none; color: var(--text-muted);
    font-size: 0.95rem; cursor: pointer; padding: 2px 4px; line-height: 1;
}
.lp-close:hover { color: var(--text); }
.lp-sorts { display: flex; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.lp-sort {
    flex: 1; padding: 5px 6px; border: 1px solid var(--border); border-radius: 8px;
    background: transparent; color: var(--text-muted); font: inherit; font-size: 0.74rem;
    cursor: pointer; white-space: nowrap;
}
.lp-sort:hover { color: var(--text); }
.lp-sort.active { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }
.lp-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.lp-row {
    display: grid;
    grid-template-columns: 9px 1fr auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 12px;
    border: 0;
    border-left: 2px solid transparent;
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.lp-row:hover { background: var(--surface-2); }
.lp-row.active { background: var(--surface-2); border-left-color: var(--primary); }
.lp-dot { width: 9px; height: 9px; border-radius: 50%; }
.lp-price { font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.lp-meta { display: block; font-size: 0.72rem; color: var(--text-muted); margin-top: 1px; }
.lp-dist { font-size: 0.78rem; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.lp-dist.up { color: var(--danger, #ef4444); }
.lp-dist.down { color: var(--success, #22c55e); }
.lp-here {
    padding: 5px 12px; margin: 3px 0;
    font-size: 0.72rem; color: var(--primary);
    border-top: 1px dashed var(--border); border-bottom: 1px dashed var(--border);
    font-variant-numeric: tabular-nums;
}
.lp-card {
    border-top: 1px solid var(--border);
    padding: 10px 12px 12px;
    background: var(--surface-2);
}
.lp-card[hidden] { display: none; }
.lp-card-price { font-size: 1.02rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.lp-card-list { margin: 7px 0 9px; display: grid; gap: 3px; }
.lp-card-list div { display: flex; justify-content: space-between; gap: 10px; font-size: 0.77rem; }
.lp-card-list span:first-child { color: var(--text-muted); }
.lp-card-list span:last-child { font-variant-numeric: tabular-nums; }
.lp-card-btn {
    width: 100%; padding: 8px 10px; border: 0; border-radius: 9px;
    background: var(--primary); color: #fff; font: inherit; font-size: 0.83rem; cursor: pointer;
}
.lp-card-btn:hover { filter: brightness(1.06); }
.lp-foot { margin: 0; padding: 7px 12px; font-size: 0.71rem; color: var(--text-muted); border-top: 1px solid var(--border); }
.lp-empty { padding: 16px 12px; font-size: 0.8rem; color: var(--text-muted); text-align: center; }

/* ----- Ключевые уровни -----
   Две карточки на первом экране: ближайшая поддержка и ближайшее
   сопротивление. Цвет — только тонкая полоса слева: цветная заливка
   всей карточки на телефоне рябит и мешает читать цифры. */
.lp-key { padding: 10px 12px 4px; }
.lp-key-title {
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-muted);
}
.lp-key-price {
    margin-top: 2px; font-size: 0.78rem; color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.lp-kcard {
    margin-top: 8px; padding: 8px 10px;
    border: 1px solid var(--border); border-left-width: 3px; border-radius: 10px;
    background: var(--surface-2); cursor: pointer;
}
.lp-kcard:hover { border-color: var(--primary); }
.lp-kcard.sup { border-left-color: var(--green); }
.lp-kcard.res { border-left-color: var(--red); }
.lp-khead {
    display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
    font-size: 0.76rem; color: var(--text-muted);
}
.lp-ktf { font-size: 0.72rem; }
.lp-kprice {
    margin: 2px 0 6px; font-size: 1.02rem; font-weight: 600;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.lp-krow { display: flex; justify-content: space-between; gap: 10px; font-size: 0.77rem; }
.lp-krow span:first-child { color: var(--text-muted); }
.lp-krow span:last-child { font-variant-numeric: tabular-nums; }
.lp-kempty {
    margin-top: 8px; padding: 8px 10px; border: 1px dashed var(--border); border-radius: 10px;
    font-size: 0.76rem; color: var(--text-muted);
}

/* Полный список лежит под складкой и растягивается только в раскрытом
   виде, иначе закрытая складка съедала бы всю высоту панели. */
.lp-all { display: flex; flex-direction: column; min-height: 0; }
/* min-height: 0 и overflow — не украшение: без них список внутри складки
   растёт за край панели и наезжает на подвал с числом уровней. */
.lp-all[open] { flex: 1; overflow: hidden; }
.lp-all > .lp-list { flex: 1; min-height: 0; overflow-y: auto; }

/* Список внутри раскрытой складки не прокручивался, и низ его уходил под
   подвал панели: свежие браузеры (Chrome 131 и новее) заворачивают
   содержимое <details> в скрытый блок ::details-content, и цепочка
   «панель → складка → список» рвалась на нём. Этот блок — обычный блочный
   контейнер по высоте содержимого, поэтому список получал всю нужную ему
   высоту, считал, что прокручивать нечего, и обрезался внешним overflow.
   Делаем обёртку такой же колонкой с нулевой минимальной высотой, как и
   остальные звенья, — тогда высоту задаёт панель, а лишнее прокручивается.
   В браузерах без ::details-content (Safari, старый Chrome) правило просто
   игнорируется: там содержимое лежит прямыми детьми складки и работает по
   правилам выше. */
.lp-all[open]::details-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}
.lp-all > summary {
    padding: 9px 12px; border-top: 1px solid var(--border);
    font-size: 0.78rem; color: var(--text-muted); cursor: pointer; user-select: none;
}
.lp-all > summary:hover { color: var(--text); }
.lp-all[open] > summary { color: var(--text); }

/* ===== Карта уровней 8levels =====
   Панель повторяет устройство «Уровней рядом» (тот же класс .levels-panel),
   но живёт по своим правилам: строк-кнопок здесь нет, потому что нажимать
   не на что — карточка уровня показывает расстояние до цены, а цены нет.
   Уровни идут группами по таймфреймам, сверху вниз, как линии на графике. */
.lm-warn {
    margin: 0;
    padding: 9px 12px;
    font-size: 0.74rem;
    line-height: 1.4;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.lm-warn[hidden] { display: none; }
/* Пометки в подвале: резервный набор и устаревшая разметка. Устаревание
   выделено цветом предупреждения — это единственное место, где человек
   узнает, что линии считались слишком давно. */
.lm-note { margin-top: 5px; line-height: 1.4; }
.lm-note-stale { color: var(--danger, #d64545); font-weight: 500; }
.lm-group { padding: 6px 0 2px; }
.lm-group + .lm-group { border-top: 1px solid var(--border); }
.lm-group-head {
    display: flex; align-items: center; gap: 7px;
    padding: 4px 12px 5px;
    font-size: 0.75rem; color: var(--text-muted);
}
.lm-group-head b { color: var(--text); font-size: 0.82rem; font-weight: 600; }
.lm-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.lm-values { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; padding: 0 12px 7px; }
.lm-val { font-size: 0.85rem; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
    .levels-panel-btn { right: 10px; bottom: 124px; padding: 9px 14px; }
    .levels-panel { left: 10px; right: 10px; top: 10px; bottom: 76px; width: auto; }
}

/* ===== Откуда котировки: плашка прямо на графике =====
   Раньше источник данных был виден только в кабинете, и человек не понимал,
   почему цена отличается от терминала. Плашка стоит в углу графика и
   по нажатию объясняет, что даёт свечи, что цену и какая задержка. */
.chart-source {
    position: absolute;
    left: 14px;
    bottom: 16px;
    z-index: 12;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: min(320px, calc(100% - 28px));
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}
.chart-source:hover { color: var(--text); border-color: var(--primary); }
/* На большом экране кнопка с подписью — значок не нужен */
.cs-glyph { display: none; }
.chart-source[hidden] { display: none; }
.cs-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; flex: none; }
.chart-source.warn .cs-dot { background: #f59e0b; }
.chart-source.off .cs-dot { background: #ef4444; }
.cs-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-q {
    flex: none; width: 14px; height: 14px; border-radius: 50%;
    border: 1px solid currentColor; font-size: 0.62rem; line-height: 12px; text-align: center;
    opacity: 0.75;
}

/* В браузере плашка источника дублировала полосу свежести и постоянно
   писала про MetaTrader, хотя агент живёт на отдельном компьютере.
   На большом экране прячем её: источник и так написан в чипе «Цена: …»,
   а окно «Откуда котировки» открывается нажатием на этот же чип.
   На телефоне и в Телеграме плашка остаётся — там она только значок в шапке. */
@media (min-width: 861px) {
    .chart-topbar .chart-source { display: none; }
    .data-fresh #df-price { cursor: pointer; }
    .data-fresh #df-price:hover { border-color: var(--primary); }
}

.chart-source-pop {
    position: absolute;
    left: 14px;
    bottom: 52px;
    z-index: 13;
    width: 300px;
    max-width: calc(100% - 28px);
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
    overflow: hidden;
}
.chart-source-pop[hidden] { display: none; }
.csp-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
.csp-close { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 0.9rem; line-height: 1; }
.csp-close:hover { color: var(--text); }
.csp-body { padding: 10px 12px; display: grid; gap: 7px; font-size: 0.79rem; }
.csp-row { display: flex; justify-content: space-between; gap: 12px; }
.csp-row span:first-child { color: var(--text-muted); flex: none; }
.csp-row span:last-child { text-align: right; }
.csp-note { color: var(--text-muted); line-height: 1.45; }
.csp-link {
    width: 100%; padding: 9px 10px; border: 0; border-top: 1px solid var(--border);
    background: none; color: var(--primary); font: inherit; font-size: 0.8rem; cursor: pointer;
}
.csp-link:hover { background: var(--surface-2); }

@media (max-width: 760px) {
    .chart-source { left: 10px; bottom: 76px; font-size: 0.72rem; max-width: calc(100% - 130px); }
    .chart-source-pop { left: 10px; right: 10px; width: auto; bottom: 112px; }
}

/* Подсветка блока настроек, к которому нас перебросили из пояснения об источнике */
.control-group.flash {
    animation: flash-block 1.6s ease;
    border-radius: 10px;
}
@keyframes flash-block {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
    25% { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.45); }
}

/* ===== Быстрый старт =====
   Новичок видит график, но не понимает, что с ним делать. Тур подсвечивает
   по одной кнопке за раз и объясняет её одним предложением. */
.tour-start {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px solid var(--primary);
    border-radius: 10px;
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.tour-start:hover { background: color-mix(in srgb, var(--primary) 20%, transparent); }
.tour-start-icon { color: var(--primary); font-size: 0.7rem; }

.tour { position: fixed; inset: 0; z-index: 3000; }
.tour[hidden] { display: none; }
.tour-mask {
    position: fixed;
    background: rgba(3, 7, 12, 0.66);
    pointer-events: auto;
}
.tour-hole {
    position: fixed;
    border-radius: 12px;
    border: 2px solid var(--primary);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.22);
    transition: all 0.2s ease;
    pointer-events: none;
}
.tour-hole[hidden] { display: none; }
.tour-card {
    position: fixed;
    width: 330px;
    max-width: calc(100vw - 24px);
    padding: 16px 18px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}
.tour-step { color: var(--text-muted); font-size: 0.72rem; margin-bottom: 6px; }
.tour-title { margin: 0 0 6px; font-size: 1rem; }
.tour-text { margin: 0 0 14px; color: var(--text-muted); font-size: 0.85rem; line-height: 1.5; }
.tour-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tour-nav { display: flex; gap: 8px; }
.tour-skip {
    border: 0; background: none; color: var(--text-muted); font: inherit; font-size: 0.8rem; cursor: pointer;
}
.tour-skip:hover { color: var(--text); }
.tour-back, .tour-next {
    padding: 8px 14px; border-radius: 9px; font: inherit; font-size: 0.82rem; cursor: pointer;
}
.tour-back { border: 1px solid var(--border); background: none; color: var(--text); }
.tour-back:hover { border-color: var(--primary); }
.tour-back[hidden] { display: none; }
.tour-next { border: 0; background: var(--primary); color: #04150c; font-weight: 600; }
.tour-next:hover { filter: brightness(1.08); }

@media (max-width: 760px) {
    .tour-card { width: auto; left: 12px; right: 12px; }
}

/* ===== Где держать панель уровней =====
   Поверх графика панель закрывала свечи, а в режимах 2 и 4 графиков закрывала
   целую панель. Поэтому по умолчанию она встаёт сбоку: область графиков
   ужимается на ширину панели, и ничего не перекрывается. Ужатие сделано
   отступом у .chart-area — панель лежит absolute в освободившейся полосе,
   а наблюдатель размера сам перерисовывает графики. */
.chart-area.lp-dock-right { padding-right: 306px; }
.chart-area.lp-dock-left { padding-left: 306px; }
.levels-panel.dock-left { left: 14px; right: auto; }
.levels-panel.dock-right { right: 14px; left: auto; }
.levels-panel.dock-float { box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); }

/* Снизу — полосой во всю ширину под графиком. Так ширина остаётся у свечей:
   уровни сравнивают глазами с ценой, и узкий график мешает этому сильнее,
   чем невысокая полоса списка. Область графиков ужимается по высоте. */
.chart-area.lp-dock-bottom { padding-bottom: 258px; }
.levels-panel.dock-bottom {
    left: 14px;
    right: 14px;
    top: auto;
    bottom: 14px;
    width: auto;
    max-width: none;
    height: 238px;
}
/* В полосе снизу места по горизонтали много, а по вертикали мало: ключевые
   карточки встают рядом, а не друг под другом, и список получает всю высоту.
   Подпись и цена занимают только своё, растягиваются лишь сами карточки —
   иначе заголовок «Ключевые уровни» отбирал треть полосы. */
.levels-panel.dock-bottom .lp-key {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-bottom: 8px;
}
.levels-panel.dock-bottom .lp-key-title,
.levels-panel.dock-bottom .lp-key-price { flex: none; }
.levels-panel.dock-bottom .lp-kcard { flex: 1; min-width: 220px; margin-top: 0; }
.levels-panel.dock-bottom .lp-list { min-height: 0; }

/* Раскрыли складку «Все уровни рядом» — полосе нужно вдвое больше высоты,
   иначе списку остаётся пара пикселей и прокрутка бессмысленна. Класс
   ставит код панели (отметитьСкладку), область ужимается на ту же величину. */
.chart-area.lp-dock-bottom.lp-bottom-tall { padding-bottom: 420px; }
.chart-area.lp-bottom-tall .levels-panel.dock-bottom { height: 400px; }
/* Место в полосе дороже подписей: с раскрытым списком ключевые карточки
   уходят — их уровни и так стоят первыми строками списка */
.levels-panel.dock-bottom.lp-open-all .lp-key { display: none; }

/* Кнопки в углах графика уводим из-под панели, чтобы не оказаться под ней */
.chart-area.lp-dock-right .levels-panel-btn,
.chart-area.lp-dock-right .quick-alert-btn { right: 320px; }
.chart-area.lp-dock-left .chart-source { left: 320px; }
.chart-area.lp-dock-left .chart-source-pop { left: 320px; }

.lp-head-btns { display: flex; align-items: center; gap: 2px; flex: none; }
.lp-dock {
    width: 22px; height: 22px; padding: 0;
    border: 1px solid transparent; border-radius: 6px;
    background: none; color: var(--text-muted);
    font: inherit; font-size: 0.8rem; line-height: 1; cursor: pointer;
}
.lp-dock:hover { color: var(--text); border-color: var(--border); }
.lp-dock.active { color: var(--primary); border-color: var(--primary); }

/* На узком экране места на две колонки нет: панель всегда лежит поверх графика,
   а переключатель положения прячем, чтобы не обманывать кнопками без действия */
@media (max-width: 1100px) {
    .chart-area.lp-dock-right { padding-right: 0; }
    .chart-area.lp-dock-left { padding-left: 0; }
    /* Стыковка «снизу» на узком экране тоже не нужна: там панель и так лист
       снизу, а высоту области считает подстроитьГрафикПодЛист() ниже */
    .chart-area.lp-dock-bottom,
    .chart-area.lp-dock-bottom.lp-bottom-tall { padding-bottom: 0; }
    .chart-area.lp-bottom-tall .levels-panel.dock-bottom,
    .levels-panel.dock-bottom { height: auto; }

    /* Лист «Уровни рядом» (и «Карта уровней») лежит поверх графика и накрывал
       его низ: под панелью прятались шкала времени и значок TradingView,
       который библиотека графиков ставит обязательной ссылкой на источник.
       Теперь область графиков ужимается снизу ровно на перекрытую часть —
       число считает подстроитьГрафикПодЛист() в app.js и кладёт в переменную. */
    .chart-area.lp-sheet { padding-bottom: var(--lp-sheet-h, 0px); }

    .chart-area.lp-dock-right .levels-panel-btn,
    .chart-area.lp-dock-right .quick-alert-btn { right: 14px; }
    .chart-area.lp-dock-left .chart-source,
    .chart-area.lp-dock-left .chart-source-pop { left: 14px; }
    .lp-dock { display: none; }
}

/* ===== Плашка источника переехала в верхнюю полосу =====
   В углу графика её закрывала легенда цветов, а в режимах 2 и 4 графиков
   легенда есть у каждого графика, и плашку было не видно совсем.
   В полосе над графиками место свободно и одинаково во всех режимах. */
.chart-topbar .chart-source {
    position: static;
    margin-left: auto;
    bottom: auto;
    left: auto;
    max-width: 260px;
    padding: 4px 9px;
    font-size: 11px;
    box-shadow: none;
}
/* Кнопка «во весь экран» прижимается вправо сама, только когда плашки нет */
.chart-topbar .chart-source:not([hidden]) ~ .topbar-icon-right { margin-left: 8px; }
.chart-topbar .chart-source .cs-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Пояснение раскрывается под плашкой, у правого края */
.chart-source-pop {
    top: 46px;
    right: 14px;
    left: auto;
    bottom: auto;
}
/* Панель уровней справа — сдвигаем пояснение из-под неё */
.chart-area.lp-dock-right .chart-source-pop { right: 320px; }
.chart-area.lp-dock-left .chart-source-pop { right: 14px; left: auto; }

@media (max-width: 700px) {
    .chart-topbar .chart-source { max-width: 150px; }
    .chart-source-pop { right: 10px; width: auto; left: 10px; }
    .chart-area.lp-dock-right .chart-source-pop { right: 10px; }
}

/* Узкая полоса на телефоне и в мини-приложении: только плашка источника */
.chart-topbar.topbar-min {
    padding: 4px 10px;
    justify-content: flex-start;
}
.chart-topbar.topbar-min .chart-source { margin-left: 0; }

/* ===== Кнопки действий переехали на полосу над графиками =====
   Пилюли «Уровни рядом» и «Свой алерт» стояли в правом нижнем углу графика и
   закрывали свечи, а в режимах 2 и 4 графиков — сразу нижний правый график.
   Теперь это значки в полосе: над свечами не висит ничего. */
.chart-topbar .topbar-act {
    position: static;
    right: auto;
    bottom: auto;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: 1px solid var(--border);
}
.chart-topbar .topbar-act svg { width: 17px; height: 17px; }
.chart-topbar .topbar-act:hover { border-color: var(--primary); color: var(--primary); }
/* Нажатая кнопка «без значений уровней» видна сразу: во время записи нужно
   одним взглядом понимать, скрыты цифры или нет. */
.chart-topbar .hide-values-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--surface-2);
}
.chart-topbar .levels-panel-btn[aria-expanded="true"] {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--surface-2);
}

/* Панель уровней тянется до низа области: место под кнопки больше не нужно */
.levels-panel { bottom: 14px; }

/* На узкой полосе оставляем плашку источника и оба значка действий */
/* Кнопку панели рисования оставляем в узкой полосе: без неё панель не достать */
.chart-topbar.topbar-min > *:not(.chart-source):not(.topbar-act):not(.topbar-icon-draw):not(.topbar-timeframe):not(.data-fresh) { display: none; }
/* Таймфрейм остаётся и в узкой полосе: период свечей меняют чаще всего,
   а иначе за ним пришлось бы раскрывать все настройки */
.chart-topbar.topbar-min .topbar-timeframe { display: inline-flex; order: -1; }

/* ===== Режим официального виджета TradingView =====
   Рисование от руки в чужом окне не работает: линии наносит наш код
   по нашей ценовой шкале, а виджет её наружу не отдаёт. Показывать
   кнопку, которая ничего не сделает, хуже, чем её не показывать: человек
   решит, что сервис сломан.
   А вот раскладки 2 и 4 и скрепка здесь работают и из полосы больше не
   убираются: сетку окон строит наш код, а бумагу и таймфрейм каждой
   рамке задаёт её адрес — то же самое, что в главном окне. */
body.chart-widget .topbar-icon-draw,
body.chart-widget .mini-btn-draw,
body.chart-widget .draw-panel { display: none; }
/* Панели уровней в этом режиме живут складками под графиком, поэтому кнопки
   их открытия из полосы убираем: два способа открыть одно и то же место
   путают, а плавающая панель закрывала бы чужое окно графика */
body.chart-widget .levels-panel-btn,
body.chart-widget .levels-map-btn { display: none; }
/* Значки свежести ставим перед кнопкой источника, справа от рисования */
.chart-topbar.topbar-min .data-fresh { display: flex; margin-left: auto; }
.chart-topbar.topbar-min .chart-source + .data-fresh,
.chart-topbar.topbar-min .data-fresh ~ .chart-source { margin-left: 6px; }
.chart-topbar.topbar-min .topbar-icon-draw { display: inline-flex; order: -1; }
/* В чужом окне рисовать нечем, поэтому карандаш убираем и в узкой полосе:
   правило выше возвращало его на телефоне и в Telegram */
body.chart-widget .chart-topbar.topbar-min .topbar-icon-draw { display: none; }
.chart-topbar.topbar-min { gap: 6px; }
.chart-topbar.topbar-min .chart-source { margin-left: auto; }

/* Отступы для кнопок в углах графика больше не нужны — кнопок там нет */
.chart-area.lp-dock-right .levels-panel-btn,
.chart-area.lp-dock-right .quick-alert-btn { right: auto; }

/* ===== Вошли — кнопка кабинета значком и в браузере =====
   Раньше в браузере в шапке стояла длинная маскированная почта: она занимала
   пол-шапки и выглядела иначе, чем на телефоне и в Телеграме. Теперь везде
   одинаково — круглый значок в один вид со справкой и темой. Сама почта
   осталась в подсказке при наведении и внутри кабинета. */
.btn-account.is-logged {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #fff;
}
.btn-account.is-logged:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: none;
    box-shadow: none;
}
.btn-account.is-logged .btn-account-text { display: none; }
.btn-account.is-logged .btn-account-icon { display: block; }

/* ===== Микро-подсказки первого запуска =====
   Три коротких «шепотка» подряд: без затемнения и без блокировки экрана,
   в отличие от быстрого старта. Стрелка смотрит на нужную кнопку. */
.hint-bubble {
    position: fixed;
    z-index: 60;
    max-width: 268px;
    padding: 10px 12px 9px;
    border: 1px solid var(--primary);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
    animation: hint-in 0.22s ease-out;
}
.hint-bubble[hidden] { display: none; }
@keyframes hint-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Носик пузыря: направление задаётся классом */
.hint-bubble::after {
    content: '';
    position: absolute;
    width: 10px; height: 10px;
    background: var(--surface);
    border-left: 1px solid var(--primary);
    border-top: 1px solid var(--primary);
    transform: rotate(45deg);
}
.hint-bubble.arrow-left::after { left: -6px; top: 18px; }
.hint-bubble.arrow-right::after { right: -6px; top: 18px; transform: rotate(225deg); }
.hint-bubble.arrow-top::after { top: -6px; left: 22px; }
.hint-bubble.arrow-bottom::after { bottom: -6px; left: 22px; transform: rotate(225deg); }
.hint-bubble.arrow-none::after { display: none; }

.hint-num { font-size: 10.5px; color: var(--text-muted); }
.hint-text { margin: 3px 0 8px; font-size: 13px; line-height: 1.35; color: var(--text); }
.hint-btns { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hint-skip {
    border: 0; background: none; padding: 0;
    color: var(--text-muted); font: inherit; font-size: 11.5px; cursor: pointer;
}
.hint-skip:hover { color: var(--text); }
.hint-ok {
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 4px 12px;
    background: var(--primary);
    color: #fff;
    font: inherit; font-size: 12px; cursor: pointer;
}
.hint-ok:hover { filter: brightness(1.06); }

/* Цель подсказки подсвечивается мягким кольцом, экран не затемняется */
.hint-target {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 8px;
}

/* Кому подходит тариф — строка под ценой, чтобы не читать весь список */
.plan-for-whom {
    /* Отступ и рамка сверху разводят эту строку со строкой выгоды: обе мелкие
       и серые, подряд они читались как одна */
    margin: 8px 0 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    font-size: 12px;
    line-height: 1.35;
    color: var(--text);
    opacity: 0.85;
}
/* Кнопка «Скоро будет доступно»: видно, что тариф есть, но платить пока некуда */
.btn-order-soon {
    width: 100%;
    cursor: default;
    opacity: 0.75;
}

/* ===== Всплывающие сообщения с отменой ===== */
.toast-wrap {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 4000;             /* выше окон: сообщение должно быть видно всегда */
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: min(520px, calc(100vw - 24px));
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    font-size: 13px;
    animation: toast-in 0.18s ease-out;
}
.toast.gone { opacity: 0; transform: translateY(6px); transition: 0.2s ease; }
.toast-bad { border-color: #ef4444; }
.toast-text { flex: 1; min-width: 0; }
.toast-action {
    flex: none;
    padding: 5px 10px;
    border: 1px solid var(--accent, #22c55e);
    border-radius: 8px;
    background: transparent;
    color: var(--accent, #22c55e);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.toast-close {
    flex: none;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Мои алерты: управление списком ===== */
.qa-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.qa-tool-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
.qa-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qa-chip {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}
.qa-chip.active {
    border-color: var(--accent, #22c55e);
    color: var(--accent, #22c55e);
    background: rgba(34, 197, 94, 0.08);
}
.qa-tools-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.qa-tool-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.qa-tool-sort {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 12px;
}
/* Панель массовых действий висит над списком, пока что-то выбрано */
.qa-bulk {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 10px;
    margin-bottom: 8px;
    border: 1px solid var(--accent, #22c55e);
    border-radius: 8px;
    background: var(--surface);
}
.qa-bulk-count { font-size: 12px; font-weight: 600; margin-right: auto; }

/* ===== Мои алерты: группы и строки ===== */
.qa-group { margin-bottom: 12px; }
.qa-group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    font-size: 12px;
    color: var(--text-muted);
}
.qa-group.is-current .qa-group-head { box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.45); }
.qa-group-name { font-size: 13px; font-weight: 700; color: var(--text); }
.qa-group-flag {
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(34, 197, 94, 0.16);
    color: var(--accent, #22c55e);
    font-size: 11px;
}
.qa-group-count { margin-left: auto; }
.qa-pick { display: inline-flex; align-items: center; }
/* Строка алерта всегда в два ряда: текст занимает всю ширину, кнопки уходят
   под него. Раньше кнопки стояли рядом и в узком окне алерта (а оно узкое и
   на большом экране) подпись сжималась в столбик по два слова. */
.qa-row2 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 8px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
}
.qa-row2 > .qa-pick { order: 0; }
/* Галочка выбора остаётся в одном ряду с заголовком: отдельной строкой она
   висела в пустоте. Кнопкам ширины не хватает — они переносятся вниз сами. */
.qa-row2 > .qa-row2-main { order: 1; flex: 1 1 220px; }
.qa-row2 > .qa-switch,
.qa-row2 > .qa-row-btn { order: 2; }
/* Первая кнопка после текста отодвигает остальные вправо */
.qa-row2 > .qa-switch { margin-left: auto; }
.qa-row2.off { opacity: 0.62; }
/* Цена рядом — подсвечиваем полосой слева: видно без чтения цифр */
.qa-row2.is-near { box-shadow: inset 3px 0 0 #ef4444; }
.qa-row2.is-soon { box-shadow: inset 3px 0 0 #f59e0b; }
.qa-row2-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.qa-row2-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.qa-row2-title { font-size: 13px; font-weight: 600; }
.qa-row2-near {
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(239, 68, 68, 0.16);
    color: #ef4444;
    font-size: 11px;
}
.qa-row2-sub { font-size: 12px; color: var(--text-muted); word-break: break-word; }
/* Заметка человека — курсивом и чуть светлее рамкой слева: это его слова,
   а не расчёт сервиса, и их надо отличать от строк с условиями */
.qa-row2-note {
    font-size: 12px;
    font-style: italic;
    color: var(--text);
    padding-left: 7px;
    border-left: 2px solid var(--border);
    word-break: break-word;
}
/* Цифры (создан, последняя цена, до уровня) — мельче: их читают вторыми */
.qa-row2-nums { font-size: 11px; color: var(--text-muted); word-break: break-word; }
/* Отметка об отправке в Телеграм. Слово «доставлено» не пишем: сайт знает
   только то, что сообщение ушло боту */
.qa-tg { padding: 1px 6px; border-radius: 999px; font-size: 11px; background: var(--border); }
.qa-tg-sent, .qa-tg-resent { background: rgba(34, 197, 94, 0.16); color: #16a34a; }
.qa-tg-error { background: rgba(239, 68, 68, 0.16); color: #ef4444; }
.qa-hist-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.qa-hist-note-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 5px; }
.qa-hist-note-edit input {
    flex: 1 1 180px;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
}
.qa-hist-count { font-size: 11px; color: var(--text-muted); }
/* В истории кнопок справа нет, поэтому строке не нужен отступ под них */
.qa-row-hist { align-items: flex-start; }
.qa-row-btn.is-danger { border-color: rgba(239, 68, 68, 0.5); color: #f87171; }
/* Переключатель паузы: одно нажатие вместо кнопки со сменой надписи */
.qa-switch { position: relative; flex: none; width: 38px; height: 22px; }
.qa-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.qa-switch-run {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.15s ease;
    pointer-events: none;
}
.qa-switch-run::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.15s ease;
}
.qa-switch input:checked + .qa-switch-run { background: var(--accent, #22c55e); }
.qa-switch input:checked + .qa-switch-run::after { transform: translateX(16px); }
.qa-switch input:focus-visible + .qa-switch-run { outline: 2px solid var(--accent, #22c55e); outline-offset: 2px; }

/* Полоса режима правки над формой */
.qa-editbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.1);
    font-size: 12px;
}
.qa-editbar span { flex: 1; min-width: 0; }

@media (max-width: 640px) {
    /* Всплывающие сообщения поднимаем над полосой кнопок и подвалом: внизу
       они закрывали реквизиты и ссылки на тарифы */
    .toast-wrap { bottom: calc(var(--legal-h, 0px) + var(--mob-bar-h) + 8px); }
}

/* ===== Нижние панели на телефоне =====
   На маленьком экране график — главное, поэтому настройки, списки, уровни и
   оповещения живут в нижних панелях: они появляются по кнопке и не отнимают место
   постоянно. Кнопка «Алерт» стоит в середине полосы и всегда видна. */
.mob-bar { display: none; }
.sheet { display: none; }
.sheet-backdrop { display: none; }

@media (max-width: 860px) {
    /* Высота полосы кнопок в одном месте: от неё считаются отступы подвала и
       графика. В мини-приложении Телеграма полоса выше — под ней ещё
       платформенная кнопка «Закрыть», и её нельзя перекрывать. */
    :root { --mob-bar-h: 58px; }

    .mob-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 46;                 /* выше выдвижных панелей, ниже окон */
        display: flex;
        align-items: stretch;
        gap: 2px;
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--border);
        background: var(--surface);
        box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.28);
    }
    /* Кнопку «Уровни» прячет код, когда показывать нечего: без разрешённой
       цены нет расстояний, а карта уровней доступна не всем тарифам. */
    .mob-btn[hidden] { display: none; }
    .mob-btn {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 50px;
        padding: 4px 2px;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--text-muted);
        font: inherit;
        font-size: 10px;
        line-height: 1.1;
        cursor: pointer;
    }
    .mob-btn svg { width: 20px; height: 20px; flex: none; }
    .mob-btn span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .mob-btn[aria-expanded="true"] { color: var(--primary); background: rgba(34, 197, 94, 0.12); }
    /* Главное действие сервиса — поставить алерт. Выделяем цветом, чтобы его
       находили без объяснений. */
    .mob-btn-main {
        background: var(--primary);
        color: #fff;
        font-weight: 600;
    }
    .mob-btn-main svg { width: 22px; height: 22px; }
    .mob-btn-main:active { filter: brightness(0.94); }

    /* Подвал с реквизитами стоит под графиком и остаётся в потоке, поэтому
       место под полосу кнопок отдаём именно ему: раньше отступ висел на .main,
       и между панелью рисования и полосой кнопок зияла пустая полоса высотой
       с подвал — сам подвал при этом прятался за полосой. */
    /* Порядок снизу вверх: подвал с реквизитами в самом низу, над ним полоса
       кнопок, над ней график. Полосу поднимаем на высоту подвала: её меряет
       код и пишет в --legal-h (0, когда подвал скрыт в режиме «во весь экран»). */
    .main { padding-bottom: calc(var(--mob-bar-h) + var(--legal-h, 0px) + env(safe-area-inset-bottom, 0px)); }
    /* Подвал закреплён у нижнего края и лежит выше выдвижных панелей: пока он
       был в общем потоке, панель настроек накрывала его собой, полоса кнопок
       висела посреди панели, а под ней оставалось пустое место. */
    .site-legal {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 47;
        margin: 0;
        border-top: 1px solid var(--border);
        background: var(--surface);
    }
    .mob-bar { bottom: var(--legal-h, 0px); }

    /* Значки «Уровни рядом» и «Свой алерт» убраны из полосы над графиком:
       на телефоне те же действия есть в нижней полосе кнопок, два одинаковых
       входа рядом только путают и отнимают место у названия бумаги. */
    #levels-panel-btn,
    #quick-alert-btn { display: none; }

    /* «Откуда котировки» переезжает в шапку рядом с кабинетом: над графиком
       пилюля с подписью занимала половину полосы. В шапке — только значок
       с цветной точкой состояния, вид как у кнопок справки и темы. */
    .header-right .chart-source {
        position: static;
        z-index: auto;
        max-width: none;
        gap: 4px;
        padding: 6px;
        border: none;
        border-radius: var(--radius-sm);
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
        box-shadow: none;
    }
    .header-right .chart-source .cs-text,
    .header-right .chart-source .cs-q { display: none; }
    .header-right .chart-source .cs-glyph { display: block; width: 18px; height: 18px; }
    .header-right .chart-source .cs-dot { width: 6px; height: 6px; }
    .site-foot, .footer { padding-bottom: calc(var(--mob-bar-h) + 4px + env(safe-area-inset-bottom, 0px)); }
    /* Полоса рабочего списка переехала в нижнюю панель «Списки» */
    .list-strip { display: none; }

    /* Настройки выезжают снизу, а не слева: до низа экрана палец достаёт легче,
       и панель не спорит с нижней полосой кнопок */
    .sidebar {
        top: auto;
        left: 0;
        right: 0;
        /* Панель кончается там, где начинается полоса кнопок: раньше она шла
           до самого низа, накрывала подвал и полосу, а место под кнопки
           держал внутренний отступ — из-за него панель «проваливалась» вниз */
        bottom: calc(var(--mob-bar-h) + var(--legal-h, 0px) + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        max-height: 78vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(102%);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
        padding-bottom: 10px;
    }
    .sidebar.open { transform: translateY(0); }
    .sidebar-backdrop { top: 0; }

    /* Панель уровней — такая же нижняя панель */
    .levels-panel {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: calc(var(--mob-bar-h) + var(--legal-h, 0px) + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        /* Раньше лист поднимался до 74vh — от графика оставалась полоска, а
           после ужатия области под лист (.chart-area.lp-sheet) свечи и вовсе
           сплющивались. Половина экрана листу хватает: список внутри
           прокручивается, а график остаётся читаемым. */
        max-height: 52vh;
        border-radius: 16px 16px 0 0;
        border-left: 0;
        border-right: 0;
        padding-bottom: 10px;
        z-index: 44;
    }

    /* Раскрыли полный список — листу нужно чуть больше места, а ключевые
       карточки уходят: их уровни всё равно стоят первыми строками списка. */
    .levels-panel.lp-open-all { max-height: 62vh; }
    /* На телефоне высоту листа считают правила выше, поэтому жёсткую высоту
       стыковки «снизу» с большого экрана снимаем — иначе лист был бы 238px */
    .levels-panel.dock-bottom { height: auto; }
    .levels-panel.lp-open-all .lp-key { display: none; }
    .levels-panel.lp-open-all .lp-list { min-height: 150px; }

    /* Панель помнит, к какому краю её пристыковали на большом экране, и классы
       dock-* перебивали правило выше: на телефоне она открывалась узкой полосой
       у правого края поверх шапки. Здесь стыковка не нужна — всегда нижний лист. */
    .levels-panel.dock-left,
    .levels-panel.dock-right,
    .levels-panel.dock-bottom,
    .levels-panel.dock-float {
        top: auto;
        left: 0;
        right: 0;
        width: auto;
        max-width: none;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
    }

    /* Нижняя панель «Списки» */
    .sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(var(--mob-bar-h) + var(--legal-h, 0px) + env(safe-area-inset-bottom, 0px));
        z-index: 44;
        display: flex;
        flex-direction: column;
        max-height: 74vh;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        background: var(--surface);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
        padding-bottom: 10px;
    }
    .sheet[hidden] { display: none; }
    .sheet-head {
        position: relative;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 14px 12px 8px;
        font-size: 14px;
    }
    .sheet-grip {
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 38px;
        height: 4px;
        border-radius: 999px;
        background: var(--border);
    }
    .sheet-head b { flex: 1; min-width: 0; }
    .sheet-close {
        flex: none;
        border: 0;
        background: transparent;
        color: var(--text-muted);
        font-size: 15px;
        line-height: 1;
        padding: 4px 6px;
        cursor: pointer;
    }
    .sheet-body { flex: 1; min-height: 0; overflow: auto; padding: 0 12px; }
    .sheet-foot { padding: 8px 12px 4px; }
    .sheet-foot .btn { width: 100%; }
    /* В панели полоса списка разворачивается в столбик: бумаг много, а
       горизонтальная прокрутка на телефоне неудобна */
    .sheet-body .list-strip {
        display: flex;
        flex-wrap: wrap;
        border-bottom: 0;
        background: transparent;
        padding: 0;
    }
    .sheet-body .strip-list { flex: 1 1 100%; }
    .sheet-body .strip-items { flex: 1 1 100%; flex-wrap: wrap; overflow: visible; }
    .sheet-body .strip-arrow { display: none; }
    .sheet-body .strip-more { display: none; }

    .sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 43;
        background: rgba(0, 0, 0, 0.5);
    }
    .sheet-backdrop[hidden] { display: none; }
}

/* В мини-приложении Телеграма полоса кнопок такая же, как в браузере телефона:
   она заметно удобнее прежней раскладки. Запас под платформенную кнопку
   Телеграма держит подвал: он лежит ниже полосы, поэтому кнопки уже не
   упираются в край экрана и добавлять им отступ не нужно. */
.tg-app .site-legal {
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

/* Скрытая полоса списка не должна проявляться в нижней панели */
.sheet-body .list-strip[hidden] { display: none; }
.sheet-empty { margin: 8px 0 4px; }

/* ---------- Название сервиса на узком экране ---------- */
/* Одной строкой «Динамические уровни» не влезало между значком и кнопками
   справа и обрезалось троеточием: оставалось «Динамические …». Пускаем его в
   две строки — по высоте это ровно столько же, сколько занимают кнопки. */
@media (max-width: 860px) {
    .header .header-left h1 {
        font-size: 11.5px;
        line-height: 1.15;
        white-space: normal;
        text-overflow: clip;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 2;       /* третьей строке взяться неоткуда, но страхуемся */
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    /* Блок с названием должен сжиматься: с жёсткой минимальной шириной он
       вылезал из шапки и уезжал под кнопку «Войти» */
    .header .header-left > div { flex: 0 1 auto; min-width: 0; }
}

/* Совсем узкие корпуса и мини-приложение: слово «Динамические» длинное,
   поэтому шрифт чуть мельче, чтобы строка не разрывалась посередине слова */
@media (max-width: 380px) {
    .header .header-left h1 { font-size: 10.5px; }
}

.tg-app .header .header-left h1 {
    font-size: 11.5px;
    line-height: 1.15;
    white-space: normal;
    text-overflow: clip;
}

/* Мини-приложение на узком корпусе: правило без медиазапроса перебивало общий
   мелкий шрифт, и слово «Динамические» рвалось посередине — «Динамически/е» */
@media (max-width: 380px) {
    .tg-app .header .header-left h1 { font-size: 10.5px; }
}

/* Совсем узкие корпуса (360 px и меньше): места под название нет — даже в две
   строки оно уезжало под кнопку «Войти». Оставляем значок «8», он и так
   подписан для чтецов экрана, а название видно на всех остальных ширинах. */
@media (max-width: 365px) {
    .header .header-left h1 { display: none; }
}

/* Обязательная отметка согласия перед оплатой.
   Кнопка оплаты остаётся видимой, но заблокирована до отметки — так покупателю
   понятно, что именно нужно сделать, а согласие фиксируется осознанно. */
.billing-consent {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin: 10px 0 4px;
    font-size: 0.86rem;
    line-height: 1.5;
    color: var(--text-muted);
    cursor: pointer;
}
.billing-consent input {
    width: 17px;
    height: 17px;
    flex: none;
    margin-top: 1px;
}
.billing-consent a { color: var(--accent); }
/* Заблокированная кнопка оплаты: гасим цвет, но клик перехватываем в скрипте,
   чтобы можно было подсказать, чего не хватает. */
.btn.is-locked {
    opacity: 0.45;
    cursor: not-allowed;
}
.site-legal-hours { color: var(--text-faint); }

/* ===== Свежесть данных (4.5) ===== */
/* Полоса под верхними кнопками: откуда цена, сколько назад обновилась, когда
   пересчитаны уровни. Раньше это было видно только внутри пояснения к
   источнику, и «график завис» было не отличить от стоящего рынка. */
/* Значки живут в верхней полосе графика (JS переставляет узел туда при
   загрузке), поэтому своих отступов и своей строки у полосы нет. Подписи
   скрыты на всех ширинах: две длинные строки «Цена: … · обновлено … назад»
   и «Уровни: 8levels · пересчитаны …» занимали место графика и повторяли
   то, что открывается нажатием. Остаётся цветная точка со значком —
   состояние читается мгновенно, подробности в подсказке. */
.data-fresh {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 0;
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.data-fresh[hidden] { display: none; }
.df-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    white-space: nowrap;
}
.df-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text-faint);
    flex: 0 0 auto;
}
.df-chip.ok .df-dot { background: #4CAF50; }
.df-chip.warn .df-dot { background: #FFB300; }
.df-chip.bad .df-dot { background: #E53935; }
.df-chip.warn { border-color: rgba(255, 179, 0, 0.45); }
.df-chip.bad { border-color: rgba(229, 57, 53, 0.5); }

/* Значок и подсказка. Значок виден всегда, подпись — никогда: полный текст
   показывается подсказкой при наведении и касании. */
.df-text { display: none; }
.df-glyph {
    display: inline-block;
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
}
.df-chip { cursor: pointer; }
.df-chip:hover { border-color: var(--primary); }
.df-chip { position: relative; cursor: default; }
.df-tip {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 40;
    display: none;
    max-width: min(78vw, 320px);
    width: max-content;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.72rem;
    line-height: 1.35;
    white-space: normal;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
    pointer-events: none;
}
.df-chip:hover .df-tip,
.df-chip:focus-visible .df-tip,
.df-chip.df-open .df-tip { display: block; }
/* Значки стоят у правого края полосы, поэтому подсказку тянем влево от
   значка — иначе она уезжает за край окна */
.df-tip { left: auto; right: 0; }

/* ===== Карта рынка сейчас (5.1) ===== */
/* Стоит справа от графика и не перекрывает свечи: область графика получает
   отступ, как и для панели «Уровни рядом». */
.market-now {
    position: absolute;
    right: 14px;
    top: 14px;
    width: 292px;
    max-width: calc(100% - 28px);
    z-index: 13;                    /* выше «Уровней рядом»: это главная подсказка */
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 11px 12px 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
}
.market-now[hidden] { display: none; }
.mn-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.mn-title b { display: block; font-size: 0.94rem; }
.mn-sub { display: block; margin-top: 2px; font-size: 0.76rem; color: var(--text-muted); }
.mn-close {
    border: 0; background: none; color: var(--text-muted);
    font-size: 0.95rem; cursor: pointer; padding: 2px 4px; line-height: 1;
}
.mn-close:hover { color: var(--text); }
.mn-price-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
}
.mn-price { font-size: 1.34rem; font-weight: 600; line-height: 1.1; }
.mn-between { font-size: 0.74rem; color: var(--text-muted); }
.mn-rows { display: flex; flex-direction: column; gap: 5px; }
.mn-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.78rem;
}
.mn-row-name {
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--text-muted);
    flex: 0 0 auto;
    /* Без запрета переноса «Старшая зона» ломалась на две строки и строка
       карточки становилась выше остальных */
    white-space: nowrap;
}
.mn-row-val { text-align: right; }
.mn-row-val b { font-weight: 600; }
/* Расстояние до уровня — второй строкой, иначе строка не влезает в 292 пкс
   и значение переносится посреди числа */
.mn-row-val span {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.mn-row .mn-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
/* Пояснение про свою же кнопку «без значений» в карте рынка: не рамка
   предупреждения, а спокойная строка мелким шрифтом. */
.mn-note { margin: 6px 0 0; font-size: 0.72rem; line-height: 1.35; color: var(--text-muted); }
.mn-note[hidden] { display: none; }
.mn-status {
    padding: 7px 9px;
    border-radius: 9px;
    background: var(--surface-2);
    font-size: 0.76rem;
    line-height: 1.4;
}
.mn-acts { display: flex; gap: 6px; }
.mn-btn {
    flex: 1;
    padding: 8px 6px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
}
.mn-btn:hover { background: var(--surface-2); }
.mn-btn-main { background: var(--primary); border-color: var(--primary); color: #fff; }
.mn-btn-main:hover { filter: brightness(1.08); background: var(--primary); }
.mn-fresh { display: none; font-size: 0.7rem; color: var(--text-faint); line-height: 1.45; }
.mn-fresh div + div { margin-top: 2px; }

/* Область графика отодвигается, чтобы карточка не легла на свечи */
.chart-area.mn-open { padding-right: 320px; }
.chart-area.mn-open .levels-panel.dock-right { right: 320px; }
/* Открытая карта рынка занимает правый край, и полоса списка снизу должна
   кончаться перед ней, иначе они лежали бы друг на друге */
.chart-area.mn-open .levels-panel.dock-bottom { right: 320px; }
.chart-area.mn-open.lp-dock-right { padding-right: 612px; }
.chart-area.mn-open .levels-panel-btn,
.chart-area.mn-open .quick-alert-btn,
.chart-area.mn-open .market-now-btn { right: auto; }

@media (max-width: 1100px) {
    /* Места на два столбца справа уже не хватает — карточка ложится поверх */
    .chart-area.mn-open { padding-right: 0; }
    .chart-area.mn-open.lp-dock-right { padding-right: 306px; }
    .market-now { box-shadow: 0 18px 46px rgba(0, 0, 0, 0.5); }
}

@media (max-width: 860px) {
    /* На телефоне карточка — выезжающий снизу лист: вертикаль дорога, а
       читать её удобнее во всю ширину. Отступ снизу — под полосу кнопок. */
    .market-now {
        position: fixed;
        left: 0;
        right: 0;
        top: auto;
        /* Лист встаёт НАД полосой кнопок, а не под ней. Раньше он доходил до
           низа экрана, полоса кнопок (она выше по слою) закрывала кнопки
           «Поставить алерт» и «Открыть сценарий», и главное действие
           приходилось искать прокруткой. */
        bottom: calc(var(--mob-bar-h, 58px) + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        z-index: 45;
        border-radius: 16px 16px 0 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
        max-height: calc(80vh - var(--mob-bar-h, 58px));
        overflow-y: auto;
    }
    /* Два значка свежести стоят в один ряд и не переносятся */
    .data-fresh {
        flex-wrap: nowrap;
        scrollbar-width: none;
    }
    .data-fresh::-webkit-scrollbar { display: none; }
    .chart-area.mn-open { padding-right: 0; }
    .chart-area.mn-open.lp-dock-right { padding-right: 0; }
    .mn-price { font-size: 1.42rem; }
    .mn-row { font-size: 0.82rem; }
    .mn-btn { padding: 11px 6px; font-size: 0.82rem; }
    /* На телефоне полоса свежести над графиком узкая, поэтому подписи
       повторяем внутри листа — там для них есть место */
    .mn-fresh { display: block; }
    .data-fresh { padding: 0; font-size: 0.68rem; }
}

/* Кнопка карты рынка подсвечивается, когда карточка открыта — как «Уровни рядом» */
.chart-topbar .market-now-btn[aria-expanded="true"] {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--surface-2);
}

/* ===== Быстрые сценарии в форме алерта =====
   Шесть готовых наборов вместо ручного подбора условия и допуска. Кнопки в
   сетку по три: в один ряд шесть штук не влезают даже в браузере, а перенос
   «по остатку» давал кривые ряды из четырёх и двух. */
.qa-scen {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}
.qa-scen-btn {
    padding: 9px 6px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
    /* Длинные названия не переносим по слогам: «Закреп-ление» читается плохо */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.qa-scen-btn:hover { border-color: var(--primary); color: var(--primary); }
.qa-scen-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}
#qa-scen-hint:empty { display: none; }

/* ===== Меню уровня по клику на линию =====
   Всплывает у самой линии, поэтому положение задаётся из кода. Ширину держим
   фиксированной: иначе меню растягивается по самой длинной подписи действия. */
.lvl-menu {
    position: fixed;
    z-index: 60;
    width: 262px;
    max-width: calc(100vw - 24px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 34px rgba(15, 23, 42, .18);
    padding: 12px 13px 11px;
}
.lvl-menu-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 9px;
}
.lvl-menu-head b { font-size: 0.95rem; display: block; }
.lvl-menu-head .modal-close { position: static; flex: 0 0 auto; }
.lvl-menu-sub {
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-top: 2px;
}
.lvl-menu-acts { display: flex; flex-direction: column; gap: 5px; }
.lvl-menu-act {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}
.lvl-menu-act:hover { border-color: var(--primary); color: var(--primary); }
.lvl-menu-act.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}
.lvl-menu-act.primary:hover { color: #fff; opacity: .92; }

/* На телефоне меню уровня — нижний лист: попасть пальцем в маленькое
   всплывающее окно у линии почти невозможно */
@media (max-width: 860px) {
    .lvl-menu {
        left: 0 !important;
        right: 0;
        top: auto !important;
        width: auto;
        max-width: none;
        border-radius: 16px 16px 0 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
        padding: 14px 15px 15px;
    }
    .lvl-menu-act { padding: 12px 12px; font-size: 0.9rem; }
    .qa-scen-btn { padding: 11px 6px; font-size: 0.8rem; }
}

/* ===== Лист «Сценарий» =====
   Отдельное окно со списком наблюдений: где цена, что рядом, что считать
   пробоем, насколько свежи данные. Раньше «Открыть сценарий» лишь раскрывал
   тонкие настройки формы алерта — человек видел поля, но не понимал, зачем.

   В браузере окно строго по содержимому: высота не задана, растёт от текста и
   упирается в 82vh, после чего прокручивается только список наблюдений.
   Пустоты снизу не остаётся — этим и отличается от прежних листов с
   фиксированной высотой. */
.scen {
    position: fixed;
    z-index: 90;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    width: 460px;
    max-width: calc(100vw - 32px);
    max-height: 82vh;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.42);
    overflow: hidden;
}
.scen[hidden] { display: none; }
.scen-backdrop {
    position: fixed;
    inset: 0;
    z-index: 89;
    background: rgba(0, 0, 0, 0.5);
}
.scen-backdrop[hidden] { display: none; }

.scen-head {
    position: relative;
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 14px 11px;
    border-bottom: 1px solid var(--border);
}
.scen-grip { display: none; }
.scen-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.scen-title b { font-size: 0.98rem; }
.scen-sub {
    color: var(--text-muted);
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.scen-close {
    flex: none;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1;
    padding: 3px 4px;
    cursor: pointer;
}
.scen-close:hover { color: var(--text); }

/* Прокручивается только список: голова и кнопки остаются на месте */
.scen-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 11px 14px 12px;
    display: grid;
    gap: 10px;
}
.scen-item {
    display: grid;
    grid-template-columns: 9px 1fr;
    gap: 9px;
    align-items: start;
}
/* Точка цвета таймфрейма: тот же язык, что на графике и в карте рынка */
.scen-dot {
    width: 9px;
    height: 9px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--text-muted);
}
.scen-item-b { min-width: 0; }
.scen-item-h {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
    font-size: 0.83rem;
    font-weight: 600;
}
.scen-item-h .scen-val { color: var(--text); }
.scen-item-h .scen-meta { color: var(--text-muted); font-weight: 400; font-size: 0.76rem; }
.scen-item-t {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.45;
}
.scen-note {
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.77rem;
    line-height: 1.45;
}
.scen-foot {
    flex: none;
    display: grid;
    gap: 8px;
    padding: 11px 14px 13px;
    border-top: 1px solid var(--border);
}
.scen-foot .btn { width: 100%; }

/* Телефон и Телеграм: обычный нижний лист над полосой кнопок. Отступ снизу
   считается по той же переменной, что и остальные листы, иначе кнопки
   уезжают под полосу и до них не дотянуться. */
@media (max-width: 860px) {
    .scen {
        left: 0;
        right: 0;
        top: auto;
        bottom: calc(var(--mob-bar-h) + var(--legal-h, 0px) + env(safe-area-inset-bottom, 0px));
        transform: none;
        width: auto;
        max-width: none;
        max-height: 76vh;
        border: 0;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
    }
    .scen-head { padding: 16px 12px 10px; }
    .scen-grip {
        display: block;
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 38px;
        height: 4px;
        border-radius: 999px;
        background: var(--border);
    }
    .scen-body { padding: 11px 12px 12px; }
    .scen-foot { padding: 10px 12px 12px; }
    .scen-item-h { font-size: 0.87rem; }
    .scen-item-t { font-size: 0.81rem; }
}

/* ===== Режим ограничения по рыночным данным ===== */
/* Плашка вверху страницы и водяной знак на графике. Оба элемента говорят об
   одном: цены и свечи сейчас демонстрационные. Цвет янтарный, а не красный:
   это не поломка сервиса, остальные возможности работают. */
.md-strip {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 20px;
    background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
    color: #fef3c7;
    border-bottom: 1px solid rgba(251, 191, 36, 0.45);
    font-size: 0.85rem;
    line-height: 1.45;
}

.md-strip-mark {
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.22);
    border: 1px solid rgba(251, 191, 36, 0.55);
    color: #fde68a;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 1px;
}

/* Заголовок и пояснение переносятся вместе, поэтому строка не рвётся
   посередине слова даже при длинном тексте из настроек */
.md-strip-body {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
    overflow-wrap: anywhere;
}

.md-strip-title { color: #fff; }
.md-strip-text { color: #fde68a; }

/* ----- свёрнутое состояние полосы -----
   По умолчанию вверху страницы видна одна строка: предупреждение на
   полэкрана перестают читать вовсе, а важное слово — само наличие
   полосы и метка — читается и в одной строке. Обрезание только
   визуальное: весь текст остаётся в разметке и доступен читалке. */
.md-strip-compact .md-strip-body {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    line-clamp: 1;
}

.md-strip-compact .md-strip-title { margin-right: 6px; }

/* Область нажатия кнопок — не меньше 44×44 px: обе живут в узкой
   полосе, и пальцем по мелкой цели попасть невозможно. Отрицательные
   отступы по вертикали держат саму полосу компактной: цель больше
   своего видимого размера, а высота строки от этого не растёт. */
.md-strip-more,
.md-strip-close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    margin: -11px 0;
    padding: 0 8px;
    background: none;
    border: none;
    border-radius: 8px;
    color: #fde68a;
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.md-strip-close {
    font-size: 1.15rem;
    font-weight: 700;
    text-decoration: none;
    line-height: 1;
}

.md-strip-more:hover,
.md-strip-close:hover { background: rgba(251, 191, 36, 0.16); color: #fff; }

.md-strip-more:focus-visible,
.md-strip-close:focus-visible {
    outline: 2px solid #fbbf24;
    outline-offset: 2px;
}

/* Знак лежит поверх графика и не перехватывает нажатия: рисовать и ставить
   алерты можно как обычно */
.chart-grid { position: relative; }

.chart-demo-mark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-18deg);
    pointer-events: none;
    z-index: 4;
    font-size: clamp(1.6rem, 6vw, 4rem);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(251, 191, 36, 0.14);
    white-space: nowrap;
    user-select: none;
}

[data-theme="light"] .chart-demo-mark { color: rgba(146, 64, 14, 0.13); }

/* Метка рядом с ценой и в полосе свежести данных */
.demo-tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(251, 191, 36, 0.5);
    color: #fbbf24;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

/* Бейдж «ТЕСТ» у заголовков разделов и в шапке каждой карточки зоны. Цвет
   тот же янтарный, что и у остальных пометок режима: человек привыкает к
   одному сигналу, а не разгадывает три разных. Метку не прячем на узком
   экране — она короче любого заголовка и важнее его. */
.test-badge {
    display: inline-block;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(251, 191, 36, 0.55);
    color: #fbbf24;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
}

[data-theme="light"] .test-badge { color: #92400e; }

/* Подпись у самого числа в карточке: цифра без пояснения рядом читается как
   биржевая цена, поэтому «тестовое значение» стоит вплотную к ней. */
.kl-test-note {
    font-size: 0.7rem;
    font-weight: 600;
    color: #fbbf24;
    white-space: nowrap;
}

[data-theme="light"] .kl-test-note { color: #92400e; }

/* Левая полоса карточки в тестовом режиме — янтарная поверх зелёной или
   красной: цвет стороны уровня остаётся в заголовке, а характер данных
   виден по всей высоте карточки. */
.kl-card.kl-test { border-left-color: rgba(251, 191, 36, 0.85); }

@media (max-width: 768px) {
    /* На телефоне плашка занимает всю ширину и текст уходит на вторую строку:
       обрезать его нельзя, иначе предупреждение потеряет смысл */
    .md-strip {
        padding: 7px 12px;
        font-size: 0.8rem;
    }

    /* На телефоне в одну строку заголовок и начало текста не влезают,
       и одного заголовка мало, чтобы понять суть. Две строки — предел:
       дальше полоса начинает съедать экран, а график на телефоне
       и так невысокий. */
    .md-strip-compact .md-strip-body {
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }
}

/* Граница между чужим графиком и числами сервиса.
   Виджет TradingView показывает биржевые свечи, а рядом стоят зоны 8levels —
   собственный расчёт сервиса, в тестовом режиме на тестовых числах. Если
   блоки соприкасаются без зазора, всё вместе читается как одна картинка от
   биржи. Поэтому между графиком и картой зон — видимая линия и воздух:
   слева на широком экране, сверху на телефоне, где блок уезжает под график. */
.chart-row .key-levels {
    border-left: 2px solid var(--border);
    padding-left: 12px;
    margin-left: 4px;
}

@media (max-width: 1024px) {
    .chart-row .key-levels {
        border-left: 0;
        padding-left: 0;
        margin-left: 0;
        border-top: 2px solid var(--border);
        padding-top: 12px;
        margin-top: 12px;
    }
}

/* Предупреждение о режиме в блоке подписки: янтарная рамка, как у остальных
   пометок режима, чтобы его не приняли за обычную серую сноску с ценами. */
.billing-test-note {
    margin: 0 0 10px;
    padding: 8px 10px;
    border: 1px solid rgba(251, 191, 36, 0.5);
    border-radius: 10px;
    background: rgba(251, 191, 36, 0.10);
    color: var(--text);
    line-height: 1.5;
}
