/* ================================================================
   RESPONSIVE DATA TABLES — عرض احترافي للجوال واللابتوب
   يعمل مع Firestore / HTML الديناميكي + feEnhanceResponsiveTables()
   ================================================================ */

.fe-table-shell,
.erh-schedule-table-wrap.fe-table-shell,
.erh-research-table-wrap.fe-table-shell,
.ql-doc-table-wrap.fe-table-shell,
.table-responsive.fe-table-shell {
    width: 100%;
    max-width: 100%;
}

/* ── Desktop: جداول نظيفة ── */
.fe-data-table,
table.fe-data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-family: 'Cairo', 'Tajawal', system-ui, sans-serif;
    font-size: 0.9rem;
    line-height: 1.45;
    background: #fff;
}

.fe-data-table thead {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    position: sticky;
    top: 0;
    z-index: 2;
}

.fe-data-table th {
    padding: 13px 14px;
    text-align: right;
    font-weight: 800;
    font-size: 0.82rem;
    color: #334155;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

.fe-data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #475569;
    vertical-align: top;
    word-break: break-word;
}

.fe-data-table tbody tr:nth-child(even) td {
    background: #fafbfc;
}

.fe-data-table tbody tr:hover td {
    background: rgba(108, 76, 241, 0.04);
}

.fe-table-shell {
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    overflow: hidden;
}

.fe-table-shell > .fe-data-table {
    border: none;
    box-shadow: none;
}

/* جداول داخل صفحات الامتحانات والأبحاث — تحسين سطح المكتب */
.erh-schedule-table.fe-data-table,
.erh-research-table.fe-data-table {
    min-width: 0;
}

@media (min-width: 992px) {
    .erh-research-table.fe-data-table {
        font-size: 0.84rem;
    }

    .erh-research-table.fe-data-table th {
        font-size: 0.78rem;
        padding: 10px 10px;
    }

    .erh-research-table.fe-data-table td {
        padding: 9px 10px;
    }
}

/* ── Mobile & Tablet: بطاقات بدلاً من التمرير الأفقي ── */
@media (max-width: 991px) {
    .fe-table-shell,
    .erh-schedule-table-wrap,
    .erh-research-table-wrap,
    .ql-doc-table-wrap {
        overflow: visible !important;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .fe-table-shell .table-responsive {
        overflow: visible !important;
    }

    .fe-data-table,
    .fe-table-shell .fe-data-table,
    .fe-table-shell .data-table,
    .fe-table-shell .admin-table,
    .fe-table-shell .stu-table,
    .fe-table-shell .erh-schedule-table,
    .fe-table-shell .erh-research-table,
    .fe-table-shell .ql-doc-table,
    .fe-table-shell .ahp-public-table,
    .fe-table-shell .td-courses-table {
        min-width: 0 !important;
        width: 100% !important;
        table-layout: auto !important;
        border: none;
    }

    .fe-data-table thead,
    .fe-table-shell table thead {
        display: none;
    }

    .fe-data-table tbody tr,
    .fe-table-shell table tbody tr {
        display: block;
        margin-bottom: 14px;
        padding: 14px 16px 10px;
        border: 1px solid #e2e8f0;
        border-radius: 14px;
        background: #fff;
        box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
        position: relative;
    }

    .fe-data-table tbody tr::before,
    .fe-table-shell table tbody tr::before {
        content: attr(data-row-label);
        display: block;
        font-weight: 800;
        font-size: 0.88rem;
        color: #6C4CF1;
        padding-bottom: 10px;
        margin-bottom: 4px;
        border-bottom: 1px solid #f1f5f9;
    }

    .fe-data-table tbody tr[data-row-num]::before,
    .fe-table-shell table tbody tr[data-row-num]::before {
        content: 'سجل #' attr(data-row-num);
    }

    .fe-data-table tbody td,
    .fe-table-shell table tbody td {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 10px 0;
        border: none !important;
        border-bottom: 1px solid #f8fafc !important;
        background: transparent !important;
        text-align: right;
        font-size: 0.9rem;
        color: #1e293b;
    }

    .fe-data-table tbody td:last-child,
    .fe-table-shell table tbody td:last-child {
        border-bottom: none !important;
    }

    .fe-data-table tbody td::before,
    .fe-table-shell table tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.76rem;
        color: #64748b;
        line-height: 1.3;
    }

    .fe-data-table tbody td[data-label=""]::before,
    .fe-data-table tbody td:not([data-label])::before,
    .fe-table-shell table tbody td[data-label=""]::before {
        display: none;
    }

    /* عمود الترقيم — إخفاء على الجوال */
    .fe-data-table .fe-col-num,
    .fe-data-table .erh-td-num,
    .fe-data-table .col-num {
        display: none !important;
    }

    /* أزرار الإجراءات */
    .fe-data-table .fe-col-actions,
    .fe-data-table td:last-child:has(button),
    .fe-data-table td:last-child:has(.btn-icon) {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 12px;
        margin-top: 4px;
        border-top: 1px dashed #e2e8f0 !important;
    }

    .fe-data-table .fe-col-actions::before {
        width: 100%;
        margin-bottom: 4px;
    }

    .erh-td-title .erh-title-text {
        display: block;
        -webkit-line-clamp: unset;
        line-clamp: unset;
        white-space: normal;
    }

    .erh-td-name,
    .erh-td-prog {
        white-space: normal;
    }
}

@media (max-width: 768px) {
    .erh-page { padding: 16px 0 40px; }
    .erh-research-public-body { padding: 8px 4px 16px; }

    .fe-data-table tbody tr {
        padding: 12px 14px 8px;
        margin-bottom: 12px;
    }
}
