/* RAG AI Chatbot Styles (Upgraded with Custom Theme Overrides) */
:root {
    --rag-primary: #C8102E;
    --rag-primary-dark: #A00D25;
    --rag-primary-light: #E31837;
    --rag-secondary: #1a1a1a;
    --rag-text: #2c2c2c;
    --rag-text-light: #666666;
    --rag-bg: #ffffff;
    --rag-bg-gray: #f5f5f5;
    --rag-border: #e0e0e0;
    --rag-shadow: rgba(200, 16, 46, 0.15);
    --rag-shadow-dark: rgba(0, 0, 0, 0.2);
    --rag-accent: #2a58e8;
}

#rag-chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#rag-chatbot-container.rag-chatbot-left { 
    right: auto; 
    left: 20px; 
}

.rag-chat-button {
    width: 60px !important; 
    height: 60px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, var(--rag-primary) 0%, var(--rag-primary-dark) 100%) !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 8px 24px var(--rag-shadow) !important;
    transition: all 0.3s ease !important;
    padding: 0 !important;
    margin: 0 !important;
}

.rag-chat-button:hover {
    transform: translateY(-4px) scale(1.05) !important;
}

.rag-chat-window {
    position: fixed;
    bottom: 100px; 
    right: 20px;
    width: 420px;
    max-width: calc(100vw - 40px);
    height: 650px;
    max-height: calc(100vh - 140px);
    background: var(--rag-bg);
    border-radius: 20px;
    box-shadow: 0 16px 48px var(--rag-shadow-dark);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 999999;
}

.rag-chat-window.rag-chat-active {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.rag-chat-header {
    background: linear-gradient(135deg, var(--rag-primary) 0%, var(--rag-primary-dark) 100%);
    color: white;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.rag-chat-header-left { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    flex: 1;
}

.rag-chat-avatar {
    width: 48px; 
    height: 48px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.rag-chat-avatar img { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; 
    padding: 8px; 
}

.rag-chat-title h3 { 
    margin: 0; 
    font-size: 18px; 
    font-weight: 600;
}

.rag-chat-subtitle { 
    font-size: 13px; 
    opacity: 0.95; 
}

/* خنثی‌سازی استایل‌های قالب برای دکمه‌های هدر */
.rag-header-actions {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
    margin-left: auto;
}

#rag-chatbot-container .rag-action-btn {
    padding: 0 !important;
    margin: 0 !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    background-color: rgba(255, 255, 255, 0.15) !important;
    border: none !important;
    border-radius: 6px !important;
    box-shadow: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    transition: background 0.2s ease;
}

#rag-chatbot-container .rag-action-btn:hover { 
    background-color: rgba(255, 255, 255, 0.3) !important; 
    color: white !important;
}

#rag-chatbot-container button svg {
    width: 22px !important;
    height: 22px !important;
    stroke: white !important;
    fill: none !important;
    display: block !important;
}

.rag-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 100px !important;
    background: var(--rag-bg-gray);
    display: flex;
    flex-direction: column;
}

.rag-chat-body::-webkit-scrollbar { width: 6px; }
.rag-chat-body::-webkit-scrollbar-track { background: transparent; }
.rag-chat-body::-webkit-scrollbar-thumb { background: var(--rag-border); border-radius: 3px; }

.rag-message {
    display: flex;
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s;
}

@keyframes messageSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.rag-message.rag-message-user { justify-content: flex-end; }
.rag-message.rag-message-bot { justify-content: flex-start; }

.rag-message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.rag-message.rag-message-bot .rag-message-content {
    background: white;
    color: var(--rag-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.rag-message.rag-message-user .rag-message-content {
    background: linear-gradient(135deg, var(--rag-primary), var(--rag-primary-dark));
    color: white;
    border-bottom-right-radius: 4px;
}

.rag-typing-indicator {
    display: flex; 
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.rag-typing-dot {
    width: 8px; 
    height: 8px;
    border-radius: 50%;
    background: var(--rag-text-light);
    animation: typingBounce 1.4s infinite;
}

.rag-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.rag-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.7;}
    30% { transform: translateY(-8px); opacity: 1;}
}

/* Products styling mapped to js structure */
.rag-product-card {
    background: #f9f9f9;
    border-radius: 20px;
    padding: 20px;
    text-align: left;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    border: 1px solid #f0f0f0;
    margin: 12px 0;
}

.rag-product-image {
    width: 100%;
    height: 160px;
    object-fit: contain;
    border-radius: 12px;
    margin-bottom: 12px;
    background: white;
}

.rag-product-title {
    font-family: serif;
    font-size: 18px;
    color: #333;
    margin: 0 0 15px 0;
    font-weight: 600;
}

.rag-product-price {
    color: #b1272c;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 20px;
}

.rag-product-button {
    background: #000000 !important;
    color: #ffffff !important;
    border-radius: 50px;
    padding: 10px 35px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.rag-product-button:hover {
    transform: translateY(-2px);
}

/* Quick Replies */
.rag-quick-replies {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    margin: 15px 0 !important;
    padding: 0 !important;
    justify-content: flex-start !important;
}

#rag-chatbot-container .rag-quick-reply-btn {
    background: #ffffff !important;
    border: 1px solid var(--rag-accent) !important;
    color: var(--rag-accent) !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    width: auto !important;
    height: auto !important;
    line-height: 1.4 !important;
    text-transform: none !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05) !important;
}

#rag-chatbot-container .rag-quick-reply-btn:hover {
    background: var(--rag-accent) !important;
    color: #ffffff !important;
    transform: translateY(-2px) !important;
}

/* Footer & Input */
.rag-chat-footer {
    padding: 16px;
    background: white;
    border-top: 1px solid var(--rag-border);
    flex-shrink: 0;
}

.rag-input-container { 
    display: flex; 
    gap: 8px; 
}

#rag-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--rag-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s ease;
}

#rag-chat-input:focus {
    border-color: var(--rag-primary);
}

.rag-send-btn {
    width: 44px !important; 
    height: 44px !important;
    background-color: var(--rag-primary) !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0;
    transition: all 0.2s ease !important;
    padding: 0 !important;
    margin: 0 !important;
}

.rag-send-btn:hover {
    transform: scale(1.1) !important;
    background-color: var(--rag-primary-dark) !important;
}

/* Fix global scrolling issues */
html, body {
    overflow-x: hidden;
    position: relative;
    max-width: 100%;
}

body.rag-chat-open {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
    .rag-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
    }

    body.rag-chat-open .rag-chat-button {
        display: none !important;
    }

    .rag-chat-header {
        padding: 15px; 
    }

    .rag-header-actions {
        gap: 15px !important; 
    }

    .rag-message-content {
        max-width: 85%;
    }
}