/* Атрибут 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);
    --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;
}

* {
    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: 260px;
    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;
}

.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: rgba(255, 149, 0, 0.95);
}

.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);
}

#chart {
    width: 100%;
    height: 100%;
    position: relative;
}

/* ===== 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: 5;
    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;
}

/* ===== 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: 230px;
        padding: 10px;
    }
    .header p { display: none; }
}

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

@media (max-width: 860px) {
    .menu-toggle {
        display: inline-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;
    }

    .header h1 { font-size: 15px; }
    .header p { display: none; }
    .logo { width: 24px; height: 24px; }

    /* Боковая панель — выдвижное меню поверх графика */
    .sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        width: 88%;
        max-width: 330px;
        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-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 {
        bottom: 54px;
        left: 8px;
        padding: 5px 8px;
        gap: 2px;
        font-size: 10px;
    }

    .chart-legend span,
    .legend-item {
        font-size: 10px;
    }
}

/* Сообщение, когда данные не загрузились */
.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 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
}

#alert-log {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 132px;
    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;
    }
}

/* ===== Панель рисования ===== */
.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);
}

@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::-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;
}

/* Инструменты для оповещений в телеграме (серверное слежение) */
.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);
}

.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 {
    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);
}

.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;
}

.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 {
    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: 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

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

.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;
    }

    .modal-box,
    .cabinet-box {
        max-width: 100%;
        width: 100%;
        max-height: calc(100dvh - 16px);
        padding: 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-owner {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

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

/* Блок ключа администратора и строки кабинета скрываются атрибутом hidden,
   а display: flex его перебивает — поэтому скрываем явно */
.auth-key-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 .header h1 {
    font-size: 13px;
}

.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;
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.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: 480px) {
    .tg-app .main {
        gap: 0;
    }

    .tg-app .header {
        height: 36px;
        padding: 4px 8px;
    }

    .tg-app .header h1 {
        font-size: 12px;
    }
}

/* ---------- Экран оплаты подписки ---------- */
.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;
}

.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); }

@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%; }
}

/* Строка условий над кнопкой оплаты */
.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;
}

.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%; }
}
