/**
 * تنسيق موحّد لجميع جداول DataTables — صفوف أرفق، شكل أوضح (يُحمَّل بعد أنماط الصفحات).
 */
:root {
    --dt-accent: #083d3d;
    --dt-accent-mid: #0d5d5d;
    --dt-gold: #d4af37;
    --dt-cell-py: 0.4rem;
    --dt-cell-px: 0.65rem;
    --dt-head-py: 0.48rem;
    --dt-body-fs: 0.8125rem;
    --dt-head-fs: 0.78rem;
}

div.dataTables_wrapper {
    padding: 0.25rem 0;
}

/*
 * صف أدوات التحكم العلوي فقط (بحث + أزرار + إظهار الصفوف).
 * صفّ المعلومات/الترقيم السفلي يستخدم .justify-content-between أيضاً؛ نستثني آخر طفل مباشر للـ wrapper.
 */
.dataTables_wrapper > .d-flex.justify-content-between:not(:last-child),
.dataTables_wrapper > .d-flex.flex-wrap:first-child {
    flex-wrap: wrap !important;
    gap: 0.65rem 1rem !important;
    align-items: center !important;
    margin-bottom: 0.65rem !important;
    padding: 0.5rem 0.65rem !important;
    background: linear-gradient(
        180deg,
        rgba(8, 61, 61, 0.045) 0%,
        rgba(255, 255, 255, 0.65) 100%
    );
    border-radius: 10px;
    border: 1px solid rgba(8, 61, 61, 0.08);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.dataTables_wrapper .d-flex .d-flex.align-items-center {
    flex-wrap: wrap !important;
    gap: 0.5rem 0.75rem !important;
    align-items: center !important;
}

/* الجدول: إطار ناعم + زوايا */
table.table.dataTable,
table.dataTable {
    border-collapse: separate !important;
    border-spacing: 0 !important;
    border-radius: 12px !important;
    overflow: hidden;
    box-shadow:
        0 1px 0 rgba(8, 61, 61, 0.07),
        0 6px 20px rgba(44, 62, 80, 0.06) !important;
}

/*
 * داخل حاوية التمرير: لا نستخدم overflow:hidden على الجدول لأنها تكسر position:sticky على الهيدر
 * (الزوايا تُقصّ من الحاوية .datatable-wrapper-content)
 */
.dataTables_wrapper .datatable-wrapper-content table.dataTable,
.datatable-wrapper-content > table.dataTable {
    overflow: visible !important;
    border-radius: 0 !important;
}

/* رأس أرفق */
table.dataTable thead th,
table.table.dataTable thead th {
    padding: var(--dt-head-py) var(--dt-cell-px) !important;
    font-size: var(--dt-head-fs) !important;
    font-weight: 600 !important;
    letter-spacing: 0.02em;
    line-height: 1.25 !important;
    vertical-align: middle !important;
    border-bottom: 2px solid rgba(212, 175, 55, 0.35) !important;
}

/* خلايا البيانات — صف رفيع */
table.dataTable tbody td,
table.table.dataTable tbody td {
    padding: var(--dt-cell-py) var(--dt-cell-px) !important;
    font-size: var(--dt-body-fs) !important;
    line-height: 1.35 !important;
    vertical-align: middle !important;
}

table.dataTable tbody tr,
table.table.dataTable tbody tr {
    border-bottom: 1px solid rgba(8, 61, 61, 0.065) !important;
    transition: background 0.18s ease, box-shadow 0.18s ease;
}

/* صفوف زوجية خفيفة */
table.dataTable tbody tr:nth-child(even),
table.table.dataTable tbody tr:nth-child(even) {
    background-color: rgba(8, 61, 61, 0.025) !important;
}

/* hover أوضح */
table.dataTable tbody tr:hover,
table.table.dataTable tbody tr:hover {
    background: linear-gradient(
        90deg,
        rgba(212, 175, 55, 0.08) 0%,
        rgba(8, 61, 61, 0.035) 100%
    ) !important;
    box-shadow: inset 3px 0 0 var(--dt-gold) !important;
}

/* محتوى الجدول داخل كارد */
.card .dataTables_wrapper,
.card-body .dataTables_wrapper {
    margin-top: 0.15rem;
}

.card-body table.dataTable {
    margin-bottom: 0 !important;
}

/* عمود الإجراءات: أزرار في صف أفقي واحد (أكثر من زرين بدون تكدس عمودي) */
table.dataTable tbody td.dt-cell-actions {
    vertical-align: middle !important;
    white-space: nowrap !important;
}

.dt-row-actions {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.1rem 0;
}

.dt-row-actions .btn,
.dt-row-actions > a,
.dt-row-actions > button {
    flex: 0 0 auto;
    padding: 0.28rem 0.42rem !important;
    min-width: 2rem;
    min-height: 2rem;
    border-radius: 8px !important;
    box-shadow: 0 1px 3px rgba(8, 61, 61, 0.07);
    line-height: 1 !important;
}

.dt-row-actions .table-action-icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

/* شريط البحث */
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 0 !important;
}

.dataTables_wrapper .dataTables_filter label {
    display: inline-flex !important;
    align-items: center;
    gap: 0.45rem;
    margin: 0 !important;
    font-size: 0.8125rem !important;
    font-weight: 600 !important;
    color: var(--dt-accent) !important;
}

.dataTables_wrapper .dataTables_filter input {
    padding: 0.38rem 0.65rem !important;
    font-size: 0.8125rem !important;
    border-radius: 9px !important;
    min-height: 2.125rem !important;
    border: 1px solid rgba(8, 61, 61, 0.14) !important;
    color: var(--dt-accent) !important;
    background: #fff !important;
    box-shadow: inset 0 1px 2px rgba(8, 61, 61, 0.05) !important;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.dataTables_wrapper .dataTables_filter input:focus {
    border-color: rgba(212, 175, 55, 0.65) !important;
    box-shadow:
        0 0 0 3px rgba(212, 175, 55, 0.12),
        inset 0 1px 2px rgba(8, 61, 61, 0.05) !important;
    outline: none !important;
}

/* إظهار عدد الصفوف */
.dataTables_wrapper .dataTables_length {
    margin-bottom: 0 !important;
}

.dataTables_wrapper .dataTables_length label {
    display: inline-flex !important;
    align-items: center;
    gap: 0.45rem;
    margin: 0 !important;
    font-size: 0.8125rem !important;
    font-weight: 600 !important;
    color: var(--dt-accent) !important;
    letter-spacing: 0.02em;
}

.dataTables_wrapper .dataTables_length select {
    padding-block: 0.38rem !important;
    padding-inline: 0.6rem 2rem !important;
    font-size: 0.8125rem !important;
    border-radius: 9px !important;
    min-height: 2.125rem !important;
    font-weight: 600 !important;
    color: var(--dt-accent) !important;
    background-color: #fff !important;
    border: 1px solid rgba(8, 61, 61, 0.14) !important;
    box-shadow: inset 0 1px 2px rgba(8, 61, 61, 0.05) !important;
    cursor: pointer;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.dataTables_wrapper .dataTables_length select:focus {
    border-color: rgba(212, 175, 55, 0.65) !important;
    box-shadow:
        0 0 0 3px rgba(212, 175, 55, 0.12),
        inset 0 1px 2px rgba(8, 61, 61, 0.05) !important;
    outline: none !important;
}

.dataTables_info {
    font-size: 0.8125rem !important;
    padding-top: 0.5rem !important;
    color: var(--dt-accent) !important;
}

/* أزرار الطباعة والتصدير */
.dataTables_wrapper .dt-buttons {
    display: inline-flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem !important;
}

.dataTables_wrapper .dt-buttons .dt-button,
.dataTables_wrapper .dt-buttons .buttons-print,
.dataTables_wrapper .dt-buttons .buttons-excel,
.dataTables_wrapper button.dt-button {
    padding: 0.42rem 0.95rem !important;
    font-size: 0.8125rem !important;
    font-weight: 600 !important;
    line-height: 1.35 !important;
    border-radius: 9px !important;
    margin: 0 !important;
    color: #062a2a !important;
    background: linear-gradient(
        145deg,
        #f0d060 0%,
        #f4d03f 42%,
        #d4af37 100%
    ) !important;
    border: 1px solid rgba(8, 61, 61, 0.18) !important;
    box-shadow:
        0 2px 10px rgba(212, 175, 55, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.45) !important;
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        border-color 0.15s ease,
        filter 0.15s ease !important;
}

.dataTables_wrapper .dt-buttons .dt-button:hover,
.dataTables_wrapper .dt-buttons .buttons-print:hover,
.dataTables_wrapper .dt-buttons .buttons-excel:hover,
.dataTables_wrapper button.dt-button:hover {
    color: #041f1f !important;
    border-color: rgba(8, 61, 61, 0.28) !important;
    filter: brightness(1.03);
    transform: translateY(-1px);
    box-shadow:
        0 4px 14px rgba(212, 175, 55, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.5) !important;
}

.dataTables_wrapper .dt-buttons .dt-button:active,
.dataTables_wrapper button.dt-button:active {
    transform: translateY(0);
    box-shadow:
        0 1px 6px rgba(8, 61, 61, 0.12),
        inset 0 1px 2px rgba(0, 0, 0, 0.06) !important;
}

.dataTables_wrapper .dt-buttons .dt-button:focus,
.dataTables_wrapper button.dt-button:focus {
    outline: none !important;
    box-shadow:
        0 0 0 3px rgba(212, 175, 55, 0.25),
        0 2px 10px rgba(212, 175, 55, 0.28) !important;
}

/* ترقيم: ارتفاع كافٍ للأيقونات والحدود — بدون height ثابت يقص المحتوى */
.dataTables_paginate .paginate_button {
    min-width: 2rem !important;
    min-height: 2.25rem !important;
    height: auto !important;
    padding: 0.35rem 0.45rem !important;
    font-size: 0.75rem !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.dataTables_wrapper .dataTables_paginate {
    overflow: visible !important;
}

.dataTables_wrapper > .d-flex:last-child {
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
    overflow: visible !important;
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
}

/* حاوية التمرير: تمرير عمودي واحد + رأس ثابت (sticky) */
.datatable-wrapper-content {
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(8, 61, 61, 0.06);
    max-height: min(62vh, 720px);
    overflow: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* يقصّ زوايا الجدول مع بقاء overflow:visible على الجدول نفسه لأجل sticky */
    isolation: isolate;
}

.datatable-wrapper-content table.dataTable tbody td {
    white-space: nowrap;
}

/* رأس الجدول يبقى ثابتاً أثناء التمرير — لون الخلفية من ثيم الصفحة (simple يضيف تدرجاً بـ !important) */
.datatable-wrapper-content table.dataTable thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 15 !important;
    /* احتياطي للصفحات بدون ثيم أخضر؛ الصفحات مع simple تبقى التدرجات كما هي */
    background-color: rgba(255, 255, 255, 0.98);
    box-shadow:
        0 2px 6px rgba(8, 61, 61, 0.08),
        0 1px 0 rgba(212, 175, 55, 0.35) !important;
}

/* إخفاء شريط التحميل الافتراضي واستبداله بسكلتون داخل منطقة الجدول */
.dataTables_wrapper.dt-processing-skeleton .dataTables_processing {
    display: none !important;
}

.dataTables_wrapper.dt-processing-skeleton .datatable-wrapper-content {
    position: relative;
    min-height: 12rem;
}

.dataTables_wrapper.dt-processing-skeleton .datatable-wrapper-content::after {
    content: '';
    position: absolute;
    left: 0.65rem;
    right: 0.65rem;
    top: 0.5rem;
    bottom: 0.5rem;
    z-index: 2;
    pointer-events: none;
    border-radius: 8px;
    background: linear-gradient(
        90deg,
        rgba(8, 61, 61, 0.06) 0%,
        rgba(212, 175, 55, 0.1) 45%,
        rgba(8, 61, 61, 0.06) 90%
    );
    background-size: 200% 100%;
    animation: dt-skeleton-shimmer 1.15s ease-in-out infinite;
    box-shadow: inset 0 0 0 1px rgba(8, 61, 61, 0.06);
}

.dataTables_wrapper.dt-processing-skeleton .datatable-wrapper-content::before {
    content: '';
    position: absolute;
    left: 0.65rem;
    right: 0.65rem;
    top: 0.5rem;
    bottom: 0.5rem;
    z-index: 1;
    pointer-events: none;
    border-radius: 8px;
    background: repeating-linear-gradient(
        0deg,
        rgba(8, 61, 61, 0.05) 0px,
        rgba(8, 61, 61, 0.05) 11px,
        transparent 11px,
        transparent 24px
    );
}

@keyframes dt-skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}
