/* ============================================
   SYSTÈME MOBILE COMPLET - STYLE APP
   ============================================ */

/* Variables mobile */
:root {
  --mobile-touch-target: 44px; /* Taille minimale pour le touch */
  --mobile-spacing: 1rem;
  --mobile-border-radius: 12px;
}

/* Safe area pour iPhone X et plus */
@supports (padding: max(0px)) {
  .app-container,
  .main-content,
  .header {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* ============================================
   NAVIGATION MOBILE - STYLE APP
   ============================================ */

@media (max-width: 900px) {
  /* Sidebar mobile - style drawer */
  .sidebar {
    width: 280px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  /* Bouton menu mobile - plus grand pour le touch */
  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.75rem;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }
  
  .mobile-menu-btn:active {
    background: rgba(0, 0, 0, 0.08);
    transform: scale(0.95);
  }
  
  /* Overlay sidebar */
  .sidebar-overlay {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
}

/* ============================================
   TABLEAUX MOBILE - TRANSFORMATION EN CARTES
   ============================================ */

@media (max-width: 768px) {
  /* Transformation en cartes : opt-in avec .table-mobile-cards */
  .table-container.table-mobile-cards table {
    display: none;
  }
  
  /* Afficher les cartes à la place */
  .table-container.table-mobile-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }
  
  /* Cartes pour chaque ligne */
  .table-card {
    display: block !important;
    background: #ffffff;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    animation: cardFadeIn 0.3s ease-out;
    animation-fill-mode: both;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    box-sizing: border-box;
  }
  
  .table-card:nth-child(1) { animation-delay: 0.05s; }
  .table-card:nth-child(2) { animation-delay: 0.1s; }
  .table-card:nth-child(3) { animation-delay: 0.15s; }
  .table-card:nth-child(4) { animation-delay: 0.2s; }
  .table-card:nth-child(5) { animation-delay: 0.25s; }
  .table-card:nth-child(n+6) { animation-delay: 0.3s; }
  
  @keyframes cardFadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .table-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  }
  
  /* En-tête de carte */
  .table-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  }
  
  .table-card__title {
    font-weight: 600;
    font-size: 1rem;
    color: #1d1d1f;
    margin: 0;
  }
  
  .table-card__badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
  }
  
  /* Corps de carte */
  .table-card__body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }
  
  .table-card__field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }
  
  .table-card__label {
    font-size: 0.75rem;
    color: #6e6e73;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  
  .table-card__value {
    font-size: 0.9375rem;
    color: #1d1d1f;
    font-weight: 500;
  }
  
  /* Actions de carte */
  .table-card__actions {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
  }
  
  .table-card__actions .btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.875rem;
    min-height: 44px;
  }
}

/* Desktop - afficher les tableaux normalement */
@media (min-width: 769px) {
  .table-card,
  .table-cards-container {
    display: none !important;
  }
  
  .table-container.table-mobile-cards table {
    display: table !important;
  }
  
  .table-container.table-mobile-cards {
    display: block !important;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    padding: 0 !important;
  }
}

/* Mobile - FORCER l'affichage des cartes */
@media (max-width: 768px) {
  /* Par défaut, conserver les tableaux visibles (sauf opt-in cartes) */
  .table-container:not(.table-mobile-cards) {
    display: block !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-container:not(.table-mobile-cards) table {
    display: table !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    width: 100% !important;
    position: static !important;
  }
  
  /* Mode cartes seulement avec .table-mobile-cards */
  .table-container.table-mobile-cards {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    margin: 0 !important;
    width: 100% !important;
  }
  
  .table-container.table-mobile-cards:not(:has(.table-cards-container))::before {
    content: '';
    display: none;
  }
  
  .table-container.table-mobile-cards table,
  .table-container.table-mobile-cards > table {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
  }
  
  .table-cards-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .table-card {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
}

/* ============================================
   BOUTONS MOBILE - TOUCH FRIENDLY
   ============================================ */

@media (max-width: 900px) {
  /* Tous les boutons doivent être touch-friendly */
  .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    font-size: 0.9375rem;
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.1);
    touch-action: manipulation;
  }
  
  .btn-sm {
    min-height: 40px;
    min-width: 40px;
    padding: 10px 16px;
    font-size: 0.875rem;
  }
  
  /* Espacement entre boutons */
  .btn-group,
  .header__actions {
    gap: 0.75rem;
  }
  
  /* Boutons pleine largeur sur mobile */
  .btn-full-mobile {
    width: 100%;
  }
}

/* ============================================
   MODALS MOBILE - PLEIN ÉCRAN
   ============================================ */

@media (max-width: 768px) {
  .modal {
    padding: 0;
    align-items: flex-end;
  }
  
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 20px 20px 0 0;
    padding: 1.5rem;
    margin: 0;
    animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  @keyframes modalSlideUp {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
  
  /* Handle pour fermer (style iOS) */
  .modal-content::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
  }
}

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

@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    min-height: 48px;
    font-size: 16px; /* Évite le zoom sur iOS */
    padding: 14px 16px;
    -webkit-appearance: none;
    appearance: none;
  }
  
  /* Labels plus espacés */
  label {
    margin-bottom: 0.75rem;
    font-size: 0.9375rem;
  }
  
  .form-group {
    margin-bottom: 1.5rem;
  }
}

/* ============================================
   HEADER MOBILE
   ============================================ */

@media (max-width: 900px) {
  .header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #ffffff;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  }
  
  .header__title {
    font-size: 1.25rem;
    font-weight: 600;
  }
  
  .header__actions {
    flex-wrap: wrap;
  }
}

/* ============================================
   CARDS MOBILE
   ============================================ */

@media (max-width: 768px) {
  .card {
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
  }
  
  .card__header {
    margin-bottom: 1.25rem;
  }
  
  .card__title {
    font-size: 1.125rem;
  }
}

/* ============================================
   STATISTIQUES MOBILE
   ============================================ */

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .stat-card {
    padding: 1.25rem;
  }
}

/* ============================================
   SCROLL SMOOTH MOBILE
   ============================================ */

@media (max-width: 900px) {
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
  
  body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  
  /* Scrollbar personnalisée (optionnel) */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  
  ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
  }
  
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
  }
}

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

@media (max-width: 900px) {
  /* Optimiser les animations */
  * {
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Réduire les ombres sur mobile pour performance */
  .card,
  .table-card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
  
  /* Désactiver les hover sur mobile */
  @media (hover: none) {
    .btn:hover,
    .card:hover,
    tbody tr:hover {
      transform: none;
      box-shadow: inherit;
    }
  }
}

/* ============================================
   SAFE AREA - iPhone X et plus
   ============================================ */

@supports (padding: max(0px)) {
  @media (max-width: 900px) {
    .main-content {
      padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    .header {
      padding-top: max(1rem, env(safe-area-inset-top));
    }
  }
}

