/**
 * PWA Mobile Optimizations
 * Optimisations spécifiques pour mobile et PWA
 */

/* ============================================
   ZONES DE TOUCH OPTIMISÉES
   ============================================ */

/* Tous les éléments interactifs doivent avoir une taille minimale de 44x44px */
.btn,
.nav-link,
.form-control,
.select2-container .select2-selection,
input[type="checkbox"],
input[type="radio"],
label,
a:not(.dropdown-item) {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Boutons spécifiques */
.btn-sm {
  min-height: 36px;
  min-width: 36px;
  padding: 0.375rem 0.75rem;
}

.btn-xs {
  min-height: 32px;
  min-width: 32px;
  padding: 0.25rem 0.5rem;
}

/* ============================================
   TABLES RESPONSIVE
   ============================================ */

/* Wrapper pour toutes les tables */
.table-responsive {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
}

/* Masquer certaines colonnes sur mobile */
@media (max-width: 767.98px) {
  .table .d-none-mobile {
    display: none !important;
  }
  
  /* Colonnes optionnelles à masquer */
  .table th.d-md-table-cell,
  .table td.d-md-table-cell {
    display: none;
  }
  
  /* Réduire la taille des cellules */
  .table td,
  .table th {
    padding: 0.5rem;
    font-size: 0.875rem;
  }
  
  /* Empêcher le wrapping forcé sur certaines colonnes importantes */
  .table td.important,
  .table th.important {
    white-space: nowrap;
    min-width: 100px;
  }
}

/* Mode Card pour tables sur très petits écrans */
@media (max-width: 575.98px) {
  .table-card-view {
    display: block;
  }
  
  .table-card-view thead,
  .table-card-view tbody,
  .table-card-view tr,
  .table-card-view td {
    display: block;
    width: 100%;
  }
  
  .table-card-view tr {
    margin-bottom: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.75rem;
    background: white;
  }
  
  .table-card-view td {
    border: none;
    padding: 0.5rem 0;
    text-align: left !important;
  }
  
  .table-card-view td:before {
    content: attr(data-label) ": ";
    font-weight: bold;
    display: inline-block;
    min-width: 100px;
  }
}

/* ============================================
   FORMULAIRES MOBILE
   ============================================ */

/* Inputs et selects sur mobile */
@media (max-width: 767.98px) {
  .form-control,
  .form-select,
  .select2-container {
    font-size: 16px; /* Évite le zoom automatique sur iOS */
    min-height: 44px;
  }
  
  /* Labels au-dessus des champs sur mobile */
  .form-label {
    margin-bottom: 0.5rem;
    font-weight: 500;
  }
  
  /* Groupes de champs */
  .input-group {
    flex-wrap: wrap;
  }
  
  .input-group > .form-control,
  .input-group > .form-select {
    flex: 1 1 100%;
    margin-bottom: 0.5rem;
  }
  
  /* Champs côte à côte sur desktop, empilés sur mobile */
  .row .col-md-6,
  .row .col-md-4,
  .row .col-md-3 {
    margin-bottom: 1rem;
  }
}

/* ============================================
   MODALS MOBILE
   ============================================ */

@media (max-width: 767.98px) {
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  
  .modal-content {
    height: 100%;
    border-radius: 0;
    border: none;
  }
  
  .modal-header {
    border-bottom: 1px solid #dee2e6;
    padding: 1rem;
  }
  
  .modal-body {
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .modal-footer {
    border-top: 1px solid #dee2e6;
    padding: 1rem;
    flex-wrap: wrap;
  }
  
  .modal-footer .btn {
    flex: 1 1 auto;
    margin: 0.25rem;
    min-width: calc(50% - 0.5rem);
  }
}

/* ============================================
   NAVIGATION MOBILE
   ============================================ */

@media (max-width: 991.98px) {
  /* Menu horizontal sur mobile */
  .horizontal-menu .navbar-nav {
    flex-direction: column;
  }
  
  .horizontal-menu .nav-link {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  /* Masquer le texte des icônes sur très petits écrans */
  @media (max-width: 575.98px) {
    .horizontal-menu .nav-link span:not(.badge) {
      display: none;
    }
    
    .horizontal-menu .navbar-brand {
      font-size: 1rem;
    }
  }
  
  /* Dropdowns full-width sur mobile */
  .dropdown-menu {
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
}

/* ============================================
   CARDS ET GRID
   ============================================ */

/* Cards responsive */
@media (max-width: 575.98px) {
  .row > [class*="col-"] {
    margin-bottom: 1rem;
  }
  
  .card {
    margin-bottom: 1rem;
  }
  
  /* Stats cards sur mobile */
  .stats-card {
    min-height: auto;
  }
}

/* ============================================
   IMAGES RESPONSIVE
   ============================================ */

img {
  max-width: 100%;
  height: auto;
}

/* Images dans les cards */
.card img {
  width: 100%;
  object-fit: cover;
}

/* ============================================
   GESTES TACTILES
   ============================================ */

/* Désactiver la sélection de texte sur les éléments interactifs */
.btn,
.nav-link,
.card {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-touch-callout: none;
  user-select: none;
}

/* Feedback visuel au touch */
.btn:active,
.nav-link:active,
.card:active {
  opacity: 0.8;
  transform: scale(0.98);
  transition: all 0.1s;
}

/* ============================================
   PERFORMANCE MOBILE
   ============================================ */

/* Réduire les animations sur mobile pour économiser la batterie */
@media (max-width: 767.98px) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  /* Garder les animations importantes */
  .spinner,
  .loading,
  .fade {
    animation-duration: 1s !important;
    transition-duration: 0.3s !important;
  }
}

/* ============================================
   UTILITAIRES MOBILE
   ============================================ */

/* Masquer sur mobile */
.d-mobile-none {
  display: none !important;
}

@media (min-width: 768px) {
  .d-mobile-none {
    display: block !important;
  }
}

/* Afficher uniquement sur mobile */
.d-mobile-only {
  display: block !important;
}

@media (min-width: 768px) {
  .d-mobile-only {
    display: none !important;
  }
}

/* Espacement mobile */
@media (max-width: 767.98px) {
  .mb-mobile-2 {
    margin-bottom: 0.5rem !important;
  }
  
  .mb-mobile-3 {
    margin-bottom: 1rem !important;
  }
  
  .p-mobile-2 {
    padding: 0.5rem !important;
  }
  
  .p-mobile-3 {
    padding: 1rem !important;
  }
}

/* ============================================
   PWA SPECIFIC
   ============================================ */

/* Indicateur de statut de connexion */
.connection-status {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-width: 575.98px) {
  .connection-status {
    top: 5px;
    right: 5px;
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* Banner d'installation PWA */
.pwa-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  margin: 0;
  border-radius: 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* Banner de mise à jour */
.pwa-update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  margin: 0;
  border-radius: 0;
}


