/* Chat Module Styles */

/* Container Geral do Chat */
.chat-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: #f0f2f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Sidebar de Conversas (Estilo WhatsApp Web) */
.chat-sidebar {
    width: 380px;
    min-width: 320px;
    background: #ffffff;
    border-right: 1px solid #d1d7db;
    display: flex;
    flex-direction: column;
    height: 100%;
    flex-shrink: 0;
}

.chat-sidebar-header {
    height: 60px;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid #d1d7db;
    flex-shrink: 0;
}

.chat-sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111b21;
    letter-spacing: -0.2px;
}

.chat-sidebar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-wa-header-icon {
    background: none;
    border: none;
    color: #54656f;
    font-size: 1.15rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

.btn-wa-header-icon:hover {
    background-color: rgba(11, 20, 26, 0.08);
    color: #111b21;
}

.chat-search-box {
    padding: 8px 12px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    flex-shrink: 0;
}

.chat-search-input-wrapper {
    position: relative;
    background: #f0f2f5;
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    height: 36px;
    transition: background 0.15s;
}

.chat-search-input-wrapper:focus-within {
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(11, 20, 26, 0.1);
}

.chat-search-icon {
    color: #54656f;
    font-size: 0.88rem;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-search-input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 14px;
    color: #111b21;
    font-family: inherit;
}

.chat-search-input::placeholder {
    color: #8696a0;
}

/* Tabs / Chips de Filtro */
.chat-tabs-bar {
    display: flex;
    gap: 6px;
    padding: 6px 12px 10px 12px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    overflow-x: auto;
    flex-shrink: 0;
}

.chat-tab-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: none;
    background: #f0f2f5;
    color: #54656f;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.chat-tab-btn:hover {
    background: #e9edef;
    color: #111b21;
}

.chat-tab-btn.active {
    background: #d9fdd3;
    color: #008069;
    font-weight: 600;
}

/* Lista de Conversas */
.chat-list {
    flex: 1;
    overflow-y: auto;
    background: #ffffff;
}

.chat-item {
    height: 72px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.15s;
    background: #ffffff;
    position: relative;
    user-select: none;
}

.chat-item:hover {
    background: #f5f6f6;
}

.chat-item.active {
    background: #f0f2f5;
}

.chat-avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    background: #dfe5e7;
    color: #54656f;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 600;
    margin-right: 15px;
    flex-shrink: 0;
    position: relative;
}

.chat-avatar.online::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 12px;
    height: 12px;
    background: #25d366;
    border: 2px solid #ffffff;
    border-radius: 50%;
}

.chat-info {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-bottom: 1px solid #f0f2f5;
    padding-right: 4px;
}

.chat-item:last-child .chat-info {
    border-bottom: none;
}

.chat-name {
    font-size: 16px;
    font-weight: 500;
    color: #111b21;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.chat-time {
    font-size: 12px;
    color: #667781;
    font-weight: 400;
}

.chat-item.has-unread .chat-time {
    color: #25d366;
    font-weight: 600;
}

.chat-preview {
    font-size: 14px;
    color: #667781;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 20px;
}

.unread-badge {
    background: #25d366;
    color: white;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    margin-left: 6px;
}

/* Empty State Autêntico WhatsApp Web */
.whatsapp-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: #f0f2f5;
    border-bottom: 6px solid #25d366;
    text-align: center;
    padding: 20px;
    user-select: none;
}

.whatsapp-empty-illustration {
    margin-bottom: 10px;
}

.whatsapp-empty-title {
    font-size: 32px;
    font-weight: 300;
    color: #41525d;
    margin: 18px 0 10px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.whatsapp-empty-subtitle {
    font-size: 14px;
    color: #667781;
    line-height: 20px;
    max-width: 480px;
    margin-bottom: 28px;
}

.whatsapp-empty-footer {
    font-size: 13px;
    color: #8696a0;
    display: flex;
    align-items: center;
}

/* Chat Main Area — Idêntico ao WhatsApp Web */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #efeae2;
    background-image: 
        radial-gradient(#d1c7b7 0.8px, transparent 0.8px), 
        radial-gradient(#d1c7b7 0.8px, #efeae2 0.8px);
    background-size: 26px 26px;
    background-position: 0 0, 13px 13px;
    position: relative;
}

.chat-header {
    height: 60px;
    background: #f0f2f5;
    border-bottom: 1px solid #d1d7db;
    display: flex;
    align-items: center;
    padding: 0 16px;
    justify-content: space-between;
    z-index: 10;
}

/* Botões de Ação no Cabeçalho */
.chat-header-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.chat-header-btn.btn-copilot {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
}

.chat-header-btn.btn-copilot:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.chat-header-btn.btn-chatbot {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.25);
}

.chat-header-btn.btn-chatbot:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.crm-chatbot-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    z-index: 1050;
    padding: 8px 0;
    text-align: left;
}

.crm-cb-header {
    padding: 8px 14px 10px 14px;
    border-bottom: 1px solid #f1f5f9;
}

.crm-cb-item {
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.crm-cb-item:hover {
    background: #f8fafc;
    border-left-color: #0284c7;
}

.crm-cb-item.highlight {
    background: #f0fdf4;
    border-left-color: #10b981;
}

.crm-cb-item.highlight:hover {
    background: #dcfce7;
}

.crm-cb-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 2px;
}

.crm-cb-desc {
    font-size: 0.72rem;
    color: #64748b;
    line-height: 1.35;
}

.crm-cb-divider {
    height: 1px;
    background: #f1f5f9;
    margin: 6px 0;
}

.crm-cb-item-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #6366f1;
    text-decoration: none;
    transition: background 0.15s;
}

.crm-cb-item-link:hover {
    background: #eef2ff;
}

.chat-header-btn.btn-personal {
    background: #f1f5f9;
    color: #475569;
    border-color: #cbd5e1;
}

.chat-header-btn.btn-personal.active {
    background: #f5f3ff;
    color: #6d28d9;
    border-color: #c4b5fd;
}

.chat-header-btn.btn-handoff {
    background: #f1f5f9;
    color: #475569;
    border-color: #cbd5e1;
}

.chat-header-btn.btn-handoff.active {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fca5a5;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

/* Badges de Contato */
.badge-tag-personal {
    font-size: 0.7rem;
    font-weight: 600;
    background: #ede9fe;
    color: #6d28d9;
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid #ddd6fe;
}

.badge-tag-human {
    font-size: 0.7rem;
    font-weight: 600;
    background: #fee2e2;
    color: #b91c1c;
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid #fecaca;
}

/* Lista de Mensagens — Estilo Autêntico WhatsApp */
.chat-messages {
    flex: 1;
    padding: 16px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message {
    max-width: 65%;
    min-width: 90px;
    padding: 6px 9px 8px 9px;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14.2px;
    line-height: 19px;
    color: #111b21;
    word-wrap: break-word;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    margin-bottom: 2px;
}

/* Mensagem Recebida (Branco com rabicho esquerdo) */
.message.received {
    background: #ffffff;
    align-self: flex-start;
    border-radius: 7.5px 7.5px 7.5px 0;
}

.message.received::before {
    content: "";
    position: absolute;
    top: 0;
    left: -8px;
    width: 8px;
    height: 13px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13' width='8' height='13'%3E%3Cpath opacity='0.13' fill='%23000' d='M1.533 2.568L8 11.193V0H2.812C1.042 0 .474 1.156 1.533 2.568z'/%3E%3Cpath fill='%23fff' d='M1.533 1.568L8 10.193V0H2.812C1.042 0 .474 1.156 1.533 1.568z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: top left;
}

/* Mensagem Enviada (Verde clássico WhatsApp com rabicho direito) */
.message.sent {
    background: #d9fdd3;
    align-self: flex-end;
    border-radius: 7.5px 7.5px 0 7.5px;
}

.message.sent::after {
    content: "";
    position: absolute;
    top: 0;
    right: -8px;
    width: 8px;
    height: 13px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 13' width='8' height='13'%3E%3Cpath opacity='0.13' fill='%23000' d='M5.188 1H0v11.193l6.467-8.625C7.526 2.156 6.958 1 5.188 1z'/%3E%3Cpath fill='%23d9fdd3' d='M5.188 0H0v11.193l6.467-8.625C7.526 1.156 6.958 0 5.188 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: top right;
}

/* Mensagem do Sistema (Cápsula centralizada estilo WhatsApp) */
.message.system {
    align-self: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 7.5px;
    padding: 6px 14px;
    font-size: 12.5px;
    line-height: 16px;
    color: #54656f;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    max-width: 82%;
    text-align: center;
    margin: 8px auto;
}

.message-meta {
    float: right;
    margin: 4px -2px -3px 8px;
    font-size: 11px;
    color: #667781;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    user-select: none;
}

.message-status {
    font-size: 11px;
    color: #8696a0;
}

/* Check duplo azul do WhatsApp Web */
.message-status.read,
.message-status.sent {
    color: #53bdeb;
}

/* Input Area — Idêntica ao WhatsApp Web */
.chat-input-area {
    background: #f0f2f5;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid #d1d7db;
    z-index: 10;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 9px 14px;
    border: none;
    border-radius: 8px;
    outline: none;
    font-size: 15px;
    background: #ffffff;
    color: #111b21;
    resize: none;
    height: 42px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

.chat-input::placeholder {
    color: #8696a0;
}

.chat-input:focus {
    background: #ffffff;
}

.chat-actions {
    display: flex;
    gap: 16px;
    color: #54656f;
    font-size: 1.3rem;
    cursor: pointer;
}

.chat-actions i:hover {
    color: #111b21;
}

.btn-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #00a884;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s, background-color 0.15s;
}

.btn-send:hover {
    background: #008f6f;
    transform: scale(1.05);
}

/* Confirm Modal */
#custom-confirm-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    /* quando JS põe display:flex, centra o .confirm-box */
}

.confirm-box {
    background: white;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    text-align: center;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.confirm-title {
    margin-top: 0;
    margin-bottom: 10px;
    color: #111827;
}

.confirm-message {
    color: #6b7280;
    margin-bottom: 20px;
}

.confirm-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.confirm-btn {
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    border: none;
    transition: filter 0.2s;
}

.confirm-btn.cancel {
    background: #f3f4f6;
    color: #374151;
}

.confirm-btn.confirm {
    background: var(--primary-color);
    color: white;
}

.confirm-btn.destructive {
    background: #ef4444;
    color: white;
}

.confirm-btn:hover {
    filter: brightness(0.95);
}

/* Toasts (antes em alerts.css — incluído aqui para não depender de ficheiro extra no servidor) */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-left: 4px solid var(--primary-color);
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    max-width: 420px;
    transform: translateX(100%);
    animation: toastSlideIn 0.3s forwards;
}

.toast.error { border-left-color: #ef4444; }
.toast.success { border-left-color: #10b981; }
.toast.info { border-left-color: #3b82f6; }
.toast.warning { border-left-color: #d97706; }

.toast-icon { font-size: 1.2rem; }
.toast.success .toast-icon { color: #10b981; }
.toast.error .toast-icon { color: #ef4444; }
.toast.info .toast-icon { color: #3b82f6; }
.toast.warning .toast-icon { color: #d97706; }

@keyframes toastSlideIn {
    to { transform: translateX(0); }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.crm-empty-conv-actions {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.crm-btn-refresh {
    padding: 8px 18px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    font-size: 0.875rem;
    cursor: pointer;
    font-weight: 500;
}

.crm-btn-refresh:hover {
    background: #f1f5f9;
}