/* نظام الشات - ملف CSS منفصل */

/* الحاوي الرئيسي للشات */
#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 600px;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    direction: rtl;
}

#chat-container.chat-open {
    transform: translateY(0);
}

#chat-container:not(.chat-open) {
    transform: translateY(500px);
}

/* رأس الشات */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-controls {
    display: flex;
    gap: 10px;
}

.chat-controls button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s ease;
}

.chat-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* حالة الاتصال */
#connection-status {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 500;
}

#connection-status.connected {
    background: #4CAF50;
    color: white;
}

#connection-status.disconnected {
    background: #f44336;
    color: white;
}

/* محتوى الشات */
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* تبويبات الشات */
.chat-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.chat-tab {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #6c757d;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.chat-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    background: white;
}

.chat-tab:hover {
    background: #e9ecef;
}

/* محتوى التبويبات */
.tab-content {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
}

/* قائمة الغرف */
#chat-rooms {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

.room-item:hover {
    background: #e9ecef;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.room-info h4 {
    margin: 0 0 5px 0;
    font-size: 16px;
    color: #333;
}

.room-description {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #666;
}

.room-meta {
    display: flex;
    gap: 15px;
    font-size: 12px;
    color: #888;
}

/* منطقة الرسائل */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
}

.message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 15px;
    max-width: 80%;
    word-wrap: break-word;
}

.message.own-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 5px;
}

.message.other-message {
    background: white;
    color: #333;
    margin-right: auto;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 5px;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 12px;
    opacity: 0.8;
}

.user-name {
    font-weight: 600;
}

.message-time {
    font-size: 11px;
}

.message-content {
    line-height: 1.4;
    font-size: 14px;
}

/* مؤشر الكتابة */
#typing-indicators {
    padding: 0 15px 10px;
    background: #f8f9fa;
}

.typing-indicator {
    font-size: 12px;
    color: #666;
    font-style: italic;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* منطقة إدخال الرسالة */
.chat-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid #e9ecef;
    border-radius: 0 0 15px 15px;
}

.chat-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

#chat-message-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    direction: rtl;
    text-align: right;
    cursor: text !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    background: white !important;
    color: #333 !important;
}

#chat-message-input:focus {
    border-color: #667eea;
}

/* ضمان تفعيل حقل الكتابة بقوة */
#chat-message-input,
#chat-message-input:not([disabled]),
#chat-message-input:not([readonly]),
input[id="chat-message-input"],
textarea[id="chat-message-input"] {
    cursor: text !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    background: white !important;
    color: #333 !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    outline: none !important;
    border: 2px solid #e9ecef !important;
    font-size: 14px !important;
    padding: 12px 16px !important;
    border-radius: 25px !important;
    direction: rtl !important;
    text-align: right !important;
}

#chat-message-input:hover {
    cursor: text !important;
    border-color: #667eea !important;
}

#chat-message-input:focus {
    cursor: text !important;
    border-color: #667eea !important;
    outline: none !important;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2) !important;
}

/* إزالة أي تعطيل */
#chat-message-input[disabled] {
    pointer-events: auto !important;
    cursor: text !important;
    opacity: 1 !important;
    background: white !important;
    color: #333 !important;
}

#chat-message-input[readonly] {
    pointer-events: auto !important;
    cursor: text !important;
    opacity: 1 !important;
    background: white !important;
    color: #333 !important;
}

/* تأكيد إضافي */
.chat-input input,
.chat-input textarea,
.chat-input #chat-message-input {
    cursor: text !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    background: white !important;
    color: #333 !important;
}

#chat-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* أعضاء الغرفة */
#chat-members {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.member {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.member:hover {
    background: #e9ecef;
}

.member-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.member-name {
    font-weight: 600;
    color: #333;
}

.member-status {
    font-size: 12px;
    color: #666;
    margin-right: auto;
}

.member.online .member-status {
    color: #4CAF50;
}

.member.offline .member-status {
    color: #999;
}

/* المستخدمين المتصلين */
#online-users {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.online-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.online-user:hover {
    background: #e9ecef;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-weight: 600;
    color: #333;
}

.user-type {
    font-size: 12px;
    color: #666;
    margin-right: auto;
    background: #e9ecef;
    padding: 2px 8px;
    border-radius: 12px;
}

/* البحث */
.chat-search {
    padding: 15px;
    background: white;
    border-bottom: 1px solid #e9ecef;
}

#chat-search-input {
    width: 100%;
    padding: 10px 16px;
    border: 2px solid #e9ecef;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    direction: rtl;
    text-align: right;
}

#chat-search-input:focus {
    border-color: #667eea;
}

/* النوافذ المنبثقة */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* النماذج */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    direction: rtl;
    text-align: right;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: #667eea;
}

/* الأزرار */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 12px;
}

/* الإشعارات */
.chat-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 3000;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* معلومات الغرفة الحالية */
#current-room-info {
    padding: 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

#current-room-info h4 {
    margin: 0 0 8px 0;
    color: #333;
}

#current-room-info p {
    margin: 0;
    font-size: 14px;
    color: #666;
}

/* الاستجابة للشاشات الصغيرة */
@media (max-width: 768px) {
    #chat-container {
        width: 100%;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    
    .chat-header {
        border-radius: 0;
    }
    
    .chat-input-area {
        border-radius: 0;
    }
}

/* تحسينات إضافية */
.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* تأثيرات الحركة */
.message {
    animation: messageSlide 0.3s ease;
}

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

/* تحسينات الوصولية */
.chat-container:focus-within {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

button:focus,
input:focus,
textarea:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}
