/* ========================================
   AMÉLIORATIONS MOBILE RESPONSIVE MyAPP
   ======================================== */

/* Variables CSS pour la cohérence */
:root {
  --mobile-breakpoint: 768px;
  --tablet-breakpoint: 1024px;
  --sidebar-width: 250px;
  --header-height: 60px;
  --mobile-padding: 10px;
  --desktop-padding: 20px;
}

/* ========================================
   1. NAVIGATION MOBILE AMÉLIORÉE
   ======================================== */

/* Barre de navigation responsive */
@media (max-width: 768px) {
  .main-header.navbar {
    padding: 0.5rem 1rem;
    height: var(--header-height);
  }

  /* Menu hamburger plus visible */
  .navbar-nav .nav-link[data-widget="pushmenu"] {
    font-size: 1.2rem;
    padding: 0.75rem;
    background-color: rgba(0, 123, 255, 0.1);
    border-radius: 8px;
    margin-right: 10px;
  }

  /* Navigation items responsive */
  .navbar-nav {
    flex-direction: row;
    align-items: center;
  }

  .navbar-nav .nav-item {
    margin: 0 5px;
  }

  /* Badges de notification plus visibles */
  .navbar-badge {
    font-size: 0.7rem;
    padding: 0.2em 0.4em;
    min-width: 18px;
    height: 18px;
    line-height: 1;
  }
}

/* ========================================
   2. RECHERCHE GLOBALE MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Container de recherche responsive */
  .navbar-nav.mx-auto {
    width: 100%;
    margin: 5px 0;
    order: 3;
  }

  .navbar-nav.mx-auto .nav-item {
    width: 100%;
  }

  /* Input de recherche mobile */
  .navbar-nav.mx-auto .input-group {
    width: 100% !important;
    max-width: none !important;
  }

  #global-search-input {
    font-size: 16px; /* Évite le zoom sur iOS */
    padding: 12px 15px;
    border-radius: 25px 0 0 25px;
  }

  #global-search-btn {
    padding: 12px 15px;
    border-radius: 0 25px 25px 0;
  }

  /* Dropdown de résultats mobile */
  #search-results-dropdown {
    position: fixed;
    top: var(--header-height);
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 80px);
    z-index: 9999;
    border-radius: 10px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  }

  /* Résultats de recherche mobile */
  .search-result-item {
    padding: 15px;
    border-bottom: 1px solid #f1f1f1;
  }

  .search-result-title {
    font-size: 14px;
    line-height: 1.4;
  }

  .search-result-subtitle {
    font-size: 12px;
    margin-top: 4px;
  }

  .search-result-type {
    font-size: 9px;
    padding: 3px 6px;
  }
}

/* ========================================
   3. SIDEBAR MOBILE OPTIMISÉE
   ======================================== */

@media (max-width: 768px) {
  /* Sidebar overlay sur mobile */
  .main-sidebar {
    position: fixed;
    top: 0;
    left: -var(--sidebar-width);
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 9998;
    transition: left 0.3s ease-in-out;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  /* Sidebar ouverte */
  .sidebar-open .main-sidebar {
    left: 0;
  }

  /* Overlay sombre */
  .sidebar-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9997;
  }

  /* Logo dans la sidebar mobile */
  .brand-link {
    padding: 15px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .brand-image {
    max-height: 40px;
  }

  /* Menu items mobile */
  .nav-sidebar .nav-item .nav-link {
    padding: 12px 20px;
    font-size: 14px;
  }

  .nav-sidebar .nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
  }

  /* Sous-menus mobile */
  .nav-treeview .nav-item .nav-link {
    padding-left: 50px;
    font-size: 13px;
  }
}

/* ========================================
   4. CONTENU PRINCIPAL MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Content wrapper responsive */
  .content-wrapper {
    margin-left: 0 !important;
    padding-top: 0 !important;
  }

  /* Content padding mobile */
  .content {
    padding: var(--mobile-padding);
  }

  .content-header {
    padding: 15px var(--mobile-padding);
  }

  .content-header h1 {
    font-size: 1.5rem;
    margin-bottom: 10px;
  }

  /* Breadcrumb mobile */
  .breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: 12px;
  }

  .breadcrumb-item + .breadcrumb-item::before {
    content: "›";
    font-size: 14px;
  }
}

/* ========================================
   5. CARTES ET WIDGETS MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Cartes responsive */
  .card {
    margin-bottom: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  }

  .card-header {
    padding: 12px 15px;
    border-radius: 12px 12px 0 0;
  }

  .card-body {
    padding: 15px;
  }

  /* Widgets dashboard mobile */
  .c-dashboardInfo {
    margin-bottom: 10px;
  }

  .c-dashboardInfo .wrap {
    padding: 15px;
    border-radius: 15px;
  }

  .c-dashboardInfo__title {
    font-size: 1.2em;
  }

  .c-dashboardInfo__count,
  .c-dashboardInfo__count2 {
    font-size: 1.8em;
    line-height: 1.2;
  }

  /* Conteneurs principaux mobile */
  .main-container,
  .main-container2,
  .main-container3 {
    width: 100%;
    max-width: 100%;
    margin: 10px 0;
    padding: 15px;
    border-radius: 15px;
  }

  .main-container {
    height: auto;
    min-height: 200px;
  }

  .main-container2 {
    height: auto;
    min-height: 100px;
  }

  .main-container3 {
    height: auto;
    min-height: 200px;
  }
}

/* ========================================
   6. TABLEAUX RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  /* Container de tableau responsive */
  .table-responsive {
    border: none;
    margin-bottom: 15px;
  }

  /* Tableaux mobile */
  .table {
    font-size: 12px;
  }

  .table th,
  .table td {
    padding: 8px 4px;
    vertical-align: middle;
  }

  /* DataTables mobile */
  .dataTables_wrapper {
    font-size: 12px;
  }

  .dataTables_filter input {
    width: 100%;
    margin-bottom: 10px;
  }

  .dataTables_length select {
    width: auto;
  }

  .dataTables_info {
    font-size: 11px;
    margin-top: 10px;
  }

  .dataTables_paginate {
    margin-top: 10px;
  }

  .paginate_button {
    padding: 5px 8px;
    margin: 0 2px;
    font-size: 12px;
  }

  /* Tableaux en mode carte sur très petit écran */
  @media (max-width: 480px) {
    .table-mobile-cards .table,
    .table-mobile-cards .table thead,
    .table-mobile-cards .table tbody,
    .table-mobile-cards .table th,
    .table-mobile-cards .table td,
    .table-mobile-cards .table tr {
      display: block;
    }

    .table-mobile-cards .table thead tr {
      position: absolute;
      top: -9999px;
      left: -9999px;
    }

    .table-mobile-cards .table tr {
      border: 1px solid #ccc;
      margin-bottom: 10px;
      padding: 10px;
      border-radius: 8px;
      background: white;
    }

    .table-mobile-cards .table td {
      border: none;
      position: relative;
      padding-left: 50%;
      padding-top: 8px;
      padding-bottom: 8px;
    }

    .table-mobile-cards .table td:before {
      content: attr(data-label) ": ";
      position: absolute;
      left: 6px;
      width: 45%;
      padding-right: 10px;
      white-space: nowrap;
      font-weight: bold;
      color: #666;
    }
  }
}

/* ========================================
   7. FORMULAIRES MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Groupes de formulaires */
  .form-group {
    margin-bottom: 15px;
  }

  .form-control {
    font-size: 16px; /* Évite le zoom sur iOS */
    padding: 12px 15px;
    border-radius: 8px;
  }

  .form-control:focus {
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
  }

  /* Labels mobile */
  .form-label,
  label {
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 14px;
  }

  /* Select2 mobile */
  .select2-container {
    width: 100% !important;
  }

  .select2-container .select2-selection--single {
    height: 45px;
    padding: 8px 12px;
    font-size: 16px;
  }

  .select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 28px;
  }

  /* Boutons mobile */
  .btn {
    padding: 12px 20px;
    font-size: 14px;
    border-radius: 8px;
    margin: 5px 2px;
  }

  .btn-sm {
    padding: 8px 12px;
    font-size: 12px;
  }

  .btn-lg {
    padding: 15px 25px;
    font-size: 16px;
  }

  /* Groupes de boutons mobile */
  .btn-group {
    display: flex;
    flex-wrap: wrap;
  }

  .btn-group .btn {
    flex: 1;
    margin: 2px;
  }
}

/* ========================================
   8. MODALES MOBILE
   ======================================== */

@media (max-width: 768px) {
  .modal-dialog {
    margin: 10px;
    max-width: calc(100% - 20px);
  }

  .modal-content {
    border-radius: 12px;
  }

  .modal-header {
    padding: 15px 20px;
    border-radius: 12px 12px 0 0;
  }

  .modal-body {
    padding: 20px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
  }

  .modal-footer {
    padding: 15px 20px;
    border-radius: 0 0 12px 12px;
  }

  .modal-title {
    font-size: 1.2rem;
  }

  /* Bouton de fermeture mobile */
  .close {
    font-size: 1.8rem;
    padding: 10px;
  }
}

/* ========================================
   9. DROPDOWNS MOBILE
   ======================================== */

@media (max-width: 768px) {
  .dropdown-menu {
    border-radius: 10px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: none;
    margin-top: 5px;
  }

  .dropdown-item {
    padding: 12px 20px;
    font-size: 14px;
  }

  .dropdown-header {
    padding: 10px 20px;
    font-size: 12px;
    font-weight: 600;
  }

  /* Dropdown de navigation mobile */
  .navbar .dropdown-menu {
    position: fixed;
    top: var(--header-height);
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
  }
}

/* ========================================
   10. ALERTES ET NOTIFICATIONS MOBILE
   ======================================== */

@media (max-width: 768px) {
  .alert {
    margin-bottom: 15px;
    padding: 12px 15px;
    border-radius: 8px;
    font-size: 14px;
  }

  /* Toast notifications mobile */
  #toast-container {
    top: auto;
    bottom: 20px;
    right: 20px;
    left: 20px;
    width: auto;
    transform: none;
  }

  .toast {
    margin-bottom: 10px;
    border-radius: 8px;
  }

  /* Callouts mobile */
  .callout {
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
  }
}

/* ========================================
   11. UTILITAIRES MOBILE
   ======================================== */

/* Classes utilitaires pour mobile */
@media (max-width: 768px) {
  .mobile-hidden {
    display: none !important;
  }

  .mobile-visible {
    display: block !important;
  }

  .mobile-text-center {
    text-align: center !important;
  }

  .mobile-full-width {
    width: 100% !important;
  }

  .mobile-no-padding {
    padding: 0 !important;
  }

  .mobile-small-padding {
    padding: var(--mobile-padding) !important;
  }

  .mobile-no-margin {
    margin: 0 !important;
  }

  .mobile-small-margin {
    margin: 5px !important;
  }

  /* Espacement mobile */
  .mobile-mt-1 { margin-top: 5px !important; }
  .mobile-mt-2 { margin-top: 10px !important; }
  .mobile-mt-3 { margin-top: 15px !important; }
  .mobile-mb-1 { margin-bottom: 5px !important; }
  .mobile-mb-2 { margin-bottom: 10px !important; }
  .mobile-mb-3 { margin-bottom: 15px !important; }
  .mobile-p-1 { padding: 5px !important; }
  .mobile-p-2 { padding: 10px !important; }
  .mobile-p-3 { padding: 15px !important; }
}

/* ========================================
   12. ANIMATIONS MOBILE
   ======================================== */

/* Animations optimisées pour mobile */
@media (max-width: 768px) {
  /* Transition douce pour la sidebar */
  .main-sidebar {
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Animation des cartes */
  .card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  }

  /* Animation des boutons */
  .btn {
    transition: all 0.2s ease;
  }

  .btn:active {
    transform: scale(0.98);
  }

  /* Animation du dropdown de recherche */
  #search-results-dropdown.show {
    animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ========================================
   13. OPTIMISATIONS PERFORMANCE MOBILE
   ======================================== */

/* Optimisations pour les performances sur mobile */
@media (max-width: 768px) {
  /* Réduction des ombres complexes */
  .card,
  .modal-content,
  .dropdown-menu {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  /* Désactivation des animations non essentielles */
  .preloader {
    animation-duration: 0.5s;
  }

  /* Optimisation des images */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Lazy loading pour les éléments non critiques */
  .lazy-load {
    opacity: 0;
    transition: opacity 0.3s;
  }

  .lazy-load.loaded {
    opacity: 1;
  }
}

/* ========================================
   14. ACCESSIBILITÉ MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Taille minimale des zones tactiles */
  .btn,
  .nav-link,
  .dropdown-item,
  .form-control,
  .close {
    min-height: 44px;
    min-width: 44px;
  }

  /* Contraste amélioré */
  .text-muted {
    color: #666 !important;
  }

  /* Focus visible */
  .btn:focus,
  .form-control:focus,
  .nav-link:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
  }

  /* Texte lisible */
  body {
    font-size: 14px;
    line-height: 1.5;
  }

  h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
  }
}

/* ========================================
   15. SUPPORT LANDSCAPE/PORTRAIT
   ======================================== */

/* Orientation paysage sur mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .main-header.navbar {
    height: 50px;
  }

  #search-results-dropdown {
    top: 50px;
    max-height: calc(100vh - 60px);
  }

  .content-wrapper {
    padding-top: 0px;
  }

  .modal-body {
    max-height: calc(100vh - 150px);
  }
}

/* Très petits écrans (< 480px) */
@media (max-width: 480px) {
  .content {
    padding: 5px;
  }

  .card-body {
    padding: 10px;
  }

  .btn {
    padding: 10px 15px;
    font-size: 13px;
  }

  .form-control {
    padding: 10px 12px;
  }

  .c-dashboardInfo__count,
  .c-dashboardInfo__count2 {
    font-size: 1.5em;
  }
}

/* ========================================
   16. DARK MODE MOBILE
   ======================================== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
  .card {
    background-color: #2d3748;
    border-color: #4a5568;
  }

  .form-control {
    background-color: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
  }

  .dropdown-menu {
    background-color: #2d3748;
    border-color: #4a5568;
  }

  .dropdown-item {
    color: #e2e8f0;
  }

  .dropdown-item:hover {
    background-color: #4a5568;
  }
}

/* ========================================
   SIDEBAR RESPONSIVE AMÉLIORÉE
   ======================================== */

/* Responsive du logo sidebar */
@media (max-width: 768px) {
  .brand-link.logo_sidebar .logo-img {
    width: 35px !important;
    height: 35px !important;
  }
}

/* Correction de l'espacement sidebar */
.main-sidebar {
  padding-top: 0;
}

/* Ajustement de la sidebar */
.main-sidebar .sidebar {
  padding-top: 0.5rem;
}

/* Mobile - sidebar overlay */
@media (max-width: 767.98px) {
  .brand-link.logo_sidebar.logo-always-visible {
    display: flex !important;
    visibility: visible !important;
  }
  
  .navbar-nav {
    flex-wrap: nowrap;
    align-items: center;
  }
}