/* ==========================================================================
   MODERN CHAT SYSTEM (v5.0 - MESSENGER STYLE)
   ========================================================================== */

/* --- Container Principal (Fixação) --- */
#chat-system-container {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 1050; /* Acima da Sidebar e Header */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: none; /* Permite clicar "através" da área vazia */
}

/* --- 1. BOTÃO DE ABRIR (ROSTER TOGGLE) --- */
.chat-roster-toggle {
    pointer-events: auto;
    background: var(--primary-color);
    color: white;
    padding: 12px 20px;
    border-radius: 30px 30px 0 0; /* Arredondado no topo */
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    margin-right: 20px;
    transition: transform 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}
.chat-roster-toggle:hover {
    transform: translateY(-2px);
    background-color: #34495e;
}

/* --- 2. PAINEL DE CONTATOS (ROSTER) --- */
.chat-roster-panel {
    pointer-events: auto;
    width: 320px;
    height: 500px;
    background: #ffffff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -5px 30px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    margin-right: 20px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.05);
    animation: slideUpChat 0.3s ease-out;
}

.chat-roster-header {
    padding: 15px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    color: var(--primary-color);
}

.chat-roster-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-roster-footer {
    padding: 10px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
}

/* Item da Lista de Contatos */
.chat-list-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 5px;
}
.chat-list-item:hover {
    background-color: #f1f5f9;
}

/* Avatar com Status */
.chat-list-item-avatar-wrapper {
    position: relative;
    margin-right: 12px;
}
.chat-list-item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem;
    box-shadow: 0 2px 5px rgba(59, 130, 246, 0.3);
}
.chat-status-indicator {
    position: absolute;
    bottom: 0; right: 0;
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
}
.chat-status-indicator.online { background-color: #10b981; box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2); }
.chat-status-indicator.offline { background-color: #94a3b8; }

/* Textos do Item */
.chat-list-item-info {
    flex-grow: 1;
    overflow: hidden;
}
.chat-list-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #334155;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-list-item-lastmsg {
    font-size: 0.8rem;
    color: #94a3b8;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}


/* --- 3. JANELAS FLUTUANTES (Conversas Abertas) --- */
.chat-windows-container {
    position: fixed;
    bottom: 0;
    right: 360px; /* Fica à esquerda do Roster */
    display: flex;
    flex-direction: row-reverse; /* Novas abrem para a esquerda */
    align-items: flex-end;
    gap: 15px;
    pointer-events: none; /* Deixa clicar no fundo */
    z-index: 1050;
}

.chat-window {
    pointer-events: auto;
    width: 320px;
    height: 420px;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 5px 25px rgba(0,0,0,0.15);
    display: flex; flex-direction: column;
    border: 1px solid #e2e8f0;
    animation: slideUpChat 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-window-header {
    background: white;
    padding: 12px 15px;
    border-bottom: 1px solid #f1f5f9;
    display: flex; justify-content: space-between; align-items: center;
    border-radius: 16px 16px 0 0;
    cursor: pointer;
}
.chat-window-title { font-weight: 700; color: var(--primary-color); font-size: 0.9rem; }

/* Corpo das Mensagens */
.chat-window-body {
    flex-grow: 1;
    background: #f8fafc;
    overflow-y: auto;
    padding: 15px;
    display: flex; flex-direction: column-reverse; /* Mensagens começam de baixo */
}

/* Rodapé (Input) */
.chat-window-footer {
    background: white;
    padding: 10px;
    border-top: 1px solid #f1f5f9;
}
.chat-input {
    border-radius: 20px !important;
    background: #f1f5f9;
    border: 1px solid transparent;
    padding-left: 15px;
}
.chat-input:focus {
    background: white;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}


/* --- 4. BOLHAS DE MENSAGEM (Style WhatsApp) --- */
.chat-message-bubble {
    max-width: 85%;
    padding: 10px 14px;
    margin-bottom: 8px;
    position: relative;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Minhas Mensagens (Enviadas) */
.chat-message-bubble.sent {
    background-color: var(--accent-color); /* Azul Principal */
    color: white;
    align-self: flex-end;
    border-radius: 16px 16px 4px 16px; /* Canto inferior direito reto */
}
.chat-message-bubble.sent .timestamp {
    color: rgba(255,255,255,0.8);
}

/* Mensagens Deles (Recebidas) */
.chat-message-bubble.received {
    background-color: #ffffff;
    color: #334155;
    align-self: flex-start;
    border-radius: 16px 16px 16px 4px; /* Canto inferior esquerdo reto */
    border: 1px solid #f1f5f9;
}
.chat-message-bubble.received .timestamp {
    color: #94a3b8;
}

.sender-name {
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 2px;
    display: block;
    opacity: 0.8;
}

.timestamp {
    display: block;
    font-size: 0.65rem;
    text-align: right;
    margin-top: 4px;
    font-weight: 500;
}

/* Status (check) */
.status-indicator i { font-size: 0.7rem; margin-left: 3px; }

/* Animação */
@keyframes slideUpChat { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Dark Mode */
body.dark-mode .chat-roster-panel, body.dark-mode .chat-window { background: #1e293b; border-color: rgba(255,255,255,0.1); }
body.dark-mode .chat-roster-header, body.dark-mode .chat-window-header, body.dark-mode .chat-window-footer, body.dark-mode .chat-roster-footer { background: #0f172a; border-color: rgba(255,255,255,0.05); }
body.dark-mode .chat-list-item-name, body.dark-mode .chat-window-title { color: #f8fafc; }
body.dark-mode .chat-list-item:hover { background: rgba(255,255,255,0.05); }
body.dark-mode .chat-window-body { background: #0f172a; }
body.dark-mode .chat-message-bubble.received { background: #334155; color: #fff; border-color: transparent; }
body.dark-mode .chat-input { background: #334155; color: white; border: none; }


