/* 
    BenWeb - AI Experience & Premium UI 
    Modern, Glassmorphism, and Intelligent Components 
*/

/* --- Dark Mode & Theming Variables --- */
:root {
    --ai-primary: #4cd7f6;
    --ai-bg-glass: rgba(21, 32, 49, 0.7);
    --ai-border: rgba(255, 255, 255, 0.1);
    --ai-text: #d8e3fb;
    --ai-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --ai-bot-msg: rgba(76, 215, 246, 0.1);
    --ai-user-msg: rgba(255, 255, 255, 0.05);
}

[data-theme="light"] {
    --surface: #ffffff;
    --surface-dim: #f8fafc;
    --surface-bright: #ffffff;
    --on-surface: #0f172a;
    --on-surface-variant: #475569;
    --outline: rgba(0, 0, 0, 0.1);
    
    --ai-bg-glass: rgba(255, 255, 255, 0.85);
    --ai-border: rgba(0, 0, 0, 0.1);
    --ai-text: #0f172a;
    --ai-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    --ai-bot-msg: rgba(76, 215, 246, 0.15);
    --ai-user-msg: rgba(0, 0, 0, 0.05);
}

/* Base transitions for smooth mode switching */
body {
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* --- Glassmorphism Utilities --- */
.ai-glass {
    background: var(--ai-bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--ai-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--ai-shadow);
}

/* --- Scroll Animations --- */
.ai-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.8s cubic-bezier(0.5, 0, 0, 1);
}
.ai-reveal.active {
    opacity: 1;
    transform: translateY(0);
}

/* --- Floating Chatbot UI --- */
.chatbot-widget {
    position: fixed;
    bottom: 30px;
    right: 100px; /* Offset from WA button */
    z-index: 1001;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--grad-main);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 30px var(--secondary-glow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
}
.chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 40px var(--secondary-glow);
}
.chatbot-toggle .material-symbols-outlined {
    font-size: 28px;
    transition: transform 0.3s ease;
}

.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    transform-origin: bottom right;
    overflow: hidden;
}

.chatbot-window.active {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0) scale(1);
}

.chatbot-header {
    padding: 15px 20px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--ai-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chatbot-header h4 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ai-text);
}
.chatbot-status {
    width: 8px;
    height: 8px;
    background: #25D366;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 10px #25D366;
}
.chatbot-close {
    cursor: pointer;
    color: var(--on-surface-variant);
    transition: color 0.2s;
}
.chatbot-close:hover {
    color: var(--error);
}

.chatbot-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Custom Scrollbar for Chat */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}
.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--outline);
    border-radius: 10px;
}

.msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: fadeInMsg 0.3s ease;
}
@keyframes fadeInMsg {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg.bot {
    background: var(--ai-bot-msg);
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.msg.user {
    background: var(--ai-user-msg);
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.chatbot-input-area {
    padding: 15px;
    border-top: 1px solid var(--ai-border);
    display: flex;
    gap: 10px;
    background: rgba(0,0,0,0.1);
}

.chatbot-input-area input {
    flex-grow: 1;
    background: var(--surface);
    border: 1px solid var(--outline);
    padding: 12px 15px;
    border-radius: 20px;
    color: var(--on-surface);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s;
}
.chatbot-input-area input:focus {
    border-color: var(--secondary);
}

.chatbot-input-area button {
    background: var(--secondary);
    color: #000;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}
.chatbot-input-area button:hover {
    transform: scale(1.05);
    background: #fff;
}
.chatbot-input-area button:disabled {
    background: var(--outline);
    cursor: not-allowed;
    transform: none;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 15px 20px;
    background: var(--ai-bot-msg);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: auto;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-5px); opacity: 1; }
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ai-toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-left: 4px solid var(--secondary);
    min-width: 300px;
    animation: toastSlideIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.ai-toast.success { border-left-color: #25D366; }
.ai-toast.error { border-left-color: var(--error); }

@keyframes toastSlideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toastSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}
.ai-toast.closing {
    animation: toastSlideOut 0.4s forwards;
}

/* --- Exit Intent Popup --- */
.exit-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.exit-popup-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.exit-popup {
    width: 90%;
    max-width: 500px;
    padding: 3rem;
    text-align: center;
    position: relative;
    transform: translateY(30px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.exit-popup-overlay.active .exit-popup {
    transform: translateY(0) scale(1);
}
.exit-close {
    position: absolute;
    top: 15px;
    right: 15px;
    cursor: pointer;
    color: var(--on-surface-variant);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chatbot-widget {
        right: 20px;
        bottom: 100px; /* Above WhatsApp */
    }
    .chatbot-window {
        width: 320px;
        right: -10px;
    }
    .toast-container {
        top: auto;
        bottom: 20px;
        left: 20px;
        right: 20px;
    }
    .ai-toast {
        min-width: 100%;
    }
}
