/* Chat Widget Styles - IA First */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-button {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    transition: all 0.3s ease;
    position: relative;
}

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

.chat-button i {
    color: white;
    font-size: 24px;
}

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

/* Botões de escalação */
.escalation-buttons {
    display: flex;
    gap: 10px;
    margin: 10px 0;
    justify-content: center;
}

.btn-escalation-yes, .btn-escalation-no {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-escalation-yes {
    background: #10b981;
    color: white;
}

.btn-escalation-yes:hover {
    background: #059669;
}

.btn-escalation-no {
    background: #6b7280;
    color: white;
}

.btn-escalation-no:hover {
    background: #4b5563;
}

.chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 420px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: scale(0) translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    overflow: hidden;
}

.chat-container.open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.chat-header {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    display: flex;
    align-items: center;
    flex-direction: column;
    align-items: flex-start;
}

.chat-title i {
    margin-right: 8px;
}

.chat-title span {
    font-weight: 600;
    font-size: 16px;
}

.chat-loading-bar {
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6b7280;
    font-size: 14px;
}

.chat-loading-bar .loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.state-ai {
    background: rgba(33, 150, 243, 0.2);
    color: #1976d2;
}

.state-human {
    background: rgba(76, 175, 80, 0.2);
    color: #388e3c;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.identification-modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10;
}

.identification-modal.show {
    opacity: 1;
    visibility: visible;
}

.identification-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 320px;
}

.identification-content h3 {
    margin: 0 0 8px 0;
    color: #1e293b;
    font-size: 18px;
}

.identification-content p {
    margin: 0 0 20px 0;
    color: #64748b;
    font-size: 14px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    color: #374151;
    font-weight: 500;
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: #2563eb;
}

.btn-primary {
    width: 100%;
    background: #2563eb;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.message.user {
    align-self: flex-end;
}

.message.ai,
.message.technician,
.message.system {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.user .message-bubble {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}

.message-bubble.ai-message {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #bbdefb;
    border-bottom-left-radius: 4px;
}

.message-bubble.technician-message {
    background: #e8f5e8;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
    border-bottom-left-radius: 4px;
}

.message-bubble.system-message {
    background: #fff3e0;
    color: #ef6c00;
    border: 1px solid #ffcc02;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

.message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    align-self: flex-end;
}

.message.user .message-time {
    align-self: flex-end;
}

.message.ai .message-time,
.message.technician .message-time,
.message.system .message-time {
    align-self: flex-start;
}

.confidence-score {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
    font-style: italic;
}

.chat-loading {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #6b7280;
    font-size: 14px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: #6b7280;
    border-radius: 50%;
    animation: loading 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loading {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.chat-input {
    padding: 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input textarea {
    flex: 1;
    border: 2px solid #e5e7eb;
    border-radius: 20px;
    padding: 12px 16px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    min-height: 40px;
    transition: border-color 0.2s;
    overflow-y: hidden;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.chat-input textarea:focus {
    outline: none;
    border-color: #2563eb;
}

.chat-input button {
    width: 40px;
    height: 40px;
    background: #2563eb;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-input button:hover:not(:disabled) {
    background: #1d4ed8;
    transform: scale(1.05);
}

.chat-input button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.escalation-panel {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
    text-align: center;
}

.escalate-btn {
    background: #10b981;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.escalate-btn:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

/* Responsive */
@media (max-width: 480px) {
    .chat-container {
        width: calc(100vw - 30px);
        height: calc(100dvh - 100px);
        top: 50%;
        left: 50%;
        bottom: auto;
        right: auto;
        transform: translateX(-50%) translateY(-50%) scale(0);
    }
    
    .chat-container.open {
        transform: translateX(-98%) translateY(-100%) scale(1);
    }
    
    .identification-content {
        width: 95%;
        padding: 20px;
    }
}

/* Scrollbar customization */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
