/* Global Mobile Adjustments */
@media (max-width: 768px) {

    /* --- Mobile Page Headers (Internal) --- */
    .mobile-page-header {
        margin-bottom: 1rem !important;
        background: #fff;
        padding: 1rem;
        margin: -1rem -0.5rem 1rem -0.5rem;
        /* Negative margin to stretch full width in container */
        border-bottom: 1px solid #f1f5f9;
        flex-direction: row;
        align-items: center;
        border-radius: 0 0 1rem 1rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    }

    .mobile-h3 {
        font-size: 1.2rem !important;
        margin-bottom: 0 !important;
    }

    .mobile-date-badge {
        padding: 0.35rem 0.75rem !important;
        font-size: 0.75rem;
    }

    /* Adjust main content padding on mobile for cleaner look */
    .container-fluid.p-4.bg-light {
        padding: 1rem 0.5rem !important;
    }

    /* Exam Header Specifics */
    .exam-header-mobile {
        margin-bottom: 1rem !important;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .exam-header-title-mobile {
        font-size: 1.4rem !important;
    }

    .small-mobile {
        font-size: 0.8rem;
    }

    /* Hide breadcrumbs on mobile to save space */
    .breadcrumb-mobile-wrapper {
        display: none !important;
    }

    /* --- Typography Scaling --- */
    h1,
    .h1 {
        font-size: 1.5rem !important;
    }

    h2,
    .h2 {
        font-size: 1.25rem !important;
    }

    h3,
    .h3 {
        font-size: 1.1rem !important;
    }

    h4,
    .h4 {
        font-size: 1rem !important;
    }

    /* --- Layout & Spacing --- */
    .container,
    .container-fluid {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }

    .main-content {
        padding: 1rem 0.5rem !important;
        /* Reduced padding on mobile */
    }

    .mb-mobile-3 {
        margin-bottom: 1rem !important;
    }

    /* --- Cards --- */
    .card {
        margin-bottom: 1rem;
        border-radius: 0.75rem !important;
    }

    .card-body {
        padding: 1rem !important;
    }

    /* --- Stats Grid (Dashboard) --- */
    .stats-grid,
    .row-cols-md-3,
    .row-cols-lg-4 {
        display: grid;
        grid-template-columns: 1fr !important;
        /* Stack columns */
        gap: 1rem;
    }

    /* Restore bootstrap row behavior if needed, but grid is often better */
    .row {
        margin-right: 0;
        margin-left: 0;
    }

    .col,
    .col-1,
    .col-2,
    .col-3,
    .col-4,
    .col-5,
    .col-6,
    .col-7,
    .col-8,
    .col-9,
    .col-10,
    .col-11,
    .col-12 {
        padding-right: 0.5rem;
        padding-left: 0.5rem;
    }

    /* --- Tables (Responsive Stack) --- */
    /* Only apply to tables that need it, or use .table-responsive wrapper */
    .table-responsive {
        border: 0;
        overflow-x: auto;
    }

    /* Stacked table style for small screens */
    .table-mobile-stack thead {
        display: none;
    }

    .table-mobile-stack tr {
        display: block;
        margin-bottom: 1rem;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
        padding: 0.5rem;
    }

    .table-mobile-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px dashed #f1f5f9;
        padding: 0.75rem 0.5rem !important;
        text-align: right;
        min-height: 48px;
    }

    .table-mobile-stack td:last-child {
        border-bottom: none;
    }

    .table-mobile-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        text-align: left;
        margin-right: 1rem;
        font-size: 0.875rem;
        text-transform: uppercase;
        letter-spacing: 0.025em;
    }

    /* --- Navbar/Header --- */
    .main-navbar {
        padding: 0 0.75rem !important;
        height: 60px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        background: #ffffff !important;
        overflow: hidden;
    }

    .main-navbar .container-fluid {
        padding: 0 !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100%;
    }

    .btn-header {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        background: #f8fafc;
        border: 1px solid #f1f5f9;
        transition: all 0.2s;
    }

    .btn-header:active {
        background: #f1f5f9;
        transform: scale(0.95);
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    /* Hide unnecessary elements on very small screens */
    @media (max-width: 360px) {
        .lang-switcher-left {
            display: none !important;
        }
    }

    /* --- Buttons --- */
    .btn-mobile-full {
        width: 100%;
        display: block;
        margin-bottom: 0.5rem;
    }

    /* --- Modals --- */
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: 1rem !important;
    }

    /* --- Forms --- */
    .form-control {
        font-size: 16px !important;
        /* Prevents iOS zoom on focus */
    }

    .btn-lg {
        font-size: 1rem;
        padding: 0.75rem 1rem;
    }


}

/* --- Mobile Bottom Navigation (Always Styled if Visible) --- */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 65px;
    background-color: #ffffff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    border-top: 1px solid #eee;
    padding-bottom: env(safe-area-inset-bottom);
}

.bloc-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    color: #64748b;
    font-size: 0.7rem;
    width: 25%;
    height: 100%;
    transition: all 0.2s ease;
}

.bloc-icon i {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

.bloc-icon.active {
    color: #4f46e5;
    font-weight: 600;
}

.bloc-icon:hover {
    color: #4f46e5;
}

@media (max-width: 768px) {
    body {
        padding-bottom: 80px !important;
    }


    /* Hide the floating action button if it conflicts with bottom nav, or move it up */
    .fab-btn,
    .fab-folder-toggle {
        bottom: 90px !important;
        /* Move FAB up above bottom nav */
    }

    /* Reduce spacing on mobile for exam header */
    .exam-header-mobile {
        margin-bottom: 1.5rem !important;
        /* Was mb-5 */
    }

    .exam-header-title-mobile {
        font-size: 1.75rem !important;
        /* Smaller than display-6 */
    }

    /* Compact breadcrumbs on mobile */
    .breadcrumb-mobile {
        padding: 0.5rem 1rem !important;
        margin-bottom: 1rem !important;
        font-size: 0.85rem;
    }

    /* --- Mobile Tab Grid (2x2) --- */
    .mobile-tab-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem !important;
    }

    .mobile-tab-grid .nav-item {
        width: 100%;
    }

    .mobile-tab-grid .nav-link {
        font-size: 0.8rem !important;
        padding: 0.75rem 0.25rem !important;
        height: 100%;
        border-radius: 12px !important;
        /* Slightly squarer for grid */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        white-space: normal !important;
    }

    .mobile-tab-grid .nav-link i {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
        margin-right: 0 !important;
        /* Center icon above text */
    }

    /* Ensure text wraps nicely */
    .mobile-tab-grid .tab-text {
        line-height: 1.1;
    }

    /* --- Mobile Horizontal Card Styles --- */
    .card-icon-wrapper {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.5rem !important;
    }

    /* Desktop overrides for icon wrapper */
    @media (min-width: 768px) {
        .card-icon-wrapper {
            width: 80px !important;
            height: 80px !important;
            font-size: 2rem !important;
        }
    }

    .mobile-text-h6 {
        font-size: 1rem !important;
    }
}

/* Landscape Mode Adjustments */
@media (max-width: 900px) and (orientation: landscape) {
    .main-navbar {
        min-height: 50px;
    }
}

/* Utilities */
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* --- Fix Admin Sidebar Scroll & Layout on Mobile --- */
@media (max-width: 768px) {
    #sidebar-wrapper {
        position: fixed !important;
        top: 0;
        bottom: 0;
        left: 0;
        width: 260px !important;
        height: auto !important;
        max-height: none !important;
        min-height: 100% !important;

        display: block !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;

        z-index: 10000 !important;
        margin-left: -260px;
        transition: margin-left 0.3s ease;
        padding-bottom: 20px;
        background-color: var(--bg-sidebar, #1e293b) !important;
    }

    #wrapper.toggled #sidebar-wrapper {
        margin-left: 0 !important;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.2);
    }

    /* Ensure the list group inside also allows scrolling if needed (though wrapper scroll is enough) */
    #sidebar-wrapper .list-group {
        padding-bottom: 40px;
    }

    /* Overlay effect when sidebar is open */
    #wrapper.toggled::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9999;
        backdrop-filter: blur(2px);
    }

    /* Fix occlusion by bottom nav - default for students */
    #page-content-wrapper {
        padding-bottom: 80px;
    }

    body {
        padding-bottom: 80px;
    }

    /* Lock body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}