/* =========================================================
   ميزان: تنسيق مشترك للجوال
   - يمنع خروج الصفحة عن عرض الشاشة
   - يحوّل الجداول العريضة إلى بطاقات مرتبة على الجوال
   - يمنع تكبير الشاشة تلقائيًا عند الكتابة في الحقول (آيفون)
   ملاحظة: كل القواعد هنا للشاشة فقط ولا تؤثر على الطباعة.
   ========================================================= */

:root {
    --mz-card-bg: #ffffff;
    --mz-card-border: #e4e9f1;
    --mz-card-shadow: 0 6px 18px rgba(15, 35, 70, .06);
    --mz-label: #6b7686;
    --mz-value: #17233a;
    --mz-divider: #eef1f6;
    --mz-accent: #0f2a5c;
}

@media screen {
    html { overflow-x: hidden; }
    @supports (overflow: clip) {
        html, body { overflow-x: clip; }
    }
    img, video, canvas, svg { max-width: 100%; }
    img { height: auto; }
}

@media screen and (max-width: 760px) {

    /* الحقول: 16px يمنع آيفون من تكبير الصفحة عند الضغط على الحقل */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    select,
    textarea {
        font-size: 16px !important;
    }

    /* ---------- الجداول كبطاقات ---------- */
    html body table.mz-cards {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        table-layout: auto !important;
    }
    html body table.mz-cards > thead { display: none; }
    html body table.mz-cards > tbody,
    html body table.mz-cards > tfoot { display: block; width: 100%; }

    html body table.mz-cards > tbody > tr,
    html body table.mz-cards > tfoot > tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 4px 14px;
        margin: 0 0 12px;
        padding: 12px 14px;
        background: var(--mz-card-bg) !important;
        border: 1px solid var(--mz-card-border) !important;
        border-radius: 16px;
        box-shadow: var(--mz-card-shadow);
        position: relative;
    }
    html body table.mz-cards > tbody > tr[hidden],
    html body table.mz-cards > tbody > tr[style*="display: none"],
    html body table.mz-cards > tbody > tr[style*="display:none"] { display: none; }

    html body table.mz-cards > tbody > tr > td,
    html body table.mz-cards > tfoot > tr > td {
        display: block;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 6px 0 !important;
        border: 0 !important;
        background: transparent !important;
        text-align: start !important;
        white-space: normal !important;
        word-break: break-word;
        overflow-wrap: anywhere;
        color: var(--mz-value);
        font-size: 14px;
        line-height: 1.6;
        position: static !important;
    }
    html body table.mz-cards > tbody > tr > td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        color: var(--mz-label);
        font-size: 12px;
        font-weight: 700;
        line-height: 1.4;
    }

    /* الخانة الرئيسية (الاسم/المدرسة) تأخذ عرض البطاقة كاملًا وبخط أوضح */
    html body table.mz-cards > tbody > tr > td.mz-cell-title {
        grid-column: 1 / -1;
        order: -1;
        font-size: 15.5px;
        font-weight: 800;
        padding-inline-end: 40px !important;
        border-bottom: 1px solid var(--mz-divider) !important;
        padding-bottom: 10px !important;
        margin-bottom: 4px;
    }
    html body table.mz-cards > tbody > tr > td.mz-cell-title::before { display: none !important; }

    /* خانة التحديد في زاوية البطاقة */
    html body table.mz-cards > tbody > tr > td.mz-cell-check {
        position: absolute !important;
        top: 12px;
        inset-inline-end: 12px;
        padding: 0 !important;
        z-index: 2;
    }
    html body table.mz-cards > tbody > tr > td.mz-cell-check::before { display: none !important; }
    html body table.mz-cards > tbody > tr > td.mz-cell-check input[type="checkbox"] {
        width: 22px; height: 22px;
    }

    /* رقم السطر غير مهم داخل البطاقة */
    html body table.mz-cards > tbody > tr > td.mz-cell-num { display: none; }

    /* الأزرار والخانات الطويلة تأخذ السطر كاملًا */
    html body table.mz-cards > tbody > tr > td.mz-cell-wide,
    html body table.mz-cards > tbody > tr > td.mz-cell-actions,
    html body table.mz-cards > tbody > tr > td[colspan] {
        grid-column: 1 / -1;
    }
    html body table.mz-cards > tbody > tr > td.mz-cell-actions {
        border-top: 1px solid var(--mz-divider) !important;
        padding-top: 10px !important;
        margin-top: 4px;
    }
    html body table.mz-cards > tbody > tr > td.mz-cell-actions::before { display: none !important; }
    html body table.mz-cards > tbody > tr > td.mz-cell-actions > *,
    html body table.mz-cards > tbody > tr > td.mz-cell-actions .actions,
    html body table.mz-cards > tbody > tr > td.mz-cell-actions form {
        flex-wrap: wrap;
    }
    html body table.mz-cards > tbody > tr > td.mz-cell-actions a,
    html body table.mz-cards > tbody > tr > td.mz-cell-actions button {
        min-height: 40px;
    }
    html body table.mz-cards > tbody > tr > td.mz-cell-wide input:not([type="checkbox"]):not([type="radio"]),
    html body table.mz-cards > tbody > tr > td.mz-cell-wide select,
    html body table.mz-cards > tbody > tr > td.mz-cell-actions input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    html body table.mz-cards > tbody > tr > td.mz-cell-actions select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    /* الحاوية التي كانت تسمح بالسحب الأفقي لم تعد تحتاجه */
    html body .mz-cards-wrap {
        overflow: visible !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        padding: 0 !important;
    }

    /* شريط "تحديد الكل" يظهر بدل رأس الجدول المخفي */
    .mz-selectall-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        margin: 0 0 10px;
        padding: 10px 14px;
        background: #f6f8fc;
        border: 1px solid var(--mz-card-border);
        border-radius: 14px;
        font-size: 14px;
        font-weight: 700;
        color: var(--mz-accent);
        cursor: pointer;
        user-select: none;
    }
    .mz-selectall-bar input { width: 20px; height: 20px; margin: 0; }
}

@media not screen, (min-width: 761px) {
    .mz-selectall-bar { display: none !important; }
}

/* ---------- الكشف اليومي: معاينة الورقة تبقى بشكلها الرسمي مع سحب أفقي ---------- */
@media screen and (max-width: 760px) {
    .imperial-session-block {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    .imperial-session-block .imperial-table {
        min-width: 700px;
    }
    .imperial-session-block .imperial-table td,
    .imperial-session-block .imperial-table th {
        word-break: normal;
        overflow-wrap: normal;
    }
}
