/* ============================================
   ОСНОВНОЙ ИНТЕРФЕЙС (ЧАТ, САЙДБАР, СООБЩЕНИЯ)
   ============================================ */

.main-interface {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: var(--dvh);
    background: var(--glass-bg);
    backdrop-filter: blur(40px);
    overflow: hidden;
    z-index: 5;
}
.main-interface.visible {
    display: flex !important;
    animation: fadeIn 0.5s ease;
}

/* Сайдбар */
.glass-sidebar {
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    height: 100%;
    width: 300px;
    min-width: 260px;
    flex-shrink: 0;
}

/* Зона чата */
.glass-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.chat-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.2);
}
.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.chat-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    overflow: hidden;
}
.chat-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-user-avatar:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 10px rgba(0, 198, 255, 0.35);
}
.chat-user-avatar.bot-avatar {
    background: #12141D;
}
.chat-user-avatar.group-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
}
.chat-info h3 {
    font-weight: 700;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-status {
    font-size: 12px;
    color: var(--text-dim);
    opacity: 0.7;
}
.current-user-badge {
    font-size: 12px;
    color: var(--text-dim);
    background: rgba(255,255,255,0.05);
    padding: 5px 10px;
    border-radius: 15px;
}

/* Сообщения */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    -webkit-overflow-scrolling: touch;
    transition: opacity 0.18s ease;
}
.messages-container.chat-loading { opacity: 0; pointer-events: none; }
.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 5px; }

.message {
    display: flex;
    gap: 10px;
    max-width: 100%;
    animation: messageAppear 0.3s ease-out;
    position: relative;
}

/* Входящие сообщения - аватарка слева */
.message.incoming {
    flex-direction: row;
    justify-content: flex-start;
}
.message.incoming .msg-avatar {
    order: 1;
    margin-right: 8px;
    margin-left: 0;
}
.message.incoming .msg-bubble {
    order: 2;
    border-bottom-left-radius: 5px;
}
.message.incoming .msg-bubble {
    background: rgba(255, 255, 255, 0.08);
}

/* Исходящие сообщения - аватарка справа */
.message.outgoing {
    flex-direction: row;
    justify-content: flex-end;
}
.message.outgoing .msg-avatar {
    order: 2;
    margin-left: 8px;
    margin-right: 0;
}
.message.outgoing .msg-bubble {
    order: 1;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    border-bottom-right-radius: 5px;
}

.msg-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.1s ease;
}
.msg-avatar:active {
    transform: scale(0.95);
}
.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.message.outgoing .msg-avatar {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
}
.message.incoming .msg-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 80%;
    position: relative;
}

.msg-sender {
    font-size: 10px;
    color: var(--accent-cyan);
    font-weight: 800;
    margin-bottom: 4px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.msg-time {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    margin-top: 5px;
    text-align: right;
}
.message.outgoing .msg-time { color: rgba(255,255,255,0.5); }
.message.incoming .msg-time { color: rgba(255,255,255,0.35); }

/* Непрочитанные сообщения */
.message.incoming.unread .msg-bubble {
    background: rgba(0, 114, 255, 0.15);
    border: 1px solid rgba(0, 114, 255, 0.3);
}
.message.outgoing.unread .msg-bubble {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    opacity: 0.8;
}

/* Сообщения бота */
.bot-message .msg-bubble {
    background: rgba(74, 85, 104, 0.3);
    border: 1px solid rgba(74, 85, 104, 0.5);
}
.bot-message .msg-sender {
    color: #a0aec0;
}

/* Каналы */
.channel-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 16px;
}
.chat-status.status-channel {
    color: var(--accent-cyan);
}
.message.incoming.channel-message .msg-avatar {
    display: none;
}
.message.outgoing.channel-message .msg-avatar {
    display: flex;
}

/* Поле ввода */
.input-zone {
    padding: 20px 30px;
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.3);
    position: relative;
}
.glass-input-wrapper {
    display: flex;
    background: rgba(0, 0, 0, 0.5);
    border-radius: var(--radius-input);
    padding: 8px 12px;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--glass-border);
}
.glass-input-wrapper input {
    flex: 1;
    background: none;
    border: none;
    color: white;
    font-size: 15px;
    padding: 8px 0;
}
.glass-input-wrapper input::placeholder { color: var(--text-dim); }
.glass-input-wrapper input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.emoji-btn, .send-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-dim);
    transition: var(--transition);
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.emoji-btn:hover, .send-btn:hover {
    color: white;
    transform: scale(1.05);
}
.send-btn:disabled, .emoji-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Эмодзи панель */
.emoji-picker {
    position: absolute;
    bottom: 80px;
    left: 20px;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 12px;
    z-index: 200;
    max-width: 320px;
    min-width: 280px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.emoji-list {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}
.emoji-item {
    font-size: 28px;
    cursor: pointer;
    text-align: center;
    padding: 8px;
    border-radius: 12px;
    transition: all 0.1s ease;
}
.emoji-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes messageAppear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-status.online {
    color: #22c55e !important;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.chat-status.online::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
    animation: pulse-green 1.5s ease-in-out infinite;
}

@keyframes pulse-green {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}
