/* ========================================
   JD Smart Building AI Chatbot Styles
   ======================================== */

/* CSS Variables for Chatbot */
:root {
    --chatbot-primary: var(--color-green, #68d391);
    --chatbot-primary-dark: var(--color-green-dark, #38a169);
    --chatbot-bg: #ffffff;
    --chatbot-text: var(--color-charcoal, #1a202c);
    --chatbot-text-light: var(--color-slate, #64748b);
    --chatbot-border: #e2e8f0;
    --chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chatbot-radius: 20px;
    --chatbot-width: 380px;
    --chatbot-height: 560px;
    --chatbot-z: 1000;
}

/* ========================================
   Floating Button (Replaces WhatsApp position)
   ======================================== */
.chatbot-trigger {
    position: fixed;
    bottom: var(--space-xl, 2rem);
    right: var(--space-xl, 2rem);
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    z-index: var(--chatbot-z);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
    padding: 1px;
}

.chatbot-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
}

.chatbot-trigger:active {
    transform: scale(1.05);
}

.chatbot-trigger__icon {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    object-fit: cover;
    object-position: top;
}

.chatbot-trigger__close {
    display: none;
    color: white;
}

.chatbot-trigger.active .chatbot-trigger__icon {
    display: none;
}

.chatbot-trigger.active .chatbot-trigger__close {
    display: block;
}

/* Pulse animation for trigger */
.chatbot-trigger::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--chatbot-primary);
    animation: chatbot-pulse 2s ease-out infinite;
    z-index: -1;
}

.chatbot-trigger.active::before {
    animation: none;
}

@keyframes chatbot-pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* ========================================
   WhatsApp Moved to Contact Section
   ======================================== */
.whatsapp-contact {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background-color: #25D366;
    color: white;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
}

.whatsapp-contact:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(37, 211, 102, 0.4);
    color: white;
}

.whatsapp-contact svg {
    width: 20px;
    height: 20px;
}

/* ========================================
   Chat Window
   ======================================== */
.chatbot-window {
    position: fixed;
    bottom: calc(var(--space-xl, 2rem) + 80px);
    right: var(--space-xl, 2rem);
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    max-height: calc(100vh - 120px);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    z-index: var(--chatbot-z);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    /* Fix antialiased white corners on dark backgrounds */
    border: 1px solid rgba(0, 0, 0, 0.1);
    outline: 1px solid transparent;
    outline-offset: -1px;
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========================================
   Chat Header
   ======================================== */
.chatbot-header {
    background: linear-gradient(135deg, var(--color-charcoal, #1a202c) 0%, #2d3748 100%);
    color: white;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.chatbot-header__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    padding: 2px;
    object-fit: cover;
}

.chatbot-header__info {
    flex: 1;
}

.chatbot-header__name {
    font-family: var(--font-heading, 'Montserrat', sans-serif);
    font-weight: 700;
    font-size: 1rem;
    margin: 0;
}

.chatbot-header__status {
    font-size: 0.75rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chatbot-header__status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #68d391;
    border-radius: 50%;
    animation: status-pulse 2s ease-in-out infinite;
}

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

.chatbot-header__close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chatbot-header__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   Quick Actions
   ======================================== */
.chatbot-quick-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    overflow-x: auto;
    background: #f8fafc;
    border-bottom: 1px solid var(--chatbot-border);
    flex-shrink: 0;
    scrollbar-width: none;
}

.chatbot-quick-actions::-webkit-scrollbar {
    display: none;
}

.chatbot-quick-action {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    background: white;
    border: 1px solid var(--chatbot-border);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--chatbot-text);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.chatbot-quick-action:hover {
    background: var(--chatbot-primary);
    color: white;
    border-color: var(--chatbot-primary);
}

/* ========================================
   Messages Container
   ======================================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

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

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

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

/* ========================================
   Message Bubbles
   ======================================== */
.chatbot-message {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
    animation: message-in 0.3s ease;
}

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

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

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

.chatbot-message__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #e2e8f0;
    object-fit: cover;
    object-position: top center;
}

/* Ensure image avatar shows properly */
img.chatbot-message__avatar {
    background: white;
    border: 1px solid #e2e8f0;
}

.chatbot-message--user .chatbot-message__avatar {
    background: var(--chatbot-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
}

.chatbot-message__content {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chatbot-message--bot .chatbot-message__content {
    background: #f1f5f9;
    color: var(--chatbot-text);
    border-bottom-left-radius: 4px;
}

.chatbot-message--user .chatbot-message__content {
    background: var(--chatbot-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Message content formatting */
.chatbot-message__content p {
    margin: 0 0 0.5rem 0;
}

.chatbot-message__content p:last-child {
    margin-bottom: 0;
}

.chatbot-message__content strong {
    font-weight: 600;
}

.chatbot-message__content a {
    color: inherit;
    text-decoration: underline;
}

.chatbot-message--bot .chatbot-message__content a {
    color: var(--chatbot-primary-dark);
}

/* Chatbot Links - Enhanced clickable styles */
.chatbot-link {
    color: var(--chatbot-primary-dark) !important;
    text-decoration: none !important;
    font-weight: 500;
    padding: 2px 6px;
    margin: 0 2px;
    border-radius: 4px;
    background: rgba(104, 211, 145, 0.15);
    transition: all 0.2s ease;
    display: inline-block;
}

.chatbot-link:hover {
    background: rgba(104, 211, 145, 0.3);
    text-decoration: none !important;
}

.chatbot-link--page::before {
    content: '📄 ';
    font-size: 0.85em;
}

/* Typing indicator */
.chatbot-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: #f1f5f9;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.chatbot-typing__dot {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.chatbot-typing__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing__dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

/* ========================================
   Input Area
   ======================================== */
.chatbot-input {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid var(--chatbot-border);
    background: white;
    flex-shrink: 0;
}

.chatbot-input__field {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--chatbot-border);
    border-radius: 24px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-input__field:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(104, 211, 145, 0.15);
}

.chatbot-input__field::placeholder {
    color: #94a3b8;
}

.chatbot-input__send {
    width: 44px;
    height: 44px;
    background: var(--chatbot-primary);
    border: none;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.chatbot-input__send:hover {
    background: var(--chatbot-primary-dark);
    transform: scale(1.05);
}

.chatbot-input__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chatbot-input__send svg {
    width: 20px;
    height: 20px;
}

/* ========================================
   Mobile Responsiveness
   ======================================== */
@media (max-width: 480px) {
    .chatbot-trigger {
        bottom: 1rem;
        right: 1rem;
        width: 56px;
        height: 56px;
        padding: 1px;
        z-index: 1001;
    }
    
    .chatbot-trigger__icon {
        width: 54px;
        height: 54px;
    }
    
    .chatbot-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        height: 100dvh; /* Dynamic viewport height */
        max-height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        z-index: 1002;
    }
    
    .chatbot-window.open {
        border-radius: 0;
    }
    
    .chatbot-header {
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        flex-shrink: 0;
        position: relative;
        background: linear-gradient(135deg, var(--chatbot-primary-dark) 0%, var(--chatbot-primary) 100%);
        z-index: 10;
    }
    
    .chatbot-quick-actions {
        padding: 0.5rem 0.75rem;
        flex-shrink: 0;
    }
    
    .chatbot-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        min-height: 0; /* Fixes flexbox overflow issue */
    }
    
    .chatbot-input {
        padding: 0.75rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
        flex-shrink: 0;
        background: var(--chatbot-bg);
        border-top: 1px solid var(--chatbot-border);
        z-index: 10;
    }
    
    /* Prevent zoom on input focus */
    .chatbot-input__field {
        font-size: 16px !important; /* Prevents iOS zoom */
        touch-action: manipulation;
    }
    
    .chatbot-message {
        max-width: 90%;
    }
}

/* Tablet adjustments */
@media (max-width: 768px) and (min-width: 481px) {
    .chatbot-window {
        width: 360px;
        height: 500px;
        bottom: calc(1.5rem + 70px);
        right: 1.5rem;
    }
    
    .chatbot-trigger {
        bottom: 1.5rem;
        right: 1.5rem;
    }
}

/* ========================================
   Animations
   ======================================== */
.chatbot-message__content.streaming::after {
    content: '▊';
    animation: blink 0.7s infinite;
    margin-left: 2px;
}

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

/* ========================================
   Action Buttons in Messages
   ======================================== */
.chatbot-action-btn {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--chatbot-primary);
    color: white;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s ease;
}

.chatbot-action-btn:hover {
    background: var(--chatbot-primary-dark);
    color: white;
}

/* ========================================
   Hide original WhatsApp float
   ======================================== */
.whatsapp-float {
    display: none !important;
}
