/* =========================================
   1. استایل‌های پایه و دکمه شناور (Toggle)
   ========================================= */
#ai-chatbot-widget {
    font-family: inherit; /* استفاده از فونت قالب */
    position: fixed;
    z-index: 999998;
}

.ai-chatbot-toggle {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); /* رنگ آبی مدرن */
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    z-index: 999998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    color: white;
}

.ai-chatbot-toggle:hover {
    transform: scale(1.1) rotate(-5deg);
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.5);
}

.ai-chatbot-toggle i {
    font-size: 28px;
}

/* انیمیشن ضربان برای جلب توجه */
.ai-chatbot-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    animation: pulse 2s infinite;
    z-index: -1;
}

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

/* =========================================
   2. کانتینر اصلی چت (Main Container)
   ========================================= */
.ai-chatbot-container {
    position: fixed;
    width: 380px;
    height: 600px;
    max-height: 80vh;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 999999;
    display: none; /* توسط JS کنترل می‌شود */
    flex-direction: column;
    overflow: hidden;
    bottom: 95px;
    right: 25px;
    border: 1px solid rgba(0,0,0,0.05);
    animation: slideUp 0.3s ease-out forwards;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   3. هدر (Header)
   ========================================= */
.ai-chatbot-header {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.ai-chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chatbot-avatar {
    width: 35px;
    height: 35px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chatbot-info h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
    line-height: 1.2;
}

.ai-chatbot-info span {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chatbot-info span::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background: #4ade80; /* رنگ سبز آنلاین */
    border-radius: 50%;
}

.ai-chatbot-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.8;
    transition: 0.2s;
    padding: 5px;
}

.ai-chatbot-close:hover {
    opacity: 1;
    transform: rotate(90deg);
}

/* =========================================
   4. ناحیه پیام‌ها (Messages Area)
   ========================================= */
.ai-chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-assistant-message {
    background: white;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 2px;
    align-self: flex-start;
    color: #334155;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.ai-user-message {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 2px;
    align-self: flex-end;
    box-shadow: 0 2px 5px rgba(37, 99, 235, 0.2);
}

.ai-user-message a {
    color: white;
    text-decoration: underline;
}

.ai-assistant-message a {
    color: #2563eb;
    font-weight: 500;
}

.message-time {
    font-size: 10px;
    margin-top: 6px;
    opacity: 0.7;
    text-align: right;
}

/* =========================================
   5. ناحیه ورودی (Input Area)
   ========================================= */
.ai-chatbot-input {
    padding: 15px;
    background: white;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 10px;
    background: #f1f5f9;
    padding: 8px;
    border-radius: 24px;
    align-items: center;
    border: 1px solid transparent;
    transition: 0.3s;
}

.input-container:focus-within {
    border-color: #2563eb;
    background: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#ai-chatbot-input {
    border: none;
    background: transparent;
    flex: 1;
    padding: 8px 12px;
    outline: none;
    font-size: 14px;
    color: #334155;
    font-family: inherit;
}

#ai-chatbot-send {
    background: #2563eb;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
}

#ai-chatbot-send:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

#ai-chatbot-send:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* =========================================
   6. لودینگ (Typing Indicator)
   ========================================= */
.typing-indicator {
    padding: 12px 16px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    border-bottom-left-radius: 2px;
    display: table;
    align-self: flex-start;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: bounce 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 bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* =========================================
   7. تنظیمات حیاتی موبایل (Mobile Fixes)
   ========================================= */
@media (max-width: 768px) {
    /* دکمه بازشو در موبایل */
    .ai-chatbot-toggle {
        bottom: 20px;
        right: 20px;
        width: 55px;
        height: 55px;
    }

    /* وقتی کلاس hidden-on-mobile اضافه شد (توسط JS) */
    .ai-chatbot-toggle.hidden-on-mobile {
        display: none !important;
        opacity: 0;
        pointer-events: none;
    }

    /* کانتینر اصلی در حالت تمام صفحه */
    .ai-chatbot-container {
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important; /* استفاده از واحد داینامیک برای حذف نوار آدرس */
        max-height: none !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 2147483647 !important; /* بالاترین اولویت */
        display: none; /* JS flex می‌کند */
    }

    .ai-chatbot-header {
        padding: 15px;
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 15px); /* فاصله از ناچ گوشی */
    }
    
    .ai-chatbot-messages {
        padding: 15px;
        font-size: 15px; /* فونت کمی بزرگتر برای خوانایی */
    }
    
    .ai-message {
        max-width: 90%;
    }

    .ai-chatbot-input {
        padding: 10px;
        padding-bottom: env(safe-area-inset-bottom, 15px); /* فاصله از پایین گوشی */
    }

    .input-container {
        padding: 10px;
    }
}
