/* ==========================================================================
   AL-MISHAL PLATFORM — UNIFIED MULTI-DEVICE RESPONSIVE ENGINE (v2.0)
   منظومة التجاوب الذكي وتوحيد العرض عبر (الكمبيوتر، التابلت، والموبايل)
   مشروع «المشعل» التعليمي
   ========================================================================== */

/* --------------------------------------------------------------------------
   TIER 1: COMMON RESPONSIVE & TOUCH STABILIZATION (ALL SCREENS <= 1024px)
   يشمل الهواتف المحمولة والأجهزة اللوحية (التابلت) بجميع أوضاعها
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
    *, *::before, *::after {
        -webkit-tap-highlight-color: transparent !important;
        box-sizing: border-box !important;
    }

    html, body {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        position: relative !important;
        touch-action: manipulation;
        -webkit-font-smoothing: antialiased;
    }

    /* تحرير مساحة المحتوى بالكامل وعدم مزاحمة القائمة الجانبية */
    .main, .page-content, .dashboard-active-content, .view, .container, .main-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }

    /* القائمة الجانبية كدرج منزلق ناعم لجميع الشاشات <= 1024px */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        width: min(320px, 86vw) !important;
        max-width: 86vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        background: rgba(11, 18, 33, 0.98) !important;
        -webkit-backdrop-filter: blur(16px) !important;
        backdrop-filter: blur(16px) !important;
        border-left: 1.5px solid rgba(56, 189, 248, 0.25) !important;
        box-shadow: -10px 0 35px rgba(0, 0, 0, 0.7) !important;
        z-index: 10000 !important;
        transform: translateX(100%) !important;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .sidebar.open {
        transform: translateX(0) !important;
    }

    .sidebar-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 0 16px !important;
        height: 60px !important;
        min-height: 60px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    }

    .sidebar-close-btn {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 38px !important;
        height: 38px !important;
        border-radius: 10px !important;
        background: rgba(255, 255, 255, 0.08) !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        color: #f1f5f9 !important;
        cursor: pointer !important;
        margin-inline-start: auto !important;
        transition: all 0.2s ease !important;
    }

    .sidebar-close-btn:active {
        background: rgba(239, 68, 68, 0.25) !important;
        border-color: rgba(239, 68, 68, 0.5) !important;
        color: #ef4444 !important;
    }

    .sidebar-scroll {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 12px 10px !important;
    }

    .sidebar-profile {
        padding: 12px 14px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
        margin-top: auto !important;
    }

    /* طبقة التعتيم الخلفية عند فتح القائمة */
    .overlay {
        position: fixed !important;
        inset: 0 !important;
        background: rgba(5, 9, 18, 0.72) !important;
        -webkit-backdrop-filter: blur(4px) !important;
        backdrop-filter: blur(4px) !important;
        z-index: 9998 !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transition: opacity 0.28s ease !important;
        display: block !important;
    }

    .overlay.open {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* زر فتح القائمة الجانبية في الشريط العلوي */
    .mobile-menu-btn {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        border-radius: 10px !important;
        background: rgba(56, 189, 248, 0.12) !important;
        border: 1.5px solid rgba(56, 189, 248, 0.35) !important;
        color: #38bdf8 !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
        padding: 0 !important;
        transition: all 0.2s ease !important;
    }

    .mobile-menu-btn:active {
        background: rgba(56, 189, 248, 0.25) !important;
        transform: scale(0.95);
    }

    .mobile-menu-btn svg {
        width: 22px !important;
        height: 22px !important;
        stroke: #38bdf8 !important;
    }

    /* الشريط العلوي المثبت للتابلت والموبايل */
    .topbar, #mainTopbar, .roadmap-header {
        position: sticky !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        z-index: 1000 !important;
        background: rgba(7, 11, 20, 0.92) !important;
        -webkit-backdrop-filter: blur(18px) !important;
        backdrop-filter: blur(18px) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35) !important;
    }

    /* معادلات KaTeX الرياضية — منع انزلاق الصفحة وتمرير لمسي سلس */
    .math-display-wrapper, .katex-display {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 6px 2px !important;
        margin: 6px 0 !important;
        scrollbar-width: thin !important;
    }

    /* مستقيم الأعداد والرسومات الهندسية */
    .math-number-line-container, .math-ch-figure-wrap {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 6px 0 !important;
        border-radius: 12px !important;
    }

    .math-number-line-container svg, .math-ch-figure-wrap svg {
        max-width: 100% !important;
        height: auto !important;
    }

    /* استوديو الدروس وتحديات التمارين */
    .math-ch-step-row, .nb-step-item, .math-ch-solution-card {
        padding: 12px 14px !important;
        border-radius: 14px !important;
        margin-bottom: 10px !important;
        font-size: 14.5px !important;
        line-height: 1.75 !important;
    }

    .scaffold-arena-grid, .math-ch-arena-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        width: 100% !important;
    }

    .scaffold-challenge-zone, .math-ch-challenge-zone {
        width: 100% !important;
        max-width: 100% !important;
        padding: 14px !important;
        border-radius: 16px !important;
    }

    .scaffold-levels-track {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 6px !important;
        padding: 4px 0 10px !important;
        scrollbar-width: none !important;
    }

    .scaffold-levels-track::-webkit-scrollbar {
        display: none !important;
    }

    .scaffold-lvl-pill {
        flex-shrink: 0 !important;
        padding: 6px 12px !important;
        font-size: 12px !important;
        border-radius: 999px !important;
    }

    /* عناصر الإدخال والأزرار بحد أدنى للّمس 44px */
    input, select, textarea {
        font-size: 16px !important;
        border-radius: 12px !important;
    }

    .btn, button.action-btn {
        min-height: 44px !important;
        border-radius: 12px !important;
        font-size: 14px !important;
    }

    body:not(.lesson-studio-page) .math-ch-modal,
    .modal-dialog,
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        max-height: 88vh !important;
        border-radius: 20px !important;
        padding: 16px !important;
        overflow-y: auto !important;
    }

    body.lesson-studio-page,
    body.lesson-studio-page .math-ch-overlay,
    body.lesson-studio-page #mathChapterOverlay {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
    }

    body.lesson-studio-page .math-ch-modal {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
        transform: none !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
}

/* --------------------------------------------------------------------------
   TIER 2: DEDICATED TABLET SYSTEM (769px to 1024px)
   تنسيق استثنائي للأجهزة اللوحية (iPad, Galaxy Tab) في الوضعين الأفقي والعمودي
   -------------------------------------------------------------------------- */
@media (min-width: 769px) and (max-width: 1024px) {
    body {
        padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .page-content, .dashboard-active-content, .container {
        padding: 16px 20px 30px !important;
    }

    /* شريط علوي أنيق للتابلت يتسع لكافة الشارات دون أي تصادم */
    .topbar, #mainTopbar {
        height: 60px !important;
        padding: 0 16px !important;
    }

    .topbar-inner {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        gap: 10px !important;
    }

    .topbar-section-right {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex: 1 !important;
    }

    .user-profile-pill {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 4px 10px 4px 6px !important;
    }

    .user-profile-name {
        max-width: 130px !important;
        font-size: 13px !important;
    }

    .user-profile-grade {
        display: none !important;
    }

    .topbar-badge-currency {
        height: 32px !important;
        padding: 4px 10px !important;
        font-size: 12px !important;
    }

    /* إخفاء الطابع الزمني المزدحم على التابلت لأنه متاح بالقائمة الجانبية */
    .topbar-datetime-badge, .topbar-date-pill {
        display: none !important;
    }

    /* 1. صف معرض الميزات وبطاقة ولي الأمر — عمودين متناسقين تماماً */
    .dashboard-visuals-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 16px !important;
        margin-bottom: 20px !important;
    }

    .dashboard-visual-card {
        height: 195px !important;
        min-height: 195px !important;
        max-height: 195px !important;
        border-radius: 18px !important;
        overflow: hidden !important;
    }

    .feature-showcase-slider {
        padding: 16px 18px !important;
    }

    /* 2. صف مؤشرات الإتقان وخريطة المهارات — عمودين متناسقين ومتجاورين */
    .dashboard-hub-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 16px !important;
        margin-bottom: 22px !important;
        width: 100% !important;
    }

    #masterLearningLoopCard, #dashboardSkillsMapCard {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
    }

    #masterLearningLoopCard .card, #dashboardSkillsMapCard .card {
        max-width: 100% !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* 3. شبكة الفصول الدراسية للتابلت — عمودين واسعين ومرتبين */
    .dashboard-chapters-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 14px !important;
        width: 100% !important;
    }

    .dashboard-chapter-card {
        padding: 14px 16px !important;
        border-radius: 16px !important;
    }

    /* 4. الشريط السفلي للتابلت */
    .mobile-bottom-nav {
        height: calc(62px + env(safe-area-inset-bottom, 0px)) !important;
        grid-template-columns: repeat(5, 1fr) !important;
    }

    .mobile-nav-item {
        font-size: 11.5px !important;
    }

    .mobile-nav-item i, .mobile-nav-item svg {
        width: 22px !important;
        height: 22px !important;
    }
}

/* --------------------------------------------------------------------------
   TIER 3: DEDICATED SMARTPHONE SYSTEM (<= 768px)
   تجربة تطبيق هاتف أصيل — فك الازدحام، تنظيم هرمي للبطاقات، وسهولة تامة باليد الواحدة
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    body {
        padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .page-content, .dashboard-active-content, .container {
        padding: 10px 12px 24px !important;
    }

    /* 1. الشريط العلوي الذكي للهاتف (صف واحد نقي بنسبة 100%) */
    .topbar, #mainTopbar {
        height: 54px !important;
        min-height: 54px !important;
        padding: 0 10px !important;
    }

    .topbar-inner {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        gap: 6px !important;
    }

    .topbar-section-right {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    .user-profile-pill, #user-profile-widget {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 3px 6px !important;
        border-radius: 999px !important;
        background: rgba(255, 255, 255, 0.06) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0 !important;
    }

    .user-profile-avatar, #user-profile-avatar {
        width: 28px !important;
        height: 28px !important;
    }

    .user-profile-name, #user-profile-name {
        font-size: 11.5px !important;
        font-weight: 800 !important;
        max-width: 80px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .user-profile-grade, #user-profile-grade {
        display: none !important;
    }

    .topbar-badge-currency {
        height: 28px !important;
        padding: 2px 7px !important;
        font-size: 11px !important;
        border-radius: 999px !important;
        gap: 3px !important;
        flex-shrink: 0 !important;
    }

    .topbar-badge-currency img {
        width: 14px !important;
        height: 14px !important;
    }

    /* إخفاء الشارات المزدحمة في الشريط العلوي على الهاتف لضمان عدم حدوث أي سطر ثانٍ */
    #streakPopoverWrap,
    #challengePopoverWrap,
    #levelPopoverWrap,
    #badge-xp,
    .topbar-datetime-badge,
    .topbar-date-pill,
    .header-stats {
        display: none !important;
    }

    .topbar-notification-wrapper {
        margin-inline-start: auto !important;
        flex-shrink: 0 !important;
    }

    .topbar-notification-btn {
        width: 34px !important;
        height: 34px !important;
        border-radius: 10px !important;
    }

    /* 2. منطقة الترحيب والمعرض — فك الازدحام الرأسي تماماً */
    .dashboard-visuals-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        margin-bottom: 14px !important;
    }

    /* بطاقة السلايدر التفاعلي المدمجة حسب حجم النصوص وبدون أي فراغ زائد */
    .dashboard-visual-card.feature-showcase-slider,
    .feature-showcase-slider,
    #featureShowcaseSlider {
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        flex: none !important;
        padding: 12px 14px 10px !important;
        border-radius: 16px !important;
        width: 100% !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        gap: 6px !important;
    }

    .showcase-badge-row {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        margin-bottom: 2px !important;
        flex-shrink: 0 !important;
    }

    .showcase-badge {
        font-size: 11px !important;
        font-weight: 800 !important;
        padding: 3px 9px !important;
        border-radius: 999px !important;
        max-width: 80% !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .showcase-counter {
        font-size: 10.5px !important;
        font-weight: 800 !important;
        padding: 2px 7px !important;
        border-radius: 10px !important;
        flex-shrink: 0 !important;
    }

    /* جعل مسار الشرائح بحجم النص تماماً بالاعتماد على CSS Grid ليحتضن النصوص بدون فراغ */
    .showcase-slide-track {
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr !important;
        min-height: auto !important;
        flex: none !important;
        width: 100% !important;
        position: relative !important;
        margin: 2px 0 !important;
    }

    .showcase-slide {
        grid-column: 1 / 2 !important;
        grid-row: 1 / 2 !important;
        position: relative !important;
        inset: auto !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        width: 100% !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        transform: translateX(12px) !important;
        transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s !important;
    }

    .showcase-slide.active {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transform: translateX(0) !important;
    }

    .showcase-content {
        display: flex !important;
        align-items: flex-start !important;
        gap: 10px !important;
        padding: 2px 0 !important;
        flex: none !important;
    }

    .showcase-icon-box {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        font-size: 19px !important;
        border-radius: 10px !important;
        margin-top: 1px !important;
        flex-shrink: 0 !important;
    }

    .showcase-texts {
        flex: 1 !important;
        min-width: 0 !important;
    }

    .showcase-title {
        font-size: 14.5px !important;
        font-weight: 900 !important;
        margin: 0 !important;
        line-height: 1.3 !important;
        color: #ffffff !important;
    }

    .showcase-subtitle {
        font-size: 11px !important;
        font-weight: 700 !important;
        margin: 2px 0 4px !important;
        line-height: 1.3 !important;
    }

    .showcase-desc {
        font-size: 11.5px !important;
        line-height: 1.5 !important;
        color: #cbd5e1 !important;
        font-weight: 500 !important;
        margin: 0 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }

    .showcase-footer-bar {
        margin-top: 4px !important;
        padding-top: 8px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }

    .showcase-cta-btn {
        font-size: 12px !important;
        padding: 6px 12px !important;
        height: 35px !important;
        border-radius: 10px !important;
        font-weight: 800 !important;
        flex: 1 !important;
        justify-content: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .showcase-nav-controls {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        flex-shrink: 0 !important;
    }

    .showcase-nav-btn {
        width: 34px !important;
        height: 34px !important;
        border-radius: 8px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255, 255, 255, 0.08) !important;
        border: 1px solid rgba(255, 255, 255, 0.14) !important;
        color: #ffffff !important;
    }

    .showcase-nav-btn svg {
        width: 17px !important;
        height: 17px !important;
    }

    /* تحويل بطاقة ولي الأمر من صورة ضخمة إلى شريط زجاجي فخم ومرتب (ارتفاع 68px بدلاً من 200px) */
    .dashboard-visual-card:not(.feature-showcase-slider) {
        min-height: unset !important;
        height: 68px !important;
        max-height: 68px !important;
        border-radius: 14px !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 8px 12px !important;
        background: radial-gradient(120% 120% at 85% 50%, rgba(2, 132, 199, 0.35) 0%, rgba(15, 23, 42, 0.95) 100%) !important;
        border: 1.5px solid rgba(56, 189, 248, 0.32) !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35) !important;
        position: relative !important;
        overflow: hidden !important;
        width: 100% !important;
    }

    .dashboard-visual-card:not(.feature-showcase-slider) .dashboard-visual-img {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        border-radius: 50% !important;
        object-fit: cover !important;
        position: static !important;
        border: 2px solid #38bdf8 !important;
        box-shadow: 0 0 10px rgba(56, 189, 248, 0.4) !important;
        margin: 0 !important;
    }

    .parent-portal-mobile-text {
        display: flex !important;
        flex-direction: column !important;
        margin-right: 12px !important;
        margin-left: auto !important;
        min-width: 0 !important;
        flex: 1 !important;
    }

    .dashboard-visual-card:not(.feature-showcase-slider) .parent-portal-glass-btn {
        position: static !important;
        background: linear-gradient(135deg, rgba(2, 132, 199, 0.85), rgba(37, 99, 235, 0.95)) !important;
        border: 1px solid rgba(56, 189, 248, 0.5) !important;
        padding: 6px 14px !important;
        font-size: 11.5px !important;
        font-weight: 800 !important;
        border-radius: 999px !important;
        box-shadow: 0 2px 10px rgba(2, 132, 199, 0.45) !important;
        color: #ffffff !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 6px !important;
    }

    /* 3. بطاقات التقدم الأكاديمي وخريطة المهارات للهاتف */
    .dashboard-hub-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        margin-bottom: 14px !important;
    }

    #masterLearningLoopCard, #dashboardSkillsMapCard {
        width: 100% !important;
        max-width: 100% !important;
        flex: 1 1 100% !important;
    }

    #masterLearningLoopCard .card, #dashboardSkillsMapCard .card {
        padding: 10px 12px !important;
        border-radius: 16px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* شبكة الـ 2x2 لمؤشرات الإتقان — متوازنة تماماً وبدون أي ضغط */
    .stat-card-critical, .stat-card-completed, .stat-card-mastered, .stat-card-practice {
        padding: 7px 8px !important;
        border-radius: 12px !important;
    }

    /* 4. شبكة الفصول الدراسية كقائمة تطبيق أصيل */
    .dashboard-chapters-section {
        margin-top: 8px !important;
        margin-bottom: 18px !important;
    }

    .dashboard-chapters-header {
        margin-bottom: 10px !important;
    }

    .dashboard-chapters-header-title {
        font-size: 15px !important;
    }

    .dashboard-chapters-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .dashboard-chapter-card {
        display: grid !important;
        grid-template-columns: auto 1fr auto !important;
        align-items: center !important;
        gap: 10px !important;
        padding: 10px 12px !important;
        border-radius: 14px !important;
        background: rgba(14, 23, 42, 0.90) !important;
        border: 1.5px solid rgba(255, 255, 255, 0.08) !important;
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25) !important;
    }

    .dashboard-chapter-icon-wrap {
        width: 38px !important;
        height: 38px !important;
        border-radius: 10px !important;
        grid-row: span 2 !important;
    }

    .dashboard-chapter-icon-wrap svg {
        width: 18px !important;
        height: 18px !important;
    }

    .dashboard-chapter-title {
        font-size: 14px !important;
        font-weight: 800 !important;
    }

    .dashboard-chapter-subtitle {
        font-size: 11px !important;
        color: #94a3b8 !important;
        max-width: 160px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .dashboard-chapter-progress-row {
        grid-column: 2 !important;
        font-size: 10.5px !important;
        margin-top: 3px !important;
    }

    .dashboard-chapter-progress-bar {
        grid-column: 2 !important;
        height: 4.5px !important;
        margin-top: 3px !important;
    }

    .dashboard-chapter-btn {
        grid-column: 3 !important;
        grid-row: span 2 !important;
        padding: 7px 11px !important;
        font-size: 11.5px !important;
        font-weight: 800 !important;
        border-radius: 10px !important;
    }

    /* 5. مسار دروس الفصل (Roadmap Vertical Track) */
    .chapter-hero {
        padding: 14px 10px 10px !important;
    }

    .chapter-hero h1 {
        font-size: 17.5px !important;
        line-height: 1.35 !important;
    }

    .chapter-hero p {
        font-size: 12px !important;
    }

    .roadmap-track-container {
        padding: 6px 0 16px !important;
    }

    .roadmap-horizontal-track {
        flex-direction: column !important;
        min-width: 0 !important;
        width: 100% !important;
        gap: 10px !important;
        align-items: stretch !important;
        padding: 0 !important;
    }

    .lesson-node-card {
        max-width: 100% !important;
        width: 100% !important;
        padding: 10px 12px !important;
        border-radius: 14px !important;
        gap: 10px !important;
        flex-direction: row !important;
        align-items: center !important;
    }

    .node-circle-wrap {
        width: 48px !important;
        height: 48px !important;
    }

    .node-title {
        font-size: 13.5px !important;
    }

    .node-desc {
        font-size: 11px !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }

    .horizontal-arrow-connector {
        transform: rotate(-90deg) !important;
        margin: 0 auto !important;
        height: 20px !important;
    }

    /* 6. الشريط السفلي للهاتف الفاخر */
    .mobile-bottom-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: calc(58px + env(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        background: rgba(10, 16, 28, 0.96) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        backdrop-filter: blur(20px) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.5) !important;
        display: grid !important;
        grid-template-columns: repeat(5, 1fr) !important;
        z-index: 9999 !important;
    }

    .mobile-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 3px !important;
        color: #94a3b8 !important;
        font-size: 10px !important;
        font-weight: 700 !important;
        background: transparent !important;
        border: none !important;
        cursor: pointer !important;
        padding: 5px 0 !important;
    }

    .mobile-nav-item i, .mobile-nav-item svg {
        width: 20px !important;
        height: 20px !important;
        stroke-width: 2.2px !important;
    }

    .mobile-nav-item.active {
        color: #38bdf8 !important;
    }

    .mobile-nav-item.active i, .mobile-nav-item.active svg {
        transform: translateY(-2px) scale(1.08) !important;
        stroke: #38bdf8 !important;
        filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.6)) !important;
    }

    /* 7. صفحة تسجيل الدخول للهاتف */
    .login-layout-wrapper {
        min-height: 100vh !important;
        overflow-y: auto !important;
        flex-direction: column !important;
    }

    .cover-image-section {
        height: 140px !important;
        width: 100% !important;
        flex: none !important;
    }

    .login-form-section {
        padding: 16px 14px 30px !important;
        width: 100% !important;
    }

    /* --------------------------------------------------------------------------
       8. LESSON STUDIO MOBILE ENGINE (استوديو شرح الدروس للهواتف الذكية)
       معالجة جذرية للتزاحم والتداخل في الشريط العلوي وشرائط التنقل وبطاقات المسائل
       -------------------------------------------------------------------------- */
    .math-ch-header {
        height: auto !important;
        min-height: auto !important;
        padding: 8px 12px !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 6px !important;
        background: rgba(13, 19, 33, 0.98) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0 !important;
        z-index: 30 !important;
    }

    .math-ch-header-info {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }

    .math-ch-studio-back-btn {
        padding: 5px 10px !important;
        font-size: 11.5px !important;
        border-radius: 8px !important;
        gap: 4px !important;
        flex-shrink: 0 !important;
        white-space: nowrap !important;
    }

    .math-ch-header-info > div {
        min-width: 0 !important;
        flex: 1 !important;
    }

    /* إخفاء اسم الفصل الطويل في الهيدر على الهاتف لمنع الاصطدام بالعناوين والأزرار */
    .math-ch-header-info > div > span {
        display: none !important;
    }

    .math-ch-header-title {
        font-size: 13.5px !important;
        font-weight: 800 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin: 0 !important;
        max-width: 175px !important;
        color: #ffffff !important;
    }

    .math-ch-header-actions {
        display: flex !important;
        align-items: center !important;
        flex-shrink: 0 !important;
        margin-inline-start: auto !important;
    }

    .math-ch-close-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
    }

    /* شريط التبويب (الشرح والأمثلة / القواعد والنظريات) ممتد بنظام النصفين في السطر الثاني */
    .math-ch-studio-tabs {
        width: 100% !important;
        order: 3 !important;
        display: flex !important;
        gap: 6px !important;
        margin-top: 4px !important;
        padding-top: 6px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
    }

    .math-ch-tab-btn {
        flex: 1 1 50% !important;
        justify-content: center !important;
        padding: 6px 8px !important;
        font-size: 12px !important;
        font-weight: 800 !important;
        border-radius: 8px !important;
        gap: 6px !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    /* شريط معلومات المسألة والمهارة العلوي */
    .math-ch-slide-strip-top {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 6px !important;
        padding: 4px 6px !important;
        margin-bottom: 4px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        flex-shrink: 0 !important;
    }
    .math-ch-slide-strip-top::-webkit-scrollbar {
        display: none !important;
    }

    .math-ch-strip-right,
    .math-ch-strip-left {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        flex-shrink: 0 !important;
    }

    .math-ch-slide-counter-badge {
        padding: 3px 8px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    .math-ch-pool-badge,
    .math-ch-diff-badge,
    .math-ch-strip-skill-badge {
        padding: 3px 8px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    /* إخفاء تكرار عنوان الدرس داخل شريط المسألة لأنه معروض بأعلى الهيدر */
    .math-ch-strip-topic-badge {
        display: none !important;
    }

    /* مساحة المحتوى وبطاقات الخطوات */
    .math-ch-body {
        padding: 6px 8px !important;
        min-height: 0 !important;
        flex: 1 !important;
    }

    .math-ch-studio-view,
    .math-ch-studio-workspace {
        gap: 6px !important;
        min-height: 0 !important;
        height: 100% !important;
    }

    .math-ch-vertical-flow {
        gap: 12px !important;
        padding: 4px 4px 16px 4px !important;
    }

    .math-ch-section-card,
    .math-ch-triptych-col {
        border-radius: 14px !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
    }

    .math-ch-col-header {
        padding: 10px 12px !important;
    }

    .math-ch-col-icon-badge {
        width: 30px !important;
        height: 30px !important;
        border-radius: 8px !important;
        font-size: 14px !important;
    }

    .math-ch-col-title {
        font-size: 13.5px !important;
    }

    .math-ch-col-subtitle {
        font-size: 10px !important;
    }

    .math-ch-section-body {
        padding: 12px 10px !important;
        gap: 12px !important;
    }

    .math-ch-problem-text {
        font-size: 14px !important;
        line-height: 1.7 !important;
    }

    .math-ch-slide-math-box {
        padding: 10px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .math-ch-theory-desc,
    .math-ch-step-text {
        font-size: 13px !important;
        line-height: 1.75 !important;
    }

    /* شريط التنقل السفلي بالأمثلة المحلولة وحل مشكلة الـ 30 عنصر وتداخل سفاري */
    .math-ch-slide-strip-bottom {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 6px !important;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)) 8px !important;
        background: rgba(11, 18, 33, 0.96) !important;
        -webkit-backdrop-filter: blur(14px) !important;
        backdrop-filter: blur(14px) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0 !important;
        z-index: 40 !important;
    }

    .math-ch-nav-icon-btn {
        padding: 7px 10px !important;
        font-size: 11.5px !important;
        border-radius: 8px !important;
        flex-shrink: 0 !important;
        gap: 4px !important;
        min-height: 36px !important;
    }

    .math-ch-continue-btn {
        padding: 7px 12px !important;
        font-size: 12px !important;
        font-weight: 800 !important;
        border-radius: 8px !important;
        flex-shrink: 0 !important;
        gap: 4px !important;
        min-height: 36px !important;
    }

    .math-ch-dots-nav {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        display: flex !important;
        align-items: center !important;
        gap: 5px !important;
        padding: 2px 6px !important;
        border-radius: 999px !important;
        background: rgba(15, 23, 42, 0.7) !important;
    }
    .math-ch-dots-nav::-webkit-scrollbar {
        display: none !important;
    }

    .math-ch-dot-pill {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        font-size: 10.5px !important;
        border-radius: 50% !important;
        flex-shrink: 0 !important;
    }
}

/* --------------------------------------------------------------------------
   TIER 4: MOBILE LANDSCAPE MODE (الوضع الأفقي للهاتف)
   -------------------------------------------------------------------------- */
@media (max-height: 560px) and (orientation: landscape) {
    .topbar, #mainTopbar {
        height: 46px !important;
        min-height: 46px !important;
    }

    .mobile-bottom-nav {
        height: 44px !important;
        padding-bottom: 0 !important;
    }

    .mobile-nav-item {
        padding: 2px 0 !important;
        font-size: 9.5px !important;
    }

    .mobile-nav-item i, .mobile-nav-item svg {
        width: 16px !important;
        height: 16px !important;
    }

    body {
        padding-bottom: 50px !important;
    }

    .dashboard-visuals-row {
        flex-direction: row !important;
        gap: 12px !important;
    }

    .dashboard-visual-card {
        flex: 1 1 50% !important;
        height: 150px !important;
        min-height: 150px !important;
    }

    .dashboard-hub-row {
        flex-direction: row !important;
        gap: 12px !important;
    }

    #masterLearningLoopCard, #dashboardSkillsMapCard {
        flex: 1 1 50% !important;
    }

    .dashboard-chapters-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    /* تهيئة استوديو الشرح والأمثلة للوضع الأفقي على الهواتف */
    body.lesson-studio-page .math-ch-header {
        height: 42px !important;
        min-height: 42px !important;
        padding: 4px 12px !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
    }

    body.lesson-studio-page .math-ch-header-info {
        gap: 6px !important;
    }

    body.lesson-studio-page .math-ch-studio-back-btn {
        padding: 4px 8px !important;
        font-size: 11px !important;
    }

    body.lesson-studio-page .math-ch-header-title {
        font-size: 12.5px !important;
        max-width: 220px !important;
    }

    body.lesson-studio-page .math-ch-studio-tabs {
        width: auto !important;
        order: unset !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        gap: 4px !important;
    }

    body.lesson-studio-page .math-ch-tab-btn {
        flex: none !important;
        padding: 4px 10px !important;
        font-size: 11px !important;
        height: 30px !important;
    }

    body.lesson-studio-page .math-ch-close-btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 12px !important;
    }

    body.lesson-studio-page .math-ch-slide-strip-top {
        padding: 2px 6px !important;
        margin-bottom: 2px !important;
        gap: 4px !important;
    }

    body.lesson-studio-page .math-ch-slide-counter-badge,
    body.lesson-studio-page .math-ch-pool-badge,
    body.lesson-studio-page .math-ch-diff-badge {
        font-size: 10px !important;
        padding: 2px 6px !important;
    }

    body.lesson-studio-page .math-ch-slide-strip-bottom {
        height: 38px !important;
        min-height: 38px !important;
        padding: 2px 8px !important;
    }

    body.lesson-studio-page .math-ch-nav-icon-btn,
    body.lesson-studio-page .math-ch-continue-btn {
        padding: 4px 8px !important;
        font-size: 11px !important;
        min-height: 30px !important;
    }

    body.lesson-studio-page .math-ch-dots-nav {
        padding: 2px 4px !important;
    }

    body.lesson-studio-page .math-ch-dot-pill {
        width: 22px !important;
        height: 22px !important;
        min-width: 22px !important;
        font-size: 10px !important;
    }

    body.lesson-studio-page .math-ch-vertical-flow {
        gap: 8px !important;
        padding: 4px 8px 10px 8px !important;
    }

    body.lesson-studio-page .math-ch-col-header {
        padding: 6px 10px !important;
    }

    body.lesson-studio-page .math-ch-section-body {
        padding: 8px 10px !important;
        gap: 8px !important;
    }
}

/* --------------------------------------------------------------------------
   TIER 5: PURE DESKTOP PROTECTION (> 1024px)
   الحفاظ الكامل والتام على تصميم الكمبيوتر الحالي المستقر والمحبوب بدون أي مساس
   -------------------------------------------------------------------------- */
@media (min-width: 1025px) {
    .mobile-menu-btn {
        display: none !important;
    }

    .sidebar-close-btn {
        display: none !important;
    }

    .mobile-bottom-nav {
        display: none !important;
    }

    .sidebar {
        transform: translateX(0) !important;
        position: fixed !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: var(--sidebar-width, 280px) !important;
        box-shadow: -6px 0 30px rgba(0, 0, 0, 0.35) !important;
    }

    .main {
        margin-right: var(--sidebar-width, 280px) !important;
        width: calc(100% - var(--sidebar-width, 280px)) !important;
    }
}
