/* ==========================================================================
   ds-responsive.css — Unified Design System · Responsive rules
   Breakpoints: xs <576 · sm ≥576 · md ≥768 · lg ≥992 · xl ≥1200
   يُطبَّق على جميع الصفحات التسع تلقائياً
   ========================================================================== */

/* ==========================================================================
   0) عام: منع التمرير الأفقي وضمان الوسائط لا تتجاوز عرضها
   ========================================================================== */
html, body { overflow-x: hidden; max-width: 100%; }
html body img, html body svg, html body video, html body canvas { max-width: 100%; height: auto; }
html body .modal-body, html body .modal-content { min-width: 0; }
html body .modal-body .row { margin-inline: 0; }

/* أحجام النوافذ الافتراضية — تُعدَّل في breakpoints أدناه */
:root {
    --ds-modal-sm:  420px;
    --ds-modal-md:  620px;
    --ds-modal-lg:  880px;
    --ds-modal-xl:  1120px;
    --ds-modal-gap: 1.25rem;
}

/* ==========================================================================
   1) لابتوب صغير / iPad أفقي (≤1199px)
   ========================================================================== */
@media (max-width: 1199.98px) {
    :root { --ds-modal-xl: 960px; --ds-modal-lg: 820px; }

    /* تقليل المسافات الداخلية في الجداول والبطاقات */
    html body .table th,
    html body .table td { padding: 0.45rem 0.6rem; font-size: 0.88rem; }

    html body .card-body { padding: 1rem; }
}

/* ==========================================================================
   2) تابلت / iPad عمودي (≤991px)
   ========================================================================== */
@media (max-width: 991.98px) {
    :root {
        --ds-modal-gap: 0.75rem;
        --ds-modal-lg:  760px;
        --ds-modal-xl:  900px;
        --ds-modal-md:  580px;
    }

    /* ——— أزرار وحقول مناسبة للمس ——— */
    html body .btn:not(.btn-xs):not(.btn-close):not([style*="width"]) { min-height: 40px; }
    html body .btn.btn-sm                                               { min-height: 36px; padding: 0.35rem 0.75rem; }
    html body .form-control:not(textarea),
    html body .form-select                                               { min-height: 40px; }
    /* يمنع تكبير iOS عند focus */
    html body .form-control,
    html body .form-select,
    html body .swal2-input,
    html body .swal2-select,
    html body .swal2-textarea                                            { font-size: 16px !important; }

    /* ——— رأس وجسم وتذييل النوافذ ——— */
    html body .modal .modal-header { padding: 0.65rem 1rem !important; }
    html body .modal .modal-body   { padding: 1rem !important; }
    html body .modal .modal-footer { padding: 0.65rem 1rem !important; gap: 0.5rem; }

    html body .dropdown-item { padding-block: 0.6rem; }

    /* ——— الشبكة داخل النوافذ: عمودان بدل أربعة ——— */
    html body .modal .row > .col-xl-3,
    html body .modal .row > .col-xl-2 { flex: 0 0 50%; max-width: 50%; }

    /* ——— أشرطة الأدوات: التفاف آمن ——— */
    html body .timetable-toolbar-wrapper,
    html body .substitute-toolbar-tier1,
    html body .supervision-header-card,
    html body .toolbar-row-view,
    html body .toolbar-row-actions,
    html body .distribution-toolbar-card   { flex-wrap: wrap !important; gap: 8px !important; }

    html body .btn-tb-teacher,
    html body .btn-tb-settings { font-size: 0.82rem; }
}

/* ==========================================================================
   3) هاتف كبير (≤767px): النوافذ تتحول إلى شاشة كاملة
   ========================================================================== */
@media (max-width: 767.98px) {
    :root { --ds-modal-gap: 0px; --ds-modal-title-fs: var(--ds-fs-md); --ds-modal-zoom: 1; }
    html body .modal .modal-dialog { --ds-fit: 1 !important; }

    /* ——— نوافذ xl/lg/md: ملء الشاشة ——— */
    html body .modal .modal-dialog:not(.modal-sm):not([data-ds-size="sm"]) {
        max-width: 100vw !important;
        width: 100vw !important;
        margin: 0 !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
    }
    html body .modal .modal-dialog:not(.modal-sm):not([data-ds-size="sm"]) .modal-content {
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border-inline: 0 !important;
    }

    /* ——— نوافذ sm: ورقة سفلية (bottom sheet) ——— */
    html body .modal .modal-dialog.modal-sm,
    html body .modal .modal-dialog[data-ds-size="sm"] {
        max-width: 100vw !important;
        margin: 0 !important;
        min-height: 100dvh !important;
        height: 100dvh !important;
        align-items: flex-end;
    }
    html body .modal .modal-dialog.modal-sm .modal-content,
    html body .modal .modal-dialog[data-ds-size="sm"] .modal-content {
        border-radius: var(--ds-radius-xl) var(--ds-radius-xl) 0 0 !important;
        border-bottom: 0 !important;
    }

    /* ——— بنية flex عمودية مع محتوى قابل للتمرير ——— */
    html body .modal .modal-content   { display: flex; flex-direction: column; }
    html body .modal .modal-body      { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    html body .modal .modal-header,
    html body .modal .modal-footer    { flex: 0 0 auto; }
    html body .modal .modal-footer    { padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important; }

    /* ——— أزرار التذييل: أفقياً متساوية ——— */
    html body .modal .modal-footer > .btn { flex: 1 1 auto; min-height: 42px; }
    html body .modal .modal-footer.justify-content-between { justify-content: stretch; }

    /* ——— شبكة الحقول: كل حقل بعرض كامل ——— */
    html body .modal .modal-body .row > [class*="col-"]:not([class*="col-6"]):not([class*="col-4"]):not([class*="col-3"]) {
        flex: 0 0 100%; max-width: 100%;
    }

    /* ——— الصفوف بجانب بعضها داخل النوافذ: تبقى ثنائية ——— */
    html body .modal .row > .col-6,
    html body .modal .row > .col-sm-6 { flex: 0 0 50%; max-width: 50%; }

    /* ——— أشرطة الأدوات على الهاتف ——— */
    html body .timetable-toolbar-wrapper,
    html body .substitute-toolbar-tier1,
    html body .tt-toolbar-tier1,
    html body .tt-toolbar-tier2,
    html body .toolbar-row-view,
    html body .toolbar-row-actions        { flex-wrap: wrap !important; align-items: stretch !important; gap: 8px !important; }

    html body .btn-tb-teacher,
    html body .btn-tb-settings,
    html body .btn-tb-stage            { width: 100%; justify-content: center; }

    /* ——— الجداول: تمرير أفقي داخلي ——— */
    html body .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    html body .table th,
    html body .table td           { font-size: 0.82rem; padding: 0.4rem 0.5rem; white-space: nowrap; }

    /* ——— SweetAlert على الهاتف ——— */
    html body .swal2-container:not(:has(.swal2-toast)):not(.swal2-top-start):not(.swal2-top-end) { padding: 0.75rem !important; }
    html body .swal2-popup        { width: 100% !important; }
    html body .swal2-actions      { flex-direction: column-reverse; width: 100%; gap: 0.5rem; }
    html body .swal2-actions .swal2-styled { width: 100%; }
    html body .swal2-title        { font-size: 1rem !important; }

    /* ——— بطاقات الإحصاء: عمود واحد ——— */
    html body .stat-card { margin-bottom: 0.75rem; }
    html body .row.g-3 > .col-md-3,
    html body .row.g-3 > .col-md-4 { flex: 0 0 50%; max-width: 50%; }
}

/* ==========================================================================
   4) هاتف صغير جداً (≤575px)
   ========================================================================== */
@media (max-width: 575.98px) {
    html body { font-size: 0.88rem; }

    html body .card,
    html body .clay-card  { border-radius: var(--ds-radius-md) !important; }
    html body .pagination { flex-wrap: wrap; justify-content: center; }

    /* نوافذ: تقليل المسافات ليناسب الشاشات الصغيرة */
    html body .modal .modal-header { padding: 0.5rem 0.75rem !important; }
    html body .modal .modal-body   { padding: 0.75rem !important; }
    html body .modal .modal-footer { padding: 0.5rem 0.75rem !important; }
    html body .modal .modal-title  { font-size: 0.95rem !important; }

    /* شبكة كل عنصر بعرض كامل على الهاتف الصغير */
    html body .modal .row > .col-6,
    html body .modal .row > .col-sm-6 { flex: 0 0 100%; max-width: 100%; }

    /* بطاقات: عمود واحد */
    html body .row.g-3 > .col-md-3,
    html body .row.g-3 > .col-md-4,
    html body .row.g-3 > .col-sm-6   { flex: 0 0 100%; max-width: 100%; }

    /* شبكة الشعب في نافذة المعلم */
    html body #teacherClassesContainer .col-6,
    html body #teacherClassesContainer .col-sm-6 { flex: 0 0 50%; max-width: 50%; }
}

/* ==========================================================================
   5) شاشات اللمس (coarse pointer — هاتف / تابلت)
   ========================================================================== */
@media (pointer: coarse) {
    html body .btn-close          { width: 40px !important; height: 40px !important; }
    html body .dropdown-item      { min-height: 44px; display: flex; align-items: center; }
    html body .nav-link           { min-height: 40px; display: flex; align-items: center; justify-content: center; }
}

/* ==========================================================================
   6) الطباعة: إخفاء أدوات الواجهة
   ========================================================================== */
@media print {
    *, *::before, *::after {
        box-sizing: border-box !important;
        transition: none !important;
        animation: none !important;
    }
    html, body {
        width: 100% !important;
        background: #ffffff !important;
    }
    table {
        box-sizing: border-box !important;
    }
    html body .modal-backdrop,
    html body .swal2-container { display: none !important; }
}


/* ==========================================================================
   7) MODALS - ZERO SCROLLBAR AUTO-FIT FOR ALL DEVICES
   ========================================================================== */

/* على الأجهزة المكتبية والمحمولة (≥768px): لا شريط تمرير أبداً، النافذة تظهر كاملة دفعة واحدة */
@media (min-width: 768px) {
    html body .modal .modal-body {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        max-height: calc((100dvh - 2 * var(--ds-modal-gap, 1.25rem)) / var(--ds-z, 1) - 75px) !important;
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
    }

    /* ——— نافذة قيود المواد (Subject Restrictions Modal) ——— */
    html body #subjectRestrictionsModal .modal-content,
    html body #subjectRestrictionsModal .subj-ref-modal-card {
        padding: 0.5rem 0.75rem !important;
    }
    html body #subjectRestrictionsModal .modal-header {
        padding: 0.25rem 0.5rem !important;
    }
    html body #subjectRestrictionsModal .modal-footer {
        padding: 0.35rem 0.5rem !important;
    }
    html body #subjectRestrictionsModal .validation-card-success {
        padding: 0.35rem 0.65rem !important;
        margin-bottom: 0.35rem !important;
    }
    html body #subjectRestrictionsModal .clay-restriction-card {
        padding: 0.35rem 0.5rem !important;
        margin-bottom: 0.25rem !important;
    }
    html body #subjectRestrictionsModal .clay-scope-box {
        padding: 0.35rem 0.5rem !important;
        margin-bottom: 0.25rem !important;
    }
    html body #subjectRestrictionsModal .clay-grid-table-container {
        padding: 0.35rem !important;
        margin-bottom: 0.35rem !important;
    }
    html body #subjectRestrictionsModal .clay-status-card {
        padding: 2px 4px !important;
        border-radius: 8px !important;
    }
    html body #subjectRestrictionsModal table td {
        height: 32px !important;
        padding: 1.5px !important;
    }
    html body #subjectRestrictionsModal table th {
        padding: 3px 2px !important;
    }

    /* حقول ونماذج النوافذ مدمجة ومريحة للعين وتوفر مساحة عمودية */
    html body .modal .form-control:not(textarea),
    html body .modal .form-select {
        min-height: 30px !important;
        height: 30px !important;
        padding: 0.18rem 0.5rem !important;
        font-size: 0.82rem !important;
        border-radius: var(--ds-radius-sm, 6px) !important;
    }

    html body .modal .form-label {
        font-size: 0.74rem !important;
        font-weight: 600 !important;
        margin-bottom: 0.15rem !important;
        line-height: 1.2 !important;
    }

    html body .modal .modal-header {
        padding: 0.45rem 1rem !important;
        min-height: auto !important;
    }

    html body .modal .modal-footer {
        padding: 0.45rem 1rem !important;
        min-height: auto !important;
    }

    html body .modal .modal-title {
        font-size: 0.95rem !important;
    }

    html body .modal hr {
        margin: 0.4rem 0 !important;
    }

    /* شبكة بطاقات الشعب في نافذة المعلم: 4 أعمدة على الشاشات الكبيرة، 3 على المحمول */
    html body #teacherClassesContainer .row > div {
        flex: 0 0 25% !important;
        max-width: 25% !important;
    }

    @media (max-width: 1199.98px) {
        html body #teacherClassesContainer .row > div {
            flex: 0 0 33.333% !important;
            max-width: 33.333% !important;
        }
    }

    /* بطاقات الشعب المدمجة والأنيقة */
    html body #teacherClassesContainer .card {
        padding: 0.35rem 0.5rem !important;
        margin-bottom: 0.35rem !important;
        border-radius: 8px !important;
    }

    html body #teacherClassesContainer .card h6 {
        font-size: 0.76rem !important;
        margin-bottom: 0.2rem !important;
    }

    html body #teacherClassesContainer .subject-class-row {
        padding: 2px 6px !important;
        min-height: 24px !important;
        border-radius: 20px !important;
        font-size: 0.76rem !important;
    }

    html body #teacherClassesContainer input[type="number"] {
        width: 36px !important;
        height: 22px !important;
        min-height: 22px !important;
        font-size: 0.8rem !important;
        padding: 0 !important;
    }

    /* تحويل حقول نافذة المعلم في العمود الأيمن إلى شبكة ثنائية مدمجة */
    html body #teacherModal .col-xl-4 .row.g-3,
    html body #teacherModal .col-lg-5 .row.g-3 {
        --bs-gutter-y: 0.35rem !important;
        --bs-gutter-x: 0.5rem !important;
    }

    /* حقل الاسم يبقى بعرض كامل */
    html body #teacherModal .col-xl-4 .row.g-3 > .col-12:first-child,
    html body #teacherModal .col-lg-5 .row.g-3 > .col-12:first-child {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* الحقول الأخرى (الشهادة، العنوان، التخصص، الجنس، الحالة، الهاتف) تصبح ثنائية 50% */
    html body #teacherModal .col-xl-4 .row.g-3 > .col-12:not(:first-child):not(#leaveToggleContainer),
    html body #teacherModal .col-lg-5 .row.g-3 > .col-12:not(:first-child):not(#leaveToggleContainer) {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    html body #teacherModal #leaveToggleContainer {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-top: 0.25rem !important;
        padding: 0.35rem 0.65rem !important;
        border-radius: 8px !important;
    }

    /* تقليص الحشو في اللوحة اليمنى واليسرى */
    html body #teacherModal .col-xl-4.p-4,
    html body #teacherModal .col-lg-5.p-4,
    html body #teacherModal .col-xl-8.p-4,
    html body #teacherModal .col-lg-7.p-4 {
        padding: 0.5rem 0.85rem !important;
    }

    html body #teacherModal hr {
        margin: 0.35rem 0 !important;
    }
    html body #teacherModal h6 {
        margin-bottom: 0.35rem !important;
        font-size: 0.82rem !important;
    }

    /* نافذة المعلم: إزالة أي أشرطة تمرير داخلية */
    html body #teacherModal .col-xl-4,
    html body #teacherModal .col-lg-5,
    html body #teacherModal .col-xl-8,
    html body #teacherModal .col-lg-7 {
        overflow: hidden !important;
        max-height: none !important;
    }
}

/* على الهواتف (<768px): النافذة بملء الشاشة مع تمرير داخلي مريح وأزرار لمس كبيرة */
@media (max-width: 767.98px) {
    html body .modal .modal-body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    html body #teacherModal .modal-body .row.g-0 {
        flex-direction: column !important;
        height: auto !important;
    }

    html body #teacherModal #teacherInfoPane,
    html body #teacherModal .col-xl-8,
    html body #teacherModal .col-lg-7 {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        overflow: visible !important;
        max-height: none !important;
    }

    html body #teacherClassesContainer .row > div {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    html body .modal .modal-footer {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    html body .modal .modal-footer .btn {
        width: 100%;
        min-height: 42px;
    }
}

