/* ==========================================================================
   Tables — جداول البيانات (v3)
   تمرير أفقي داخل الحاوية فقط (لا تمرير للصفحة كلها)، رأس ثابت، أرقام بعرض
   ثابت. تشمل .table من Bootstrap حتى تتوحد كل جداول الصفحات.
   ========================================================================== */

.table-responsive {
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    max-width: 100%;
}
.app-card > .table-responsive, .card > .table-responsive { border-radius: 0; }

.table-custom, .table {
    width: 100%;
    margin-bottom: 0;
    font-size: var(--text-sm);
    color: var(--color-foreground);
    border-collapse: collapse;
    --bs-table-bg: transparent;
    --bs-table-hover-bg: var(--color-primary-soft);
    --bs-table-striped-bg: #f8fafc;
    --bs-table-border-color: var(--color-border);
}

.table-custom thead th, .table thead th {
    background-color: var(--color-surface-muted);
    color: var(--color-muted-foreground);
    font-weight: 600;
    font-size: var(--text-sm);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    vertical-align: middle;
}
.table-custom thead th { text-align: right; }

/* الرأس الداكن (.table-dark) بلون العلامة بدل الأسود */
.table .table-dark th, .table thead.table-dark th, .table-dark > tr > th {
    background-color: var(--color-primary-strong) !important;
    color: #fff !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
}

.table-custom tbody td, .table tbody td {
    padding: var(--space-3) var(--space-4);
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle);
}
.table-sm thead th, .table-sm tbody td { padding: var(--space-2) var(--space-3); }

.table-custom tbody tr, .table-hover tbody tr { transition: background-color var(--transition-fast); }
.table-custom tbody tr:hover td { background-color: var(--color-primary-soft); }
.table-custom tbody tr:last-child td { border-bottom: none; }
.table tfoot td, .table tfoot th { background: var(--color-surface-muted); font-weight: 700; }

/* ---- Compact (جداول الدرجات الكثيفة) ---- */
.table-compact thead th { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
.table-compact tbody td { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }

/* ---- Student cell ---- */
.student-cell { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.student-initials-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--color-primary-subtle);
    color: var(--color-primary);
    font-weight: 700;
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.student-name-text { font-weight: 600; color: var(--color-foreground); line-height: var(--leading-tight); }
.student-num-sub { font-size: var(--text-xs); color: var(--color-subtle-foreground); }

/* ---- Row actions ---- */
.table-actions { display: flex; align-items: center; gap: var(--space-1); justify-content: flex-end; }
.action-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--color-muted-foreground);
    background: transparent;
    border: 1px solid transparent;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.action-btn:hover { background-color: var(--color-surface-muted); border-color: var(--color-border); color: var(--color-primary); }
.action-btn.delete:hover { background-color: var(--color-danger-soft); border-color: var(--color-danger-border); color: var(--color-danger); }

/* ---- Pagination ---- */
.pagination-container {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
    background-color: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
}
.pagination-info { font-size: var(--text-sm); color: var(--color-subtle-foreground); }
.app-pagination, .pagination { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1); margin: 0; list-style: none; padding: 0; }
.app-pagination .page-link, .pagination .page-link {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 600;
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--color-border);
    color: var(--color-muted-foreground);
    background-color: var(--color-surface);
    margin: 0;
}
.app-pagination .page-link:hover, .pagination .page-link:hover { background: var(--color-surface-muted); color: var(--color-primary); border-color: var(--color-border-strong); }
.app-pagination .active .page-link, .pagination .active .page-link { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.app-pagination .disabled .page-link, .pagination .disabled .page-link { opacity: 0.6; pointer-events: none; }

/* رؤوس المجموعات (colspan) تلتف بدل أن تتداخل مع ما بجانبها */
.table thead th[colspan], .table-custom thead th[colspan] { white-space: normal; }
