/* =========================================================
   MIK N-MOBILE — couche responsive pour Mikhmon
   S'ajoute aux feuilles existantes sans les remplacer.
   Objectif : utilisable au doigt sur téléphone et tablette,
   sans rien changer au fonctionnement de l'application.
   ========================================================= */

/* ---------- 1. Base : jamais de défilement horizontal ---------- */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Défaut d'origine : .main-container démarre après le menu (marge de 210 px)
   mais garde width:100 %, donc la partie droite est rognée. Avec width:auto
   et border-box, le contenu occupe exactement l'espace restant. */
.main-container,
.card,
.box,
.card-body,
.box-body,
.nm-table-scroll {
  box-sizing: border-box !important;
}
.main-container {
  width: auto !important;
  max-width: 100% !important;
}

/* #main reçoit une marge à gauche égale à la largeur du menu (210 px)
   tout en gardant width:100 % : la partie droite dépasse et se fait rogner.
   Avec width:auto, il occupe exactement l'espace restant, que le menu
   soit ouvert ou fermé. */
#main {
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

@media (max-width: 991px) {
  body {
    -webkit-text-size-adjust: 100%;
  }
}

/* ---------- 2. Barre du haut ---------- */
@media (max-width: 640px) {
  /* Le nom de marque et la page courante prennent trop de place */
  #brand {
    min-width: 0 !important;
    font-size: 15px !important;
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
  #cpage {
    display: none !important;
  }
  .navbar-left > a,
  .navbar-right > a {
    padding-left: 9px !important;
    padding-right: 9px !important;
  }
  .navbar-right a i {
    margin-right: 0 !important;
  }
  /* Le libellé « Logout » devient superflu, l'icône suffit */
  #logout .mr-1 {
    margin-right: 0 !important;
  }
}

@media (max-width: 380px) {
  #brand {
    font-size: 13px !important;
  }
  .navbar-left > a,
  .navbar-right > a {
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
}

/* ---------- 3. Menu latéral : tiroir au-dessus du contenu ---------- */
/* Le mécanisme d'ouverture existant (largeur animée) est conservé ;
   on ajoute seulement le voile et la priorité d'affichage. */
.sidenav {
  z-index: 1040 !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

@media (max-width: 991px) {
  .sidenav {
    box-shadow: 0 0 40px rgba(0, 0, 0, .45);
  }
  /* Cibles tactiles confortables */
  .sidenav .menu,
  .sidenav .dropdown-btn,
  .sidenav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .sidenav .dropdown-container a {
    min-height: 40px;
    padding-left: 18px !important;
  }
}

/* Voile derrière le tiroir ouvert (classe posée par le script) */
.nm-nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 30, .55);
  z-index: 1035;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
body.nm-nav-open .nm-nav-backdrop {
  opacity: 1;
  pointer-events: auto;
}
@media (min-width: 992px) {
  .nm-nav-backdrop { display: none; }
}

/* ---------- 4. Grille : une colonne sur téléphone ---------- */
@media (max-width: 767px) {
  .row > [class*="col-"] {
    width: 100% !important;
    max-width: 100% !important;
    float: none !important;
    flex: 0 0 100% !important;
    padding-left: 4px !important;
    padding-right: 4px !important;
  }
  /* Les quatre compteurs restent par deux, côte à côte */
  .row > .col-box-6 {
    width: 50% !important;
    flex: 0 0 50% !important;
  }
  .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .main-container {
    padding: 6px 8px 24px !important;
  }
}

@media (max-width: 400px) {
  .row > .col-box-6 {
    width: 50% !important;
    flex: 0 0 50% !important;
  }
}

/* ---------- 5. Cartes : respiration et lisibilité ---------- */
@media (max-width: 767px) {
  .box,
  .card {
    border-radius: 14px;
    margin-bottom: 10px;
  }
  .card-body,
  .box-body {
    padding: 10px;
  }
  .card-header h3 {
    font-size: 16px !important;
    line-height: 1.3;
  }
  .box-group {
    padding: 10px !important;
  }
  .box-group-area {
    font-size: 13px !important;
    line-height: 1.45;
  }
  .box-group-icon i,
  .box-group-icon {
    font-size: 24px !important;
  }
}

/* ---------- 6. Tableaux : défilement latéral, pas d'écrasement ---------- */
/* Le script enveloppe chaque tableau dans .nm-table-scroll et n'élargit
   que les tableaux réellement larges (6 colonnes et plus). */
.nm-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 991px) {
  .table,
  table.table {
    font-size: 13px;
  }
  .table > thead > tr > th,
  .table > tbody > tr > td {
    padding: 7px 8px !important;
  }
  .nm-table-scroll table.wide {
    white-space: nowrap;
  }
  /* Certaines colonnes très larges (commentaires) peuvent se replier */
  .table > tbody > tr > td:nth-child(n+6) {
    white-space: normal;
    min-width: 90px;
  }
}

/* ---------- 7. Formulaires : pleine largeur et champs confortables ---------- */
@media (max-width: 767px) {
  .form-group {
    margin-bottom: 12px;
  }
  .form-control,
  select.form-control,
  textarea.form-control {
    font-size: 16px !important; /* évite le zoom automatique iOS */
    min-height: 44px;
    width: 100% !important;
  }
  .input-group {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
  }
  .btn {
    min-height: 42px;
    font-size: 14px;
  }
  /* Les boutons de ligne (modifier/supprimer) restent cliquables */
  .table .btn,
  .table a.btn {
    min-height: 36px;
    padding: 6px 10px;
  }
}

/* ---------- 8. Graphiques et blocs de code ---------- */
@media (max-width: 767px) {
  #container,
  .highcharts-container,
  .chart,
  .nm-chart {
    max-width: 100% !important;
    width: 100% !important;
  }
  pre,
  code {
    white-space: pre-wrap;
    word-break: break-word;
  }
  img {
    max-width: 100%;
    height: auto;
  }
}

/* ---------- 9. Confort de lecture ---------- */
@media (max-width: 767px) {
  body {
    font-size: 14px;
    line-height: 1.5;
  }
  h1 { font-size: 22px; }
  h2 { font-size: 19px; }
  h3 { font-size: 16px; }
}

/* ---------- 10. Ordinateur : rien ne change, sauf les écrans très larges ---------- */
@media (min-width: 1600px) {
  .main-container {
    max-width: 1600px;
    margin-left: auto;
    margin-right: auto;
  }
}
