/**
 * Chat Widget - Estilo Elegante e Moderno
 * AutoPeças Vitória
 */

/* ==================== VARIÁVEIS ====================*/

:root {
    /* Integrar ao tema global (fallbacks para funcionar isolado) */
    --chat-primary: var(--dark, #0F172A);
    --chat-secondary: var(--primary, #1D4ED8);
    --chat-accent: var(--secondary, #0F766E);
    --chat-bg: var(--white, #FFFFFF);
    --chat-user-msg: #EAF2FF;
    --chat-assistant-msg: #F6F7FB;
    --chat-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
    --chat-shadow-lg: 0 18px 44px rgba(15, 23, 42, 0.18);
}

/* ==================== BOTÃO FLUTUANTE ====================*/

.chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-secondary) 0%, var(--chat-primary) 100%);
    color: white;
    border: none;
    box-shadow: var(--chat-shadow);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.chat-button:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: var(--chat-shadow-lg);
}

.chat-button:active {
    transform: translateY(-2px) scale(1.02);
}

.chat-button.active {
    background: var(--chat-primary);
}

/* Badge de notificação */
.chat-button .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--chat-secondary);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ==================== JANELA DO CHAT ====================*/

.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: var(--chat-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* ==================== HEADER ====================*/

.chat-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, #111827 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chat-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chat-status {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    transition: opacity 0.2s;
}

.chat-close-btn:hover {
    opacity: 0.8;
}

/* ==================== CORPO DO CHAT ====================*/

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #F8F9FA;
}

.chat-body::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-thumb {
    background: #CBD5E0;
    border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: #A0AEC0;
}

/* ==================== MENSAGENS ====================*/

.chat-message {
    display: flex;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.message-avatar.user-avatar {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.message-content {
    max-width: 70%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.assistant .message-bubble {
    background: var(--chat-assistant-msg);
    color: #2D3748;
    border-bottom-left-radius: 4px;
}

.chat-message.user .message-bubble {
    background: var(--chat-user-msg);
    color: #1A365D;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.message-time {
    font-size: 11px;
    color: #718096;
    margin-top: 4px;
    display: block;
}

.chat-message.user .message-time {
    text-align: right;
}

/* ==================== DIGITANDO ====================*/

.typing-indicator {
    display: flex;
    gap: 12px;
    padding: 12px 0;
}

.typing-indicator .message-bubble {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94A3B8;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ==================== FOOTER ====================*/

.chat-footer {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #E2E8F0;
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #E2E8F0;
    border-radius: 24px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-input::placeholder {
    color: #A0AEC0;
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: #34495E;
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== MENSAGEM DE BOAS-VINDAS ====================*/

.welcome-message {
    text-align: center;
    padding: 32px 20px;
}

.welcome-message h3 {
    font-size: 20px;
    color: var(--chat-primary);
    margin: 0 0 12px 0;
}

.welcome-message p {
    font-size: 14px;
    color: #64748B;
    margin: 0 0 24px 0;
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-action-btn {
    padding: 12px 20px;
    background: white;
    border: 2px solid #E2E8F0;
    border-radius: 12px;
    color: var(--chat-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-action-btn:hover {
    border-color: var(--chat-primary);
    background: #F7FAFC;
    transform: translateY(-2px);
}

/* ==================== RESPONSIVO ====================*/

@media (max-width: 480px) {
    .chat-window {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .chat-button {
        bottom: 16px;
        right: 16px;
    }
}
