/* ---------------------------------------------------- */
/* تنسيقات عامة - للحفاظ على تناسق الخطوط والاتجاه */
/* ---------------------------------------------------- */
body {
    font-family: 'Cairo', sans-serif; /* استخدام خط كايرو */
    direction: rtl; /* للغة العربية */
    text-align: right; /* محاذاة النص لليمين */
    background-color: #f8f9fa; /* لون خلفية فاتح جداً */
    color: #343a40; /* لون نص داكن قليلاً */
}

/* تنسيقات الرابط الرئيسي في الـ Navbar */
.navbar-brand img {
    max-height: 40px; /* ضمان حجم مناسب للشعار */
}

/* تنسيقات روابط التنقل في الـ Navbar */
.navbar-nav .nav-link {
    font-weight: 500;
    color: #495057;
    transition: color 0.3s ease;
}

    .navbar-nav .nav-link:hover {
        color: #007bff; /* لون أزرق عند التمرير */
    }

    .navbar-nav .nav-link.active {
        color: #007bff;
        font-weight: 700;
    }

/* تنسيق زر تسجيل الخروج ليكون مثل الروابط */
.logout-btn {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    color: #dc3545; /* لون أحمر */
    font-weight: 500;
    cursor: pointer;
    transition: color 0.3s ease;
}

    .logout-btn:hover {
        color: #b02a37;
    }

/* ---------------------------------------------------- */
/* التخطيط الرئيسي للصفحة (Sidebar + Main Content) */
/* ---------------------------------------------------- */
.page-content-wrapper {
    display: flex; /* تفعيل Flexbox */
    gap: 30px; /* مسافة بين الشريط الجانبي والمحتوى الرئيسي */
    padding-top: 20px; /* مسافة من أعلى الناف بار */
    padding-bottom: 20px; /* مسافة من أسفل قبل الفوتر */
    align-items: flex-start; /* لضمان بدء العناصر من الأعلى */
}

/* الشريط الجانبي للفلاتر */
.sidebar-filters {
    flex: 0 0 300px; /* عرض ثابت 300px، لا يتمدد ولا ينكمش */
    background-color: #ffffff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08); /* ظل خفيف */
    position: sticky; /* لجعل الفلتر يلتصق عند التمرير */
    top: 20px; /* مسافة من أعلى النافذة عند الالتصاق */
    max-height: calc(100vh - 40px); /* يمنع الشريط من تجاوز ارتفاع الشاشة بالكامل */
    overflow-y: auto; /* يسمح بالتمرير إذا كان المحتوى أطول من الشاشة */
}

    .sidebar-filters h2 {
        font-size: 1.5rem;
        color: #343a40;
        margin-bottom: 25px;
        padding-bottom: 15px;
        border-bottom: 1px solid #e9ecef;
        display: flex;
        align-items: center;
        gap: 10px; /* مسافة بين الأيقونة والنص */
    }

    .sidebar-filters .form-label {
        font-weight: 600;
        margin-bottom: 8px;
        color: #495057;
    }

    .sidebar-filters .form-select,
    .sidebar-filters .form-control {
        padding: 0.6rem;
        background-color: #f8f9fa;
        border: 1px solid #ddd;
        border-radius: 10px;
        font-size: 0.95rem;
        width: 100%;
    }

    .sidebar-filters .btn-primary {
        background-color: #007bff;
        border-color: #007bff;
        font-weight: 600;
    }

        .sidebar-filters .btn-primary:hover {
            background-color: #0056b3;
            border-color: #0056b3;
        }

    .sidebar-filters .btn-outline-secondary {
        color: #6c757d;
        border-color: #6c757d;
        font-weight: 600;
    }

        .sidebar-filters .btn-outline-secondary:hover {
            background-color: #6c757d;
            color: #fff;
        }

    .sidebar-filters .btn-outline-danger {
        color: #dc3545;
        border-color: #dc3545;
        font-weight: 600;
    }

        .sidebar-filters .btn-outline-danger:hover {
            background-color: #dc3545;
            color: #fff;
        }

    .sidebar-filters .btn-success {
        background-color: #28a745;
        border-color: #28a745;
        font-weight: 600;
    }

        .sidebar-filters .btn-success:hover {
            background-color: #218838;
            border-color: #1e7e34;
        }

/* المحتوى الرئيسي للإعلانات */
.main-content {
    flex: 1; /* يستهلك كل المساحة المتبقية */
    min-width: 0; /* مهم لـ flexbox لمنع العناصر الداخلية من تجاوز الحدود */
}

/* ---------------------------------------------------- */
/* تنسيقات كروت الإعلانات (List Item) والأنماط الرئيسية */
/* ---------------------------------------------------- */

/* الحاوية الرئيسية للقوائم - تضبط كـ Grid افتراضيًا لـ Grid View */
.listings-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* لـ Grid View */
    gap: 20px;
    margin-bottom: 20px;
}

/* عندما تكون الحاوية في وضع القائمة */
.listings-list-view {
    display: flex; /* نجعلها flex container */
    flex-direction: column; /* العناصر تتكدس عموديًا */
    gap: 15px; /* مسافة بين عناصر القائمة */
}

/* رابط الكارد لضمان أنه كتلة قابلة للنقر */
.list-item-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

/* التنسيقات العامة لكارت الإعلان */
.list-item {
    background-color: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    padding: 15px;
    transition: all 0.3s ease-in-out;
    display: flex; /* لكل كارد نفسه */
    width: 100%; /* يأخذ عرض الحاوية */
}

.list-item-link:hover .list-item {
    transform: translateY(-4px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}

/* الصورة في الكارد - التنسيقات الافتراضية (لـ Grid View) */
.item-image-wrapper {
    width: 100%; /* الصورة تأخذ عرض الكارد بالكامل */
    height: 180px; /* ارتفاع ثابت للصور في الشبكة */
    overflow: hidden;
    border-radius: 8px;
    background-color: #f1f1f1;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.item-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

/* المحتوى النصي داخل الكارد - التنسيقات الافتراضية (لـ Grid View) */
.item-content-wrapper {
    display: flex;
    flex-direction: column; /* المحتوى يتكدس عموديًا في الشبكة */
    justify-content: space-between;
    width: 100%;
    align-items: flex-start;
    flex-grow: 1;
}

.item-main-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    width: 100%;
}

.item-stats-price {
    text-align: right;
    flex-shrink: 0;
    width: 100%;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* لكي يظهر المحتوى بشكل صحيح عندما لا تكون هناك صورة */
.list-item:not(:has(.item-image-wrapper)) .item-content-wrapper {
    width: 100%;
}

/* ***************************************************** */
/* ********** تنسيقات خاصة بـ List View *************** */
/* ***************************************************** */

.listings-list-view .list-item {
    flex-direction: row; /* الصورة والمحتوى في صف واحد */
    align-items: center; /* محاذاة رأسية */
    gap: 15px; /* المسافة بين الصورة والمحتوى */
    padding: 10px; /* تقليل padding قليلاً ليتناسق */
    min-height: 120px; /* ارتفاع أدنى للكارد لضمان التناسق */
}

.listings-list-view .item-image-wrapper {
    width: 100px; /* عرض أصغر للصورة في وضع القائمة */
    min-width: 100px; /* منع الانكماش */
    height: 80px; /* ارتفاع أصغر للصورة في وضع القائمة */
    margin-left: 15px; /* مسافة لليسار عن النص في RTL */
    margin-bottom: 0; /* لا يوجد هامش سفلي */
}

/* إذا لم تكن هناك صورة في List View */
.listings-list-view .list-item:not(:has(.item-image-wrapper)) .item-content-wrapper {
    width: 100%; /* المحتوى يأخذ العرض الكامل */
    margin-right: 0; /* إزالة أي هامش محتمل من الصورة */
}


.listings-list-view .item-content-wrapper {
    flex-direction: row; /* جعل المحتوى الرئيسي والمشاهدات/السعر في صف واحد */
    flex-wrap: nowrap; /* منع الالتفاف */
    justify-content: space-between; /* توزيع المساحة */
    align-items: flex-start; /* محاذاة علوية */
    flex-grow: 1; /* السماح بالتمدد */
}

.listings-list-view .item-main-info {
    flex-basis: 65%; /* تعيين أساس مرن */
    flex-grow: 1;
    max-width: 65%; /* عرض أقصى لـ main info */
    width: auto; /* مهم لتجاوز الـ 100% الافتراضية */
}

.listings-list-view .item-stats-price {
    flex-basis: 30%; /* تعيين أساس مرن */
    flex-shrink: 0;
    max-width: 35%; /* عرض أقصى لـ stats-price */
    text-align: end;
    margin-top: 0; /* لا يوجد هامش علوي */
    align-items: flex-end; /* محاذاة السعر والمشاهدات لليمين */
    white-space: nowrap; /* منع كسر سطر للسعر */
}


.item-title-content {
    font-size: 1.25rem;
    font-weight: bold;
    color: #28a745;
    margin-bottom: 8px;
    line-height: 1.3;
}

.item-badges .badge {
    font-size: 0.8em;
    padding: 0.4em 0.7em;
    border-radius: 0.25rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

    .item-badges .badge i {
        font-size: 0.9em;
    }

p.text-muted.small {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px !important;
}

    p.text-muted.small i {
        color: #007bff;
        font-size: 1.1em;
    }

p.mb-1 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px !important;
}

.price-display {
    font-size: 1.1em;
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Align right for Arabic */
    gap: 8px;
    white-space: nowrap;
}

    .price-display i {
        font-size: 1.2em;
    }

/* نهاية التحميل */
.central-loader {
    background-color: #ffffff;
    padding: 20px;
    border-radius: 8px;
    margin: 20px auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    text-align: center;
}

    .central-loader .spinner-border {
        width: 3rem;
        height: 3rem;
        color: #007bff !important;
    }

/* ---------------------------------------------------- */
/* Chat Page Specific Styles (WebChats/Chat) */
/* ---------------------------------------------------- */

.chat-page-wrapper {
    max-width: 800px;
    margin: 30px auto;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    padding: 25px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
}

.chat-header-title {
    color: #007bff;
    font-size: 2rem;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
    padding-bottom: 15px;
}

.chat-messages-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background-color: #fcfcfc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.message-bubble {
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 75%;
    position: relative;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

    .message-bubble .sender-name {
        font-size: 0.8rem;
        margin-bottom: 3px;
        opacity: 0.8;
    }

    .message-bubble .message-content {
        margin: 0;
        padding: 0;
    }

    .message-bubble .timestamp {
        font-size: 0.7rem;
        color: rgba(0, 0, 0, 0.4);
        margin-top: 5px;
        text-align: inherit;
    }

.message-from-me {
    background-color: #dcf8c6;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

    .message-from-me .sender-name {
        color: #4CAF50;
        text-align: left;
    }

.message-from-other {
    background-color: #e0e0e0;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

    .message-from-other .sender-name {
        color: #333;
        text-align: right;
    }

.chat-input-form {
    display: flex;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

    .chat-input-form .form-control {
        flex-grow: 1;
        border-radius: 25px;
        padding: 10px 20px;
        font-size: 1rem;
        border-color: #ced4da;
    }

        .chat-input-form .form-control:focus {
            border-color: #80bdff;
            box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
        }

.chat-send-btn {
    border-radius: 25px;
    padding: 10px 25px;
    background-color: #007bff;
    border-color: #007bff;
    font-weight: 600;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

    .chat-send-btn:hover {
        background-color: #0056b3;
        border-color: #0056b3;
    }

#typingStatus {
    text-align: right;
    font-style: italic;
    color: #6c757d;
    height: 20px;
}

/* ---------------------------------------------------- */
/* Media Queries for Chat Page */
/* ---------------------------------------------------- */

@media (max-width: 768px) {
    .chat-page-wrapper {
        padding: 15px;
        height: calc(100vh - 100px);
        margin: 15px auto;
        box-shadow: none;
    }

    .chat-header-title {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }

    .message-bubble {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .chat-input-form {
        flex-direction: row;
        gap: 8px;
    }

        .chat-input-form .form-control {
            padding: 8px 15px;
            font-size: 0.9rem;
        }

    .chat-send-btn {
        padding: 8px 15px;
        font-size: 0.9rem;
    }
}

@media (max-width: 576px) {
    .chat-page-wrapper {
        border-radius: 0;
        box-shadow: none;
        height: 100vh;
        margin: 0;
        padding-top: 15px;
        padding-bottom: 15px;
    }

        .chat-page-wrapper.container {
            padding-left: 10px;
            padding-right: 10px;
        }
}

.chat-main-full-width {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

/* ---------------------------------------------------- */
/* Media Queries للاستجابة (Responsive Design) */
/* ---------------------------------------------------- */

@media (max-width: 992px) {
    .page-content-wrapper {
        flex-direction: column;
        padding: 15px;
        gap: 20px;
    }

    .sidebar-filters {
        position: static;
        width: 100%;
        max-height: none;
        margin-bottom: 0;
        order: 1;
    }

    .main-content {
        width: 100%;
        order: 2;
    }

    /* Grid View: Keep grid for larger screens that collapse sidebar */
    .listings-container.listings-grid-view {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        display: grid; /* Ensure it's a grid here */
    }

    /* List View: Maintain horizontal for larger tablets */
    .listings-list-view .list-item {
        flex-direction: row; /* Keep horizontal for list view */
        gap: 15px;
        padding: 12px;
        min-height: 100px; /* Adjust min-height */
    }

    .listings-list-view .item-image-wrapper {
        width: 100px; /* Fixed width for list view image */
        min-width: 100px;
        height: 70px; /* Adjusted height */
        margin-bottom: 0;
        margin-left: 15px; /* Space for text */
    }

    .listings-list-view .item-content-wrapper {
        flex-direction: row; /* Main info and stats/price side-by-side */
        flex-wrap: nowrap;
        align-items: flex-start;
    }

    .listings-list-view .item-main-info {
        flex-basis: 60%;
        max-width: 60%;
    }

    .listings-list-view .item-stats-price {
        flex-basis: 35%;
        max-width: 40%;
        text-align: end;
        align-items: flex-end;
    }

    .listings-list-view .price-display {
        justify-content: flex-end;
    }

    .navbar-collapse {
        text-align: center;
    }

    .navbar-nav {
        align-items: center;
    }
}

@media (max-width: 768px) {
    .page-content-wrapper {
        gap: 15px;
    }

    .sidebar-filters {
        padding: 15px;
    }

        .sidebar-filters h2 {
            font-size: 1.3rem;
            margin-bottom: 15px;
        }

    /* Grid View: Ensure grid works well on smaller tablets */
    .listings-container.listings-grid-view {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        display: grid; /* Ensure it's a grid here */
    }

    /* List View: Stack vertically for smaller tablets/phones */
    .listings-list-view .list-item {
        flex-direction: column; /* Transform to vertical */
        align-items: flex-start;
        gap: 10px;
        padding: 10px;
        min-height: auto; /* Remove min-height for stacked items */
    }

    .listings-list-view .item-image-wrapper {
        width: 100%; /* Image takes full width */
        min-width: auto;
        height: 150px;
        margin-bottom: 10px; /* Add bottom margin for image */
        margin-left: 0; /* No left margin */
    }

    .listings-list-view .item-content-wrapper {
        flex-direction: column; /* Content stacks vertically */
        width: 100%;
        flex-wrap: wrap; /* Allow wrapping */
    }

    .listings-list-view .item-main-info,
    .listings-list-view .item-stats-price {
        width: 100%; /* Each part takes full width in vertical stack */
        min-width: auto;
        max-width: none;
        margin-right: 0;
        text-align: start;
        align-items: flex-start; /* Align left in vertical mode */
        flex-basis: auto; /* Revert basis */
    }

    .price-display {
        justify-content: flex-start; /* Align price to left in vertical mode */
    }
}

@media (max-width: 576px) {
    /* For very small screens, both list and grid become single column */
    .listings-container.listings-grid-view,
    .listings-container.listings-list-view {
        grid-template-columns: 1fr; /* Single column always */
        display: grid; /* Ensure it's still a grid layout, just one column */
        gap: 15px; /* Adjust gap for single column */
    }

    /* Ensure individual list-item always stacks its content */
    .listings-grid-view .list-item,
    .listings-list-view .list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 10px;
    }

    .listings-grid-view .item-image-wrapper,
    .listings-list-view .item-image-wrapper {
        width: 100%;
        height: 180px;
        margin: 0 auto 15px auto;
    }

    .item-title-content {
        font-size: 1.1rem;
    }

    .item-badges .badge, p.text-muted.small, p.mb-1 {
        font-size: 0.85rem;
    }

    .price-display {
        font-size: 1em;
        justify-content: flex-start;
    }

    .view-toggle-buttons {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-bottom: 15px;
    }

        .view-toggle-buttons .btn {
            flex-grow: 1;
            padding: 8px 12px;
            font-size: 0.9rem;
        }

    .sidebar-filters .btn {
        width: 100%;
        font-size: 1rem;
    }

    .sidebar-filters .d-grid {
        gap: 10px;
    }

    .navbar-brand img {
        max-height: 35px;
    }

    .navbar-toggler {
        font-size: 0.9rem;
    }
}

/* لكي تعمل ايقونات بوتستراب بشكل صحيح */
[class^="bi-"]::before, [class*=" bi-"]::before {
    font-family: "bootstrap-icons" !important;
    font-style: normal;
    font-weight: normal !important;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    vertical-align: -0.125em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
