* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: #f5f7fa;
    color: #222;
}

/* زر فتح الشات */
.chat-open-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 10000;
    width: 65px;
    height: 65px;
    font-size: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #ff5500, #ff5500);
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 24px rgb(255, 255, 255);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.3s ease, transform 0.2s ease;
}

.chat-open-btn:hover,
.chat-open-btn:focus {
    background: linear-gradient(135deg, #ffd700, #ffd700);
    outline: none;
    transform: scale(1.1);
}

/* نافذة الشات */
.chat-popup {
    position: fixed;
    bottom: 100px;
    right: 25px;
    width: 400px;
    max-height: 600px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: 15px;
    z-index: 10000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    direction: rtl;
}

/* إخفاء النافذة */
.chat-popup[hidden] {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* رأس الشات */
.chat-header {
    background: linear-gradient(90deg, #00cc66, #cc0007);
    padding: 16px 24px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.chat-title {
    margin: 0;
    font-size: 1.25rem;
    user-select: none;
}

/* زر إغلاق الشات */
.chat-close-btn {
    font-size: 28px;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    transition: color 0.25s ease;
}

.chat-close-btn:hover,
.chat-close-btn:focus {
    color: #00cc66;
    outline: none;
}

/* صندوق الرسائل */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f0f5ff;
    scroll-behavior: smooth;
    outline: none;
}

/* رسالة واحدة */
.message {
    display: flex;
    gap: 14px;
    margin-bottom: 18px;
    align-items: flex-start;
}

/* صورة المستخدم */
.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #ccc;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

/* محتوى الرسالة */
.content {
    background: #d6e3ff;
    padding: 12px 18px;
    border-radius: 18px;
    max-width: 75%;
    box-shadow: 0 1px 6px rgba(0,0,0,0.12);
    word-wrap: break-word;
    position: relative;
    direction: rtl;
}

/* اسم المستخدم */
.username {
    font-weight: 800;
    color: #ff5500;
    margin-bottom: 6px;
    user-select: none;
    font-size: 14px;
}

/* نص الرسالة */
.content > div:last-child {
    color: #222;
    white-space: pre-wrap;
    font-size: 15px;
    line-height: 1.4;
}

/* نموذج إرسال الرسالة */
.chat-form {
    display: flex;
    padding: 18px 24px;
    border-top: 1px solid #d8e1ff;
    background: white;
    align-items: center;
    gap: 12px;
}

/* حقل الإدخال */
#message-input {
    flex: 1;
    padding: 12px 18px;
    font-size: 15px;
    border-radius: 30px;
    border: 2px solid #c5d0ff;
    outline: none;
    transition: border-color 0.3s ease;
    direction: rtl;
}

#message-input:focus {
    border-color: #ff5500;
}

/* زر الإرسال */
#send-btn {
    background: #ff5500;
    border: none;
    color: white;
    font-weight: 700;
    font-size: 15px;
    padding: 12px 26px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 15px rgb(255, 85, 0);
    transition: background 0.3s ease, transform 0.15s ease;
}

#send-btn:hover,
#send-btn:focus {
    background: #ff5500;
    outline: none;
    transform: scale(1.05);
}

/* استجابة الهواتف */
@media (max-width: 600px) {
    .chat-popup {
        width: 95vw;
        height: 70vh;
        bottom: 80px;
        right: 2.5vw;
        border-radius: 15px;
    }

    #message-input {
        font-size: 14px;
        padding: 10px 15px;
    }

    #send-btn {
        font-size: 14px;
        padding: 10px 18px;
    }

    .chat-open-btn {
        width: 55px;
        height: 55px;
        font-size: 28px;
        bottom: 20px;
        right: 20px;
    }
}

/* دعم اللغة الإنجليزية (ltr) */
[dir="ltr"] .chat-popup,
[dir="ltr"] .chat-messages,
[dir="ltr"] .content {
    direction: ltr;
}

[dir="ltr"] #message-input {
    direction: ltr;
}

[dir="ltr"] .username {
    color: #ffd700;
}