/* ============================================================
   Мини-чат — стили (десктоп + мобильный)
   ============================================================ */

#global-chat-mini {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    font-family: var(--font-main);
}

/* Кнопка открытия чата */
.gcm-button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-highlight);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s;
}

.gcm-button:hover {
    transform: scale(1.05);
}

/* Бейдж непрочитанных */
.gcm-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #c41e3a;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* Панель чата */
.gcm-panel {
    position: fixed;
    bottom: 70px;
    right: 16px;
    width: 700px;
    height: 520px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    min-width: 400px;
    min-height: 300px;
    resize: both;
}

/* Заголовок панели */
.gcm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--color-highlight);
    min-height: 40px;
}

/* Кнопки в заголовке */
.gcm-sound-btn,
.gcm-close,
#gcm-expand-btn {
    background: none;
    border: none;
    color: var(--color-text-dim);
    cursor: pointer;
    font-size: 1rem;
}

.gcm-sound-btn:hover,
.gcm-close:hover,
#gcm-expand-btn:hover {
    color: var(--color-text);
}

/* Тело чата (сайдбар + область сообщений) */
.gcm-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Сайдбар */
.gcm-sidebar {
    width: 240px;
    min-width: 240px;
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

/* Поиск */
.gcm-search {
    padding: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    position: relative;
}

.gcm-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
}

.gcm-search-item {
    padding: 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gcm-search-item:hover {
    background: var(--color-bg);
}

/* Список чатов */
.gcm-sidebar-list {
    flex: 1;
    overflow-y: auto;
}

.gcm-sidebar-section {
    border-bottom: 1px solid var(--color-border);
}

.gcm-sidebar-section-header {
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    color: var(--color-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Элемент чата */
.gcm-chat-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.1s;
}

.gcm-chat-item:hover {
    background: var(--color-surface);
}

.gcm-chat-item.active {
    background: var(--color-surface);
}

/* Аватар в списке */
.gcm-chat-item-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-highlight);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* Информация о чате */
.gcm-chat-item-info {
    flex: 1;
    min-width: 0;
}

.gcm-chat-item-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Бейдж непрочитанных в чате */
.gcm-unread-badge {
    background: var(--color-highlight);
    color: #fff;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    font-size: 0.65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    padding: 0 4px;
}

/* Статусы */
.gcm-online { background: #4caf50; }
.gcm-away { background: #ffa726; }
.gcm-dnd { background: #ef5350; }
.gcm-invisible,
.gcm-offline { background: #666; }

.gcm-online,
.gcm-away,
.gcm-dnd,
.gcm-invisible,
.gcm-offline {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Область сообщений */
.gcm-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    height: 100%;
    position: relative;
}

/* Окно чата */
.gcm-chat-window {
    display: none;
}

.gcm-chat-window.active {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    overflow: hidden;
}

/* Сообщения */
.gcm-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.5rem;
    font-size: 0.8rem;
    min-height: 0;
}

.gcm-msg {
    margin-bottom: 0.3rem;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    max-width: 80%;
    word-wrap: break-word;
    cursor: default;
}

.gcm-msg.mine {
    background: rgba(108, 92, 231, 0.15);
    border: 1px solid rgba(108, 92, 231, 0.25);
    margin-left: auto;
}

.gcm-msg.theirs {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    margin-right: auto;
}

.gcm-msg-sender {
    color: var(--color-highlight);
    font-weight: 600;
    font-size: 0.7rem;
    margin-bottom: 0.15rem;
}

.gcm-msg-text {
    line-height: 1.4;
    font-size: 0.8rem;
}

.gcm-msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
    margin-top: 0.15rem;
}

.gcm-msg-time {
    color: var(--color-text-dim);
    font-size: 0.6rem;
}

.gcm-msg-status {
    color: var(--color-text-dim);
    font-size: 0.65rem;
}

.gcm-msg-status.read {
    color: #4caf50;
}

/* Ответ на сообщение */
.gcm-msg-reply {
    font-size: 0.7rem;
    padding: 0.3rem 0.4rem;
    margin-bottom: 0.3rem;
    border-left: 3px solid var(--color-highlight);
    background: rgba(108, 92, 231, 0.08);
    border-radius: 4px;
    cursor: pointer;
}

.gcm-msg-reply-name {
    color: var(--color-highlight);
    font-weight: 600;
    font-size: 0.65rem;
}

.gcm-msg-reply-text {
    color: var(--color-text-dim);
    font-size: 0.65rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Превью ответа */
.gcm-reply-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: var(--color-bg);
    border-left: 3px solid var(--color-highlight);
    font-size: 0.7rem;
    border-radius: 4px;
}

.gcm-reply-preview-name {
    color: var(--color-highlight);
    font-weight: 600;
}

.gcm-reply-preview-text {
    color: var(--color-text-dim);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gcm-reply-preview-close {
    cursor: pointer;
    color: var(--color-text-dim);
    font-size: 0.8rem;
}

/* Поле ввода */
.gcm-input-area {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--color-border);
}

.gcm-input-row {
    display: flex;
    padding: 0.4rem;
    gap: 0.3rem;
    align-items: flex-end;
}

.gcm-input-row textarea {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.8rem;
    border-radius: 4px;
    resize: none;
    min-height: 32px;
    max-height: 80px;
    font-family: inherit;
}

.gcm-input-row button {
    padding: 0.3rem 0.6rem;
    background: var(--color-highlight);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Эмодзи */
.gcm-emoji-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.3rem;
}

.gcm-emoji-panel {
    position: absolute;
    bottom: 100%;
    right: 0;
    width: 280px;
    height: 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gcm-emoji-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
    min-height: 28px;
}

.gcm-emoji-tab {
    padding: 0.2rem 0.5rem;
    font-size: 0.65rem;
    cursor: pointer;
    border-right: 1px solid var(--color-border);
    white-space: nowrap;
    color: var(--color-text-dim);
}

.gcm-emoji-tab.active {
    color: var(--color-highlight);
    font-weight: 600;
}

.gcm-emoji-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    align-content: flex-start;
}

.gcm-emoji-item {
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.1rem;
    border-radius: 4px;
}

.gcm-emoji-item:hover {
    background: var(--color-bg);
}

/* Ресайз */
.gcm-resize-left {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: ew-resize;
    z-index: 10;
}

.gcm-resize-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    cursor: ns-resize;
    z-index: 10;
}

.gcm-resize-corner {
    position: absolute;
    left: 0;
    top: 0;
    width: 12px;
    height: 12px;
    cursor: nwse-resize;
    z-index: 11;
}

/* Контекстное меню */
.gcm-context-menu {
    position: absolute;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 100;
    min-width: 180px;
    padding: 0.25rem 0;
}

.gcm-context-item {
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
}

.gcm-context-item:hover {
    background: var(--color-bg);
    color: var(--color-highlight);
}

.gcm-context-item[data-action="block"],
.gcm-context-item[data-action="remove"] {
    color: #ef5350;
}

/* Кнопка закрытия на мобиле */
.gcm-close-mobile {
    display: flex;
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
}

/* Кнопка "Назад" на мобиле */
.gcm-mobile-back {
    display: none;
}

/* ======================== МОБИЛЬНАЯ ВЕРСИЯ ======================== */
@media (max-width: 768px) {
    .gcm-panel {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100dvh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
        min-width: 100vw !important;
        min-height: 100dvh !important;
        position: fixed !important;
        z-index: 10000 !important;
    }

    .gcm-body {
        flex-direction: column;
    }

    .gcm-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-height: 100%;
        border-right: none;
        display: flex;
        flex-shrink: 0;
    }

    .gcm-chat-area {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10001;
        background: var(--color-surface);
    }

    .gcm-chat-area.mobile-open {
        display: flex !important;
        flex-direction: column;
    }

    .gcm-chat-window.active {
        position: relative;
    }

    .gcm-mobile-back {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem;
        cursor: pointer;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--color-highlight);
        border-bottom: 1px solid var(--color-border);
    }

    .gcm-mobile-back::before {
        content: '←';
        font-size: 1.2rem;
    }

    .gcm-resize-left,
    .gcm-resize-top,
    .gcm-resize-corner {
        display: none !important;
    }

    .gcm-close-mobile {
        display: flex !important;
        background: none;
        border: none;
        color: var(--color-text);
        font-size: 1.2rem;
        cursor: pointer;
        padding: 0.25rem;
    }
}

/* Десктоп */
@media (min-width: 769px) {
    .gcm-resize-left {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 6px;
        cursor: ew-resize;
        z-index: 10;
    }
    .gcm-resize-top {
        display: block !important;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 6px;
        cursor: ns-resize;
        z-index: 10;
    }
    .gcm-resize-corner {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 14px;
        height: 14px;
        cursor: nwse-resize;
        z-index: 11;
    }
}