/* ============================================================
   ГЛОБАЛЬНЫЕ БАЗОВЫЕ СТИЛИ
   ============================================================ */
*, *::before, *::after {
    user-select: none !important;
    -webkit-user-select: none !important;
}
input, textarea, [contenteditable] {
    user-select: text !important;
    -webkit-user-select: text !important;
}
html { background-color: #000000; }
body {
    margin: 0;
    background: transparent;
    font-family: 'Roboto', sans-serif;
    overflow: hidden;
    color: #eee;
    touch-action: none;
    height: 100dvh;
}
body::before {
    content: "";
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to top, #001401 65%, #000000 100%);
    z-index: -1;
    pointer-events: none;
}
* { scrollbar-width: thin; scrollbar-color: #4e5561 #161a1e; }
::-webkit-scrollbar { width: 6px; height: 6px; background: #161a1e; }
::-webkit-scrollbar-track { background: #161a1e; }
::-webkit-scrollbar-thumb { background: #4e5561; border-radius: 3px; border: 1px solid #161a1e; }
::-webkit-scrollbar-thumb:hover { background: #848e9c; }
::-webkit-scrollbar-corner { background: #161a1e; }

/* ============================================================
   LAYOUT
   ============================================================ */
.main-body {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: row;
}
.charts-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
#price-container  { width: 100%; position: relative; flex: 72 1 0%; min-height: 0; background: transparent; }
#gd-container     { width: 100%; position: relative; flex: 14 1 0%; min-height: 20px; background: transparent; overflow: hidden; }
#macd-container   { width: 100%; position: relative; flex: 14 1 0%; min-height: 20px; background: transparent; overflow: hidden; }

/* ============================================================
   RESIZER
   ============================================================ */
.resizer {
    height: 1px;
    background-color: rgba(255,255,255,0.15);
    background-clip: content-box;
    cursor: row-resize;
    z-index: 100;
    position: relative;
    padding: 4px 0;
    margin: -4px 0;
}
.resizer:hover, .resizer.dragging { background-color: #0ecb81 !important; }
.resizer-vertical {
    width: 1px;
    background-color: rgba(255,255,255,0.15);
    cursor: col-resize;
    z-index: 100;
    position: relative;
    padding: 0 5px;
    margin: 0 -5px;
    background-clip: content-box;
    transition: background-color 0.1s;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}
.resizer-vertical:hover, .resizer-vertical.dragging { background-color: #0ecb81 !important; }

/* ============================================================
   SYMBOL BUTTON & MODAL
   ============================================================ */
#symbol-btn:hover { background: rgba(255,255,255,0.05); border-radius: 6px; }
#sym-modal-overlay { display: none; }
#sym-list::-webkit-scrollbar { width: 6px; }
#sym-list::-webkit-scrollbar-track { background: transparent; }
#sym-list::-webkit-scrollbar-thumb { background: #363a45; border-radius: 3px; }
#sym-search::placeholder { color: #4a505e; }

/* ============================================================
   STATUS ICONS
   ============================================================ */
.status-icon { width: 18px; height: 18px; border-radius: 4px; margin-right: 8px; }
.status-on  { border: 2.5px solid #00ff88; padding: 1px; }
.status-off { border: 2.5px solid #f6465d; filter: grayscale(1); opacity: 0.5; padding: 1px; }

/* ============================================================
   DASH TABLE
   ============================================================ */
.dash-table-container tr:first-child { display: none; }
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner img {
    height: 16px !important; width: 16px !important; vertical-align: middle; border-radius: 3px;
}
.dash-spreadsheet td, .dash-spreadsheet th { padding: 2px 4px !important; height: auto !important; line-height: 12px !important; }

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
    order: -1;
    width: 52px;
    min-width: 52px;
    background-color: #000000;
    border-right: 1px solid #2b3139;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
    z-index: 50;
}
.tool-btn {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #848e9c;
    margin-bottom: 8px;
    transition: all 0.1s ease;
    position: relative;
}
.tool-btn:hover { background-color: #2b3139; color: #fff; }
.tool-btn.active { background-color: #2b3139; color: #0ecb81; }

/* ============================================================
   TOOL GROUP & SUBMENU (из chart.js, авторитетная версия)
   ============================================================ */
.tv-tool-group {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-bottom: 4px;
}
.tv-group-btn {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.1s;
    position: relative;
    color: #848e9c;
}
.tv-group-btn:hover, .tv-group-btn.active { background: #2a2e39; color: #fff; }

.tv-submenu-arrow {
    position: absolute;
    right: -10px;
    top: 0;
    width: 10px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    opacity: 0;
    border-radius: 3px 0 0 3px;
    cursor: pointer;
    transition: opacity 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.tv-submenu-arrow::after {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    border-top: 1.5px solid #848e9c;
    border-right: 1.5px solid #848e9c;
    transform: rotate(45deg);
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.tv-group-btn:hover .tv-submenu-arrow { opacity: 1; }
.tv-submenu-arrow:hover { background: rgba(255,255,255,0.12) !important; opacity: 1 !important; }
.tv-submenu-arrow:hover::after { border-color: #ffffff; }
.tv-submenu-arrow.open { opacity: 1; background: rgba(255,255,255,0.08); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.3); }
.tv-submenu-arrow.open::after,
.tool-btn.menu-open .tv-submenu-arrow::after {
    transform: rotate(-135deg);
    border-color: #ffffff;
}

.tv-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: 6px;
    background: #131722;
    border: 1px solid #2a2e39;
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.7);
    padding: 4px 0;
    z-index: 10000;
    flex-direction: column;
    min-width: 240px;
}
.tv-submenu.active { display: flex; }

.tv-submenu-header {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    color: #787b86;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    user-select: none;
}

.tv-submenu-separator {
    height: 1px;
    background: #434651;
    margin: 4px 0;
}

.tv-submenu-item {
    display: flex;
    align-items: center;
    padding: 0 8px;
    margin: 0 4px;
    height: 36px;
    cursor: pointer;
    font-size: 13px;
    color: #d1d4dc;
    white-space: nowrap;
    border-radius: 4px;
    transition: background-color 0.1s ease, color 0.1s ease;
}
.tv-submenu-item:hover { background: #2a2e39; color: #ffffff; }
.tv-submenu-item.active {
    background: #e0e3eb;
    color: #131722;
}
.tv-submenu-item.active .tv-submenu-shortcut { color: #434651; }
.tv-submenu-item.active img { filter: brightness(0) !important; }

.tv-submenu-shortcut {
    margin-left: auto;
    padding-left: 20px;
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
}

.tv-submenu-item-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tv-submenu-item-label {
    flex: 1;
    margin-left: 6px;
}

/* ============================================================
   TRENDLINE TOOLBAR (из chart.js)
   ============================================================ */
#trendline-toolbar {
    position: fixed; display: none; z-index: 9999;
    background: #1e222d; border: 1px solid #434651; border-radius: 6px;
    padding: 4px; gap: 2px; align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    color: #848e9c; user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#tl-drag-handle:hover { color: #fff; }
#tl-drag-handle:active { cursor: grabbing !important; }

.tv-tool-btn {
    width: 32px; height: 32px;
    display: flex; justify-content: center; align-items: center;
    border-radius: 4px; cursor: pointer; transition: 0.1s;
    position: relative; flex-direction: column; gap: 2px;
}
.tv-tool-btn-row { flex-direction: row; gap: 4px; width: auto; padding: 0 8px; font-size: 13px; font-weight: 500; color: #d1d4dc; }
.tv-tool-btn:hover, .tv-tool-btn.active-btn { background: #2a2e39; color: #fff; }
.tv-divider { width: 1px; height: 24px; background: #434651; margin: 0 4px; }
.tl-color-indicator { width: 16px; height: 3px; border-radius: 1.5px; margin-top: -2px; }
.tl-delete:hover { color: #f6465d; }
#ahl-del:hover { color: #f6465d; }

.tv-popover {
    position: absolute; top: 100%; left: 0; margin-top: 6px;
    background: #1e222d; border: 1px solid #434651; border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    display: none; flex-direction: column; padding: 8px;
    z-index: 10000; cursor: default;
}
.tv-popover.active { display: flex; }
#tl-color-popover { width: 190px; }
#tl-style-popover { width: 170px; padding: 4px; }

.tl-colors-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-bottom: 12px; }
.tl-color-item { width: 18px; height: 18px; border-radius: 3px; cursor: pointer; border: 1px solid rgba(255,255,255,0.05); box-sizing: border-box; }
.tl-color-item:hover { border-color: #d1d4dc; }
.tl-color-item.active { border-color: #fff; box-shadow: 0 0 0 1px #2962ff; }

.tl-opacity-container { border-top: 1px solid #434651; padding-top: 8px; }
.tl-op-header { font-size: 12px; margin-bottom: 8px; color: #848e9c; }
.tl-op-slider-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #d1d4dc; }
#tl-opacity-slider { flex: 1; -webkit-appearance: none; height: 4px; background: #434651; border-radius: 2px; outline: none; }
#tl-opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 12px; height: 12px; border-radius: 50%;
    background: #2962ff; border: 2px solid #fff; cursor: pointer;
}
#tl-width-popover { width: 100px; padding: 4px; }
.tl-width-option { display: flex; align-items: center; gap: 4px; padding: 6px 8px; cursor: pointer; border-radius: 4px; font-size: 13px; color: #d1d4dc; }
.tl-width-option:hover { background: #2a2e39; color: #fff; }
.tl-width-option.active { background: #2962ff; color: #fff; }
.tl-w-line { background: currentColor; }

/* ============================================================
   CUSTOM DROPDOWN (tf-selector, vol-filter)
   ============================================================ */

/* Кнопка */
.custom-dropdown .Select-control {
    background-color: #161a1e !important;
    border: 1px solid #474d57 !important;
    height: 24px !important;
    min-height: 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 4px !important;
    cursor: pointer;
    border-radius: 4px !important;
    overflow: visible !important;
}
.custom-dropdown .Select-multi-value-wrapper {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    width: auto !important;
}
.custom-dropdown .Select-value {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1 !important;
    order: 1 !important;
}
.custom-dropdown .Select-value-label {
    color: #eaecef !important;
    font-family: 'Roboto', sans-serif !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    padding: 0 !important;
}
.custom-dropdown .Select-arrow-zone {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    padding: 0 !important;
    margin-left: 3px !important;
    width: auto !important;
    order: 2 !important;
}
.custom-dropdown .Select-arrow {
    border-color: #848e9c transparent transparent !important;
    border-width: 4px 3px 0 !important;
    display: inline-block !important;
    position: static !important;
}
.custom-dropdown .Select-input,
.custom-dropdown .Select-placeholder,
.custom-dropdown .Select-clear-zone { display: none !important; }

/* Выпадающий список */
.custom-dropdown .Select-menu-outer {
    background-color: #1e2329 !important;
    border: 1px solid #474d57 !important;
    margin-top: 5px !important;
    min-width: 100% !important;
    width: max-content !important;
    overflow: hidden !important;
}
.custom-dropdown .Select-menu {
    overflow: hidden !important;
}
/* Скрываем AutoSizer-div (второй дочерний элемент .Select-menu),
   он создаёт лишнее пустое пространство по высоте и ширине */
.custom-dropdown .Select-menu > div:nth-child(2) {
    display: none !important;
}
/* Опции */
.custom-dropdown .VirtualizedSelectOption,
.custom-dropdown [class*="VirtualSelectGrid"] .ReactVirtualized__Grid__innerScrollContainer > div > div {
    padding: 6px 12px !important;
    font-size: 12px !important;
    color: #848e9c !important;
}
.custom-dropdown .VirtualizedSelectFocusedOption,
.custom-dropdown .is-focused {
    background-color: #2b3139 !important;
    color: #f0b90b !important;
}

/* ============================================================
   АВТОРИЗАЦИЯ
   ============================================================ */
.auth-tab {
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #848e9c;
    padding: 8px 2px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    user-select: none;
}
.auth-tab:hover { color: #d1d4dc; }
.auth-tab-active { color: #eaecef !important; border-bottom-color: #0ecb81 !important; }
#auth-email-input:focus, #auth-password-input:focus, #auth-password2-input:focus {
    border-color: #0ecb81 !important;
    box-shadow: 0 0 0 2px rgba(14,203,129,0.15) !important;
}
#auth-login-btn:hover { background-color: #0ab86e !important; }
#auth-logout-btn:hover { background-color: rgba(246,70,93,0.1) !important; }
#auth-save-now-btn:hover { background-color: #3c4150 !important; }
#auth-modal-overlay { backdrop-filter: blur(4px); }

/* ============================================================
   TABLE COLLAPSE
   ============================================================ */
/* Resizer has padding:0 5px → padding-box = 11px wide,
   the actual 1px line sits at offset 5–6px inside that box.
   Button on TABLE side: left: 6px  (starts right at the line's right edge)
   Button on CHART side: right: 6px (ends right at the line's left edge) */
.table-collapse-tab {
    position: absolute;
    bottom: 80px;
    left: 6px;
    right: auto;
    width: 10px;
    height: 26px;
    background: #2b3139;
    border: 1px solid #474d57;
    border-radius: 0 4px 4px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer !important;
    font-size: 11px;
    line-height: 1;
    color: #848e9c;
    z-index: 500;
    pointer-events: all !important;
    transition: background 0.15s, color 0.15s;
}
.table-collapse-tab:hover { background: #3c4150; color: #c9d1dc; }
/* Collapsed: button flips to chart/scale side, resizer becomes non-interactive */
.resizer-vertical.table-collapsed { cursor: default !important; pointer-events: none; }
.resizer-vertical.table-collapsed .table-collapse-tab {
    left: auto;
    right: 6px;
    border-radius: 3px 0 0 3px;
    pointer-events: all !important;
    cursor: pointer !important;
}
.table-wrapper.table-collapsed { width: 0 !important; overflow: hidden; }

/* ============================================================
   МОБИЛЬНАЯ ВЕРСИЯ (≤768px)
   ============================================================ */
@media (max-width: 768px) {
    * { box-sizing: border-box; }
    body { overflow-y: auto !important; touch-action: pan-y !important; height: auto !important; }
    .main-container { display: flex !important; flex-direction: column !important; height: auto !important; }
    .main-body { flex-direction: column !important; }
    .charts-wrapper {
        width: 100vw !important;
        height: calc(100dvh - 120px) !important;
        max-height: calc(100dvh - 120px) !important;
        flex: none !important;
    }
    .toolbar {
        order: 0;
        width: 100vw !important;
        height: 80px !important;
        min-height: 80px !important;
        flex-direction: row !important;
        border-right: none !important;
        border-top: 1px solid #2b3139 !important;
        justify-content: center !important;
        align-items: flex-start !important;
        padding-top: 12px !important;
        padding-bottom: 40px !important;
        background-color: #000000 !important;
        flex: none !important;
        box-sizing: border-box !important;
    }
    .tool-btn { margin-bottom: 0 !important; margin-right: 10px !important; height: 32px !important; width: 32px !important; }
    .tv-tool-group { margin-bottom: 0 !important; margin-right: 10px !important; }
    .tv-tool-group .tv-group-btn { margin: 0 !important; }
    .tv-submenu-shortcut { display: none !important; }
    .table-wrapper { width: 100vw !important; border-left: none !important; display: block !important; height: auto !important; flex: none !important; }
    .table-collapse-tab { display: none !important; }
    #price-container { flex: 50 1 0%; min-height: 50px; }
    #gd-container    { flex: 25 1 0%; min-height: 40px; }
    #macd-container  { flex: 25 1 0%; min-height: 40px; }
    #time-area { flex: 0 0 24px !important; height: 24px !important; }

    .tv-submenu-arrow {
        opacity: 1 !important;
        left: 50% !important;
        right: auto !important;
        top: -8px !important;
        bottom: auto !important;
        transform: translateX(-50%) !important;
        width: 32px !important;
        height: 8px !important;
        border-radius: 0 0 3px 3px !important;
    }
    .tv-submenu-arrow::after {
        transform: rotate(-45deg) !important;
    }
    .tv-submenu-arrow.open::after,
    .tool-btn.menu-open .tv-submenu-arrow::after {
        transform: rotate(135deg) !important;
    }
    .tv-submenu {
        top: auto !important;
        bottom: 100% !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin-left: 0 !important;
        margin-bottom: 8px !important;
    }
    .resizer {
        display: block !important; height: 24px !important; background: transparent !important;
        z-index: 1000; position: relative; cursor: row-resize; margin: -12px 0 !important;
        touch-action: none; -webkit-tap-highlight-color: transparent;
        outline: none !important; border: none !important;
    }
    .resizer::after {
        content: ""; display: block; position: absolute; top: 50%; left: 0;
        width: 100%; height: 1px; background-color: rgba(255,255,255,0.15);
        transform: translateY(-50%); transition: background-color 0.1s; pointer-events: none;
    }
    .resizer.dragging::after { background-color: #0ecb81 !important; height: 1px !important; }
    .resizer-vertical { display: none !important; }
}
