:root { 
    --bg-color: #141414; 
    --panel-color: #1e1e1e; 
    --accent-color: #2480f8; 
    --text-color: #ffffff; 
    --text-muted: #aaaaaa; 
    --border-color: #2d2d2d;
    --msg-own-color: #2480f8;
    --msg-other-color: #2a2a2a;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    -webkit-tap-highlight-color: transparent;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    background: var(--bg-color); 
    color: var(--text-color); 
    height: 100vh; 
    width: 100vw;
    display: flex; 
    justify-content: center; 
    align-items: center; 
    overflow: hidden;
}

/* Экран авторизации */
#auth-screen { 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    width: 90%; 
    max-width: 360px; 
    padding: 30px; 
    background: var(--panel-color); 
    border-radius: 16px; 
    box-shadow: 0 12px 32px rgba(0,0,0,0.4); 
}

#auth-screen h2 { 
    text-align: center; 
    margin-bottom: 5px; 
    font-weight: 600;
}

#app-screen { 
    display: none; 
    width: 100%; 
    height: 100vh; 
}

.messenger-container { 
    display: flex; 
    width: 100%; 
    height: 100%; 
}

/* Боковая панель */
.sidebar { 
    width: 300px; 
    min-width: 300px;
    background: var(--panel-color); 
    border-right: 1px solid var(--border-color); 
    display: flex; 
    flex-direction: column; 
    transition: transform 0.3s ease;
}

.sidebar-header { 
    padding: 20px; 
    font-weight: bold; 
    border-bottom: 1px solid var(--border-color); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    height: 65px;
}

.scrollable-sidebar-content {
    flex: 1;
    overflow-y: auto;
}

.section-title { 
    padding: 20px 20px 5px 20px; 
    font-size: 0.75rem; 
    font-weight: 700; 
    color: var(--text-muted); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    letter-spacing: 0.8px; 
}

.section-title button { 
    background: transparent; 
    border: none; 
    color: var(--text-muted); 
    cursor: pointer; 
    font-size: 1.2rem; 
    padding: 0 5px; 
}

.section-title button:hover { color: var(--text-color); }

.status-badge { 
    width: 10px; 
    height: 10px; 
    border-radius: 50%; 
    background: #ff4d4d; 
    transition: background 0.3s; 
}

.status-badge.online { background: #4caf50; box-shadow: 0 0 6px #4caf50;}

.channels-list { padding: 5px 10px; }

.channel-item { 
    padding: 12px 14px; 
    border-radius: 10px; 
    margin-bottom: 4px; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    color: var(--text-muted); 
    display: flex;
    align-items: center;
    text-overflow: ellipsis; 
    overflow: hidden; 
    white-space: nowrap; 
}

.channel-item:hover {
    background: #252525;
    color: var(--text-color);
}

.channel-item.active { 
    background: #2a2a2a; 
    color: var(--text-color); 
    font-weight: 500; 
}

.dm-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #ff4d4d;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
}

.dm-status.online {
    background-color: #4caf50;
    box-shadow: 0 0 6px #4caf50;
}

.sidebar-footer { 
    padding: 15px 20px; 
    border-top: 1px solid var(--border-color); 
}

/* Область чата */
.chat-area { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    background: var(--bg-color); 
}

.chat-header { 
    padding: 0 20px; 
    background: var(--panel-color); 
    border-bottom: 1px solid var(--border-color); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    height: 65px;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
}

#typing-indicator { 
    font-size: 0.85rem; 
    color: #4caf50; 
    font-style: italic; 
    font-weight: 400;
}

.messages-container { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 14px; 
}

.empty-chat-placeholder {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    max-width: 300px;
    line-height: 1.5;
}

/* Сообщения */
.message { 
    max-width: 75%; 
    padding: 12px 16px; 
    border-radius: 16px; 
    background: var(--msg-other-color); 
    align-self: flex-start; 
    animation: fadeIn 0.2s ease-out; 
    position: relative;
    word-break: break-word;
}

.message.own { 
    background: var(--msg-own-color); 
    align-self: flex-end; 
}

.msg-meta { 
    font-size: 0.72rem; 
    color: var(--text-muted); 
    margin-bottom: 6px; 
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.message.own .msg-meta { color: #e0e0e0; }

.msg-actions {
    display: inline-flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .msg-actions { opacity: 1; }

.action-link {
    font-size: 0.72rem;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: underline;
}
.action-link:hover { color: var(--text-color); }
.action-link.delete { color: #ff4d4d; }
.action-link.delete:hover { color: #ff6b6b; }

.edited-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    margin-left: 5px;
}

/* Зона ввода */
.input-container { 
    padding: 15px 20px; 
    background: var(--panel-color); 
    display: flex; 
    gap: 12px; 
    align-items: center;
    border-top: 1px solid var(--border-color);
}

input { 
    background: #252525; 
    border: 1px solid #353535; 
    color: white; 
    padding: 14px; 
    border-radius: 10px; 
    font-size: 1rem; 
    outline: none; 
    transition: border-color 0.2s;
}
input:focus { border-color: var(--accent-color); }
input:disabled, button:disabled { opacity: 0.3; cursor: not-allowed; }

button { 
    background: var(--accent-color); 
    color: white; 
    border: none; 
    padding: 14px 24px; 
    border-radius: 10px; 
    font-weight: 600; 
    cursor: pointer; 
    font-size: 1rem; 
    transition: opacity 0.2s;
}
button:hover { opacity: 0.9; }

.logout-btn { 
    background: transparent; 
    color: var(--text-muted); 
    padding: 10px; 
    font-size: 0.9rem; 
    border: 1px solid #353535; 
    width: 100%;
}
.delete-chat-btn { background: #ff4d4d !important; padding: 8px 14px !important; font-size: 0.85rem !important; border-radius: 8px !important; }

.mobile-back-btn {
    display: none; /* Прячем на десктопе */
    background: transparent;
    padding: 5px 10px 5px 0;
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--text-color);
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================================================
   MEDIA QUERIES (АДАПТИВНАЯ СЕТКА ПОД МОБИЛЬНЫЕ УСТРОЙСТВА)
   ========================================================================= */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        height: 100%;
        z-index: 10;
    }
    .chat-area {
        width: 100%;
        height: 100%;
        position: absolute;
    }
    .mobile-back-btn {
        display: block; /* Показываем стрелочку на телефонах */
    }
    
    /* Классы состояний переключения экранов, которые будет вешать JS */
    .layout-show-chat .sidebar {
        transform: translateX(-100%); /* Прячем боковую панель влево */
    }
    .layout-show-sidebar .chat-area {
        transform: translateX(100%); /* Прячем чат вправо */
    }
}
