/* أنماط أساسية وإعادة ضبط */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Cairo', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* حاوية الصفحة الرئيسية */
.main-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    margin: 20px;
    padding: 20px;
    box-shadow: 0 12px 24px rgba(31, 38, 135, 0.2);
    width: 100%;
    max-width: 1200px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* الشريط الجانبي للعملاء */
.sidebar {
    background: linear-gradient(145deg, #00297f, #00205f);
    color: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    flex-shrink: 0;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar h4 {
    color: #ecf0f1;
    font-weight: 600;
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.client-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.client-list-item {
    cursor: pointer;
    padding: 15px 20px;
    margin-bottom: 10px;
    border-radius: 10px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* للغة العربية */
    gap: 5px;
}

.client-list-item::before {
    content: '';
    position: absolute;
    top: 0;
    right: -100%; /* للغة العربية */
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: right 0.5s;
}

.client-list-item:hover::before {
    right: 100%; /* للغة العربية */
}

.client-list-item:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(-5px); /* للغة العربية */
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.client-list-item.active {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    transform: translateX(-10px); /* للغة العربية، تمييز أكثر للعنصر النشط */
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.4);
    border-right: 4px solid #ecf0f1; /* للغة العربية */
}

.unread-messages-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: #dc3545;
    border-radius: 50%;
    margin-left: 5px; /* للغة العربية */
    margin-right: 0;
}


/* 💥💥 ابدأ الاستبدال من هنا 💥💥 */

/* أنماط التبويبات الرئيسية */
.main-tabs {
    position: sticky;
    top: 0;
    z-index: 1020;
    background-color: #f8f9fa;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* منع التصغير */
}

/* حاوية محتوى التبويبات */
.tab-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Keep this */
    min-height: 0; /* Keep this */
}

/* لوحة التبويب الفردية */
.tab-pane {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Keep this */
    min-height: 0; /* 💥 إضافة (احترازي) */
}

/* حاوية الدردشة */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* Keep this */
    min-height: 0; /* 💥 إضافة: مساعدة حساب flex */
}

/* منطقة عرض الرسائل (الأهم) */
.chat-area {
    flex-grow: 1;
    overflow-y: auto; /* Keep this */
    padding: 20px;
    background-color: #dfcbb2;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 100px; /* Keep this */
    flex-basis: 0; /* 💥 إضافة: تحديد أساس النمو */
}

/* مؤشر التحميل */
.chat-loader {
    text-align: center;
    padding: 10px;
    color: #0d6efd;
}

/* 💥💥 نهاية الجزء الذي سيتم استبداله 💥💥 */


.chat-header {
    background: linear-gradient(135deg, #00297f, #0058ab); /* Navy Blue to Blue */
    color: white;
    padding: 20px 25px;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0; /* Keep this - important */
    /* 💥 إضافة (احترازي): ضمان عدم أخذ مساحة مرنة */
    flex-grow: 0;
    flex-basis: auto;
}

.chat-header h5 {
    margin: 0;
    font-weight: 600;
}

.chat-header small {
    opacity: 0.9;
    font-size: 0.85em;
}

/* فقاعات الرسائل */
.message-bubble {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* ظل أوضح قليلاً */
}

.message-in {
    align-self: flex-start;
    background: #ffffff; /* أبيض نقي للوضوح */
    color: #693e2d; /* Carafe (بني داكن) للنص */
    border-bottom-left-radius: 4px;
}

.message-in::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px; /* للغة العربية */
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-left-color: #e0e4eb; /* ذيل الفقاعة لليسار للغة العربية */
    border-bottom: 0;
}

.message-out {
    align-self: flex-end;
    background: #0058ab; /* Blue */
    color: #ffffff; /* أبيض للنص */
    border-bottom-right-radius: 4px;
}

.message-out::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px; /* للغة العربية */
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #2980b9; /* ذيل الفقاعة لليمين للغة العربية */
    border-bottom: 0;
}

.message-time {
    font-size: 0.75em;
    color: #693e2d; /* Carafe (بني داكن) */
    opacity: 0.8; /* لجعله أقل بروزًا من النص الرئيسي */
    margin-top: 5px;
    margin-right: 5px;
    text-align: left;
    float: left;
}

.message-out .message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* وسائط الرسائل */
.media-content img,
.media-content video,
.media-content audio {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
}

.document-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
}
.document-link i {
    color: #007bff;
    margin-left: 0;
    margin-right: 0;
}
.document-link:hover {
    text-decoration: underline;
}

/* منطقة إدخال الدردشة */
.chat-input-area {
    padding: 20px 25px;
    background: white;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0; /* Keep this - important */
    /* 💥 إضافة (احترازي): ضمان عدم أخذ مساحة مرنة */
    flex-grow: 0;
    flex-basis: auto;
}

.file-input-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    direction: rtl; /* للغة العربية */
}
.attach-button {
    border-radius: 25px;
    padding: 10px 15px;
    background: linear-gradient(45deg, #1abc9c, #16a085);
    border: none;
    color: white;
    font-weight: 600;
    transition: all 0.3s ease;
    flex-shrink: 0;
    cursor: pointer;
}
.attach-button:hover:not(:disabled) {
    background: linear-gradient(45deg, #16a085, #138d75);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(26, 188, 156, 0.3);
}
.attached-file-info {
    display: flex;
    align-items: center;
    gap: 5px;
    background: #e9ecef;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    color: #495057;
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    justify-content: flex-end; /* للغة العربية */
    direction: rtl;
}
.attached-file-info .remove-file {
    cursor: pointer;
    color: #dc3545;
    font-weight: bold;
    margin-right: 5px; /* للغة العربية */
    margin-left: 0;
}

.message-input {
    border-radius: 25px;
    padding: 12px 20px;
    transition: all 0.3s ease;
    resize: none;
    flex: 1;
    border: 2px solid #e9ecef;
}

.message-input:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 0.25rem rgba(52, 152, 219, 0.25);
}

.btn-send {
    border-radius: 25px;
    padding: 12px 25px;
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    border: none;
    color: white;
    font-weight: 600;
    transition: all 0.3s ease;
    flex-shrink: 0;
    cursor: pointer;
}

.btn-send:hover:not(:disabled) {
    background: linear-gradient(45deg, #229954, #27ae60);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}

/* الأزرار العامة */
.action-buttons,
.form-button-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
    justify-content: flex-start; /* للغة العربية */
    align-items: center;
    direction: rtl; /* للغة العربية */
}

.btn-common {
    border-radius: 20px;
    padding: 10px 20px;
    font-weight: 500;
    transition: all 0.3s ease;
    flex-grow: 1;
    min-width: 160px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    color: white;
    cursor: pointer;
}
.btn-common i {
    margin-left: 8px; /* للغة العربية */
    margin-right: 0;
}
.btn-common:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* الأزرار المخصصة */
.btn-cv {
    background: linear-gradient(45deg, #9b59b6, #8e44ad);
}
.btn-cv:hover:not(:disabled) {
    background: linear-gradient(45deg, #8e44ad, #7d3c98);
    box-shadow: 0 4px 12px rgba(155, 89, 182, 0.3);
}

.btn-download {
    background: linear-gradient(45deg, #f39c12, #e67e22);
}
.btn-download:hover:not(:disabled) {
    background: linear-gradient(45deg, #e67e22, #d35400);
    box-shadow: 0 4px 12px rgba(243, 156, 18, 0.3);
}

.btn-send-cv {
    background: linear-gradient(45deg, #007bff, #0056b3);
}
.btn-send-cv:hover:not(:disabled) {
    background: linear-gradient(45deg, #0056b3, #004085);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-review-optimize {
    background: linear-gradient(45deg, #17a2b8, #138496);
}
.btn-review-optimize:hover:not(:disabled) {
    background: linear-gradient(45deg, #138496, #0e6c7b);
    box-shadow: 0 4px 12px rgba(32, 201, 151, 0.3);
}

.btn-confirm-data {
    background: linear-gradient(45deg, #0d6efd, #0b5ed7); /* Primary blue */
}
.btn-confirm-data:hover:not(:disabled) {
    background: linear-gradient(45deg, #0b5ed7, #0a58ca);
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
}

.btn-confirm-payment {
    background: linear-gradient(45deg, #198754, #157347); /* Success green */
}
.btn-confirm-payment:hover:not(:disabled) {
    background: linear-gradient(45deg, #157347, #136b43);
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.3);
}

.btn-manual-ai-input {
    background: linear-gradient(45deg, #0dcaf0, #0aa3c3); /* Info cyan */
}
.btn-manual-ai-input:hover:not(:disabled) {
    background: linear-gradient(45deg, #0aa3c3, #0987a0);
    box-shadow: 0 4px 12px rgba(13, 202, 240, 0.3);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* تحميل / مؤشرات حالة */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.typing-indicator {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    align-self: flex-start;
    margin-bottom: 10px;
    direction: rtl; /* للغة العربية */
}

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

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3498db;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* المودال للصور */
.image-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
}

.image-modal-content {
    max-width: 90%;
    max-height: 90%;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-modal img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
}

.close-modal {
    position: absolute;
    top: 20px;
    left: 35px; /* للغة العربية */
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close-modal:hover {
    color: #3498db;
}

/* أنماط نموذج بيانات العميل */
.client-data-form-area {
    background: #ffffff;
    border-radius: 15px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    flex-shrink: 0;
}
.form-section-header {
    background: linear-gradient(45deg, #e0e4eb, #f0f2f5);
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: bold;
    color: #2c3e50;
    border-bottom: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    text-align: right; /* للغة العربية */
    font-size: 1.1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.form-group label {
    text-align: right; /* للغة العربية */
    width: 100%;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}
.form-control {
    direction: rtl; /* افتراضي للغة العربية */
    text-align: right; /* افتراضي للغة العربية */
    border-radius: 8px;
    border: 1px solid #ced4da;
    padding: 10px 15px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}
/* تجاوزات محددة للمدخلات التي تتطلب اتجاه LTR */
.form-control.ltr-input {
    direction: ltr;
    text-align: left;
}
.form-group-item {
    border: 1px solid #e9ecef;
    padding: 18px;
    padding-left: 50px;
    border-radius: 10px;
    margin-bottom: 15px;
    background: #fdfdfd;
    position: relative;
    direction: rtl; /* للغة العربية */
}
.remove-item-btn {
    position: absolute;
    top: 10px;
    left: 10px; /* للغة العربية */
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    z-index: 1;
}
.remove-item-btn:hover {
    background: #c82333;
    transform: scale(1.1);
}
.add-item-btn {
    background: linear-gradient(45deg, #007bff, #0056b3);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    margin-top: 15px; /* <-- تم التصحيح هنا */
    transition: all 0.2s ease;
}
.add-item-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.form-button-group .btn-success {
    margin-inline-end: auto; /* للغة العربية: يدفع زر الحفظ لليسار */
}
/* ضبط عنصر التحديد (select) للغة العربية */
.action-buttons .form-select {
    flex-grow: 1;
    min-width: 160px;
    text-align: right; /* للغة العربية */
    direction: rtl; /* للغة العربية */
}

/* تحسينات الاستجابة */
@media (max-width: 768px) {
    .main-container {
        margin: 10px;
        padding: 10px;
    }
    .message-bubble {
        max-width: 85%;
    }
    .action-buttons,
    .form-button-group {
        flex-direction: column;
        align-items: stretch;
    }
    .btn-common,
    .btn-action {
        width: 100%;
    }
    .sidebar {
        position: static;
        max-height: none;
    }
}

/* تحسينات أشرطة التمرير */
.chat-area::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 6px;
}
.chat-area::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}
.chat-area::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #3498db, #2980b9);
    border-radius: 10px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

/* SortableJS ghost class */
.sortable-ghost {
    opacity: 0.4;
    background-color: #c9e2f1 !important; /* A light blue */
    border: 1px dashed #3498db;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.4);
    transform: scale(1.02);
}

/* 💥💥 أنماط جديدة لتنظيم المحتوى داخل التبويبات 💥💥 */
/* بطاقة الإجراءات الجانبية */
.action-card {
    border: 1px solid #e9ecef;
    border-radius: 12px;
    background-color: #f8f9fa;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    height: fit-content;
}

.action-card .card-header {
    font-weight: 600;
    background-color: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.action-card .card-body {
    padding: 1rem;
}

/* تنسيق مجموعة الأزرار داخل البطاقة */
.action-card .action-buttons {
    display: flex;
    flex-direction: column; /* يجعل الأزرار مكدسة فوق بعضها */
    align-items: stretch; /* يجعل الأزرار تملأ عرض البطاقة */
    gap: 0.75rem; /* مسافة بين الأزرار */
    margin-top: 0; /* إزالة الهامش العلوي */
}

/* تنسيق الأزرار المشتركة داخل البطاقة */
.action-card .btn-common {
    width: 100%; /* تأكيد أن الزر يملأ العرض */
    margin: 0;
    flex-grow: 0; /* منع النمو غير المرغوب فيه */
}

/* تنسيق حاوية ترتيب الأقسام كبطاقة */
#section-ordering-container.card {
    border: 1px solid #e9ecef;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

#section-ordering-container.card .card-header {
    font-weight: 600;
    background-color: #e9ecef;
    border-bottom: 1px solid #dee2e6;
}

/* تنسيق أزرار إضافة العناصر */
.form-button-group {
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
    flex-wrap: wrap-reverse; /* لجعل الأزرار الرئيسية تظهر أولاً */
    justify-content: flex-end;
    gap: 0.5rem;
}
.form-button-group hr {
    width: 100%;
    border-color: #dee2e6;
}

/* 💥💥 تحسينات لقائمة ترتيب الأقسام 💥💥 */

#section-ordering-container .list-group-item {
    font-size: 1.1rem; /* زيادة حجم الخط */
    padding: 1rem 1.25rem; /* زيادة المساحة الداخلية */
    display: flex; /* استخدام Flexbox للمحاذاة */
    align-items: center; /* محاذاة رأسية لعلامة السحب والنص */
    cursor: grab; /* تغيير شكل المؤشر للإشارة إلى إمكانية السحب */
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    margin-bottom: 8px !important; /* إضافة مسافة بين العناصر */
    border-radius: 8px !important;
}

#section-ordering-container .list-group-item:active {
    cursor: grabbing; /* تغيير شكل المؤشر أثناء السحب الفعلي */
}

#section-ordering-container .list-group-item .fa-grip-vertical {
    margin-left: 15px; /* مسافة بين علامة السحب والنص */
    color: #6c757d; /* لون أغمق لعلامة السحب */
    font-size: 1.3rem; /* تكبير أيقونة السحب */
}

/* تعديل على حاوية البيانات لجعلها تتناسب مع التصميم الجديد */
#cv-data-pane .client-data-form-area {
    border: 1px solid #dee2e6;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* 💥💥 أنماط جديدة لدعم الحقول الإنجليزية (LTR) 💥💥 */
input[dir="ltr"],
textarea[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

/* 💥💥 START: تمت إضافة هذه الأنماط الجديدة 💥💥 */

/* فاصل التاريخ والوقت */
.date-separator {
    align-self: center;
    background-color: #e9ecef;
    color: #6c757d;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    margin: 10px 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* تعديلات على الرسائل المجمعة */
.message-bubble.grouped {
    margin-top: -10px; /* تقليل المسافة العلوية لتقريبها من الرسالة السابقة */
    border-radius: 18px; /* جعل كل الزوايا دائرية */
}

/* إخفاء "ذيل" الفقاعة للرسائل المجمعة */
.message-bubble.grouped::before {
    content: none;
}

/* تعديل نصف القطر للرسائل الأولى في المجموعة لتبدو متصلة (متوافق مع RTL) */
.message-in + .message-in.grouped {
    /* message-in هي (align-self: flex-start) وهي على اليمين في RTL */
    border-top-right-radius: 4px;
}

.message-out + .message-out.grouped {
    /* message-out هي (align-self: flex-end) وهي على اليسار في RTL */
    border-top-left-radius: 4px;
}

/* 💥💥 END: نهاية الأنماط المضافة 💥💥 */

/* Fix for Toastify z-index issue */
.toastify {
    z-index: 99999 !important;
}

/* Style for client list when loading data */
.client-list.is-loading {
    opacity: 0.6;
    pointer-events: none; /* This is the key part that disables clicks */
}