/* ============================================================
   MOBILE ONLY — معزول تمامًا عن الديسكتوب
   يُطبَّق فقط عند max-width: 768px
   ============================================================ */

/* ---- إخفاء الهيدر الأصلي على الجوال ---- */
@media (max-width: 768px) {
    nav.navbar, 
    .app-layout .sb2, 
    .app-layout .topbar,
    .sidebar-overlay,
    .mobile-toggle,
    .sb2 {
        display: none !important;
    }
    .app-layout .main-content {
        margin-right: 0 !important;
        margin-left: 0 !important;
        padding-top: 62px !important; /* لترك مساحة للهيدر الجديد */
        width: 100% !important;
        max-width: 100vw !important;
    }
    div[style*="margin-top: 70px"] {
        margin-top: 0 !important;
    }
}

/* ============================================================
   MOBILE TOPBAR — الشريط العلوي للجوال
   ============================================================ */
.mobile-topbar {
    display: none;
}

@media (max-width: 768px) {
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        z-index: 1050;
        height: 62px;
        padding: 0 16px;
        background: var(--navbar-bg, rgba(255,255,255,0.97));
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
        box-shadow: 0 2px 12px rgba(0,0,0,0.08);
        border-bottom: 1px solid rgba(0,0,0,0.05);
        color: var(--navbar-text, #1a1a2e);
    }

    /* Logo + Site name */
    .mobile-topbar .mob-brand {
        display: flex;
        align-items: center;
        gap: 8px;
        text-decoration: none;
        color: var(--navbar-text, #1a1a2e);
        font-weight: 700;
        font-size: 0.95rem;
        flex: 1;
        min-width: 0;
    }

    .mobile-topbar .mob-brand img,
    .mobile-topbar .mob-brand .mob-logo-icon {
        width: 34px;
        height: 34px;
        object-fit: contain;
        flex-shrink: 0;
    }

    .mobile-topbar .mob-brand span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-topbar .mob-home-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 38px;
        padding: 0 10px;
        border-radius: 999px;
        border: 1px solid rgba(0,0,0,0.08);
        background: #fff;
        color: var(--navbar-text, #1a1a2e);
        text-decoration: none;
        font-size: 0.78rem;
        font-weight: 700;
        flex-shrink: 0;
        white-space: nowrap;
    }

    .mobile-topbar .mob-home-btn:hover,
    .mobile-topbar .mob-home-btn:active {
        background: rgba(0,0,0,0.05);
    }

    .mobile-topbar .mob-home-btn.is-active,
    .mobile-topbar .mob-home-btn[aria-disabled="true"] {
        background: rgba(var(--bs-primary-rgb, 13,110,253), 0.10);
        border-color: rgba(var(--bs-primary-rgb, 13,110,253), 0.20);
        color: var(--bs-primary, #0d6efd);
        pointer-events: none;
    }

    /* زر القائمة الجانبية */
    .mobile-topbar .mob-menu-btn {
        background: none;
        border: none;
        padding: 8px;
        cursor: pointer;
        color: var(--navbar-text, #1a1a2e);
        font-size: 1.25rem;
        flex-shrink: 0;
        border-radius: 10px;
        transition: background 0.2s;
    }

    .mobile-topbar .mob-menu-btn:hover,
    .mobile-topbar .mob-menu-btn:active {
        background: rgba(0,0,0,0.07);
    }

    /* أيقونة الحساب */
    .mobile-topbar .mob-account-btn {
        background: none;
        border: none;
        padding: 4px;
        cursor: pointer;
        color: var(--navbar-text, #1a1a2e);
        font-size: 1.3rem;
        flex-shrink: 0;
        border-radius: 50%;
        width: 38px;
        height: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.2s;
        text-decoration: none;
    }

    .mobile-topbar .mob-account-btn:hover {
        background: rgba(0,0,0,0.07);
    }

    .mobile-topbar .mob-account-btn img {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        object-fit: cover;
        border: 2px solid rgba(var(--bs-primary-rgb, 13,110,253), 0.3);
    }

    /* Spacer بعد الهيدر */
    .mobile-spacer {
        height: 62px;
    }
}

@media (max-width: 560px) {
    .mobile-topbar .mob-home-btn span {
        display: none;
    }

    .mobile-topbar .mob-home-btn {
        width: 38px;
        padding: 0;
        justify-content: center;
    }
}

/* ============================================================
   MOBILE DRAWER — القائمة الجانبية المنزلقة
   ============================================================ */
.mobile-drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 1080;
    transition: background 0.3s ease;
}

.mobile-drawer {
    position: fixed;
    top: 0;
    right: -100%;
    width: 82%;
    max-width: 340px;
    height: 100%;
    background: #fff;
    z-index: 1090;
    box-shadow: -6px 0 30px rgba(0,0,0,0.15);
    transition: right 0.35s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

@media (min-width: 769px) {
    .mobile-drawer-overlay,
    .mobile-drawer {
        display: none !important;
    }
}

@media (max-width: 768px) {
    /* عند الفتح */
    .mobile-drawer-overlay.open {
        display: block;
        background: rgba(0,0,0,0.45);
    }

    .mobile-drawer.open {
        right: 0;
    }

    /* هيدر القائمة الجانبية */
    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18px 16px 14px;
        border-bottom: 1px solid rgba(0,0,0,0.07);
        flex-shrink: 0;
        background: var(--navbar-bg, #fff);
    }

    .mobile-drawer-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        text-decoration: none;
        color: var(--navbar-text, #1a1a2e);
        font-weight: 700;
        font-size: 1rem;
    }

    .mobile-drawer-brand img,
    .mobile-drawer-brand .mob-logo-icon {
        width: 36px;
        height: 36px;
        object-fit: contain;
        border-radius: 8px;
    }

    .mobile-drawer-close {
        background: rgba(0,0,0,0.06);
        border: none;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        color: #555;
        transition: background 0.2s;
    }

    .mobile-drawer-close:hover {
        background: rgba(0,0,0,0.12);
    }

    /* قائمة العناصر */
    .mobile-drawer-nav {
        list-style: none;
        margin: 0;
        padding: 12px 0;
        flex: 1;
    }

    .mobile-drawer-nav li a {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 13px 20px;
        text-decoration: none;
        color: #2c2c2c;
        font-weight: 600;
        font-size: 0.97rem;
        border-right: 3px solid transparent;
        transition: all 0.2s ease;
    }

    .mobile-drawer-nav li a:hover,
    .mobile-drawer-nav li a.active {
        background: rgba(var(--bs-primary-rgb, 13,110,253), 0.06);
        color: var(--primary-color, #0d6efd);
        border-right-color: var(--primary-color, #0d6efd);
    }

    .mobile-drawer-nav li a i {
        width: 20px;
        text-align: center;
        font-size: 1rem;
        color: var(--primary-color, #0d6efd);
        flex-shrink: 0;
    }

    .mobile-drawer-nav li.drawer-divider {
        height: 1px;
        background: rgba(0,0,0,0.06);
        margin: 8px 16px;
    }

    /* تذييل القائمة الجانبية */
    .mobile-drawer-footer {
        padding: 16px;
        border-top: 1px solid rgba(0,0,0,0.07);
        flex-shrink: 0;
    }

    .mobile-drawer-footer a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 16px;
        border-radius: 10px;
        text-decoration: none;
        font-weight: 600;
        font-size: 0.9rem;
    }

    .mob-logout-btn {
        color: #dc3545;
        background: rgba(220,53,69,0.06);
    }

    .mob-login-btn {
        color: var(--primary-color, #0d6efd);
        background: rgba(var(--bs-primary-rgb, 13,110,253), 0.08);
        margin-bottom: 8px;
    }
}

/* ============================================================
   MOBILE BOTTOM NAV — القائمة السفلية الثابتة
   ============================================================ */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        align-items: stretch;
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        z-index: 9999; /* Higher z-index to stay on top */
        height: 65px;
        background: rgba(255, 255, 255, 0.9);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        box-shadow: 0 -2px 20px rgba(0,0,0,0.08);
        border-top: 1px solid rgba(0,0,0,0.05);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mobile-bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: #888;
        font-size: 0.68rem;
        font-weight: 600;
        transition: color 0.2s ease;
        position: relative;
        padding: 6px 2px;
    }

    .mobile-bottom-nav a i {
        font-size: 1.15rem;
        transition: transform 0.2s ease;
    }

    .mobile-bottom-nav a:hover,
    .mobile-bottom-nav a.active {
        color: var(--primary-color, #0d6efd);
    }

    .mobile-bottom-nav a.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        right: 20%;
        height: 3px;
        border-radius: 0 0 4px 4px;
        background: var(--primary-color, #0d6efd);
    }

    .mobile-bottom-nav a.active i {
        transform: scale(1.15);
    }

    /* padding للمحتوى حتى لا تغطيه القائمة السفلية */
    body {
        padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ============================================================
   MOBILE PAGE ENHANCEMENTS — تحسينات الصفحة الرئيسية للجوال
   ============================================================ */

/* شريط البحث بعد الهيدر */
.mobile-search-bar {
    display: none;
}

@media (max-width: 768px) {
    .mobile-search-bar {
        display: block;
        padding: 12px 16px 8px;
        background: var(--navbar-bg, #f8f9fa);
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }

    .mobile-search-bar form {
        display: flex;
        align-items: center;
        background: #fff;
        border: 1.5px solid rgba(0,0,0,0.1);
        border-radius: 25px;
        padding: 6px 16px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    }

    .mobile-search-bar input {
        flex: 1;
        border: none;
        outline: none;
        background: transparent;
        font-size: 0.9rem;
        font-family: 'Cairo', sans-serif;
        color: #333;
        padding: 0;
    }

    .mobile-search-bar button {
        background: none;
        border: none;
        color: var(--primary-color, #0d6efd);
        font-size: 1rem;
        padding: 0;
        cursor: pointer;
    }
}

/* ============================================================
   FASLY SYSTEM RESPONSIVENESS — تحسينات نظام فصلي للجوال
   ============================================================ */
@media (max-width: 768px) {
    /* تحسينات الجداول */
    .table-responsive {
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        margin-bottom: 20px;
    }
    
    .data-table th, .data-table td {
        padding: 10px 12px !important;
        font-size: 0.85rem !important;
    }

    /* تحسينات البطاقات */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important; /* عمودين في الإحصائيات */
        gap: 10px !important;
    }
    
    .stat-card {
        padding: 12px !important;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .stat-icon {
        margin-bottom: 8px;
    }

    .stat-info h4 {
        font-size: 1.25rem !important;
    }

    .classrooms-grid {
        grid-template-columns: 1fr !important; /* عمود واحد للفصول */
        gap: 15px !important;
    }

    .page-content {
        padding: 12px !important;
    }

    /* المودالات على الجوال */
    .modal {
        width: 95% !important;
        max-height: 85vh !important;
    }
}
