/* ==========================================
   БОКОВАЯ ПАНЕЛЬ ЧАТА — капля + 3 режима
   ========================================== */

/* Место под скроллбар резервируется на десктопе —
   страница не "расширяется" при блокировке скролла в оверлее */
@media (min-width: 769px) {
    html {
        scrollbar-gutter: stable;
    }
}

.chat-drop-btn {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 84px;
    background: rgba(22, 24, 30, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: none;
    backdrop-filter: blur(6px);
    color: #777;
    cursor: pointer;
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.chat-drop-btn svg {
    width: 18px;
    height: 18px;
}

.chat-drop-btn:hover {
    color: #fff;
    width: 40px;
    background: rgba(55, 55, 55, 0.9);
}

/* Когда панель открыта — капля прячется в стену */
.chat-drop-btn.hidden {
    transform: translateY(-50%) translateX(-110%);
    pointer-events: none;
}

/* === Затемнение + размытие страницы (режим оверлея) === */
.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    z-index: 9995;
}

.chat-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

/* === Сама панель === */
.chat-panel {
    position: fixed;
    top: 50px;
    bottom: 50px;
    left: 15px;
    width: 420px;
    max-width: calc(100vw - 30px);
    background: rgba(18, 18, 18, 0.92);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    z-index: 9996;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* закрыта — уехала за левый край */
    transform: translateX(calc(-100% - 60px));
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1),
                left 0.45s cubic-bezier(0.4, 0, 0.2, 1),
                right 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

/* закрыта и прижата справа — уезжает за правый край */
.chat-panel.side-right {
    transform: translateX(calc(100% + 60px));
}

.chat-panel.open {
    transform: translateX(0);
}

/* во время перетаскивания/ресайза — без транзишенов */
.chat-panel.dragging,
.chat-panel.resizing {
    transition: none;
}

/* === Шапка панели: 3 кнопки режимов === */
.chat-panel-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    user-select: none;
}

/* в свободном плавании шапка = ручка перетаскивания */
.chat-panel.mode-free .chat-panel-header {
    cursor: grab;
}

.chat-panel.mode-free.dragging .chat-panel-header {
    cursor: grabbing;
}

.panel-mode-btn {
    background: transparent;
    border: none;
    color: #555;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    transition: all 0.25s ease;
}

.panel-mode-btn:hover {
    color: #ccc;
}

.panel-mode-btn.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.panel-mode-btn svg {
    width: 18px;
    height: 18px;
}

/* ✅ Стало: скрыт по умолчанию, плавно появляется в режиме фиксации */
.pin-side-switch {
    display: flex;
    gap: 2px;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    margin-left: 0;
    transition: max-width 0.3s ease,
                opacity 0.3s ease,
                margin-left 0.3s ease,
                visibility 0s linear 0.3s;
}

.chat-panel.mode-pin .pin-side-switch {
    max-width: 130px;
    opacity: 1;
    visibility: visible;
    margin-left: 6px;
    transition: max-width 0.3s ease,
                opacity 0.3s ease,
                margin-left 0.3s ease;
}

.pin-side-btn {
    background: transparent;
    border: none;
    color: #555;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    transition: all 0.25s ease;
}

.pin-side-btn:hover {
    color: #ccc;
}

.pin-side-btn.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.pin-side-btn svg {
    width: 16px;
    height: 16px;
}

/* === Крестик закрытия === */
.chat-panel-close {
    margin-left: auto;
    background: transparent;
    border: none;
    color: #555;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    transition: all 0.25s ease;
}

.chat-panel-close:hover {
    color: #fff;
}

.chat-panel-close svg {
    width: 16px;
    height: 16px;
}

/* === Ручка ресайза === */
.chat-panel-resize {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    right: 0;
    cursor: ew-resize;
    z-index: 5;
}

.chat-panel.side-right .chat-panel-resize {
    right: auto;
    left: 0;
}

.chat-panel.mode-free .chat-panel-resize {
    right: 0;
    left: auto;
}

.chat-panel-resize:hover {
    background: rgba(255, 255, 255, 0.07);
}

/* === Сетка веток 2×3 === */
.branch-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, auto);
    grid-auto-flow: column;
    gap: 8px;
    margin-bottom: 10px;
}

.branch-item {
    padding: 10px;
    border-radius: 10px;
    color: #aaa;
    font-family: 'MyCustomFont';
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.branch-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.branch-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* === Верхняя зона: ветки + создание === */
.chat-panel-top {
    display: flex;
    flex-direction: column;
    max-height: 45%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.branch-scroll {
    overflow-y: auto;
    padding: 14px 14px 4px;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
}

.create-branch-btn {
    flex-shrink: 0;
    margin: 10px 14px 14px;
    padding: 12px;
    background: transparent;
    border: 1px dashed rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    color: #888;
    font-family: 'MyCustomFont';
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.create-branch-btn:hover {
    border-color: #fff;
    color: #fff;
}

.panel-hint {
    margin-top: 14px;
    font-size: 13px;
    color: #555;
    text-align: center;
}

/* === Кнопка прокрутки вниз === */
.chat-scroll-down-btn {
    position: absolute;
    bottom: 100%;
    right: 16px;
    margin-bottom: 8px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #2A2F32;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.chat-scroll-down-btn:hover {
    background: #3A3F42;
    transform: scale(1.1);
}

.chat-scroll-down-btn.show {
    opacity: 1;
    pointer-events: auto;
}

/* === Поле ввода === */
.chat-panel-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
}

.chat-panel-input textarea {
    flex: 1;
    min-height: 24px;
    max-height: 90px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    color: #eee;
    font-family: 'MyCustomFont', sans-serif;
    font-size: 14px;
    resize: none;
    outline: none;
    scrollbar-width: thin;
    scrollbar-color: #444 transparent;
    transition: border-color 0.2s ease;
}

.chat-panel-input textarea:focus {
    border-color: rgba(255, 255, 255, 0.25);
}

.chat-panel-input textarea.scrollable {
    overflow-y: auto;
}

.chat-panel-input textarea::placeholder {
    color: #666;
}

#panel-send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#panel-send-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* === Заглушка для неавторизованных === */
.chat-login-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
    color: #aaa;
    font-family: 'MyCustomFont', sans-serif;
    font-size: 15px;
    text-align: center;
    padding: 20px;
}

.chat-login-hint a {
    color: #fff;
    text-decoration: underline;
    transition: opacity 0.2s ease;
}

.chat-login-hint a:hover {
    opacity: 0.8;
}

/* === Мобильная адаптация панели чата === */
@media (max-width: 768px) {
    .chat-drop-btn {
        top: 50% !important;
        bottom: auto !important;
        transform: translateY(-50%) !important;
        left: 0 !important;
        width: 28px !important;
        height: 54px !important;
        border-radius: 0 14px 14px 0 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .chat-drop-btn.hidden {
        transform: translateY(-50%) translateX(-110%) !important;
        display: none !important;
    }

    .chat-overlay {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(0, 0, 0, 0.85) !important;
    }

    .chat-panel:not(.open) {
        display: none !important;
    }

    .chat-panel {
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 99999 !important;
        transform: none !important;
        background: #0c0e14 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .chat-panel-resize {
        display: none !important;
    }
}

