/**
 * ============================================================
 * CasaAgentMatch Chatbot Widget - Modern 2025 Design
 * ============================================================
 * 
 * Color scheme: Green (#006D4F) + Orange (#FF6B35) + Blue (#00D9FF)
 * Font: Inter, Poppins
 * 
 * ============================================================
 */

/* ===== CSS VARIABLES ===== */
:root {
    --chat-primary: #006D4F;
    --chat-primary-light: #00A571;
    --chat-secondary: #FF6B35;
    --chat-accent: #00D9FF;
    --chat-dark: #0F172A;
    --chat-text: #1A1A1A;
    --chat-text-light: #666666;
    --chat-border: #E5E7EB;
    --chat-bg: #F8F9FA;
}

/* ===== WIDGET CONTAINER ===== */
#chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== TOGGLE BUTTON ===== */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #006D4F 0%, #00A571 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 109, 79, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 109, 79, 0.5);
}

.chatbot-toggle.active {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}

.chatbot-icon,
.chatbot-close-icon {
    font-size: 28px;
    transition: all 0.3s ease;
}

.chatbot-close-icon {
    position: absolute;
    color: white;
    font-size: 24px;
    opacity: 0;
    transform: scale(0);
}

.chatbot-toggle.active .chatbot-icon {
    opacity: 0;
    transform: scale(0);
}

.chatbot-toggle.active .chatbot-close-icon {
    opacity: 1;
    transform: scale(1);
}

/* ===== PROACTIVE POPUP ===== */
.chatbot-proactive {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 280px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    padding: 16px;
    animation: slideUp 0.3s ease-out;
}

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

.proactive-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.proactive-close:hover {
    background: #e5e7eb;
}

.proactive-content {
    margin-bottom: 12px;
}

.proactive-content strong {
    display: block;
    color: var(--chat-text);
    margin-bottom: 6px;
}

.proactive-content p {
    color: var(--chat-text-light);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

.proactive-btn {
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #006D4F 0%, #00A571 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.proactive-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 109, 79, 0.3);
}

/* ===== CHAT WINDOW ===== */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatOpen 0.3s ease-out;
}

@keyframes chatOpen {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===== CHAT HEADER ===== */
.chatbot-header {
    background: linear-gradient(135deg, #006D4F 0%, #00A571 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatbot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chatbot-info {
    flex: 1;
}

.chatbot-name {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 2px;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-lang {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chatbot-lang:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== CHAT MESSAGES ===== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--chat-bg);
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

.chat-message {
    display: flex;
    gap: 10px;
    animation: messageIn 0.3s ease-out;
}

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

.chat-message.bot {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #006D4F 0%, #00A571 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-message.user .message-avatar {
    background: linear-gradient(135deg, #FF6B35 0%, #FF8A5B 100%);
}

.message-content {
    max-width: 75%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.chat-message.bot .message-bubble {
    background: white;
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chat-message.user .message-bubble {
    background: linear-gradient(135deg, #006D4F 0%, #00A571 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #94A3B8;
    margin-top: 4px;
    text-align: right;
}

.chat-message.bot .message-time {
    text-align: left;
}

/* ===== QUICK REPLIES ===== */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.quick-reply-btn {
    padding: 8px 16px;
    background: white;
    border: 2px solid #006D4F;
    color: #006D4F;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-reply-btn:hover {
    background: #006D4F;
    color: white;
    transform: translateY(-2px);
}

/* Role Selection Buttons */
.role-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.role-btn {
    padding: 14px 20px;
    background: white;
    border: 2px solid var(--chat-border);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
}

.role-btn:hover {
    border-color: #006D4F;
    background: rgba(0, 109, 79, 0.05);
    transform: translateX(4px);
}

.role-btn.client {
    border-color: #006D4F;
}

.role-btn.client:hover {
    background: #006D4F;
    color: white;
}

.role-btn.agent {
    border-color: #FF6B35;
}

.role-btn.agent:hover {
    background: #FF6B35;
    color: white;
}

.role-btn.faq {
    border-color: #00D9FF;
}

.role-btn.faq:hover {
    background: #00D9FF;
    color: white;
}

.role-icon {
    font-size: 20px;
}

/* ===== CHAT INPUT ===== */
.chatbot-input {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

.chatbot-input input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--chat-border);
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.chatbot-input input:focus {
    border-color: #006D4F;
    box-shadow: 0 0 0 4px rgba(0, 109, 79, 0.1);
}

.chatbot-input input::placeholder {
    color: #94A3B8;
}

.chatbot-send {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #006D4F 0%, #00A571 100%);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 109, 79, 0.3);
}

.chatbot-send:disabled {
    background: #CBD5E1;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #006D4F;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 480px) {
    #chatbot-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .chatbot-toggle {
        width: 56px;
        height: 56px;
    }
    
    .chatbot-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        border-radius: 20px 20px 0 0;
    }
    
    .chatbot-proactive {
        width: calc(100vw - 40px);
        right: -4px;
    }
    
    .chatbot-header {
        padding: 14px 16px;
    }
    
    .chatbot-messages {
        padding: 16px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chatbot-input {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    
    .chatbot-input input {
        padding: 10px 14px;
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* ===== iOS SAFARI FIXES ===== */
@supports (-webkit-touch-callout: none) {
    .chatbot-window {
        max-height: calc(100dvh - 120px);
    }
    
    @media (max-width: 480px) {
        .chatbot-window {
            height: 100dvh;
            max-height: 100dvh;
        }
        
        .chatbot-input {
            padding-bottom: calc(12px + env(safe-area-inset-bottom, 20px));
        }
    }
}

/* ===== HIDDEN STATE ===== */
.chatbot-window.hidden,
.chatbot-proactive.hidden {
    display: none;
}

/* ===== ANIMATIONS ===== */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== LINK STYLES IN MESSAGES ===== */
.message-bubble a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}

.chat-message.bot .message-bubble a {
    color: #006D4F;
}

.chat-message.user .message-bubble a {
    color: rgba(255, 255, 255, 0.9);
}

/* ===== ERROR STATE ===== */
.message-bubble.error {
    background: #FEE2E2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

/* ===== SUCCESS STATE ===== */
.message-bubble.success {
    background: #D1FAE5;
    color: #065F46;
    border: 1px solid #A7F3D0;
}
