/* ==========================================================================
   TELA DE AUDITORIA & HISTÓRICO DE CONVERSAS WHATSAPP (VIEWPORT LOCKED)
   ========================================================================== */
.wa-hist-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 55px); /* Encaixe exato abaixo da navbar do YGIA */
    max-height: calc(100vh - 55px);
    background-color: #f8fafc;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #0f172a;
    overflow: hidden; /* Elimina qualquer rolagem vertical da página externa */
    box-sizing: border-box;
}

/* 1. CABEÇALHO DA PÁGINA (FIXO NO TOPO) */
.wa-hist-top-header {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Impede encolhimento */
}

.wa-hist-brand-box {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wa-hist-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px !important;
    background: linear-gradient(135deg, #00a884 0%, #008069 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.25);
    flex-shrink: 0;
}

.wa-hist-title {
    font-size: 18px;
    font-weight: 800;
    color: #0f172a;
    margin: 0;
    line-height: 1.2;
}

.wa-hist-subtitle {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}


/* 2. BARRA DE FILTROS GLOBAIS (FIXA) */
.wa-hist-filter-bar {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.wa-hist-filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.wa-hist-filter-label {
    font-size: 11.5px;
    font-weight: 700;
    color: #475569;
    margin: 0;
    white-space: nowrap;
}

.wa-hist-input {
    height: 32px;
    border-radius: 6px !important;
    border: 1px solid #cbd5e1;
    padding: 3px 8px;
    font-size: 12px;
    outline: none;
    background: #ffffff;
}

    .wa-hist-input:focus {
        border-color: #00a884;
        box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.15);
    }

.btn-wa-filter {
    height: 32px;
    padding: 0 14px;
    border-radius: 6px !important;
    background-color: #00a884;
    color: #ffffff;
    border: none;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

    .btn-wa-filter:hover {
        background-color: #008f6f;
    }

.btn-wa-clear {
    height: 32px;
    padding: 0 10px;
    border-radius: 6px !important;
    background-color: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

    .btn-wa-clear:hover {
        background-color: #e2e8f0;
        color: #1e293b;
    }

/* 3. PALCO PRINCIPAL MASTER-DETAIL (OCUPA EXATAMENTE O RESTO DA TELA) */
.wa-hist-main-stage {
    display: flex;
    flex: 1;
    min-height: 0; /* CRUCIAL PARA FLEXBOX NÃO TRANSBORDAR */
    overflow: hidden;
}

/* PAINEL ESQUERDO: LISTA DE CHATS */
.wa-hist-chats-panel {
    width: 360px;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.wa-hist-chats-header {
    padding: 10px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.wa-hist-count-badge {
    font-size: 11px;
    font-weight: 700;
    background: #e2e8f0;
    color: #334155;
    padding: 2px 8px;
    border-radius: 10px;
}

.wa-hist-chat-list {
    flex: 1;
    overflow-y: auto; /* Rolagem interna independente */
    min-height: 0;
}

.wa-hist-chat-card {
    padding: 11px 16px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    display: flex;
    gap: 12px;
    align-items: center;
    transition: background 0.15s ease;
}

    .wa-hist-chat-card:hover {
        background: #f8fafc;
    }

    .wa-hist-chat-card.active {
        background: #eef2f6;
        border-left: 4px solid #00a884;
    }

.wa-hist-avatar-box {
    width: 42px;
    height: 42px;
    border-radius: 50% !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13.5px;
    font-weight: 700;
    color: #ffffff;
    flex-shrink: 0;
}

.wa-hist-chat-meta {
    flex: 1;
    min-width: 0;
}

.wa-hist-row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.wa-hist-chat-name {
    font-size: 13.5px;
    font-weight: 700;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wa-hist-chat-date {
    font-size: 11px;
    color: #64748b;
    flex-shrink: 0;
}

.wa-hist-row-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wa-hist-chat-preview {
    font-size: 12px;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

.wa-hist-badge-tag {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    background: #e0f2fe;
    color: #0369a1;
}

/* PAINEL DIREITO: VISUALIZADOR DE MENSAGENS ESTILO WHATSAPP */
.wa-hist-view-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #efeae2;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

/* Topo do Visualizador do Chat */
.wa-hist-view-header {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.wa-hist-view-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wa-hist-user-title {
    font-size: 15px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
}

.wa-hist-user-sub {
    font-size: 11.5px;
    color: #64748b;
}

.wa-hist-view-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Barra interna de pesquisa rápida no chat */
.wa-hist-search-inner {
    position: relative;
    display: flex;
    align-items: center;
}

    .wa-hist-search-inner input {
        height: 32px;
        width: 220px;
        border-radius: 16px !important;
        border: 1px solid #cbd5e1;
        padding: 0 12px 0 28px;
        font-size: 12px;
        background: #f8fafc;
    }

    .wa-hist-search-inner i {
        position: absolute;
        left: 10px;
        color: #94a3b8;
        font-size: 12px;
    }

/* Scroll das mensagens */
.wa-hist-messages-scroll {
    flex: 1;
    overflow-y: auto; /* Rolagem interna das mensagens */
    padding: 16px 28px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background-image: radial-gradient(#d1d7db 1px, transparent 1px);
    background-size: 20px 20px;
    min-height: 0;
}

/* Balões WhatsApp */
.wa-hist-bubble-row {
    display: flex;
    width: 100%;
    margin-bottom: 3px;
}

    .wa-hist-bubble-row.outbound {
        justify-content: flex-end;
    }

    .wa-hist-bubble-row.inbound {
        justify-content: flex-start;
    }

.wa-hist-bubble {
    max-width: 65%;
    padding: 7px 10px 5px 10px;
    border-radius: 8px !important;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
    font-size: 13.5px;
    line-height: 1.45;
}

    .wa-hist-bubble.outbound {
        background-color: #d9fdd3;
        color: #111b21;
        border-top-right-radius: 0 !important;
    }

    .wa-hist-bubble.inbound {
        background-color: #ffffff;
        color: #111b21;
        border-top-left-radius: 0 !important;
    }

.wa-hist-bubble-text {
    word-break: break-word;
    white-space: pre-line;
}

.wa-hist-bubble-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    color: #667781;
    margin-top: 2px;
}

    .wa-hist-bubble-meta.read {
        color: #53bdeb;
    }

/* Separadores de Data e Carregar Mais */
.wa-hist-date-separator-box {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 12px 0 8px 0;
}

.wa-hist-date-badge {
    background-color: #ffffff;
    color: #54656f;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 6px !important;
    box-shadow: 0 1px 2px rgba(11,20,26,0.1);
    text-transform: capitalize;
    border: 1px solid rgba(0,0,0,0.04);
}

.wa-hist-load-more-box {
    display: flex;
    justify-content: center;
    padding: 4px 0 12px 0;
    width: 100%;
}

.btn-wa-load-more {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    color: #008069;
    font-size: 11.5px;
    font-weight: 700;
    padding: 5px 14px;
    border-radius: 20px !important;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

    .btn-wa-load-more:hover {
        background-color: #f1f5f9;
        color: #005c4b;
    }

.wa-hist-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #64748b;
    text-align: center;
    padding: 20px;
}

.wa-hist-empty-icon {
    font-size: 44px;
    color: #94a3b8;
    margin-bottom: 10px;
}

.highlight-text {
    background-color: #fef08a;
    font-weight: 700;
    padding: 0 2px;
    border-radius: 2px;
}
