/*
 * css/style.css
 *
 * هذا الملف يحتوي على الأنماط (CSS) المخصصة لتطبيق الدردشة.
 * يكمل أنماط Bootstrap ويوفر تخصيصات إضافية.
 */

/* ========================================= */
/* 1. الأساسيات والخطوط العامة           */
/* ========================================= */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* خط عام مقروء */
    background-color: #f0f2f5; /* لون خلفية فاتح للصفحات */
    color: #333;
    line-height: 1.6;
    direction: rtl; /* لتعيين الاتجاه الافتراضي من اليمين إلى اليسار */
    text-align: right; /* لمحاذاة النص الافتراضية لليمين */
}

/* إعادة تعيين بعض أنماط Bootstrap لضمان الاتجاه الصحيح */
.form-control, .btn, .input-group-text {
    direction: rtl;
    text-align: right;
}

/* ========================================= */
/* 2. شريط التنقل (Navbar)                   */
/* ========================================= */
.navbar {
    background-color: #007bff !important; /* لون أزرق أساسي لشريط التنقل */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar-brand {
    font-weight: bold;
    font-size: 1.5rem;
    color: #fff !important;
}

.navbar-nav .nav-link {
    color: #ffffffc0 !important;
    padding-right: 1rem; /* مسافة للروابط في الـ RTL */
    padding-left: unset;
}

.navbar-nav .nav-link:hover {
    color: #fff !important;
}

.navbar-toggler {
    border-color: rgba(255,255,255,.1);
}

/* ========================================= */
/* 3. الحاويات العامة والبطاقات (Cards)    */
/* ========================================= */
.container {
    max-width: 1200px;
}

.card {
    border-radius: 10px;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    border-radius: 10px 10px 0 0;
    padding: 1rem 1.25rem;
    font-weight: bold;
    font-size: 1.2rem;
    color: #343a40;
}

.card-body {
    padding: 1.5rem;
}

/* ========================================= */
/* 4. نماذج المصادقة (Login/Register Forms) */
/* ========================================= */
.auth-container {
    max-width: 450px;
    margin: 60px auto;
    padding: 30px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.auth-container h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #007bff;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

.form-control {
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 1rem;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 1.1rem;
    font-weight: 600;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

.text-center a {
    color: #007bff;
    text-decoration: none;
}

.text-center a:hover {
    text-decoration: underline;
}

/* ========================================= */
/* 5. لوحة التحكم (Dashboard Specific)      */
/* ========================================= */

/* الملف الشخصي */
.profile-card .profile-avatar {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border: 4px solid #007bff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.profile-card h4 {
    margin-top: 15px;
    font-weight: 600;
    color: #212529;
}

.status-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-left: 8px; /* مسافة عن النص في RTL */
    vertical-align: middle;
}

.status-indicator.online {
    background-color: #28a745; /* أخضر */
}

.status-indicator.offline {
    background-color: #6c757d; /* رمادي */
}

/* قوائم الأصدقاء/طلبات الصداقة/المستخدمين */
.list-group-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid #e0e0e0;
    transition: background-color 0.2s ease;
}

.list-group-item:hover {
    background-color: #f0f0f0;
}

.friend-item, .friend-request-item, .user-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s ease;
}

.friend-item:hover, .friend-request-item:hover, .user-item:hover {
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}

.friend-avatar, .request-avatar, .user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    margin-left: 15px; /* مسافة لليمين في RTL */
    border: 2px solid #ddd;
}

.friend-info, .request-info, .user-info {
    flex-grow: 1;
}

.friend-info h4, .request-info h4, .user-info h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.friend-info p, .user-info p {
    margin: 0;
    font-size: 0.9rem;
    color: #6c757d;
}

.request-date {
    font-size: 0.8em;
    color: #888;
}

.request-actions, .user-actions {
    display: flex;
    gap: 10px; /* مسافة بين الأزرار */
}

.btn-success {
    background-color: #28a745;
    border-color: #28a745;
}
.btn-success:hover {
    background-color: #218838;
    border-color: #1e7e34;
}

.btn-danger {
    background-color: #dc3545;
    border-color: #dc3545;
}
.btn-danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

.btn-info {
    background-color: #17a2b8;
    border-color: #17a2b8;
}
.btn-info:hover {
    background-color: #138496;
    border-color: #117a8b;
}

.status-badge {
    padding: .3em .6em;
    border-radius: .25rem;
    font-size: 0.85em;
    font-weight: 600;
}

.status-badge.friend {
    background-color: #28a745;
    color: #fff;
}
.status-badge.pending {
    background-color: #ffc107;
    color: #333;
}

/* رسائل لا توجد عناصر */
.no-items-message, .error-message {
    text-align: center;
    color: #6c757d;
    padding: 20px;
}

.error-message {
    color: #dc3545;
    font-weight: bold;
}

/* ========================================= */
/* 6. التنبيهات (Alerts) من main.js        */
/* ========================================= */
#alertContainer {
    padding: 15px;
    z-index: 1050; /* فوق معظم العناصر */
    display: flex;
    justify-content: center;
    width: 100%;
    left: 0;
    right: 0;
}

#alertContainer .alert {
    width: auto;
    max-width: 600px; /* لتحديد عرض معقول للتنبيهات */
    text-align: right;
    direction: rtl;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    opacity: 0; /* مخفي في البداية */
    transition: opacity 0.5s ease-in-out;
}

#alertContainer .alert.show {
    opacity: 1; /* يظهر */
}

#alertContainer .alert.fade-out {
    opacity: 0;
}

/* إغلاق زر التنبيه */
#alertContainer .alert .close {
    float: left; /* لجعله على اليسار في RTL */
    background-color: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: inherit;
    opacity: .5;
    transition: opacity .2s ease;
}
#alertContainer .alert .close:hover {
    opacity: .8;
}

/* ========================================= */
/* 7. الأنماط الخاصة بصفحة الدردشة (Chat Page) */
/* (هذه الأنماط قد تتكرر جزئياً من chat.php <style> */
/* ولكن يفضل أن تكون هنا في ملف CSS خارجي) */
/* ========================================= */
/* إذا كنت قد وضعت هذه الأنماط بالفعل في <style> بـ chat.php،
   يمكنك إزالتها من هناك ووضعها هنا للحفاظ على تنظيم الكود. */

.sidebar {
    width: 300px;
    background-color: #343a40;
    color: white;
    padding: 20px;
    height: 100vh;
    overflow-y: auto;
    position: fixed;
    right: 0; /* لجعله في اليمين (RTL) */
    top: 0;
    bottom: 0;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    z-index: 1000; /* لضمان ظهوره فوق المحتوى */
}

.chat-container {
    margin-right: 300px; /* لترك مسافة للشريط الجانبي في اليمين */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 20px;
    overflow-y: hidden; /* لمنع شريط التمرير على الحاوية نفسها */
}

.chat-header {
    background-color: #007bff;
    color: white;
    padding: 15px;
    border-radius: 8px; /* لا يوجد حواف سفلية مستديرة */
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.chat-header h3 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
}
.chat-header .friend-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 8px; /* مسافة عن النص في RTL */
    vertical-align: middle;
}
.chat-header .friend-status-dot.online { background-color: #28a745; }
.chat-header .friend-status-dot.offline { background-color: #dc3545; }

.messages-box {
    flex-grow: 1;
    background-color: #e9ecef;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto; /* لجعل صندوق الرسائل قابلًا للتمرير */
    display: flex;
    flex-direction: column-reverse; /* لعرض أحدث الرسائل في الأسفل */
    gap: 10px; /* مسافة بين الرسائل */
    margin-bottom: 10px; /* مسافة من حقل الإدخال */
}
.no-messages-yet {
    margin-top: auto; /* ليدفع الرسالة إلى الأسفل */
}

.message {
    margin-bottom: 0; /* تم التعامل مع الفجوة بواسطة gap */
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 75%; /* زيادة قليلاً */
    word-wrap: break-word;
    font-size: 0.95rem;
    position: relative; /* لتحديد موضع الطابع الزمني */
}
.message.sent {
    background-color: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-left-radius: 5px; /* حافة مستقيمة من الأسفل اليسار */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.message.received {
    background-color: #ffffff;
    color: #333;
    align-self: flex-start;
    border: 1px solid #dee2e6;
    border-bottom-right-radius: 5px; /* حافة مستقيمة من الأسفل اليمين */
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.message-content {
    margin-bottom: 2px;
}
.message-timestamp {
    font-size: 0.7em;
    color: rgba(255,255,255,0.7);
    text-align: left; /* ليكون في الزاوية اليسرى للرسائل المرسلة */
    display: block;
    margin-top: 5px; /* مسافة من المحتوى */
}
.message.received .message-timestamp {
    color: #6c757d;
    text-align: right; /* ليكون في الزاوية اليمنى للرسائل المستلمة */
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 10px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
}
.chat-input-area #messageInput {
    flex-grow: 1;
    border-radius: 20px;
    padding-left: 20px;
    padding-right: 20px;
}
.chat-input-area button {
    border-radius: 50px; /* لجعل الأزرار دائرية */
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    flex-shrink: 0; /* لمنع الأزرار من الانكماش */
}

.message-media img, .message-media video, .message-media audio {
    max-width: 100%;
    height: auto;
    display: block;
    margin-top: 8px; /* مسافة من النص أو الرسالة نفسها */
    border-radius: 8px;
}
.message-media audio {
    width: 100%;
}

/* أنماط قائمة الأصدقاء في الشريط الجانبي للدردشة */
.sidebar #friendsListSidebar .friend-list-item {
    display: flex;
    align-items: center;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    background-color: #495057; /* لون مختلف عن الخلفية */
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.sidebar #friendsListSidebar .friend-list-item:hover,
.sidebar #friendsListSidebar .friend-list-item.active {
    background-color: #007bff; /* لون مميز للصديق النشط */
}
.sidebar #friendsListSidebar .friend-list-item img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    margin-left: 15px; /* للغة العربية */
    border: 2px solid #6c757d;
    object-fit: cover;
}
.sidebar #friendsListSidebar .friend-list-item .friend-name {
    flex-grow: 1;
    color: white;
    font-weight: 500;
    font-size: 1.1rem;
}
.sidebar #friendsListSidebar .friend-list-item .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px; /* مسافة في RTL */
    flex-shrink: 0;
}
.sidebar #friendsListSidebar .friend-list-item .status-dot.online { background-color: #28a745; }
.sidebar #friendsListSidebar .friend-list-item .status-dot.offline { background-color: #dc3545; }

/* مودال مكتبة الصوتيات */
#audioLibraryModal .modal-content {
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
#audioLibraryModal .modal-header {
    border-bottom: 1px solid #eee;
    background-color: #007bff;
    color: white;
    border-radius: 10px 10px 0 0;
}
#audioLibraryModal .modal-body {
    max-height: 400px;
    overflow-y: auto;
    padding: 15px;
}
#audioLibraryList .audio-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #eee;
    margin-bottom: 5px;
    border-radius: 5px;
    background-color: #fefefe;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
#audioLibraryList .audio-item:last-child {
    border-bottom: none;
}
#audioLibraryList .audio-item .audio-title {
    flex-grow: 1;
    font-weight: 500;
    margin-left: 10px; /* مسافة عن زر الإرسال */
}
#audioLibraryList .audio-item audio {
    width: calc(100% - 120px); /* مساحة للمشغل وزر الإرسال */
    flex-shrink: 1;
}
#audioLibraryList .audio-item button {
    flex-shrink: 0;
}
.upload-audio-section {
    padding: 15px;
    border-top: 1px solid #eee;
    background-color: #f8f9fa;
    border-radius: 0 0 10px 10px;
    text-align: center;
}
.upload-audio-section button {
    font-size: 1rem;
    padding: 8px 15px;
}


/* ========================================= */
/* 8. استجابة التصميم (Responsive Design)   */
/* ========================================= */
@media (max-width: 768px) {
    body {
        flex-direction: column; /* الشريط الجانبي فوق المحتوى */
    }

    .sidebar {
        position: relative; /* إزالة التثبيت */
        width: 100%;
        height: auto;
        padding: 15px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        z-index: 900; /* أقل من المودال */
    }

    .chat-container {
        margin-right: 0; /* إزالة الهامش */
        padding: 15px;
        height: calc(100vh - 120px); /* تقليل الارتفاع للسماح بالشريط الجانبي والأزرار السفلية */
    }

    .chat-header {
        font-size: 1.2rem;
        padding: 10px;
    }

    .messages-box {
        padding: 10px;
    }

    .message {
        max-width: 90%; /* السماح للرسائل بأخذ مساحة أكبر على الشاشات الصغيرة */
    }

    .chat-input-area {
        flex-wrap: wrap; /* تسمح للأزرار بالنزول لصف جديد */
        padding: 10px;
        justify-content: center;
    }

    .chat-input-area #messageInput {
        flex-basis: 100%; /* حقل الإدخال يأخذ عرضًا كاملاً */
        margin-bottom: 10px;
    }

    .chat-input-area button {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    /* أزرار تسجيل الدخول/التسجيل */
    .auth-container {
        margin: 30px auto;
        padding: 20px;
    }
}

@media (max-width: 576px) {
    .navbar-brand {
        font-size: 1.3rem;
    }

    .chat-container {
        padding: 10px;
    }

    .chat-input-area button {
        width: 38px;
        height: 38px;
        font-size: 0.9rem;
    }

    .profile-card .profile-avatar {
        width: 100px;
        height: 100px;
    }
}