/* ===============================================
   CHAT INTERFACE - WhatsApp Web Style
   =============================================== */

/* Variables CSS para el chat (fallback si no están definidas) */
:root {
    --primary: #3b82f6;
    --primary-rgb: 59, 130, 246;
    --card: #ffffff;
    --bg: #f8fafc;
    --text: #1e293b;
    --muted: #64748b;
    --muted-rgb: 100, 116, 139;
    --border: #e2e8f0;
    --hover: #f1f5f9;
    --error: #ef4444;
}

.chat-container {
    display: flex;
    height: calc(100vh - 120px);
    background: var(--card, #ffffff);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border, #e2e8f0);
}

/* Sidebar de chats */
.chat-sidebar {
    width: 350px;
    border-right: 1px solid var(--border, #e2e8f0);
    display: flex;
    flex-direction: column;
    background: var(--card, #ffffff);
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border, #e2e8f0);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-sidebar-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text, #1e293b);
}

.evolution-config-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    background: var(--bg, #f8fafc);
    color: var(--text, #1e293b);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.evolution-config-select:hover {
    border-color: var(--primary, #3b82f6);
}

.evolution-config-select:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #e2e8f0);
}

.chat-search input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 24px;
    background: var(--bg, #f8fafc);
    color: var(--text, #1e293b);
    font-size: 14px;
    transition: all 0.2s;
}

.chat-search input:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-search input::placeholder {
    color: var(--muted, #64748b);
}

.chats-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bg, #f8fafc);
}

.chat-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #e2e8f0);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-item:hover {
    background: var(--hover, #f1f5f9);
}

.chat-item.active {
    background: var(--primary, #3b82f6);
    color: white;
}

.chat-item.active .chat-item-name,
.chat-item.active .chat-item-preview,
.chat-item.active .chat-item-time {
    color: white;
}

.chat-item-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary, #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--muted, #64748b);
    white-space: nowrap;
}

.chat-item-preview {
    font-size: 13px;
    color: var(--muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-unread {
    background: var(--primary, #3b82f6);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

/* Área de chat principal */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg, #f8fafc);
    position: relative;
}

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted, #64748b);
    text-align: center;
    padding: 40px;
}

.empty-chat-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty-state h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    color: var(--text, #1e293b);
}

.chat-empty-state p {
    margin: 0;
    font-size: 14px;
    color: var(--muted, #64748b);
}

/* Chat activo */
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #e2e8f0);
    background: var(--card, #ffffff);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-contact-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary, #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-contact-details h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text, #1e293b);
}

.chat-contact-number {
    margin: 2px 0 0 0;
    font-size: 13px;
    color: var(--muted, #64748b);
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: transparent;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text, #1e293b);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.btn-icon:hover {
    background: var(--hover, #f1f5f9);
}

/* Mensajes */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg, #f8fafc);
    background-image: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 10px,
            rgba(100, 116, 139, 0.03) 10px,
            rgba(100, 116, 139, 0.03) 20px
        );
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    display: flex;
    margin-bottom: 8px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    word-wrap: break-word;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-text {
    word-break: break-word;
    line-height: 1.4;
}

.message-icon {
    font-size: 18px;
    margin-right: 4px;
    display: inline-block;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

.message.sent .message-bubble {
    background: var(--primary, #3b82f6);
    color: white;
    border-bottom-right-radius: 2px;
}

.message.received .message-bubble {
    background: var(--card, #ffffff);
    color: var(--text, #1e293b);
    border: 1px solid var(--border, #e2e8f0);
    border-bottom-left-radius: 2px;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.message.received .message-time {
    text-align: left;
}

.message-status {
    font-size: 11px;
    margin-left: 4px;
    opacity: 0.7;
}

/* Input de mensaje */
.chat-input-container {
    padding: 12px 16px;
    border-top: 1px solid var(--border, #e2e8f0);
    background: var(--card, #ffffff);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-input-container input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 24px;
    background: var(--bg, #f8fafc);
    color: var(--text, #1e293b);
    font-size: 14px;
    transition: all 0.2s;
}

.chat-input-container input:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-input-container input::placeholder {
    color: var(--muted, #64748b);
}

/* Scrollbar personalizado */
.chats-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chats-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chats-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--muted, #64748b);
    border-radius: 3px;
}

.chats-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary, #3b82f6);
}

/* Responsive */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
        height: calc(100vh - 80px);
    }
    
    .chat-sidebar {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border, #e2e8f0);
    }
    
    .chat-main {
        height: 60%;
    }
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted, #64748b);
    font-size: 14px;
}
