/* --- CORE VARIABLES (Fallbacks if inline CSS fails) --- */
:root {
    --nexus-primary: #333333;
    --nexus-width: 360px;
    --nexus-height: 500px;
}

/* --- CONTAINER & POSITION --- */
#nexus-wrapper {
    position: fixed;
    z-index: 999999;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    pointer-events: none; /* Clicks pass through empty space */
}

/* Re-enable clicking for actual elements */
#nexus-icon, #nexus-chat-window, .nexus-help-bubble, #nexus-frontend-toast {
    pointer-events: auto;
}

/* --- CHAT ICON --- */
#nexus-icon {
    width: 60px;
    height: 60px;
    background-color: var(--nexus-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: transform 0.2s ease;
    animation: icon-pulse-primary 2s infinite;
    position: absolute;
    bottom: 0;
    right: 0;
}

#nexus-icon img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Makes default icon white */
}

#nexus-icon:hover { 
    transform: scale(1.08); 
}

/* --- HELP BUBBLE --- */
.nexus-help-bubble {
    background-color: var(--nexus-primary);
    color: #FFFFFF;
    padding: 8px 16px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 13px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    position: absolute;
    bottom: 75px; 
    right: 0;     
    white-space: nowrap;
    opacity: 0;
    z-index: 99999;
    
    animation: nexusPopFloat 3s ease-in-out infinite;
    animation-fill-mode: forwards;
    transition: opacity 0.3s, visibility 0.3s;
}

.nexus-help-bubble::after {
    content: "";
    position: absolute;
    bottom: -6px; 
    right: 22px; 
    border-width: 8px 8px 0;
    border-style: solid;
    border-color: var(--nexus-primary) transparent transparent;
}

/* Hide bubble when chat is open */
#nexus-wrapper.nexus-chat-open .nexus-help-bubble {
    opacity: 0 !important;
    visibility: hidden !important;
    animation: none !important;
}

/* --- MAIN WINDOW --- */
#nexus-chat-window {
    width: var(--nexus-width);
    height: var(--nexus-height);
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0,0,0,0.2);
    display: none; /* Start hidden */
    flex-direction: column; 
    overflow: hidden;
    margin-bottom: 80px; /* Lift above icon */
    border: 1px solid #e0e0e0;
}

/* --- HEADER --- */
#nexus-header {
    background: var(--nexus-primary);
    color: #ffffff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.nexus-header-info {
    display: flex; 
    flex-direction: column; 
    line-height: 1.2;
}

.nexus-title {
    font-size: 16px;
    font-weight: 600;
}

.nexus-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}

.nexus-status-dot {
    width: 8px;
    height: 8px;
    background-color: #2ecc71; 
    border-radius: 50%;
    display: inline-block;
    animation: pulse-green 2s infinite;
}

#nexus-close { 
    cursor: pointer; 
    font-size: 24px; 
    line-height: 20px; 
    opacity: 0.8;
    transition: opacity 0.2s;
}
#nexus-close:hover { opacity: 1; }

/* --- LEAD CAPTURE FORM --- */
#nexus-lead-capture {
    flex-grow: 1;
    background: #fdfdfd;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
}

.nexus-lead-inner {
    width: 100%;
    text-align: center;
}

.nexus-lead-inner p {
    margin-top: 0;
    margin-bottom: 20px;
    color: #555;
    font-size: 14px;
}

.nexus-lead-inner input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 15px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.nexus-lead-inner input:focus {
    border-color: var(--nexus-primary);
}

#nexus-start-btn {
    width: 100%;
    background: var(--nexus-primary);
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s;
}

#nexus-start-btn:hover {
    opacity: 0.9;
}

/* --- CHAT AREA WRAPPER --- */
#nexus-chat-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- MESSAGES AREA --- */
#nexus-messages {
    flex-grow: 1;
    background: #f4f6f8;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#nexus-messages::-webkit-scrollbar { width: 6px; }
#nexus-messages::-webkit-scrollbar-track { background: #f1f1f1; }
#nexus-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
#nexus-messages::-webkit-scrollbar-thumb:hover { background: var(--nexus-primary); }

/* BUBBLES */
.bot-msg, .user-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}

.user-msg {
    align-self: flex-end;
    background-color: var(--nexus-primary);
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.bot-msg {
    align-self: flex-start;
    background-color: #ffffff;
    color: #333333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Bot Message Formatting Formatting */
.bot-msg strong { color: #000; font-weight: 700; }
.chat-list-item { margin: 6px 0; padding-left: 5px; display: block; }
.chat-list-num { font-weight: bold; color: var(--nexus-primary); margin-right: 4px; }

/* --- INPUT AREA --- */
#nexus-input-area {
    flex-shrink: 0;
    padding: 15px;
    background: #ffffff;
    border-top: 1px solid #eeeeee;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#nexus-user-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    height: 40px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

#nexus-user-input:focus { border-color: var(--nexus-primary); }

#nexus-send {
    width: 40px; 
    height: 40px;
    background: var(--nexus-primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
#nexus-send:hover { opacity: 0.9; }

/* --- ANIMATIONS --- */
@keyframes icon-pulse-primary {
    0% { box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 0 rgba(0, 0, 0, 0.1); }
    70% { box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 12px rgba(0, 0, 0, 0); }
    100% { box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 0 rgba(0, 0, 0, 0); }
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.5); }
    70% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

@keyframes nexusPopFloat {
    0% { opacity: 0; transform: translateY(10px) scale(0.8); }
    10% { opacity: 1; transform: translateY(0) scale(1); }
    50% { transform: translateY(-5px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* --- THINKING ANIMATION --- */
.typing-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}
.typing-text { font-size: 10px; color: #999; font-style: italic; margin-left: 2px; }
.typing-dots { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.typing-dots span {
    width: 6px; height: 6px; background: #95a5a6; border-radius: 50%;
    animation: typing-bounce 1.3s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* --- FRONTEND TOAST NOTIFICATION --- */
#nexus-frontend-toast {
    position: absolute;
    bottom: 80px; 
    right: 0;
    width: 300px;
    background: #ffffff;
    border-left: 4px solid var(--nexus-primary);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    border-radius: 6px;
    overflow: hidden;
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transform: translateX(20px);
    transition: all 0.3s ease;
}

#nexus-frontend-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.nexus-toast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f9f9f9;
    border-bottom: 1px solid #eeeeee;
}

.nexus-toast-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--nexus-primary);
}

#nexus-toast-close {
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: #999;
    transition: color 0.2s;
}

#nexus-toast-close:hover {
    color: #333;
}

#nexus-frontend-toast-msg {
    padding: 15px;
    font-size: 13px;
    color: #444;
    line-height: 1.5;
}

#nexus-frontend-toast-msg ul {
    margin: 8px 0 0 15px;
    padding: 0;
}

#nexus-frontend-toast-msg li {
    margin-bottom: 4px;
}

#nexus-frontend-toast-progress {
    height: 3px;
    background: var(--nexus-primary);
    width: 100%;
}

@keyframes nexusToastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

#nexus-frontend-toast.animate-progress #nexus-frontend-toast-progress {
    animation: nexusToastProgress 5s linear forwards;
}
/* --- MOBILE RESPONSIVENESS (FULL SCREEN CHAT) --- */
@media screen and (max-width: 768px) {
    
    /* Expand the wrapper to fill the screen when open */
    #nexus-wrapper.nexus-chat-open {
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: #ffffff; 
    }

    /* Force the chat window to take up all available space */
    #nexus-wrapper.nexus-chat-open #nexus-chat-window {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100% !important;
        max-height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border: none !important;
    }

    /* Hide the floating trigger icon while the chat is full screen */
    #nexus-wrapper.nexus-chat-open #nexus-icon {
        display: none !important;
    }

    /* Ensure the error toast notification fits nicely on small screens */
    #nexus-frontend-toast {
        width: 90% !important;
        right: 5% !important;
        bottom: 20px !important;
    }
}
/* --- LUXURY ACTION BUTTONS --- */
.nexus-action-btn-wrapper {
    margin-top: 12px;
    margin-bottom: 2px;
    display: flex;
    justify-content: flex-start;
}

.nexus-action-btn {
    display: inline-block;
    padding: 10px 24px;
    background-color: var(--btn-color, var(--nexus-primary));
    color: #ffffff !important;
    text-decoration: none !important;
    border-radius: 30px; /* Pill shape for luxury feel */
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.12);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.15);
}

.nexus-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0,0,0,0.18);
    opacity: 0.95;
}

/* Sweeping Shine Animation */
.nexus-action-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.4) 50%, rgba(255,255,255,0) 100%);
    transform: skewX(-25deg);
    animation: nexus-shine 3.5s infinite;
}

@keyframes nexus-shine {
    0% { left: -100%; }
    20% { left: 200%; }
    100% { left: 200%; }
}