/* Botão Flutuante do Chat */
.chat-toggle-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #9333ea 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s ease;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* Modal do Chat */
.chat-modal {
    display: none;
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 999;
    flex-direction: column;
    overflow: hidden;
}

.chat-modal.active {
    display: flex;
}

.chat-modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    background: linear-gradient(135deg, #2563eb 0%, #9333ea 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h5 {
    margin: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Mesmo X dos outros modais (modal-close), adaptado ao header escuro do chat */
.chat-modal .modal-close {
    position: static;
    right: auto;
    top: auto;
    color: #fff;
    font-size: 2rem;
}

.chat-modal .modal-close:hover {
    color: rgba(255, 255, 255, 0.9);
}

.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Lista de Conversas */
.chat-conversas-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-loading {
    text-align: center;
    padding: 20px;
    color: #6b7280;
}

.chat-conversa-item {
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 8px;
    margin-bottom: 5px;
}

.chat-conversa-item:hover {
    background: #f3f4f6;
}

.chat-conversa-item.active {
    background: #eff6ff;
}

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

.chat-conversa-nome {
    font-weight: 600;
    color: #1f2937;
    font-size: 14px;
}

.chat-conversa-badge {
    background: #ef4444;
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: bold;
}

.chat-conversa-preview {
    font-size: 12px;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-conversa-service {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
}

/* Área de Mensagens */
.chat-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages-header {
    padding: 12px 15px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f9fafb;
}

.chat-back-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: #6b7280;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-back-btn:hover {
    background: #e5e7eb;
}

.chat-contact-info {
    flex: 1;
}

.chat-contact-info strong {
    display: block;
    font-size: 14px;
    color: #1f2937;
}

.chat-contact-info small {
    display: block;
    font-size: 12px;
    color: #6b7280;
}

.chat-messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f9fafb;
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
}

.chat-message.own {
    justify-content: flex-end;
}

.chat-message-bubble {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    font-size: 14px;
}

.chat-message.own .chat-message-bubble {
    background: linear-gradient(135deg, #2563eb 0%, #9333ea 100%);
    color: white;
}

.chat-message.other .chat-message-bubble {
    background: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
}

.chat-message-info {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 5px;
    padding: 0 5px;
}

.chat-message.own .chat-message-info {
    text-align: right;
}

/* Mensagem otimista (sendo enviada) */
.chat-message-optimistic {
    opacity: 0.8;
    animation: pulse-optimistic 1.5s ease-in-out infinite;
}

.chat-message-optimistic .chat-message-bubble {
    position: relative;
}

.chat-message-loading {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes pulse-optimistic {
    0%, 100% {
        opacity: 0.8;
    }
    50% {
        opacity: 0.9;
    }
}

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

.chat-input-container {
    display: flex;
    padding: 15px;
    border-top: 1px solid #e5e7eb;
    background: white;
    gap: 10px;
}

.chat-message-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
}

.chat-message-input:focus {
    border-color: #2563eb;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #9333ea 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.1);
}

.chat-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
}

.chat-empty-state i {
    font-size: 48px;
    margin-bottom: 10px;
    display: block;
}

/* Responsivo */
@media (max-width: 768px) {
    .chat-modal {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    
    .chat-toggle-btn {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}
