:root {
    --wa-green: #008069;
    --wa-header: #00a884;
    --wa-bg: #d1d7db;
    --wa-white: #ffffff;
    --wa-chat-bg: #efeae2;
    --wa-border: #e9edef;
    --wa-header-h: 60px;
}

/* 1. RESET E BLOQUEIO DE ROLAGEM GERAL */
* { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0; padding: 0;
    font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
    background-color: #d1d7db;
    /* TRUQUE PARA MOBILE: 100dvh desconta a barra do navegador */
    height: 100vh; 
    height: 100dvh; 
    width: 100vw;
    overflow: hidden; 
    position: fixed; /* Trava a tela no iOS para não quicar */
}

#app {
    height: 100%; width: 100%;
    display: flex;
}

/* --- LOGIN COM IMAGEM DE FUNDO --- */
#login-screen {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh;
    display: flex; 
    align-items: center; 
    justify-content: center;
    z-index: 9999;

    /* Configuração da Imagem */
    background-color: #d1d7db; /* Cor de fundo caso a imagem falhe */
    background-image: url('../img/fundo.png'); /* Caminho da imagem */
    background-size: cover; /* Cobre toda a tela (responsivo) */
    background-position: center; /* Centraliza a imagem */
    background-repeat: no-repeat; /* Não repete */
}

/* Ajuste na caixa para destacar do fundo */
.login-box {
    background: rgba(255, 255, 255, 0.95); /* Leve transparência para ficar moderno */
    padding: 40px; 
    width: 90%; 
    max-width: 450px;
    border-radius: 10px; 
    box-shadow: 0 15px 25px rgba(0,0,0,0.2); /* Sombra mais forte para destacar */
    text-align: center;
    backdrop-filter: blur(5px); /* Efeito de desfoque atrás da caixa (opcional) */
}

.app-container {
    display: flex;
    width: 100%; height: 100%;
    background: var(--wa-white);
    position: relative;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 30%; min-width: 350px;
    height: 100%;
    display: flex; flex-direction: column;
    border-right: 1px solid var(--wa-border);
    background: #fff;
    z-index: 10;
    transition: transform 0.3s ease-in-out;
}

.sidebar-header {
    height: var(--wa-header-h); min-height: var(--wa-header-h);
    background: #f0f2f5; padding: 10px 16px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid rgba(0,0,0,0.05); flex-shrink: 0;
}

/* BUSCA (NOVO ESTILO) */
.search-box {
    padding: 10px; border-bottom: 1px solid var(--wa-border); background: #fff; flex-shrink: 0;
}
.search-wrapper {
    background: #f0f2f5; border-radius: 8px; padding: 8px 15px; display: flex; align-items: center;
}
.search-input { border: none; background: transparent; width: 100%; margin-left: 10px; font-size: 0.9rem; }

.contact-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.contact-item {
    display: flex; align-items: center; padding: 12px 15px;
    cursor: pointer; border-bottom: 1px solid #f0f2f5; min-height: 72px; position: relative;
}
.contact-item:hover { background: #f5f6f6; }
.contact-item.active { background: #f0f2f5; }

/* Botão de Lixeira na Lista (NOVO) */
.delete-session-btn {
    display: none; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    color: #aebac1; padding: 8px; font-size: 14px;
}
.contact-item:hover .delete-session-btn { display: block; }
.delete-session-btn:hover { color: #f15c6d; }

/* --- CHAT AREA --- */
.chat-area {
    flex: 1; 
    display: flex; 
    flex-direction: column;
    height: 100%; 
    background-color: var(--wa-chat-bg);
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    position: relative;
    transition: transform 0.3s ease-in-out;
    z-index: 5;
}

.chat-header {
    height: var(--wa-header-h); min-height: var(--wa-header-h);
    background: #f0f2f5; padding: 0 16px;
    display: flex; align-items: center; border-bottom: 1px solid var(--wa-border); width: 100%;
    flex-shrink: 0; z-index: 20;
}
.chat-avatar {
    width: 40px; height: 40px; border-radius: 50%; margin-right: 15px;
    background: #ddd; display: flex; align-items: center; justify-content: center;
}

/* MENSAGENS (COM AVATAR E MENU) */
.messages-container {
    flex: 1; 
    padding: 20px 5%; 
    overflow-y: auto; 
    -webkit-overflow-scrolling: touch; 
    display: flex; flex-direction: column; gap: 5px; width: 100%;
}

.msg-wrapper { display: flex; align-items: flex-end; margin-bottom: 10px; max-width: 85%; }
.msg-wrapper.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-wrapper.theirs { align-self: flex-start; }

.msg-avatar {
    width: 28px; height: 28px; border-radius: 50%; margin: 0 8px;
    flex-shrink: 0; background: #ccc; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-avatar i { font-size: 14px; color: #555; }

.msg-bubble {
    padding: 8px 12px; border-radius: 7.5px; font-size: 0.95rem; line-height: 1.4; position: relative;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13); word-wrap: break-word; background: #fff; min-width: 100px;
}
.msg-wrapper.mine .msg-bubble { background: #d9fdd3; border-top-right-radius: 0; }
.msg-wrapper.theirs .msg-bubble { background: #fff; border-top-left-radius: 0; }

/* MENU DA MENSAGEM (NOVO) */
.msg-menu-btn {
    position: absolute; top: 5px; right: 5px;
    display: none; cursor: pointer; color: #54656f;
    padding: 0 5px; background: inherit; border-radius: 50%;
}
.msg-bubble:hover .msg-menu-btn { display: block; }

.msg-dropdown {
    position: absolute; top: 25px; right: 0;
    background: white; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 100; min-width: 150px; overflow: hidden;
    display: none; flex-direction: column;
}
.msg-dropdown.show { display: flex; }
.msg-dropdown-item {
    padding: 10px 15px; cursor: pointer; font-size: 13px; color: #333;
    display: flex; align-items: center; gap: 10px;
}
.msg-dropdown-item:hover { background: #f0f2f5; }

/* INPUT BAR */
.chat-input-bar {
    min-height: 62px; background: #f0f2f5; padding: 5px 10px;
    display: flex; align-items: center; gap: 10px; width: 100%;
    flex-shrink: 0; position: relative; z-index: 50;
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-bottom: env(safe-area-inset-bottom, 10px);
}
.text-input { flex: 1; padding: 12px; border-radius: 8px; border: none; font-size: 1rem; background: #fff; }

/* MOBILE ESPECÍFICO (MANTIDO DO SEU ORIGINAL) */
@media(max-width: 768px) {
    .sidebar { width: 100%; min-width: 100%; position: absolute; height: 100%; left: 0; top: 0; }
    .app-container.chat-active .sidebar { transform: translateX(-100%); }
    .chat-area { 
        position: absolute; width: 100%; height: 100%; left: 0; top: 0;
        transform: translateX(100%); z-index: 200; background-color: var(--wa-chat-bg); 
    }
    .app-container.chat-active .chat-area { transform: translateX(0); }
    .back-btn { display: block !important; margin-right: 15px; font-size: 1.2rem; cursor: pointer; }
    .sidebar-header, .chat-header { background: var(--wa-header); color: white; }
    .sidebar-header i, .chat-header i { color: white !important; }
    
    /* Ajuste do Perfil Mobile */
    .profile-view.active { width: 100%; border-left: none; }
    
    /* Login Mobile */
    .login-box { width: 90%; }
}
.back-btn { display: none; }

/* --- PROFILE VIEW (SEU ORIGINAL + AJUSTES) --- */
.profile-view {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: 100%; max-width: 400px;
    background: #f0f2f5; z-index: 300;
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.1, 0.82, 0.25, 1);
    display: flex; flex-direction: column; border-left: 1px solid var(--wa-border);
    box-shadow: -2px 0 5px rgba(0,0,0,0.05);
}
.profile-view.active { transform: translateX(0); }

.profile-header {
    height: var(--wa-header-h); background: #f0f2f5; display: flex; align-items: center;
    padding: 0 16px; border-bottom: 1px solid rgba(0,0,0,0.1); color: #3b4a54; font-size: 1rem;
}
.profile-content { flex: 1; overflow-y: auto; padding-bottom: 20px; }

.info-card {
    background: #fff; padding: 14px 20px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.big-avatar-container {
    display: flex; justify-content: center; align-items: center; padding: 30px 0; background: #fff; margin-bottom: 10px;
}
.big-avatar { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; border: 1px solid #ddd; }
.profile-name { font-size: 1.4rem; color: #111b21; margin-top: 10px; text-align: center; }
.profile-phone { font-size: 1.1rem; color: #666; text-align: center; margin-top: 5px; }
.section-title { font-size: 0.9rem; color: #666; margin-bottom: 10px; font-weight: 500; }

.media-gallery { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 5px; }
.media-gallery::-webkit-scrollbar { height: 4px; }
.media-gallery::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }
.media-thumb { width: 80px; height: 80px; flex-shrink: 0; border-radius: 5px; object-fit: cover; background: #ddd; cursor: pointer; }

/* UTILITARIOS */
.btn-hidden { display: none !important; }
.mic-btn { border: none; background: none; font-size: 1.3rem; color: #54656f; cursor: pointer; padding: 10px; border-radius: 50%; }
.send-btn { border: none; background: none; font-size: 1.3rem; color: var(--wa-green); cursor: pointer; padding: 10px; }
.recording-active { color: #e53935 !important; background-color: rgba(229, 57, 53, 0.1); animation: pulse-red 1.5s infinite; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }

@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.4); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(229, 57, 53, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(229, 57, 53, 0); }
}

/* --- ADMIN PANEL RESPONSIVO --- */

/* 1. Ajuste do Formulário (Empilhar no Mobile) */
.admin-grid {
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 10px; 
    margin-bottom: 15px;
}

/* 2. Tabela Responsiva (Table to Cards) */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { text-align: left; color: #666; padding: 10px; border-bottom: 2px solid #eee; }
.admin-table td { padding: 10px; border-bottom: 1px solid #eee; }

/* REGRAS MOBILE */
@media (max-width: 768px) {
    /* Formulário vira uma coluna só */
    .admin-grid { grid-template-columns: 1fr !important; }
    
    /* Esconde o cabeçalho da tabela */
    .admin-table thead { display: none; }
    
    /* Transforma a tabela em blocos */
    .admin-table, .admin-table tbody, .admin-table tr, .admin-table td {
        display: block;
        width: 100%;
    }
    
    /* Cada linha vira um cartão */
    .admin-table tr {
        background: #fff;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        padding: 5px;
    }
    
    /* Ajusta as células para parecerem linhas do cartão */
    .admin-table td {
        padding: 10px;
        text-align: right;
        border-bottom: 1px solid #f0f0f0;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .admin-table td:last-child { border-bottom: none; }
    
    /* Insere o rótulo (Nome, Login) automaticamente antes do valor */
    .admin-table td::before {
        content: attr(data-label);
        font-weight: bold;
        color: #54656f;
        text-transform: uppercase;
        font-size: 0.75rem;
    }
    
    /* Ajuste de botões */
    .admin-actions { display: flex; gap: 10px; justify-content: flex-end; }
}