/* ============================================================
   ISA Santé — Correctif responsive mobile
   Objectif : rendre l'interface propre et utilisable sur téléphone.
   ============================================================ */

.mobile-shellbar,
.mobile-sidebar-backdrop { display: none; }

@media (max-width: 768px) {
    :root {
        --topbar-h: auto;
        --sidebar-w: 292px;
    }

    html, body { width: 100%; overflow-x: hidden; }
    body { font-size: 14px; background: #f6faf8; }

    .mobile-shellbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 58px;
        z-index: 900;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 12px;
        background: linear-gradient(135deg, var(--isa-dark), var(--isa-primary));
        color: #fff;
        box-shadow: 0 8px 24px rgba(10, 75, 89, .18);
    }

    .mobile-menu-btn {
        width: 42px;
        height: 42px;
        border: 0;
        border-radius: 14px;
        background: rgba(255, 255, 255, .14);
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        cursor: pointer;
        flex: 0 0 auto;
    }
    .mobile-menu-btn span {
        width: 18px;
        height: 2px;
        border-radius: 4px;
        background: #fff;
        display: block;
        transition: transform .18s ease, opacity .18s ease;
    }
    body.mobile-menu-open .mobile-menu-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    body.mobile-menu-open .mobile-menu-btn span:nth-child(2) { opacity: 0; }
    body.mobile-menu-open .mobile-menu-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    .mobile-shellbrand {
        width: 42px;
        height: 42px;
        border-radius: 14px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: rgba(255,255,255,.10);
        text-decoration: none;
        overflow: hidden;
        flex: 0 0 auto;
    }
    .mobile-shellbrand img {
        width: 34px;
        height: 34px;
        object-fit: contain;
        display: block;
    }
    .mobile-shellbrand span { color:#fff; font-weight:900; font-family:'Heebo',sans-serif; }

    .mobile-shelltext {
        min-width: 0;
        display: flex;
        flex-direction: column;
        line-height: 1.15;
    }
    .mobile-shelltext strong {
        display: block;
        color: #fff;
        font-size: 14px;
        font-weight: 800;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100vw - 132px);
    }
    .mobile-shelltext span {
        margin-top: 3px;
        color: rgba(255,255,255,.72);
        font-size: 10px;
        text-transform: capitalize;
    }

    .app-layout {
        display: block !important;
        min-height: 100vh;
        padding-top: 58px;
    }

    .sidebar {
        display: flex !important;
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        max-width: 320px;
        height: 100vh;
        z-index: 1001;
        transform: translateX(-105%);
        transition: transform .24s ease;
        box-shadow: 20px 0 48px rgba(2, 34, 41, .34);
        border-right: 1px solid rgba(255,255,255,.08);
        padding-bottom: env(safe-area-inset-bottom);
    }
    body.mobile-menu-open .sidebar { transform: translateX(0); }

    .mobile-sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1000;
        display: block;
        background: rgba(2, 34, 41, .46);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
    }
    body.mobile-menu-open .mobile-sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-brand { padding: 16px 18px 14px; }
    .brand-logo { width: 44px !important; height: 44px !important; background: transparent !important; border-radius: 12px; }
    .brand-logo img { object-fit: contain !important; }
    .brand-text .brand-name { font-size: 13px !important; }
    .nav-section { padding-top: 14px; }
    .nav-item { padding: 11px 18px; font-size: 13px; }

    .topbar,
    .topbar-context {
        position: relative !important;
        top: auto !important;
        grid-column: auto !important;
        min-height: auto !important;
        height: auto !important;
        padding: 10px 12px 8px !important;
        align-items: flex-start !important;
        background: #f8fbfa;
        border-bottom: 1px solid rgba(10,75,89,.08);
        box-shadow: none;
        overflow: hidden;
    }

    .contextbar-left { width: 100%; min-width: 0; display: block; }
    .contextbar-form {
        width: 100%;
        display: flex;
        flex-wrap: nowrap !important;
        gap: 8px;
        overflow-x: auto;
        padding: 0 0 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .contextbar-form::-webkit-scrollbar { display: none; }
    .context-field {
        height: 38px;
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 156px;
        padding: 0 10px;
        border-radius: 12px;
        box-shadow: 0 2px 9px rgba(10,75,89,.045);
    }
    .context-school { min-width: 190px; }
    .context-icon, .context-icon svg { width: 16px; height: 16px; }
    .context-select {
        min-width: 102px;
        max-width: 168px !important;
        width: auto !important;
        font-size: 12px;
        font-weight: 700;
    }
    .context-static {
        max-width: 146px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
    }
    .context-active-period { display: none !important; }
    .contextbar-right { display: none !important; }

    .main-content {
        grid-column: auto !important;
        padding: 14px 12px 28px !important;
        overflow-x: hidden;
    }

    h1 { font-size: 22px; }
    h2 { font-size: 20px; }
    h3 { font-size: 16px; }

    .card {
        border-radius: 16px;
        box-shadow: 0 4px 16px rgba(10,75,89,.06);
        overflow: hidden;
    }
    .card-header {
        padding: 14px 14px 0 !important;
        gap: 10px;
        align-items: flex-start !important;
        flex-wrap: wrap;
    }
    .card-header > * { min-width: 0; }
    .card-body { padding: 14px !important; }
    .card-footer { padding: 12px 14px !important; }

    .stats-grid,
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        margin-bottom: 14px !important;
    }
    .stat-card,
    .kpi {
        padding: 14px !important;
        border-radius: 16px !important;
    }
    .stat-value,
    .kpi .value { font-size: 24px !important; }
    .stat-label,
    .kpi .label { font-size: 10px !important; }

    .main-grid,
    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .filter-bar {
        padding: 10px 14px !important;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .filter-pill { flex: 0 0 auto; }

    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        white-space: nowrap;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }
    .tab-item { flex: 0 0 auto; padding: 9px 12px; }

    .table-container {
        width: auto;
        overflow-x: auto;
        margin-left: -12px;
        margin-right: -12px;
        padding-left: 12px;
        padding-right: 12px;
        -webkit-overflow-scrolling: touch;
    }
    .isa-table {
        min-width: 720px;
        font-size: 12px;
    }
    .isa-table thead th { padding: 9px 12px; font-size: 9px; }
    .isa-table td { padding: 10px 12px; font-size: 12px; }
    .isa-table th:first-child,
    .isa-table td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: #fff;
        box-shadow: 6px 0 12px rgba(15,23,42,.04);
    }
    .isa-table thead th:first-child { background: #f8fafc; z-index: 3; }

    .btn {
        min-height: 38px;
        justify-content: center;
        padding: 8px 12px;
        font-size: 12px;
    }
    .btn-sm { min-height: 32px; padding: 6px 10px; }
    .btn-lg { min-height: 44px; width: 100%; }

    .form-control,
    select.form-control,
    textarea.form-control {
        min-height: 42px;
        font-size: 16px !important;
    }
    .form-group { margin-bottom: 14px; }

    .modal-overlay { padding: 10px; align-items: flex-end; }
    .modal {
        max-height: 88vh;
        border-radius: 18px 18px 0 0;
    }
    .modal-header,
    .modal-body,
    .modal-footer { padding-left: 16px !important; padding-right: 16px !important; }
    .modal-footer { flex-direction: column-reverse; }
    .modal-footer .btn { width: 100%; }

    .toast-stack {
        top: 66px !important;
        left: 10px !important;
        right: 10px !important;
        max-width: none !important;
    }
    .toast { border-radius: 14px; font-size: 12px; }

    .student-cell { gap: 8px; }
    .stu-avatar { width: 30px; height: 30px; }
    .stu-name { font-size: 12px; }
    .stu-mat { font-size: 9px; }

    .dash-hero {
        padding: 18px !important;
        border-radius: 18px !important;
        margin-bottom: 14px !important;
    }
    .dash-hero h1 { font-size: 22px !important; }
    .chart-bars { overflow-x: auto; min-width: 520px; }

    .mini-row { align-items: flex-start; gap: 8px; }

    .card-body[style*="display:flex"] {
        flex-wrap: wrap !important;
        gap: 12px !important;
    }
    .card-body [style*="margin-left:auto"] {
        margin-left: 0 !important;
        width: 100%;
    }
}

@media (max-width: 560px) {
    .stats-grid,
    .kpi-grid { grid-template-columns: 1fr !important; }
    .main-content { padding-left: 10px !important; padding-right: 10px !important; }
    .context-field { min-width: 146px; }
    .context-school { min-width: 176px; }
    .context-select { max-width: 150px !important; }
    .card-header { flex-direction: column; }
    .card-header .btn { width: 100%; }
}

/* Connexion mobile */
@media (max-width: 760px) {
    body.auth-mobile-page {
        align-items: flex-start !important;
        justify-content: center !important;
        padding: 14px !important;
        background: linear-gradient(135deg, var(--isa-dark), var(--isa-primary)) !important;
    }
    .login-wrapper {
        grid-template-columns: 1fr !important;
        max-width: 440px !important;
        min-height: auto !important;
        border-radius: 22px !important;
        margin: 0 auto;
    }
    .login-left {
        min-height: auto !important;
        padding: 24px 22px !important;
        gap: 16px;
    }
    .login-brand-logo { width: 48px !important; height: 48px !important; }
    .login-brand-name { font-size: 19px !important; }
    .login-tagline h1 {
        font-size: 25px !important;
        line-height: 1.1 !important;
        margin-bottom: 8px !important;
    }
    .login-tagline p { font-size: 12px !important; line-height: 1.55 !important; }
    .login-features { display: none !important; }
    .login-right { padding: 26px 22px !important; }
    .login-right h2 { font-size: 22px !important; }
    .login-right p { margin-bottom: 22px !important; }
}

@media (max-width: 420px) {
    .login-left { padding: 20px !important; }
    .login-tagline h1 { font-size: 22px !important; }
    .login-right { padding: 22px 18px !important; }
}
