/* RESET BRUTAL E DEFINITIVO */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root { 
    --primary: #075e54; --secondary: #128c7e; 
    --bg-msg-me: #dcf8c6; --bg-msg-friend: #fff; 
    --bg-body: #f0f0f0; 
    --green-leaf: #2E7D32; --purple-berry: #8E24AA; 
}

html, body {
    width: 100vw; height: 100dvh; overflow: hidden; 
    background: var(--bg-body) !important;
    margin: 0 !important; padding: 0 !important; top: 0 !important; left: 0 !important;
}

.master-container {
    position: fixed; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; 
    background: var(--bg-body); font-family: 'Poppins', sans-serif;
    display: flex; flex-direction: column; z-index: 99999;
    margin: 0 !important; padding: 0 !important;
}

/* --- HEADER MAJESTOSO --- */
.chat-header { 
    height: auto; min-height: 60px; padding-top: env(safe-area-inset-top); 
    background: linear-gradient(to right, var(--green-leaf), var(--purple-berry)); 
    color: white; display: flex; align-items: center; padding-left: 10px; padding-right: 10px; 
    z-index: 50; flex-shrink: 0; width: 100%; border: none; box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.back-btn { background: none; border: none; color: white; cursor: pointer; display: flex; align-items: center; margin-right: 5px; padding: 5px; }

.header-info { flex: 1; display: flex; align-items: center; gap: 10px; overflow: hidden; cursor: pointer; min-width: 0; }
.header-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: #ccc; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.3); display: none; }
.header-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: 5px 0; }
.header-name { font-size: 18px; font-weight: 600; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 100%; }
.header-status { font-size: 11px; opacity: 0.85; font-weight: 400; }

.header-actions { display: flex; gap: 15px; align-items: center; padding-right: 5px; flex-shrink: 0; }
.action-icon { color: white; background: none; border: none; cursor: pointer; padding: 5px; display: flex; }

/* --- LAYOUT E LISTAS --- */
.chat-layout { flex: 1; display: flex; overflow: hidden; position: relative; width: 100%; }

.inbox-list { width: 100%; background: white; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; z-index: 10; }

.search-container { padding: 10px 15px; background: #f7f7f7; border-bottom: 1px solid #eee; display: flex; align-items: center; }
.search-box { display: flex; align-items: center; background: white; border-radius: 20px; padding: 8px 15px; width: 100%; border: 1px solid #e0e0e0; }
.search-box .material-icons-round { color: #999; font-size: 20px; margin-right: 8px; }
.search-input { border: none; outline: none; background: transparent; width: 100%; font-family: 'Poppins', sans-serif; font-size: 14px; }

.tabs-container { display: flex; background: white; border-bottom: 1px solid #ddd; }
.tab { flex: 1; text-align: center; padding: 12px 0; font-size: 14px; font-weight: 600; color: #666; cursor: pointer; border-bottom: 3px solid transparent; transition: 0.2s; }
.tab.active { color: var(--primary); border-bottom: 3px solid var(--primary); }

.conversation-item { display: flex; align-items: center; gap: 15px; padding: 12px 15px; border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: 0.2s; background: white; }
.conversation-item:active { background: #f5f5f5; }
.conv-avatar { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; }
.conv-info { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 3px; }
.conv-name { font-weight: 600; font-size: 16px; color: #111; }
.conv-time { font-size: 11px; color: #999; }
.conv-last-msg { font-size: 14px; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px; }

/* --- TELA DE CHAT --- */
.chat-area { 
    position: absolute; top: 0; left: 0; right: 0; bottom: 0; 
    background-color: #f0f0f0; 
    display: flex; flex-direction: column; 
    transform: translateX(100%); transition: transform 0.3s ease-in-out; z-index: 20; 
}
.chat-area.active { transform: translateX(0); }

@media (min-width: 800px) {
    .inbox-list { width: 350px; border-right: 1px solid #ddd; }
    .chat-area { position: static; flex: 1; transform: none; }
}

.messages-container { 
    flex: 1; overflow-y: auto; overflow-x: hidden; padding: 10px 15px; 
    display: flex; flex-direction: column; gap: 2px; width: 100%;
    background-color: #e5ddd5; background-image: url('../imagem/fundo-chat.png'); background-size: cover; background-position: center; background-attachment: local;
}

.msg-row { display: flex; width: 100%; max-width: 100%; margin-bottom: 2px; min-width: 0; }
.msg-row.me { justify-content: flex-end; }

/* 🔥 MENSAGENS BLINDADAS E COM ANIMAÇÃO 🔥 */
.msg-bubble { 
    max-width: 85%; padding: 6px 9px 8px 9px; border-radius: 7.5px; 
    font-size: 14px; line-height: 19px; position: relative; 
    word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; 
    box-shadow: 0 1px 1px rgba(0,0,0,0.1); display: flex; flex-direction: column; flex-shrink: 1; min-width: 0; 
    -webkit-user-select: none; user-select: none;
    transition: transform 0.2s ease-out; 
}

@keyframes piscarMensagem {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.02); filter: brightness(0.8) drop-shadow(0 0 8px var(--purple-berry)); }
    100% { transform: scale(1); filter: brightness(1); }
}
.msg-highlight { animation: piscarMensagem 1.2s ease-in-out; }

.msg-me { background: var(--bg-msg-me); border-top-right-radius: 0; color: #111; }
.msg-friend { background: var(--bg-msg-friend); border-top-left-radius: 0; color: #111; }

.msg-meta { font-size: 10px; color: rgba(0,0,0,0.45); align-self: flex-end; margin-top: -3px; margin-left: 10px; display: flex; align-items: center; gap: 3px; float: right; padding-top: 5px; }

.msg-image { max-width: 100%; border-radius: 5px; margin-bottom: 5px; cursor: pointer; display: block; }
.msg-file { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,0.05); padding: 10px; border-radius: 5px; text-decoration: none; color: #333; font-weight: 500; font-size: 13px; }
.msg-deleted { font-style: italic; color: #888; font-size: 13px; display: flex; align-items: center; gap: 5px; }

.reaction-badge { position: absolute; bottom: -10px; right: -5px; background: white; border-radius: 15px; padding: 2px 4px; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); z-index: 2; border: 1px solid #eee; pointer-events: none; }
.msg-row.me .reaction-badge { right: auto; left: -5px; }

/* CITAÇÃO CLICÁVEL */
.reply-block { background: rgba(0,0,0,0.05); border-left: 3px solid var(--primary); padding: 5px 8px; border-radius: 4px; font-size: 12px; margin-bottom: 5px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.reply-block:active { background: rgba(0,0,0,0.1); }

.reply-preview-bar { display: none; background: #f0f0f0; padding: 10px 15px; border-left: 4px solid var(--primary); font-size: 13px; color: #444; position: absolute; bottom: 100%; left: 0; width: 100%; z-index: 99; align-items: center; justify-content: space-between; box-shadow: 0 -2px 5px rgba(0,0,0,0.05); border-top-right-radius: 10px; border-top-left-radius: 10px; }
.reply-preview-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; margin-right: 10px; }
.cancel-reply-btn { cursor: pointer; color: #999; font-size: 20px; font-weight: bold; }

/* --- INPUT E MENUS --- */
.input-area { 
    position: relative; 
    background: linear-gradient(to right, var(--green-leaf), var(--purple-berry)) !important;
    padding: 8px 10px !important; 
    padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
    display: none; align-items: center; gap: 8px; min-height: 60px; width: 100%; flex-shrink: 0; z-index: 100;
    border-top: none !important; box-shadow: none !important;
}
.input-area.visible { display: flex !important; }

.chat-input { 
    flex: 1; min-width: 0; width: 100%; height: 45px; padding: 12px 15px; 
    border-radius: 25px; border: none; background: white; outline: none; 
    font-family: inherit; font-size: 15px; resize: none; overflow: hidden; line-height: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); color: #111;
}

.btn-circle { width: 45px; height: 45px; border-radius: 50%; border: none; background: none; color: white; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; flex-shrink: 0; }
@media (hover: hover) { .btn-circle:hover { background: rgba(255,255,255,0.2); } }
.send-btn { background: rgba(255,255,255,0.2); color: white; flex-shrink: 0; }

/* EXTRAS */
.status-dropdown { position: absolute; top: 60px; right: 10px; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.2); z-index: 100; display: none; flex-direction: column; min-width: 150px; }
.status-opt { padding: 10px 15px; display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.status-opt:hover { background: #f5f5f5; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.online { background: #4caf50; } .busy { background: #f44336; } .offline { background: #9e9e9e; }

.attach-menu { position: absolute; bottom: 70px; left: 10px; background: white; border-radius: 15px; box-shadow: 0 4px 20px rgba(0,0,0,0.2); display: none; flex-direction: column; z-index: 100; overflow: hidden; }
.attach-opt { padding: 15px 20px; display: flex; align-items: center; gap: 15px; font-size: 15px; cursor: pointer; }
.attach-opt:hover { background: #f5f5f5; }

/* 🔥 MENU DE CONTEXTO GIGANTE 🔥 */
.msg-context-menu { 
    position: fixed; 
    background: white; 
    border-radius: 12px; 
    box-shadow: 0 5px 25px rgba(0,0,0,0.5); 
    z-index: 999999; 
    display: none; 
    flex-direction: column; 
    min-width: 180px; 
    overflow: hidden; 
}
.ctx-reactions { display: flex; justify-content: space-around; padding: 12px 10px; background: #f9f9f9; border-bottom: 1px solid #eee; }

/* 🔥 EMOJIS BLOQUEADOS PARA NÃO SEREM SELECIONADOS 🔥 */
.ctx-emoji { 
    font-size: 22px; 
    cursor: pointer; 
    transition: transform 0.2s; 
    user-select: none; 
    -webkit-user-select: none; 
}
.ctx-emoji:hover { transform: scale(1.3); }

.ctx-item { padding: 12px 15px; font-size: 14px; cursor: pointer; display: flex; align-items: center; gap: 10px; color: #333; font-weight: 500;}
.ctx-item:hover { background: #f0f0f0; }

.skiptranslate > iframe { display: none !important; }
#goog-gt-tt { display: none !important; }
.goog-logo-link { display: none !important; }
.goog-te-gadget { color: transparent !important; font-size: 0px !important; }
font, font > span { display: contents !important; }

/* 🔥 FASE 1: TELA DE ARQUIVOS E MENU DO CHAT 🔥 */
.files-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); z-index: 999999;
    display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.files-modal-content {
    background: white; border-radius: 15px; width: 100%; max-width: 400px;
    max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.files-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 20px; background: #f0f0f0; border-bottom: 1px solid #ddd;
}
.files-modal-header h3 { font-size: 16px; color: #333; font-weight: 600; }
.close-modal-btn { background: none; border: none; cursor: pointer; color: #666; display: flex; padding: 5px; }

.files-tabs { display: flex; border-bottom: 1px solid #ddd; background: white; flex-shrink: 0;}
.f-tab { flex: 1; text-align: center; padding: 12px 0; font-size: 14px; font-weight: 600; color: #666; cursor: pointer; border-bottom: 3px solid transparent; transition: 0.2s;}
.f-tab.active { color: var(--primary); border-bottom: 3px solid var(--primary); }

.files-grid {
    padding: 15px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
    overflow-y: auto; flex: 1; background: #f9f9f9; align-content: start;
}
.file-item-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; border: 1px solid #eee; box-shadow: 0 1px 3px rgba(0,0,0,0.1);}
.file-item-doc { 
    grid-column: 1 / -1; display: flex; align-items: center; gap: 15px; 
    background: white; padding: 10px 15px; border-radius: 8px; border: 1px solid #eee;
    text-decoration: none; color: #333; font-size: 14px; font-weight: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}