/* =====================================================================
   وضع العرض الكثيف لصفحات العمل (المشترك والمدير)
   على غرار الأنظمة المحاسبية وأنظمة CRM: بيانات أكثر في الشاشة الواحدة،
   أزرار وحقول مدمجة، جداول بصفوف قصيرة ورأس ثابت.
   كل القواعد مقيّدة بـ body.app-dense حتى لا تتأثر الصفحات التعريفية العامة.
   ===================================================================== */

body.app-dense {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ---------- الهيكل ---------- */
body.app-dense .app-header {
    padding: 8px 20px;
}

body.app-dense .app-header h1 {
    font-size: 1.05rem;
}

body.app-dense .app-content {
    padding: 12px 16px 20px;
}

body.app-dense .app-content .container,
body.app-dense .app-content .container-fluid {
    max-width: none;
    padding-inline: 0;
}

body.app-dense .app-content > .container.mt-4,
body.app-dense .app-content > .container-fluid.mt-4,
body.app-dense .app-content > .container.mt-5 {
    margin-top: 0 !important;
}

body.app-dense .app-footer {
    padding: 8px 16px;
    font-size: 0.75rem;
}

/* عنوان الصفحة الكبير يكرر عنوان الشريط العلوي؛ يُخفى على الشاشة ويبقى في الطباعة */
@media screen {
    body.app-dense .app-content h2.display-6 {
        display: none;
    }
}

body.app-dense .app-content h2.h4,
body.app-dense .app-content h2.h5 {
    font-size: 1.05rem;
}

body.app-dense h5 {
    font-size: 0.98rem;
}

/* ---------- شريط أزرار الصفحة ---------- */
body.app-dense .page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

body.app-dense .page-actions .spacer {
    flex: 1;
}

/* ---------- الأزرار ---------- */
body.app-dense .btn {
    border-radius: 6px;
    padding: 0.3rem 0.75rem;
    font-size: 0.82rem;
    line-height: 1.45;
}

body.app-dense .btn-sm,
body.app-dense .btn-group-sm > .btn {
    padding: 0.15rem 0.5rem;
    font-size: 0.76rem;
}

body.app-dense .btn-lg {
    padding: 0.45rem 1.1rem;
    font-size: 0.92rem;
}

body.app-dense .btn:hover {
    transform: none;
}

body.app-dense .btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ---------- البطاقات ---------- */
body.app-dense .card {
    border-radius: 8px;
}

body.app-dense .card-header {
    padding: 0.45rem 0.75rem;
}

body.app-dense .card-header h5,
body.app-dense .card-header h6 {
    font-size: 0.9rem;
}

body.app-dense .card-body {
    padding: 0.75rem;
}

body.app-dense .card.p-3 {
    padding: 0.6rem 0.75rem !important;
}

/* ---------- الحقول ---------- */
body.app-dense .form-control,
body.app-dense .form-select {
    border-width: 1px;
    border-radius: 6px;
    padding: 0.32rem 0.6rem;
    font-size: 0.85rem;
}

body.app-dense .form-control-sm,
body.app-dense .form-select-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
    min-height: 30px;
}

body.app-dense .form-label,
body.app-dense label {
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
}

body.app-dense .input-group-text {
    border-width: 1px;
    padding: 0.25rem 0.55rem;
    font-size: 0.82rem;
}

body.app-dense .form-control:focus,
body.app-dense .form-select:focus {
    box-shadow: 0 0 0 2px rgba(14, 63, 99, 0.12);
}

body.app-dense .mb-3 {
    margin-bottom: 0.75rem !important;
}

body.app-dense .mb-4 {
    margin-bottom: 1rem !important;
}

/* ---------- لوحات الفلاتر: شبكة تتكيف مع عرض الشاشة ---------- */
body.app-dense #filtersPanel > form.row,
body.app-dense form.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 0.4rem 0.6rem;
    margin: 0;
    align-items: end;
}

body.app-dense #filtersPanel > form.row > *,
body.app-dense form.filter-grid > * {
    width: auto;
    max-width: none;
    padding: 0;
    margin: 0 !important;
}

body.app-dense #filtersPanel > form.row > .col-12,
body.app-dense form.filter-grid > .col-12 {
    grid-column: 1 / -1;
    text-align: start !important;
}

body.app-dense .filter-toggle {
    cursor: pointer;
}

body.app-dense .filter-toggle h6 {
    font-size: 0.85rem;
}

/* ---------- الجداول ---------- */
body.app-dense .table {
    font-size: 0.82rem;
}

body.app-dense .table > :not(caption) > * > * {
    padding: 0.32rem 0.5rem;
}

body.app-dense .table thead th,
body.app-dense .table > thead.table-primary > tr > th {
    font-size: 0.78rem;
    white-space: nowrap;
    border-bottom-width: 1px;
}

body.app-dense .table-responsive {
    border-radius: 8px;
}

body.app-dense .table .badge {
    font-size: 0.72rem;
    font-weight: 600;
}

/* على الشاشات الكبيرة: الجدول يمرر داخلياً ورأسه ثابت مثل الأنظمة المحاسبية */
@media screen and (min-width: 992px) {
    body.app-dense .app-content .table-responsive {
        max-height: calc(100vh - 170px);
        overflow: auto;
    }

    body.app-dense .app-content .table-responsive > .table > thead > tr > th {
        position: sticky;
        top: 0;
        z-index: 2;
    }
}

/* نص طويل يُقص بسطر واحد ويظهر كاملاً عند التمرير */
body.app-dense .cell-clip {
    display: block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.app-dense .cell-sub {
    display: block;
    font-size: 0.74rem;
    color: var(--text-muted);
    line-height: 1.3;
}

body.app-dense .num {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---------- التنبيهات ---------- */
body.app-dense .alert {
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 0.84rem;
    margin-bottom: 0.6rem;
}

body.app-dense .alert-dismissible {
    padding-left: 2.5rem;
}

body.app-dense .alert-dismissible .btn-close {
    padding: 0.6rem 0.75rem;
}

body.app-dense .alert h4,
body.app-dense .alert h5 {
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
}

/* ---------- القوائم المنسدلة وTom Select ---------- */
body.app-dense .dropdown-menu {
    padding: 4px;
    font-size: 0.82rem;
    border-radius: 8px;
}

body.app-dense .dropdown-item {
    padding: 5px 10px;
    border-radius: 5px;
}

.ts-dropdown {
    min-width: 260px;
    font-size: 0.82rem;
    z-index: 1060;
}

/* الإطار والخلفية على الغلاف نفسه (سمة Bootstrap في Tom Select) */
body.app-dense .ts-wrapper.form-select,
body.app-dense .ts-wrapper.form-control {
    font-size: 0.82rem;
}

body.app-dense .ts-wrapper .ts-control {
    font-size: 0.82rem;
}

/* ---------- الترقيم الموحد ---------- */
.list-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-top: 0.6rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.list-pager .pagination {
    gap: 3px;
}

.list-pager .page-link {
    padding: 0.2rem 0.6rem;
    border-radius: 6px !important;
}

.list-pager .pager-size {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    font-weight: 500;
}

.list-pager .pager-size select {
    width: auto;
    min-width: 70px;
}

/* ---------- الجوال ---------- */
@media (max-width: 767.98px) {
    body.app-dense .app-content {
        padding: 10px 10px 16px;
    }

    body.app-dense #filtersPanel > form.row,
    body.app-dense form.filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.app-dense .list-pager {
        justify-content: center;
    }

    body.app-dense .page-actions .btn {
        flex: 1 1 auto;
    }
}

/* نص الزر يظهر على الشاشات العريضة فقط، والأيقونة تكفي في غيرها */
.label-wide {
    display: none;
}

@media (min-width: 1600px) {
    .label-wide {
        display: inline;
    }
}

/* أزرار الإجراءات المكدسة عمودياً في خلايا الجداول القديمة تصير صفاً واحداً مدمجاً */
body.app-dense .table td > .btn-group-vertical {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 3px;
    width: auto !important;
}

body.app-dense .table td > .btn-group-vertical > *,
body.app-dense .table td > .btn-group-vertical > form > .btn {
    margin: 0 !important;
    width: auto !important;
}

body.app-dense .table td > .btn-group-vertical > .btn,
body.app-dense .table td > .btn-group-vertical > form > .btn {
    border-radius: 5px !important;
    padding: 0.12rem 0.45rem !important;
    font-size: 0.74rem !important;
    white-space: nowrap;
}

body.app-dense .table td:has(> .btn-group-vertical) {
    width: 1% !important;
    min-width: 0 !important;
    white-space: nowrap;
}

/* مصغرات المرفقات داخل الجداول */
body.app-dense .table .thumbnail-grid {
    gap: 2px;
}

body.app-dense .table .attachment-thumbnail {
    width: 28px !important;
    height: 28px !important;
}

/* Tom Select يخفي القائمة الأصلية وحقل قياس خارج الشاشة يساراً؛ في صفحة RTL
   يوسّع ذلك عرض الصفحة ويظهر تمرير أفقي. تُثبَّت مكانها ويُقص أي فائض أفقي للصفحة. */
select.ts-hidden-accessible,
.ts-hidden-accessible {
    position: absolute !important;
    inset-inline-start: 0 !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
}

html,
body {
    overflow-x: clip;
}

/* ---------- القائمة الجانبية المدمجة: كل الروابط تظهر دون تمرير على الشاشات المعتادة ---------- */
@media (min-width: 769px) {
    body.app-dense {
        --sidebar-width: 210px;
    }
}

body.app-dense .sidebar-header {
    padding-block: 10px;
}

body.app-dense .sidebar-nav {
    padding: 4px 0;
}

body.app-dense .nav-section {
    padding: 8px 16px 2px;
    font-size: 0.64rem;
}

body.app-dense .sidebar-nav .nav-item {
    padding: 6px 16px;
    gap: 10px;
    font-size: 0.85rem;
}

body.app-dense .sidebar-nav .nav-item i {
    font-size: 0.9rem;
}

body.app-dense .nav-section-divider {
    margin: 6px 16px;
}

body.app-dense .sidebar-footer {
    padding: 8px 16px;
}

/* ---------- أزرار الجداول القديمة الملوّنة تصير أزراراً محددة هادئة ---------- */
body.app-dense .table td > .btn-group-vertical > .btn-warning {
    background: #fff;
    color: #9c6b00;
    border-color: #f0c75e;
}

body.app-dense .table td > .btn-group-vertical > .btn-danger,
body.app-dense .table td > .btn-group-vertical > form > .btn-danger {
    background: #fff;
    color: #c92a2a;
    border-color: #f1aeb5;
}

body.app-dense .table td > .btn-group-vertical > .btn-info {
    background: #fff;
    color: #0b7285;
    border-color: #99d6e2;
}

body.app-dense .table td > .btn-group-vertical > .btn-warning:hover {
    background: #fff4d6;
}

body.app-dense .table td > .btn-group-vertical > .btn-danger:hover,
body.app-dense .table td > .btn-group-vertical > form > .btn-danger:hover {
    background: #fff0f0;
}

body.app-dense .table td > .btn-group-vertical > .btn-info:hover {
    background: #e7f7fa;
}
