/* --- Иконка чата --- */
.chat-icon-section {
    position: fixed;
    bottom: 20px;
    right: 100px;
    z-index: 1000;
}
#chat-icon {
    width: 60px;
    cursor: pointer;
    transition: transform 0.3s;
    filter: drop-shadow(0 0 8px #4da6ff);
}
#chat-icon:hover {
    transform: scale(1.1);
}

/* --- Оверлей и окно чата --- */
.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 4000;
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.chat-overlay.active {
    display: flex;
    opacity: 1;
}

.chat-window {
    width: 90%;
    max-width: 450px;
    height: 80vh;
    max-height: 600px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* --- ИСПРАВЛЕННЫЙ Экран входа в чат --- */
.chat-login-screen {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: rgba(30, 28, 36, 0.8);
    backdrop-filter: blur(4px);
    /* Используем flex для идеального центрирования */
    display: flex;
    justify-content: center;
    align-items: center;
}
.chat-login-screen.hidden { display: none; }
.chat-login-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
#nickname-input {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 8px;
    color: var(--text-color);
    width: 200px;
    text-align: center;
}

/* --- Основной экран чата --- */
.chat-main-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px 0 20px;
    height: 50px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.chat-title {
    font-size: 1.1rem;
    font-weight: bold;
}
.chat-close-btn { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }

/* --- Сообщения --- */
.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    /* УБИРАЕМ display: flex и flex-direction. Теперь это обычный блочный контейнер. */
}
.chat-messages-inner {
    display: flex;
    flex-direction: column; /* Сообщения теперь идут сверху вниз */
    padding: 0 5px;
}
.date-separator {
    text-align: center;
    margin: 15px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    background: var(--bg-color);
    padding: 2px 10px;
    border-radius: 10px;
    align-self: center;
}
.message-bubble {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    line-height: 1.4;
    word-break: break-word;
    display: flex;
    flex-direction: column;
    margin-top: 10px;
}
.nickname {
    font-weight: bold;
    font-size: 0.9rem;
    display: block;
    margin-bottom: 4px;
    color: var(--primary-glow);
}
.message-text {
    margin-bottom: 5px;
}
.timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    align-self: flex-end;
}
.message-bubble.sent {
    background-color: #3b3942;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.message-bubble.received {
    background-color: var(--bg-color);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.message-bubble.received .nickname { color: #4da6ff; }

/* --- Футер чата --- */
.chat-footer {
    display: flex;
    padding: 10px;
    border-top: 1px solid var(--border-color);
    gap: 10px;
    flex-shrink: 0;
}
#chat-message-input {
    flex-grow: 1;
    background: var(--bg-color);
    border: none;
    color: var(--text-color);
    padding: 10px 15px;
    border-radius: 20px;
}
#chat-message-input:focus {
    outline: none;
}
#chat-send-btn {
    background: rgba(255, 77, 166, 0.2);
    border: 1px solid rgba(255, 77, 166, 0.4);
    color: #fff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}
#chat-send-btn:hover {
    background: var(--primary-glow);
    box-shadow: 0 0 15px var(--primary-glow);
    transform: scale(1.1);
}