/* ============================================================
   TradeBot Dashboard — Стили (исправленная версия)
   Тёмная тема с фиолетовым акцентом #974ba2
   ============================================================ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0e1217;
    --bg-card: #131a22;
    --bg-border: #1f2a33;
    --bg-hover: #1a2332;
    --accent: #974ba2;
    --accent-hover: #7d3d87;
    --text-primary: #e0e5ec;
    --text-secondary: #8b9aa8;
    --text-muted: #5a6a7a;
    --green: #26a69a;
    --red: #ef5350;
    --purple: #7b68ee;
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 8px;
    --sidebar-width: 350px;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* === ШАПКА === */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--bg-border);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 24px;
    color: var(--accent);
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.logo-text .accent {
    color: var(--accent);
}

.header-center {
    display: flex;
    align-items: center;
}

.price-block {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.price-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.price-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.price-change {
    font-size: 13px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}

.price-change.up {
    color: var(--green);
    background: rgba(38, 166, 154, 0.12);
}

.price-change.down {
    color: var(--red);
    background: rgba(239, 83, 80, 0.12);
}

.header-right {
    display: flex;
    align-items: center;
}

.signal-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--bg-primary);
    border: 1px solid var(--bg-border);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.signal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s ease;
}

.signal-badge.buy .signal-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.signal-badge.sell .signal-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.signal-badge.hold .signal-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.signal-badge.buy { border-color: rgba(38,166,154,0.3); color: var(--green); }
.signal-badge.sell { border-color: rgba(239,83,80,0.3); color: var(--red); }
.signal-badge.hold { border-color: rgba(151,75,162,0.3); color: var(--accent); }

/* === ОСНОВНАЯ ОБЛАСТЬ === */
.main {
    display: flex;
    height: calc(100vh - 56px - 32px);
    gap: 0;
}

/* === ГРАФИК === */
.chart-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid var(--bg-border);
}

/* === ТУЛБАР ГРАФИКА === */
.chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--bg-border);
    min-height: 42px;
}

.chart-toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.chart-toolbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

.chart-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chart-status {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 140px;
    text-align: right;
    white-space: nowrap;
}

/* === КНОПКИ ТАЙМФРЕЙМОВ === */
.timeframe-selector {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    padding: 3px;
    border-radius: 6px;
    border: 1px solid var(--bg-border);
}

.tf-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font);
}

.tf-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tf-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 4px rgba(151, 75, 162, 0.3);
}

/* === КОНТЕЙНЕР ГРАФИКА === */
#chartContainer {
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* === БОКОВАЯ ПАНЕЛЬ === */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-primary);
    flex-shrink: 0; /* не даём сжиматься */
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: var(--bg-border);
    border-radius: 2px;
}

/* === ПАНЕЛИ === */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--bg-border);
    border-radius: var(--radius);
    overflow: hidden;
    flex-shrink: 0; /* каждая панель не сжимается */
    min-height: 80px; /* минимальная высота, чтобы не схлопывалась */
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--bg-border);
    background: rgba(31, 42, 51, 0.3);
}

.panel-icon {
    font-size: 15px;
}

.panel-body {
    padding: 12px 14px;
}

/* === ПАНЕЛЬ СИГНАЛА (фиксированная высота) === */
.signal-panel {
    flex-shrink: 0;
    min-height: 180px; /* чтобы всегда было видно все строки */
}

/* === ПАНЕЛЬ УПРАВЛЕНИЯ (фиксированная) === */
.position-panel {
    flex-shrink: 0;
    min-height: 240px; /* достаточно для полей и кнопки */
}

/* === ПАНЕЛЬ УРОВНЕЙ (с прокруткой) === */
.levels-panel {
    flex-shrink: 0;
    max-height: none; /* при превышении – прокрутка */
    overflow-y: auto;
    display: none; /* по умолчанию скрыта */
}
.levels-panel .panel-body {
    padding: 12px 14px;
}

/* === ПРОЧИЕ СТИЛИ === */
.signal-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.signal-row:not(:last-child) {
    border-bottom: 1px solid rgba(31, 42, 51, 0.5);
}

.signal-row .label {
    font-size: 12px;
    color: var(--text-secondary);
}

.signal-row .value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.signal-row .value.small {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

.signal-row .value.buy { color: var(--green); }
.signal-row .value.sell { color: var(--red); }
.signal-row .value.hold { color: var(--accent); }

/* === ФОРМА === */
.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.form-group select,
.form-group input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--bg-border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s ease;
}

.form-group select:focus,
.form-group input[type="number"]:focus {
    border-color: var(--accent);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b9aa8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    appearance: none;
    -moz-appearance: textfield;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 0;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--bg-primary);
    border: 1px solid var(--bg-border);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.checkbox-group input[type="checkbox"]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 12px;
}

.btn-calculate {
    width: 100%;
    padding: 10px;
    margin-top: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-calculate:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(151, 75, 162, 0.4);
}

.btn-calculate:active {
    transform: translateY(0);
}

.btn-calculate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* === ПЕРЕКЛЮЧАТЕЛЬ НАПРАВЛЕНИЯ === */
.direction-toggle {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.dir-btn {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--bg-border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.dir-btn:hover {
    border-color: var(--text-muted);
}

.dir-btn.buy-btn.active {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
    box-shadow: 0 2px 8px rgba(38, 166, 154, 0.3);
}

.dir-btn.sell-btn.active {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
    box-shadow: 0 2px 8px rgba(239, 83, 80, 0.3);
}

.dir-btn:not(.active) {
    opacity: 0.5;
}

.dir-btn:not(.active):hover {
    opacity: 0.7;
}

/* === УРОВНИ === */
.level-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

/* Убираем границу у строки "Трейлинг-стоп" (она находится перед разделителем) */
.levels-panel .level-row.trail {
    border-bottom: none !important;
}

/* Убираем границу у строки "Размер позиции" */
.levels-panel .level-row.position-size {
    border-bottom: none !important;
}

.level-row:not(:last-child) {
    border-bottom: 1px solid rgba(31, 42, 51, 0.4);
}

.level-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.level-label {
    flex: 1;
    font-size: 12px;
    color: var(--text-secondary);
}

.level-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 90px;
}

.level-pct {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 50px;
    text-align: right;
}

.level-divider {
    height: 1px;
    background: var(--bg-border);
    margin: 4px 0;
}

/* === ФУТЕР === */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 32px;
    padding: 0 20px;
    background: var(--bg-card);
    border-top: 1px solid var(--bg-border);
    font-size: 11px;
    color: var(--text-muted);
}

.footer-time {
    font-variant-numeric: tabular-nums;
}

/* === АНИМАЦИИ === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel {
    animation: fadeIn 0.3s ease;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chart-status.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* === КНОПКА УДАЛЕНИЯ ПОЗИЦИИ === */
.btn-remove {
    width: 100%;
    padding: 8px;
    margin-top: 12px;
    background: transparent;
    color: var(--red);
    border: 1px solid var(--red);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-remove:hover {
    background: rgba(239, 83, 80, 0.1);
}

/* === АДАПТИВНОСТЬ === */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 280px;
    }
    .header-center {
        display: none;
    }
}

@media (max-width: 700px) {
    .main {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 40vh;
    }
    .chart-section {
        border-right: none;
        border-bottom: 1px solid var(--bg-border);
        min-height: 300px;
    }
}