/* ==========================================================================
   LevelWatch — Тёмный трейдинговый интерфейс
   ========================================================================== */

/* --- Reset & Base --------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-body:        #0d1117;
    --bg-surface:     #161b22;
    --bg-surface-alt: #1c2333;
    --bg-elevated:    #21262d;
    --border-default: #30363d;
    --border-active:  #58a6ff;
    --text-primary:   #e6edf3;
    --text-secondary: #8b949e;
    --text-muted:     #6e7681;
    --accent-green:   #3fb950;
    --accent-red:     #f85149;
    --accent-blue:    #58a6ff;
    --accent-yellow:  #d2991d;
    --candle-green:   #26a69a;
    --candle-red:     #ef5350;

    --radius-sm: 6px;
    --radius-md: 10px;
    --gap: 12px;

    --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body {
    height: 100%;
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

a { color: var(--accent-blue); text-decoration: none; }

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

/* --- Header --------------------------------------------------------------- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
}

.header__brand {
    display: flex;
    flex-direction: column;
}

.header__title {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-blue);
    letter-spacing: -0.3px;
}

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

.header__status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 14px;
    background: var(--bg-surface-alt);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}

.status-dot--connected    { background: var(--accent-green); }
.status-dot--connecting   { background: var(--accent-yellow); animation: pulse 1.2s infinite; }
.status-dot--disconnected { background: var(--text-muted); }
.status-dot--error        { background: var(--accent-red); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

/* --- Main Content --------------------------------------------------------- */
.main {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: var(--gap);
    padding: var(--gap);
}

/* --- Sidebar (список монет) ----------------------------------------------- */
.sidebar {
    width: 200px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.symbol-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 4px;
    flex: 1;
    overflow-y: auto;
}

.symbol-list__title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 10px 6px;
}

.symbol-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.symbol-btn:hover {
    background: var(--bg-surface-alt);
    color: var(--text-primary);
}

.symbol-btn--active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-active);
}

.symbol-btn__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.symbol-btn--active .symbol-btn__dot {
    background: var(--accent-green);
}

/* --- Chart Area ----------------------------------------------------------- */
.chart-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    min-width: 0;
}

.chart-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
    min-height: 0;
}

.chart-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-default);
    flex-shrink: 0;
}

.chart-card__symbol-info {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.chart-card__symbol {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-card__price {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-green);
}


/* --- Interval Buttons (выбор таймфрейма) --------------------------------- */
.chart-card__controls {
    display: flex;
    align-items: center;
    gap: 14px;
}

.interval-buttons {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.interval-btn {
    padding: 4px 8px;
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    line-height: 1.4;
}

.interval-btn:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.interval-btn--active {
    color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.12);
    font-weight: 600;
}
/* --- Drawing Toolbar ----------------------------------------------------- */
.drawing-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    margin-left: 12px;
}

.drawing-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.drawing-tool-btn:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
    border-color: var(--border-default);
}

.drawing-tool-btn--active {
    color: var(--accent-yellow);
    background: rgba(210, 153, 29, 0.1);
    border-color: var(--accent-yellow);
    box-shadow: 0 0 6px rgba(210, 153, 29, 0.15);
}

.drawing-toolbar__hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 340px;
}


.chart-card__last-update {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.chart-container {
    position: relative;
    flex: 1;
    min-height: 0;
    cursor: crosshair;
}

.chart-container--grabbing {
    cursor: grabbing;
}

/* --- Info Panel (правый блок) --------------------------------------------- */
.info-panel {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    overflow-y: auto;
    min-height: 0;
    padding-right: 2px;
}

.info-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 14px 16px;
}

.info-card__title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.info-card__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 13px;
}

.info-card__label {
    color: var(--text-secondary);
}

.info-card__value {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
}

/* ==========================================================================
   Алерты — блок, кнопки, поле ввода, список
   ========================================================================== */

/* Карточка алертов: не даём ей сжаться в ноль, если много контента */
.alerts-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 340px;
    overflow: hidden;
}

/* Общий стиль кнопок алертов */
.alert-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-sans);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}

.alert-btn:hover {
    background: var(--bg-surface-alt);
    border-color: var(--border-active);
}

/* Кнопка «Добавить» */
.alert-btn--add {
    flex-shrink: 0;
    background: var(--accent-blue);
    color: #fff;
    border-color: var(--accent-blue);
}

.alert-btn--add:hover {
    background: #4a8edc;
    border-color: #4a8edc;
}

/* Кнопка «Линия по текущей цене» */
.alert-btn--quick {
    width: 100%;
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
}

.alert-btn--quick:hover {
    background: var(--bg-surface-alt);
}

/* Строка ввода цены + кнопка */
.alerts-input-row {
    display: flex;
    gap: 6px;
}

.alerts-price-input {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--text-primary);
    background: var(--bg-body);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s ease;
}

.alerts-price-input:focus {
    border-color: var(--accent-blue);
}

.alerts-price-input::placeholder {
    color: var(--text-muted);
}

/* Скрываем стрелочки в числовом поле (Chrome/Safari/Edge) */
.alerts-price-input::-webkit-outer-spin-button,
.alerts-price-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Скрываем стрелочки (Firefox) */
.alerts-price-input[type="number"] {
    -moz-appearance: textfield;
}

/* Подсказка */
.alerts-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
    padding: 2px 0;
}

/* Список алертов */
.alerts-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    max-height: 160px;
}

/* Сообщение «нет алертов» */
.alerts-list__empty {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 10px 0;
}

/* Элемент списка алертов */
.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: var(--font-mono);
    background: var(--bg-body);
    border: 1px solid var(--border-default);
}

/* Активный алерт */
.alert-item--active {
    border-color: var(--accent-yellow);
    background: rgba(210, 153, 29, 0.08);
}

.alert-item--active .alert-item__price {
    color: var(--accent-yellow);
}

/* Сработавший алерт */
.alert-item--triggered {
    border-color: var(--text-muted);
    background: rgba(110, 118, 129, 0.06);
    opacity: 0.7;
}

.alert-item--triggered .alert-item__price {
    color: var(--text-muted);
    text-decoration: line-through;
}

/* Цена алерта */
.alert-item__price {
    font-weight: 600;
}

/* Метка статуса */
.alert-item__status {
    font-size: 10px;
    font-family: var(--font-sans);
    color: var(--text-muted);
    margin-left: 6px;
}

/* Кнопка удаления */
.alert-item__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
    flex-shrink: 0;
    margin-left: 6px;
}

.alert-item__delete:hover {
    color: var(--accent-red);
    background: rgba(248, 81, 73, 0.1);
}


/* --- Zones Overlay -------------------------------------------------------- */
.zones-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.zone-rect {
    position: absolute;
    border: 1px solid rgba(240, 185, 11, 0.85);
    background: rgba(240, 185, 11, 0.12);
    box-shadow: inset 0 0 0 1px rgba(240, 185, 11, 0.12);
    border-radius: 4px;
}
.zone-rect--preview {
    border-style: dashed;
    border-color: rgba(240, 185, 11, 0.9);
    border-width: 1px;
    opacity: 0.75;
    background: rgba(240, 185, 11, 0.2);
    box-shadow: inset 0 0 0 1px rgba(240, 185, 11, 0.2);
    pointer-events: none;
}


/* --- Блок «Зоны» в info-panel --------------------------------------------- */
.zones-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
}

.zone-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 7px 12px;
    font-size: 13px;
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--accent-yellow);
    background: rgba(210, 153, 29, 0.06);
    border: 1px solid var(--accent-yellow);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.zone-btn:hover {
    background: rgba(210, 153, 29, 0.12);
}

.zone-btn--active {
    background: rgba(210, 153, 29, 0.15);
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
    box-shadow: 0 0 6px rgba(210, 153, 29, 0.25);
}

.zone-btn--cancel {
    color: var(--text-muted);
    border-color: var(--border-default);
    background: var(--bg-surface-alt);
}

.zone-btn--cancel:hover {
    color: var(--accent-red);
    border-color: var(--accent-red);
    background: rgba(248, 81, 73, 0.08);
}

.zones-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
    padding: 2px 0;
}

.zones-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    max-height: 120px;
}

/* Сообщение «нет зон» */
.zones-list__empty {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 10px 0;
}

/* Элемент списка зон */
.zone-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: var(--font-mono);
    background: var(--bg-body);
    border: 1px solid var(--accent-yellow);
    background: rgba(210, 153, 29, 0.06);
}

.zone-item__range {
    font-weight: 600;
    color: var(--accent-yellow);
}

.zone-item__status {
    font-size: 10px;
    font-family: var(--font-sans);
    color: var(--text-muted);
    margin-left: 6px;
}

.zone-item__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
    flex-shrink: 0;
    margin-left: 6px;
}

.zone-item__delete:hover {
    color: var(--accent-red);
    background: rgba(248, 81, 73, 0.1);
}
/* --- Footer (опционально) ------------------------------------------------- */
.footer {
    flex-shrink: 0;
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-default);
    background: var(--bg-surface);
}

/* --- Scrollbar ------------------------------------------------------------ */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Floating drawing action button --------------------------------------- */
.drawing-action {
    display: none;
    position: absolute;
    z-index: 10;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    color: var(--accent-red);
    background: rgba(22, 27, 34, 0.92);
    border: 1px solid var(--accent-red);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    pointer-events: auto;
}

.drawing-action:hover {
    background: rgba(248, 81, 73, 0.12);
    border-color: var(--accent-red);
}

.alert-item--selected,
.zone-item--selected {
    border-color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.1);
}



/* --- SVG Icons ------------------------------------------------------------- */
.icon {
    display: block;
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}

.icon-trash {
    width: 16px;
    height: 16px;
}

.alert-item__delete .icon-trash,
.zone-item__delete .icon-trash {
    width: 14px;
    height: 14px;
}

.drawing-action .icon-trash {
    width: 18px;
    height: 18px;
}

/* --- Mobile (≤768px) ------------------------------------------------------ */
@media (max-width: 768px) {
    .main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-shrink: 0;
        max-height: 140px;
    }

    .symbol-list {
        flex-direction: row;
        flex-wrap: wrap;
        overflow-y: auto;
        gap: 4px;
        padding: 6px;
    }

    .symbol-list__title {
        width: 100%;
        padding: 2px 4px;
    }

    .symbol-btn {
        flex: 0 0 auto;
        padding: 6px 10px;
        font-size: 12px;
    }

    .info-panel {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .info-card {
        flex: 1;
        min-width: 140px;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .alerts-card {
        max-height: none;
    }
}


/* --- H1 Pattern Monitor --------------------------------------------------- */
.pattern-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pattern-monitor__summary {
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary);
}

.pattern-monitor__patterns {
    font-size: 10px;
    line-height: 1.45;
    color: var(--text-muted);
}

.pattern-notification-btn {
    width: 100%;
    padding: 7px 10px;
    font-size: 12px;
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--accent-yellow);
    background: rgba(210, 153, 29, 0.06);
    border: 1px solid var(--accent-yellow);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.pattern-notification-btn:hover:not(:disabled) {
    background: rgba(210, 153, 29, 0.12);
}

.pattern-notification-btn:disabled {
    cursor: default;
    color: var(--text-muted);
    border-color: var(--border-default);
    background: var(--bg-body);
}

.pattern-monitor__status {
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-muted);
}

.pattern-monitor__status--ok {
    color: var(--accent-green);
}

.pattern-monitor__status--warn {
    color: var(--accent-yellow);
}

.pattern-monitor__status--error {
    color: var(--accent-red);
}

/* In-page fallback notification. System Notification API may be unavailable
   on an insecure local origin, so pattern signals are always shown here too. */
.pattern-toast-container {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(360px, calc(100vw - 36px));
    pointer-events: none;
}

.pattern-toast {
    padding: 12px 14px;
    background: rgba(22, 27, 34, 0.97);
    border: 1px solid var(--accent-yellow);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.pattern-toast__title {
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.pattern-toast__body {
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-secondary);
}
