* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #25d366;
    --secondary-color: #128c7e;
    --background: #0d1418;
    --surface: #1e2a2e;
    --surface-hover: #2a3942;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --border-color: #2a3942;
    --success: #00a884;
    --warning: #ffa726;
    --error: #ef5350;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    --sidebar-width: 380px;
    --header-height: 70px;
}

/* Mobile first: tamanhos menores por padrão */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --header-height: auto;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
}

body.sidebar-open {
    overflow: hidden;
}

/* ========== HEADER ========== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    flex-shrink: 0;
    padding: 1rem 1.5rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.mobile-menu-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
    flex-shrink: 0;
    align-self: center;
}

.mobile-menu-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

/* Mobile: Mostrar botão menu */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block !important;
    }
}

.header h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin: 0;
    white-space: nowrap;
}

.instance-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.instance-selector label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

#instanceSelect {
    flex: 1;
    min-width: 150px;
    max-width: 250px;
    padding: 0.5rem 1rem;
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

/* Mobile: Header responsivo */
@media (max-width: 768px) {
    .header {
        padding: 0.5rem 0.75rem;
    }
    
    .header-content {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: nowrap;
    }
    
    .header-left {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: nowrap;
        flex: 1;
        min-width: 0;
    }
    
    .header h1 {
        display: none; /* Ocultar título no mobile */
    }
    
    .instance-selector {
        flex-direction: row;
        align-items: center;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
    }
    
    .instance-selector label {
        display: none; /* Ocultar label no mobile */
    }
    
    #instanceSelect {
        max-width: 100%;
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }
    
    .header-stats {
        display: none; /* Ocultar stats no mobile para economizar espaço */
    }
}

#instanceSelect:hover {
    border-color: var(--primary-color);
}

#instanceSelect:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.2);
}

.header-stats {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.stat-item {
    display: flex;
    gap: 0.4rem;
    align-items: baseline;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.stat-value {
    color: var(--primary-color);
    font-weight: bold;
    font-size: 1rem;
}

/* ========== LAYOUT PRINCIPAL ========== */
.app-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    height: 100%;
    position: relative;
    min-height: 0;
}

/* Mobile: Sidebar oculta por padrão, overlay quando visível */
@media (max-width: 768px) {
    .app-container {
        height: 100%;
    }
}

/* ========== SIDEBAR DE CHATS ========== */
.chats-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
    height: 100%;
}

/* Mobile: Sidebar com overlay */
@media (max-width: 768px) {
    .chats-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        min-width: unset;
        z-index: 1000;
        transform: translateX(-100%);
        border-right: none;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }
    
    .chats-sidebar.mobile-visible {
        transform: translateX(0);
    }
    
    /* Backdrop quando sidebar está aberta */
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    body.sidebar-open::before {
        opacity: 1;
        pointer-events: auto;
    }
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    margin: 0;
}

.btn-refresh {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-refresh:hover {
    background: var(--surface-hover);
}

.instances-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.instance-item {
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.instance-item:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
}

.instance-item.active {
    background: var(--surface-hover);
    border-color: var(--primary-color);
}

.instance-name {
    font-weight: bold;
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.instance-status {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-weight: normal;
}

.status-open {
    background: var(--success);
    color: white;
}

.status-close {
    background: var(--error);
    color: white;
}

.instance-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Content Area */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.section {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    height: 100%;
    width: 100%;
    position: relative;
}

/* Quando messagesSection está oculto, chats-sidebar ocupa todo espaço */
.section:has(#messagesSection[style*="display: none"]) .chats-sidebar {
    flex: 1;
}

/* Quando messagesSection está visível, ambos dividem o espaço */
.section:has(#messagesSection[style*="display: flex"]) .chats-sidebar {
    flex: 0 0 320px;
}

.messages-header {
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .messages-header {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
}

.messages-header h2 {
    margin: 0;
    font-size: 1.1rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .messages-header h2 {
        font-size: 0.95rem;
    }
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.sync-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    white-space: nowrap;
}

.sync-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.sync-btn:disabled {
    background: var(--surface-hover);
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

.sync-btn.syncing #syncBtnIcon {
    animation: rotate 1s linear infinite;
}

.sync-btn.success {
    background: var(--success);
}

.sync-btn.error {
    background: var(--error);
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.back-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.back-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
}

.section-header {
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h2 {
    font-size: 1.3rem;
}

.filters, .message-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
}

.filters select,
.message-filters select,
.message-filters input[type="text"],
#searchInput,
#messageTypeFilter,
#chatTypeFilter,
#chatSortFilter {
    padding: 0.5rem 0.8rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 180px;
}

.filters {
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    #messageTypeFilter,
    #chatTypeFilter,
    #chatSortFilter {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
        min-width: 120px;
    }
}

#searchInput {
    min-width: 250px;
    padding: 0.5rem;
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
}

@media (max-width: 768px) {
    #searchInput {
        min-width: unset;
        width: 100%;
        padding: 0.4rem;
        font-size: 0.85rem;
    }
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-back {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-back:hover {
    background: var(--surface-hover);
}

/* Chats List */
.chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-item {
    display: flex;
    gap: 0.8rem;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    align-items: center;
}

.chat-item:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
}

.chat-item.active {
    background: var(--surface-hover);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.2);
}

/* Avatar do Chat */
.chat-avatar-container {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    position: relative;
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.chat-avatar-fallback {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    border: 2px solid var(--border-color);
}

/* Conteúdo do Chat */
.chat-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.chat-name {
    font-weight: 600;
    font-size: 0.95rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chat-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-type-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 10px;
    background: var(--surface-hover);
    color: var(--text-secondary);
    white-space: nowrap;
}

.chat-unread {
    margin-top: 0.2rem;
    font-size: 0.75rem;
    color: var(--primary-color);
    font-weight: 600;
}

.chat-media-count {
    margin-top: 0.2rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Messages List */
.messages-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2px; /* Espaço menor entre mensagens, igual WhatsApp */
    scroll-behavior: smooth;
    background: 
        linear-gradient(rgba(11, 20, 26, 0.95), rgba(11, 20, 26, 0.95)), /* #0b141a - WhatsApp Web Dark Background */
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 10px,
            rgba(255, 255, 255, 0.03) 10px,
            rgba(255, 255, 255, 0.03) 20px
        );
}

.message-item {
    max-width: 65%; /* WhatsApp style width */
    width: fit-content;
    padding: 6px 7px 8px 9px;
    margin-bottom: 8px;
    border-radius: 7.5px;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    position: relative;
    word-wrap: break-word;
    font-size: 14.2px;
    line-height: 19px;
    color: #e9edef;
    cursor: default;
}

.message-detail-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.6;
    margin-left: 4px;
}

.message-item:hover .message-detail-btn {
    opacity: 1;
}

.message-detail-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-color);
}

.message-item.received {
    background-color: #202c33; /* Dark Gray */
    align-self: flex-start;
    border-top-left-radius: 0;
}

.message-item.sent {
    background-color: #005c4b; /* Greenish */
    align-self: flex-end;
    border-top-right-radius: 0;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
}

.message-content {
    margin-bottom: 4px; /* Espaço para o meta info */
    white-space: pre-wrap;
}

/* Metadata (Hora + Status) */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: -4px;
    margin-right: -4px;
    float: right; /* Flutuar para ficar ao lado do texto se houver espaço */
    padding-left: 10px;
    padding-bottom: 0;
    position: relative;
    top: 4px;
}

.message-time {
    font-size: 11px;
    color: rgba(241, 241, 242, 0.6);
    line-height: 15px;
}

.status-icon {
    font-size: 14px; /* Ícone um pouco maior */
    line-height: 14px;
}

.status-icon.sent { color: rgba(241, 241, 242, 0.6); }
.status-icon.delivered { color: rgba(241, 241, 242, 0.6); }
.status-icon.read { color: #53bdeb; } /* Azul WhatsApp */

/* --- QUOTED MESSAGES (RESPOSTAS) --- */
.message-quote {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    margin-bottom: 8px;
    display: flex;
    overflow: hidden;
    cursor: pointer;
    font-size: 0.85rem;
    max-width: 100%;
}

.quote-bar {
    width: 4px;
    background: var(--primary);
    flex-shrink: 0;
}

.quote-content-wrapper {
    display: flex;
    flex: 1;
    justify-content: space-between;
    padding: 4px 8px;
    background: rgba(0,0,0,0.03);
}

.quote-content {
    overflow: hidden;
}

.quote-author {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 2px;
}

.quote-thumb {
    width: 40px;
    height: 40px;
    margin-left: 8px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quote-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.quote-thumb.video-thumb {
    background: #333;
    color: white;
    font-size: 1.2rem;
}

/* Cor da barra diferente para mensagens enviadas por mim */
.message-item.sent .message-quote {
    background-color: rgba(0, 0, 0, 0.2);
    border-left-color: #35cd96; /* Pode variar a cor se quiser */
}

.quote-content {
    flex: 1;
    overflow: hidden;
    padding-left: 4px;
}

.quote-author {
    font-size: 12.8px;
    font-weight: 500;
    color: #35cd96; /* Verde autor */
    margin-bottom: 2px;
}

.message-item.sent .quote-author {
    color: #35cd96;
}

.quote-text {
    font-size: 13px;
    color: rgba(233, 237, 239, 0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 18px;
}

.quote-type {
    font-size: 11px;
    color: rgba(233, 237, 239, 0.6);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Highlight Animation */
@keyframes flashHighlight {
    0%, 100% { background-color: #202c33; }
    50% { background-color: #364349; } /* Um pouco mais claro */
}

.highlight-message {
    animation: flashHighlight 1s ease-in-out;
}

.message-item.sent.highlight-message {
    animation-name: flashHighlightSme;
}

@keyframes flashHighlightSme {
    0%, 100% { background-color: #005c4b; }
    50% { background-color: #027a64; }
}

/* Mobile: Ajustes */
@media (max-width: 768px) {
    .message-item {
        max-width: 85%;
        padding: 5px 6px 7px 8px;
    }
    
    .messages-list {
        padding: 0.5rem 1rem;
    }
    
    .media-container {
        width: 100%;
        max-width: 300px;
    }
    
    .message-image,
    .message-video {
        max-width: 100%;
        height: auto;
    }
    
    .message-header {
        display: none;
    }
    
    .message-from {
        font-size: 0.8rem;
    }
    
    .message-time {
        font-size: 0.6rem;
    }
}

.message-item.received {
    margin-right: auto;
    margin-left: 0;
    border-bottom-left-radius: 2px;
}

.message-item.sent {
    margin-left: auto;
    margin-right: 0;
    background: rgba(0, 168, 132, 0.2);
    border-bottom-right-radius: 2px;
}

.message-item:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.message-item.sent:hover {
    background: rgba(0, 168, 132, 0.3);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.3rem;
    gap: 1rem;
    position: relative;
    z-index: 1;
}

.message-from {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.85rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-item.sent .message-from {
    color: var(--success);
}

.message-item.received .message-from {
    color: #06cf9c;
}

.message-time {
    font-size: 0.65rem;
    color: var(--text-secondary);
    white-space: nowrap;
    font-family: monospace;
    opacity: 0.7;
    margin-left: 0.5rem;
    align-self: flex-end;
}

.message-content {
    margin-top: 0.5rem;
    line-height: 1.5;
    color: var(--text-primary);
    word-wrap: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    position: relative;
    z-index: 1;
    display: block;
}

/* Mídia inline */
.media-container {
    margin-top: 0.5rem;
    max-width: 100%;
    width: 100%;
    display: block;
    position: relative;
    z-index: 1;
}

.message-image,
.message-video {
    max-width: 300px;
    max-height: 300px;
    width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    cursor: pointer;
    display: block;
    transition: transform 0.2s;
    display: block;
    background: rgba(0, 0, 0, 0.1);
}

/* Mobile: Mídias responsivas */
@media (max-width: 768px) {
    .message-image,
    .message-video {
        max-width: 100%;
        max-height: 250px;
    }
}

.message-image:hover,
.message-video:hover {
    transform: scale(1.02);
}

.message-sticker {
    max-width: 150px;
    max-height: 150px;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: pointer;
    transition: transform 0.2s;
    display: block;
}

.message-sticker:hover {
    transform: scale(1.05);
}

.message-audio {
    width: 100%;
    max-width: 350px;
    min-width: 280px;
    height: 54px;
    border-radius: 24px;
    pointer-events: auto;
}

/* Estilização específica do player de áudio */
.message-audio::-webkit-media-controls-panel {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 24px;
}

.message-audio::-webkit-media-controls-play-button {
    background-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
}

.message-audio::-webkit-media-controls-current-time-display,
.message-audio::-webkit-media-controls-time-remaining-display {
    font-size: 14px;
    font-weight: 500;
}

.decrypt-badge,
.minio-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-top: 0.3rem;
    display: inline-block;
    font-weight: 600;
}

.decrypt-badge {
    background: rgba(255, 167, 38, 0.2);
    color: #ffa726;
    border: 1px solid rgba(255, 167, 38, 0.3);
}

.minio-badge {
    background: rgba(0, 168, 132, 0.2);
    color: var(--success);
    border: 1px solid rgba(0, 168, 132, 0.3);
}

.media-loading {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.media-caption {
    margin-top: 0.5rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    pointer-events: none;
}

.media-placeholder {
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
    color: var(--text-secondary);
    text-align: center;
    pointer-events: none;
}

.document-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.document-icon {
    font-size: 1.8rem;
}

.document-name {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.download-btn {
    padding: 0.4rem 0.8rem;
    background: var(--success);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
    pointer-events: auto;
}

.download-btn:hover {
    background: #00d856;
    transform: translateY(-1px);
}

/* Botão de ação inline em mensagens */
.message-type button {
    transition: all 0.2s ease;
}

.message-type button:hover {
    background: #f57c00 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
}

.message-type button:active {
    transform: translateY(0);
}

/* Links */
.message-link {
    color: #53bdeb;
    text-decoration: none;
    word-break: break-all;
    pointer-events: auto;
}

.message-link:hover {
    text-decoration: underline;
}

.link-preview {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--background);
    border-left: 3px solid var(--primary-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.link-preview-icon {
    font-size: 1.2rem;
}

.link-preview-url {
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-type {
    display: inline-block;
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-radius: 12px;
    background: var(--surface-hover);
    color: var(--text-secondary);
    margin-top: 0.3rem;
    font-weight: 500;
}

.message-type button {
    pointer-events: auto;
}

.date-separator {
    text-align: center;
    padding: 0.4rem 0.8rem;
    margin: 1.5rem auto;
    color: var(--text-secondary);
    font-size: 0.75rem;
    background: rgba(42, 57, 66, 0.8);
    border-radius: 6px;
    display: block;
    width: fit-content;
    align-self: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    font-weight: 500;
    position: relative;
    z-index: 2;
    clear: both;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Galeria de Mídia da Conversa */
.gallery-modal-content {
    max-width: 1100px;
    width: 92vw;
}

.gallery-filters {
    margin: 1rem 0;
}

.gallery-filters select {
    padding: 0.5rem 0.8rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 180px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.6rem;
    min-height: 120px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--background);
    cursor: pointer;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item img,
.gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item .gallery-item-icon {
    font-size: 2.2rem;
}

.gallery-video-play-icon {
    position: absolute;
    font-size: 1.6rem;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

.gallery-item .gallery-item-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.3rem;
    font-size: 0.7rem;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.gallery-load-more-wrap {
    display: flex;
    justify-content: center;
    margin-top: 1.2rem;
}

.gallery-lightbox-content {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-lightbox-content img,
.gallery-lightbox-content video {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 6px;
}

.gallery-lightbox-content .modal-close {
    position: fixed;
    right: 2rem;
    top: 1.5rem;
    color: white;
}

/* Decrypt Section */
.decrypt-section {
    padding: 2rem;
}

.decrypt-form {
    max-width: 600px;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--secondary-color);
}

.btn-download {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.btn-download:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.btn-download:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    transform: none;
}

.btn-download.secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.btn-download.secondary:hover {
    background: var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#decryptResult {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 6px;
}

#decryptResult.success {
    background: rgba(0, 168, 132, 0.2);
    border: 1px solid var(--success);
    color: var(--success);
}

#decryptResult.error {
    background: rgba(239, 83, 80, 0.2);
    border: 1px solid var(--error);
    color: var(--error);
}

/* Utility Classes */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading-more {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.load-more-btn {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0.5rem;
    background: var(--background);
}

.load-more-btn button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.2);
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.error-message {
    padding: 1rem;
    background: rgba(239, 83, 80, 0.2);
    border: 1px solid var(--error);
    border-radius: 6px;
    color: var(--error);
    margin: 1rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--surface-hover);
}

/* Responsive */
@media (max-width: 1024px) {
    .instances-sidebar,
    .chats-sidebar {
        width: 280px;
        min-width: 280px;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }
    
    .container,
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    .instances-sidebar,
    .chats-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 400px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .main-content {
        flex: 1;
        min-height: 60vh;
    }
    
    #messagesSection.main-content {
        height: calc(100vh - 400px);
        min-height: 500px;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .stats-bar {
        flex-wrap: wrap;
        gap: 0.8rem;
    }
    
    .messages-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.8rem;
    }
    
    .messages-controls {
        width: 100%;
        flex-wrap: wrap;
    }
    
    
    #messageTypeFilter {
        flex: 1;
        min-width: 150px;
    }
    
    .message-item {
        max-width: 95%;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0.8rem;
    }
    
    .header h1 {
        font-size: 1.1rem;
    }
    
    .subtitle {
        font-size: 0.8rem;
    }
    
    .stat-label,
    .stat-value {
        font-size: 0.85rem;
    }
    
    .sidebar-header h2 {
        font-size: 1rem;
    }
    
    .btn-refresh,
    .btn-back,
    .btn-sync,
    .btn-action {
        padding: 0.3rem 0.6rem;
        font-size: 0.85rem;
    }
}

/* ========== NOVOS ESTILOS - LAYOUT WHATSAPP ========== */

/* Filtros na sidebar */
.filters {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.filters select {
    width: 100%;
}

/* Lista de chats */
.chats-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    min-height: 0;
    height: 100%;
}

/* Main - Área de mensagens */
.messages-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
    overflow: hidden;
    height: 100%;
    position: relative;
    z-index: 1;
}

/* Estados vazios */
.empty-state-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    text-align: center;
}

.empty-icon {
    font-size: 5rem;
    opacity: 0.5;
}

.empty-state-main h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin: 0;
}

.empty-state-main p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Container de mensagens */
.messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header das mensagens */
.messages-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.chat-info {
    flex: 0 0 auto;
}

.chat-info h2 {
    font-size: 1.2rem;
    margin: 0;
}

.chat-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0.2rem 0 0 0;
}

.messages-actions {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    flex-wrap: wrap;
}

.btn-action {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
    white-space: nowrap;
}

.btn-action:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
}

.btn-action:disabled {
    background: var(--surface-hover);
    cursor: not-allowed;
    opacity: 0.6;
}

.messages-actions input[type="text"] {
    padding: 0.5rem 0.8rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 200px;
}

.messages-actions select {
    padding: 0.5rem 0.8rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    min-width: 150px;
}

/* Botão refresh */
.btn-refresh {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    padding: 0.3rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.btn-refresh:hover {
    background: var(--surface-hover);
    color: var(--primary-color);
}

/* ========== MEDIA QUERIES EXTRAS PARA MOBILE ========== */
@media (max-width: 480px) {
    .header {
        padding: 0.5rem 0.75rem;
    }
    
    .header h1 {
        font-size: 1rem;
    }
    
    .mobile-menu-btn {
        font-size: 1.25rem;
        padding: 0.4rem 0.6rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    .stat-value {
        font-size: 0.85rem;
    }
    
    .message-from {
        font-size: 0.8rem;
    }
    
    .message-time {
        font-size: 0.6rem;
    }
    
    .message-content {
        font-size: 0.9rem;
    }
}

/* Landscape mobile */
@media (max-width: 896px) and (orientation: landscape) {
    .header-content {
        flex-direction: row;
        flex-wrap: nowrap;
    }
    
    .header h1 {
        font-size: 1.1rem;
    }
    
    .header-stats {
        gap: 0.75rem;
    }
}

/* Touch targets maiores para mobile */
@media (hover: none) and (pointer: coarse) {
    .chat-item,
    .message-item,
    button,
    select {
        min-height: 44px; /* Recomendação Apple/Google */
    }
    
    .btn-refresh,
    .mobile-menu-btn {
        min-width: 44px;
        min-height: 44px;
    }
}
