/* نافذة الشات */
#chat-container {
    position: fixed;
    bottom: 120px; /* تم تعديله ليترك مكانًا لزر الدعم */
    right: 20px;
    width: 320px;
    height: 400px;
    background: white;
    border: 3px solid #8e44ad;
    border-radius: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.chat-header {
    background: linear-gradient(135deg, #8e44ad, #6c5ce7);
    color: white;
    padding: 12px 15px;
    text-align: center;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 17px;
    border-top-right-radius: 17px;
}

.chat-header h4 {
    margin: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#close-chat {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 20px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#close-chat:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.chat-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    margin: 0;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 80%;
    line-height: 1.4;
    font-size: 14px;
    position: relative;
    animation: fadeIn 0.3s ease-in-out;
}

.msg.user {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 5px rgba(52, 152, 219, 0.3);
}

.msg.ai {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 5px rgba(46, 204, 113, 0.3);
}

.msg::before {
    content: '';
    position: absolute;
    bottom: -5px;
    width: 10px;
    height: 10px;
    background: inherit;
    clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.msg.user::before {
    right: 0;
    transform: rotate(-5deg);
}

.msg.ai::before {
    left: 0;
    transform: rotate(95deg);
}

.chat-footer {
    display: flex;
    padding: 12px;
    border-top: 2px solid #eee;
    background: white;
    gap: 8px;
}

#chat-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

#chat-input:focus {
    border-color: #8e44ad;
}

#send-chat {
    background: linear-gradient(135deg, #8e44ad, #6c5ce7);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    box-shadow: 0 3px 8px rgba(142, 68, 173, 0.3);
}

#send-chat:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 12px rgba(142, 68, 173, 0.4);
}

/* زر فتح الشات - [تم التعديل] */
#open-chat-btn {
    /* تم إخفاء الزر بشكل دائم لأنه لم يعد ضروريًا */
    display: none !important; 
}

#open-chat-btn.hidden {
    display: none !important;
}

/* تأثيرات للرسائل */
@keyframes messagePop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.msg {
    animation: messagePop 0.2s ease-out;
}

/* شريط التمرير المخصص */
.chat-body::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb {
    background: #8e44ad;
    border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: #6c5ce7;
}

/* --- أزرار الفئات التفاعلية (تمت إضافتها دون حذف أي شيء) --- */

.category-btn, .subcategory-btn {
    display: block;
    background: #8e44ad;
    color: white;
    margin: 8px 0;
    padding: 10px 15px;
    border-radius: 12px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.category-btn:hover, .subcategory-btn:hover {
    background: #6c5ce7;
    transform: translateY(-2px);
}

.category-btn {
    font-weight: bold;
    font-size: 15px;
}

/* تأثير نقاط الكتابة (مُحسّن) */
.typing-dots {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #8e44ad;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* تأثيرات للهواتف */
@media (max-width: 768px) {
    #chat-container {
        width: 85%;
        height: 50%;
        right: 50%;
        transform: translateX(50%);
        bottom: 70px;
    }
    
    #open-chat-btn {
        /* القاعدة الأصلية لم تعد ضرورية ولكن إبقاؤها لا يضر */
        right: 50%;
        transform: translateX(50%);
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .msg {
        max-width: 85%;
    }
    
    /* تحسين زر الفئات على الجوال */
    .category-btn, .subcategory-btn {
        font-size: 13px;
        padding: 10px;
    }
}

/* ======================================================= */
/* ✅✅✅ إضافات جديدة لتفعيل سحب نافذة الشات ✅✅✅ */
/* ======================================================= */

.chat-header {
    /* تغيير شكل المؤشر للإشارة لإمكانية السحب */
    cursor: grab; 
    /* منع تحديد النص في الهيدر أثناء السحب */
    user-select: none; 
}

/* كلاس جديد يطبق أثناء السحب الفعلي */
.chat-header.dragging {
    cursor: grabbing;
}