/* Main Container & Font */
#ai-chat-widget-container {
    font-family: var(--ai-chat-font, inherit);
    box-sizing: border-box;
    z-index: 99999;
    position: fixed;
    /* Positioning handles bottom/top left/right */
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    pointer-events: none;
    /* Let clicks pass through except on elements */
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#ai-chat-widget-container * {
    box-sizing: border-box;
}

/* Specific elements that SHOULD capture clicks */
.ai-chat-button,
.ai-chat-window.open,
.ai-chat-overlay.show {
    pointer-events: auto;
}

/* The window itself handles its own pointer-events via .open class, but let's be safe */
.ai-chat-window {
    pointer-events: none;
}

/* Chat Button */
.ai-chat-button {
    position: absolute;
    width: var(--ai-chat-icon-size, 60px);
    height: var(--ai-chat-icon-size, 60px);
    border-radius: 50%;
    background: var(--ai-chat-primary, #7C3AED);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    z-index: 10000;
}

.ai-chat-button:hover {
    transform: scale(1.05);
}

.ai-chat-button img {
    width: 60%;
    height: auto;
    object-fit: contain;
}

.ai-chat-default-icon {
    font-size: 24px;
    color: #fff;
}

/* Overlay for Mobile */
.ai-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 9999;
}

.ai-chat-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

/* Chat Window */
.ai-chat-window {
    position: absolute;
    background: var(--ai-chat-bg-window, #1a1a2e);
    color: var(--ai-chat-text, #fff);
    border-radius: var(--ai-chat-radius, 16px);
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    max-height: 80vh;
    z-index: 10001;

    /* Dynamic Size */
    width: var(--ai-chat-width, 360px);
    height: var(--ai-chat-height, 520px);
    border: 1px solid var(--ai-chat-border, rgba(255, 255, 255, 0.05));
}

.ai-chat-window.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}



/* Positions */
.ai-chat-pos-bottom-right .ai-chat-button {
    bottom: 20px;
    right: 20px;
}

.ai-chat-pos-bottom-right .ai-chat-window {
    bottom: calc(var(--ai-chat-icon-size, 60px) + 25px);
    right: 20px;
    transform-origin: bottom right;
}

.ai-chat-pos-bottom-left .ai-chat-button {
    bottom: 20px;
    left: 20px;
}

.ai-chat-pos-bottom-left .ai-chat-window {
    bottom: calc(var(--ai-chat-icon-size, 60px) + 25px);
    left: 20px;
    transform-origin: bottom left;
}

.ai-chat-pos-top-right .ai-chat-button {
    top: 20px;
    right: 20px;
}

.ai-chat-pos-top-right .ai-chat-window {
    top: calc(var(--ai-chat-icon-size, 60px) + 25px);
    right: 20px;
    transform-origin: top right;
}

.ai-chat-pos-top-left .ai-chat-button {
    top: 20px;
    left: 20px;
}

.ai-chat-pos-top-left .ai-chat-window {
    top: calc(var(--ai-chat-icon-size, 60px) + 25px);
    left: 20px;
    transform-origin: top left;
}

/* Header */
.ai-chat-header {
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-send-btn) 100%);
    padding: 20px;
    border-top-left-radius: var(--ai-chat-radius, 16px);
    border-top-right-radius: var(--ai-chat-radius, 16px);
}

.ai-chat-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    color: #fff;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.ai-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Quick Questions */
.ai-quick-questions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-quick-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-quick-btn:hover {
    background: #fff;
    color: var(--ai-chat-primary);
    border-color: #fff;
}

/* Messages & Scrollbar */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--ai-chat-bg-messages, #10101c);
    /* Very dark background */
    scrollbar-width: thin;
    scrollbar-color: var(--ai-chat-scrollbar, rgba(124, 58, 237, 0.3)) transparent;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--ai-chat-scrollbar, rgba(124, 58, 237, 0.3));
    border-radius: 20px;
}

.ai-chat-message {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    animation: aiFadeIn 0.3s ease;
}

.ai-chat-message.user {
    align-items: flex-end;
    text-align: inherit;
}

.ai-chat-message.bot {
    align-items: flex-start;
    text-align: inherit;
}

@keyframes aiFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-bubble {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}

.ai-chat-message.user .ai-message-bubble {
    background: linear-gradient(135deg, var(--ai-chat-primary, #7C3AED) 0%, var(--ai-chat-send-btn, #5B21B6) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.2);
}

.ai-chat-message.bot .ai-message-bubble {
    background: var(--ai-chat-bot-bubble-bg, #1e293b);
    color: var(--ai-chat-bot-bubble-text, #e2e8f0);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ai-chat-border, rgba(255, 255, 255, 0.05));
}

.ai-message-time {
    font-size: 11px;
    color: #64748b;
    margin-top: 6px;
    padding: 0 6px;
}

/* Input Area */
.ai-chat-input-wrapper {
    padding: 16px 20px 20px;
    background: var(--ai-chat-bg-messages, #10101c);
    border-top: 1px solid var(--ai-chat-border, rgba(255, 255, 255, 0.05));
}

.ai-chat-input-row {
    position: relative;
    display: flex;
    align-items: center;
}

.ai-chat-input-container {
    width: 100%;
}

.ai-chat-input {
    width: 100%;
    padding: 16px 50px 16px 16px;
    /* Right padding for button */
    border-radius: 12px;
    border: 1px solid var(--ai-chat-border, rgba(124, 58, 237, 0.3));
    background: var(--ai-chat-bg-input, #0f172a);
    color: var(--ai-chat-input-text, #ffffff) !important;
    /* Force white color */
    outline: none;
    font-size: 14px;
    line-height: 1.5;
    transition: all 0.3s ease;
    box-shadow: 0 0 0 1px transparent;
}

.ai-chat-input:focus {
    border-color: var(--ai-chat-primary);
    box-shadow: 0 0 0 1px var(--ai-chat-primary), 0 0 15px rgba(124, 58, 237, 0.2);
    background: var(--ai-chat-bg-input-focus, #131c31);
}

.ai-chat-input::placeholder {
    color: var(--ai-chat-placeholder, #94a3b8);
}

.ai-chat-send-btn {
    position: absolute;
    right: 8px;
    /* Inside the input */
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-send-btn) 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}

.ai-chat-send-btn:hover {
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.5);
}

.ai-chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
    /* Visual adjustment */
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-chat-mobile-responsive .ai-chat-window {
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
        z-index: 100001 !important;
        /* Extremely high on mobile */
    }
}

/* RTL Support */
[dir="rtl"] .ai-chat-send-btn {
    right: auto;
    left: 8px;
}

[dir="rtl"] .ai-chat-input {
    padding: 16px 16px 16px 50px;
}

[dir="rtl"] .ai-chat-send-btn svg {
    transform: scaleX(-1);
    margin-left: 0;
    margin-right: 2px;
}

[dir="rtl"] .ai-chat-close {
    margin-left: 0;
    margin-right: auto;
}

/* Maintain visual Right/Left positions regardless of direction */
[dir="rtl"] .ai-chat-message.user {
    align-items: flex-start;
    /* In RTL, flex-start is Right */
}

[dir="rtl"] .ai-chat-message.bot {
    align-items: flex-end;
    /* In RTL, flex-end is Left */
}

[dir="rtl"] .ai-chat-message.user .ai-message-bubble {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
    /* Maintain tail on the Right edge */
}

[dir="rtl"] .ai-chat-message.bot .ai-message-bubble {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
    /* Maintain tail on the Left edge */
}

/* Typing Indicator Animation */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px !important;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background-color: currentColor;
    border-radius: 50%;
    opacity: 0.4;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1.0);
        opacity: 1;
    }
}