/* =========================================================
   SCHOOL APP — couche mobile
   N’altère JAMAIS le desktop : tout est sous max-width 991.98px
   ========================================================= */

.mobi-tabbar,
.mobi-backdrop,
.mobi-sidebar-close {
  display: none;
}

@media (max-width: 991.98px) {
  :root {
    --mobi-bar: 52px;
    --mobi-tab: 58px;
    --mobi-accent: #0078d4;
    --mobi-bg: #f4f6f8;
    --mobi-safe-b: env(safe-area-inset-bottom, 0px);
    --mobi-safe-t: env(safe-area-inset-top, 0px);
  }

  html.desk-app,
  html.desk-app body {
    height: auto !important;
    min-height: 100% !important;
    overflow: auto !important;
    font-size: 13px !important;
    background: var(--mobi-bg) !important;
  }

  html.desk-app body.mobi-drawer-open {
    overflow: hidden !important;
  }

  html.desk-login-page,
  html.desk-login-page body.desk-login-body {
    overflow: auto !important;
    background: #0b2a4a !important;
  }

  .desk-shell {
    height: auto !important;
    min-height: 100dvh;
    overflow: visible;
    padding-bottom: calc(var(--mobi-tab) + var(--mobi-safe-b));
  }

  /* --- Barre titre compacte --- */
  .desk-menubar {
    height: auto;
    min-height: 34px;
    padding: 5px 10px;
    padding-top: calc(5px + var(--mobi-safe-t));
  }

  .desk-menubar-brand > .desk-menubar-meta,
  .desk-menubar > .desk-menubar-meta {
    display: none !important;
  }

  .desk-menubar-brand > span:first-of-type {
    font-size: 13px;
  }

  /* --- Toolbar app --- */
  .desk-toolbar {
    height: var(--mobi-bar);
    padding: 0 10px;
    position: sticky;
    top: 0;
    z-index: 40;
  }

  .desk-toolbar .desk-btn {
    height: 36px;
    min-width: 36px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 8px;
  }

  .desk-toolbar .desk-status {
    height: 28px;
    font-size: 11px;
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Docs déjà dans la tabbar → cacher le bouton bleu vide */
  .mobi-hide-toolbar-docs,
  .mobi-hide-sm {
    display: none !important;
  }

  .desk-toolbar-right .desk-btn {
    font-size: 12px;
    padding: 0 10px;
  }

  .desk-toolbar-right .desk-btn i {
    font-size: 13px !important;
    margin: 0;
  }

  .desk-user-menu summary.desk-btn {
    font-size: 0;
    padding: 0 8px;
    min-width: 36px;
  }

  .desk-user-menu summary.desk-btn img {
    width: 20px !important;
    height: 20px !important;
  }

  .desk-user-dropdown {
    width: min(280px, calc(100vw - 24px));
    font-size: 12.5px;
  }

  /* --- Corps : plus de rail Windows --- */
  .desk-body {
    display: block;
    overflow: visible;
  }

  .desk-main {
    min-height: calc(100dvh - 90px);
  }

  .desk-content {
    overflow: visible !important;
    display: block;
  }

  .desk-content > .content,
  .desk-content .content {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 8px 10px 14px !important;
  }

  /* --- Drawer menu --- */
  .desk-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    width: min(86vw, 320px) !important;
    z-index: 120;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: none;
    padding-bottom: calc(var(--mobi-tab) + var(--mobi-safe-b));
  }

  .desk-shell.sidebar-open .desk-sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.22);
  }

  .desk-shell.sidebar-collapsed .desk-sidebar {
    width: min(86vw, 320px) !important;
  }

  .desk-shell.sidebar-collapsed .desk-sidebar-head-text,
  .desk-shell.sidebar-collapsed .desk-nav-section,
  .desk-shell.sidebar-collapsed .desk-nav-label,
  .desk-shell.sidebar-collapsed .desk-sidebar-head .sub {
    display: block;
  }

  .desk-shell.sidebar-collapsed .desk-nav-link {
    justify-content: flex-start;
    padding: 10px 12px 10px 10px;
    border-left-width: 3px;
  }

  .desk-sidebar-head {
    min-height: 48px;
    padding-top: calc(10px + var(--mobi-safe-t));
  }

  .desk-sidebar-head .title {
    font-size: 12px;
  }

  .desk-sidebar-head .sub {
    font-size: 10.5px;
  }

  .desk-sidebar-head .desk-sidebar-toggle {
    display: none !important;
  }

  .mobi-sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid #d0d0d0;
    background: #fff;
    color: #333;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
  }

  .mobi-sidebar-close:hover {
    background: #f3f3f3;
  }

  .desk-nav-section {
    font-size: 10px;
  }

  .desk-nav-link {
    min-height: 40px;
    padding: 9px 12px 9px 10px;
    margin: 2px 6px;
    border-radius: 8px;
    font-size: 13px;
  }

  .desk-nav-link .desk-ico {
    width: 16px !important;
    height: 16px !important;
    font-size: 12px !important;
  }

  .desk-sidebar-scroll {
    -webkit-overflow-scrolling: touch;
  }

  .desk-sidebar-foot {
    display: none;
  }

  .mobi-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 15, 0.42);
    z-index: 110;
  }

  .desk-shell.sidebar-open .mobi-backdrop {
    display: block;
  }

  /* --- Barre du bas --- */
  .mobi-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    height: calc(var(--mobi-tab) + var(--mobi-safe-b));
    padding-bottom: var(--mobi-safe-b);
    background: #fff;
    border-top: 1px solid #cfcfcf;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  }

  .mobi-tabbar a,
  .mobi-tabbar button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    background: transparent;
    color: #444;
    text-decoration: none !important;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--desk-font-ui) !important;
    min-height: var(--mobi-tab);
  }

  .mobi-tabbar a i,
  .mobi-tabbar button i {
    font-size: 14px !important;
  }

  .mobi-tabbar a.is-active,
  .mobi-tabbar a:hover,
  .mobi-tabbar button:hover {
    color: var(--mobi-accent);
  }

  /* --- Formulaires / cartes (plus compacts) --- */
  .desk-content .form-label,
  .desk-content label {
    font-size: 11.5px !important;
  }

  .desk-content .form-control,
  .desk-content .form-select,
  .desk-content select.form-control,
  .desk-content input.form-control,
  .desk-content .form-control-sm,
  .desk-content input[type="search"] {
    height: 36px !important;
    min-height: 36px !important;
    font-size: 14px !important; /* évite le zoom iOS trop agressif, mais plus petit */
    border-radius: 8px !important;
    max-width: none !important;
    width: 100% !important;
    padding: 4px 8px !important;
  }

  .desk-content textarea.form-control {
    min-height: 80px !important;
    font-size: 14px !important;
  }

  .desk-content .btn,
  .desk-content .btn-sm,
  .desk-content .btn-primary,
  .desk-content .btn-phoenix-primary {
    height: 36px !important;
    min-height: 36px !important;
    line-height: 1.2 !important;
    padding: 6px 12px !important;
    border-radius: 8px !important;
    font-size: 12.5px !important;
  }

  .desk-content .btn.w-100 {
    min-height: 40px !important;
  }

  .desk-content .btn i,
  .desk-content .btn .fa {
    font-size: 11px !important;
  }

  .desk-content .card,
  .desk-content .wizard-panel {
    border-radius: 10px !important;
  }

  .desk-content .card-body {
    padding: 10px !important;
  }

  .desk-content .card-header {
    font-size: 12.5px !important;
    padding: 6px 10px !important;
  }

  .desk-content h1 { font-size: 17px !important; }
  .desk-content h2 { font-size: 15.5px !important; }
  .desk-content h3 { font-size: 14px !important; }
  .desk-content h4 { font-size: 13px !important; }

  .desk-content .breadcrumb,
  .desk-content .breadcrumb-item,
  .desk-content .breadcrumb-item a {
    font-size: 12px !important;
  }

  .desk-content .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .desk-content .table {
    font-size: 12px !important;
  }

  .desk-content .table > :not(caption) > * > * {
    padding: 7px 6px !important;
  }

  .desk-content .table thead th {
    font-size: 11.5px !important;
  }

  .desk-content .badge,
  .desk-content .badge-phoenix,
  .desk-content .alert,
  .desk-content .text-danger,
  .desk-content .invalid-feedback,
  .desk-content small,
  .desk-content .small {
    font-size: 11.5px !important;
  }

  .desk-content .form-control.desk-total-field,
  .desk-content .form-control.desk-total-field[readonly] {
    font-size: 13px !important;
  }

  .desk-page-inscription,
  .desk-page-inscription > .row,
  .desk-page-inscription .multisteps-form {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
  }

  .desk-data-panel,
  .desk-picker-panel,
  .desk-content [style*="height: 80vh"],
  .desk-content [style*="height:80vh"],
  .desk-content .card-body[style*="height"] {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html.desk-docs .desk-content .col-md-9 > .card > .card-body[style*="overflow"],
  html.desk-docs .desk-content .col-md-12 > .card > .card-body[style*="overflow"] {
    height: auto !important;
    max-height: none !important;
    overflow: auto !important;
    padding: 10px !important;
  }

  .desk-content .col-md-3,
  .desk-content .col-md-4,
  .desk-content .col-md-5,
  .desk-content .col-md-6,
  .desk-content .col-md-7,
  .desk-content .col-md-8,
  .desk-content .col-md-9 {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
  }

  .desk-content > .content > .row.d-flex.justify-content-between,
  .desk-content > .content > .d-flex.justify-content-between.mb-3 {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    overflow: hidden;
  }

  .desk-content > .content > .row.d-flex.justify-content-between > .item,
  .desk-content > .content > .row.d-flex.justify-content-between > [class*="col-"].d-flex {
    width: auto !important;
    flex: 0 0 auto !important;
    justify-content: flex-end !important;
    margin-left: auto !important;
    gap: 4px !important;
  }

  /* Titre / breadcrumb : une seule ligne, actions icon-only */
  .desk-content nav[aria-label="breadcrumb"],
  .desk-content .d-flex.justify-content-between:has(.breadcrumb) {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
  }

  .desk-content nav[aria-label="breadcrumb"] .breadcrumb {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 !important;
    overflow: hidden;
    white-space: nowrap;
  }

  .desk-content nav[aria-label="breadcrumb"] .breadcrumb-item:not(.active) {
    display: none !important;
  }

  .desk-content nav[aria-label="breadcrumb"] .breadcrumb-item.active {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px !important;
    font-weight: 700 !important;
  }

  .desk-content nav[aria-label="breadcrumb"] .breadcrumb-item + .breadcrumb-item::before {
    display: none !important;
  }

  .desk-content nav[aria-label="breadcrumb"] > .d-flex,
  .desk-content nav[aria-label="breadcrumb"] .w-50 {
    width: auto !important;
    flex: 0 0 auto !important;
    gap: 4px;
  }

  /* Cacher Corbeille sur mobile ; Actualiser = icône seule */
  .desk-content nav[aria-label="breadcrumb"] a.btn-danger,
  .desk-content nav[aria-label="breadcrumb"] .btn-danger {
    display: none !important;
  }

  .desk-content nav[aria-label="breadcrumb"] .btn {
    width: 34px !important;
    min-width: 34px !important;
    height: 34px !important;
    padding: 0 !important;
    font-size: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  .desk-content nav[aria-label="breadcrumb"] .btn i {
    font-size: 12px !important;
    margin: 0 !important;
  }

  /* Titres de sections (Frais / Paiements bus) + recherche en ligne */
  .desk-content .mb-1.d-flex.justify-content-between,
  .desk-content h4.py-2.d-flex.justify-content-between {
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
  }

  .desk-content .mb-1.d-flex.justify-content-between h4,
  .desk-content .mb-1.d-flex.justify-content-between > h4 {
    font-size: 13px !important;
    margin: 0 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
  }

  .desk-content .mb-1.d-flex.justify-content-between .search-input,
  .desk-content .mb-1.d-flex.justify-content-between input[type="search"] {
    width: 110px !important;
    max-width: 38vw !important;
    min-width: 0 !important;
    height: 32px !important;
    min-height: 32px !important;
    font-size: 12px !important;
  }

  .desk-content .search-input,
  .desk-content input.search,
  .desk-content input[type="search"] {
    max-width: 100% !important;
    width: 100% !important;
  }

  .fournitures-modal-dialog {
    max-height: calc(100dvh - 24px);
  }

  /* --- Choix élève : bouton + bottom sheet (mobile only) --- */
  .mobi-eleve-trigger {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 40px !important;
    min-height: 40px !important;
    margin: 8px 0 4px;
    border-radius: 8px !important;
    font-size: 13px !important;
  }

  .mobi-eleve-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 160;
    align-items: flex-end;
    justify-content: center;
  }

  .mobi-eleve-panel.is-open {
    display: flex;
  }

  .mobi-eleve-panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
  }

  .mobi-eleve-panel-sheet {
    position: relative;
    z-index: 1;
    width: 100%;
    max-height: min(72dvh, 520px);
    background: #fff;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    padding: 10px 12px calc(12px + var(--mobi-safe-b));
  }

  .mobi-eleve-panel-sheet::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: #d0d0d0;
    margin: 2px auto 10px;
  }

  .mobi-eleve-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
  }

  .mobi-eleve-panel-head strong {
    font-size: 14px;
  }

  .mobi-eleve-panel-close {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid #d0d0d0;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobi-eleve-panel .mobi-eleve-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #fafafa;
    max-height: none !important;
    height: auto !important;
    margin: 0 !important;
  }

  .mobi-eleve-panel .mobi-eleve-list table {
    margin: 0 !important;
  }

  .mobi-eleve-panel .mobi-eleve-list tr {
    cursor: pointer;
  }

  .mobi-eleve-panel .mobi-eleve-list td {
    padding: 10px 8px !important;
    font-size: 13px !important;
  }

  .mobi-eleve-panel .mobi-eleve-search {
    margin-top: 8px !important;
  }

  body.mobi-eleve-open {
    overflow: hidden !important;
  }

  /* Tables de résultats : scroll horizontal propre */
  .desk-content .card .table-responsive,
  .desk-content .wizard-panel .table-responsive,
  .desk-content .card[style*="overflow"],
  .desk-content .wizard-panel[style*="overflow"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .desk-content .wizard-panel[style*="height: 230px"],
  .desk-content .card[style*="height: 230px"] {
    height: auto !important;
    max-height: 280px !important;
    overflow: auto !important;
  }

  /* Login plein écran — auth */
  html.desk-login-page,
  html.desk-login-page body.desk-login-body {
    overflow: auto !important;
    background: #0b2a4a !important;
  }

  .auth-shell {
    min-height: 100dvh;
  }

  .auth-hero-img {
    object-position: center 28%;
  }

  .auth-stage {
    padding: 22px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    gap: 18px;
  }

  .auth-crest {
    width: 84px;
    border-radius: 12px;
    margin-bottom: 16px;
  }

  .auth-title {
    font-size: clamp(1.9rem, 8vw, 2.45rem) !important;
  }

  .auth-lead {
    font-size: 0.95rem !important;
  }

  .auth-panel {
    padding: 22px 18px 18px;
    border-radius: 16px;
  }

  .auth-panel-title {
    font-size: 1.25rem !important;
  }

  .auth-input {
    height: 48px !important;
    min-height: 48px !important;
    font-size: 16px !important; /* anti-zoom iOS */
    border-radius: 12px !important;
  }

  .auth-submit {
    height: 48px;
    border-radius: 12px;
    font-size: 1rem;
  }

  .auth-foot {
    font-size: 0.72rem;
  }

  /* Reset password compact (écrase les tailles login) */
  .auth-stage--reset {
    padding: 14px 14px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    gap: 12px !important;
  }

  .auth-brand--compact .auth-crest {
    width: 56px !important;
    margin-bottom: 0 !important;
  }

  .auth-brand--compact .auth-title {
    font-size: 1.35rem !important;
  }

  .auth-brand--compact .auth-lead {
    font-size: 0.82rem !important;
  }

  .auth-panel--reset {
    padding: 16px 14px 14px !important;
  }

  .auth-panel--reset .auth-input {
    height: 42px !important;
    min-height: 42px !important;
    font-size: 16px !important;
  }

  .auth-panel--reset .auth-submit,
  .auth-panel--reset .auth-submit--send {
    height: 42px !important;
    font-size: 0.9rem !important;
  }

  /* Legacy desk-login (si encore présent) */
  .desk-login-shell {
    align-items: stretch;
    padding: 0;
    min-height: 100dvh;
  }

  .desk-perm {
    min-height: 0;
  }

  .desk-perm-head {
    flex-direction: column;
    align-items: stretch;
  }

  .desk-perm-head h1 {
    font-size: 16px !important;
  }

  .desk-perm-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .desk-perm-users {
    border-right: 0;
    border-bottom: 1px solid #cfcfcf;
    max-height: 240px;
  }

  .desk-perm-detail-head {
    flex-direction: column;
  }

  .desk-perm-actions .desk-btn {
    flex: 1;
  }

  .desk-perm-grid {
    grid-template-columns: 1fr;
  }

  .desk-perm-matrix-wrap {
    overflow-x: auto;
  }

  .desk-perm-matrix {
    min-width: 640px;
    font-size: 12px;
  }
}

@media (min-width: 992px) {
  .mobi-tabbar,
  .mobi-backdrop,
  .mobi-sidebar-close,
  .mobi-eleve-trigger,
  .mobi-eleve-panel-backdrop,
  .mobi-eleve-panel-head {
    display: none !important;
  }

  .mobi-eleve-panel {
    display: block !important;
    position: static !important;
    inset: auto !important;
  }

  .mobi-eleve-panel-sheet {
    display: flex !important;
    flex-direction: column !important;
    max-height: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  .mobi-eleve-panel-sheet::before {
    display: none !important;
  }

  /* Liste scrollable : la recherche reste SOUS le cadre, sans chevauchement */
  .mobi-eleve-panel .mobi-eleve-list {
    height: var(--desk-picker-h, 200px) !important;
    max-height: 220px !important;
    min-height: 160px !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 0;
  }

  .mobi-eleve-panel .mobi-eleve-search {
    position: relative;
    z-index: 1;
    margin-top: 0.75rem !important;
    flex-shrink: 0;
  }
}
