/* ════════════════════════════════════════════════
   RESPONSIVE MOBILE — fichier isolé
   Tout est sous @media (max-width:768px) : le desktop n'est JAMAIS affecté.
   ════════════════════════════════════════════════ */

/* Barre d'onglets du bas : cachée par défaut (desktop), affichée sur mobile */
.mobile-tabbar { display: none; }
.mobile-menu-overlay { display: none; }

@media (max-width: 768px) {

  /* ── Empêcher tout débordement horizontal (cause du pincement à l'arrivée) ── */
  html, body { max-width: 100%; overflow-x: hidden; width: 100%; }
  .main { max-width: 100vw; }
  /* (on NE met PAS overflow-x:hidden sur page-content : le kanban a besoin de scroller) */

  /* Filet de sécurité : aucun élément ne dépasse la largeur de l'écran.
     Le kanban-board (scroll horizontal voulu) et ses colonnes sont exclus. */
  .page-content > *:not(.kanban-board),
  .page-header,
  .dash-card, .card, .analyse-card {
    max-width: 100%;
    box-sizing: border-box;
  }
  /* Images et médias jamais plus larges que leur conteneur */
  img, svg, video, canvas { max-width: 100%; }

  /* ── Layout : une seule colonne, sidebar masquée ── */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
    height: 100dvh;   /* hauteur visible réelle sur mobile (100vh déborde sous la tabbar) */
  }
  .sidebar { display: none; }

  /* ── Header compact ── */
  .header { padding: 0 10px; gap: 8px; }
  .header-logo-text { font-size: 13px; }
  .header-site { display: none; }           /* gain de place */
  .header-role { display: none; }
  .header-username { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-btn { padding: 6px 9px; font-size: 11px; }

  /* ── Contenu : pleine largeur + marge basse pour la tabbar ── */
  .main { padding-bottom: 76px; }           /* espace pour la barre du bas */
  .page-header { padding: 14px 14px 0; flex-direction: column; gap: 8px; }
  .page-content { padding: 12px 14px 14px; }
  .page-title { font-size: 18px; }
  .page-actions { width: 100%; flex-wrap: wrap; }

  /* ── Barre d'onglets du bas ── */
  .mobile-tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 66px;
    background: var(--white);
    border-top: 1px solid var(--border);
    z-index: 200;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
    padding-bottom: env(safe-area-inset-bottom, 0);  /* encoches iPhone */
  }
  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    font-family: inherit;
    font-size:11px;
    font-weight: 600;
    padding: 6px 2px;
    transition: color 0.15s;
    position: relative;
  }
  .mobile-tab .mt-icon { font-size:22px; line-height: 1; }
  .mobile-tab.active { color: var(--accent); }
  .mobile-tab .mt-badge {
    position: absolute; top: 4px; right: 22%;
    background: var(--green); color: #fff;
    font-size:11px; font-weight: 700;
    min-width: 15px; height: 15px; line-height: 15px;
    border-radius:8px; padding: 0 3px;
  }

  /* ── Menu complet (overlay quand on tape "Menu") ── */
  .mobile-menu-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
  }
  .mobile-menu-overlay.open { display: block; }
  .mobile-menu-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: var(--white);
    border-radius:12px 12px 0 0;
    padding: 8px 12px calc(20px + env(safe-area-inset-bottom, 0));
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.22s ease;
  }
  @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .mobile-menu-handle { width: 40px; height: 4px; background: var(--border); border-radius:6px; margin: 8px auto 12px; }
  .mobile-menu-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 10px 12px 4px; }
  .mobile-menu-item {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 12px;
    border-radius:12px;
    font-size: 15px; font-weight: 500;
    color: var(--text);
    cursor: pointer;
  }
  .mobile-menu-item:active { background: var(--wood-pale); }
  .mobile-menu-item .mm-icon { font-size:22px; width: 24px; text-align: center; }

  /* ── Confort tactile général ── */
  .btn-primary, .header-btn, button { min-height: 40px; }
  .form-input { font-size:15px; }          /* évite le zoom auto iOS */

  /* ── Tableaux : scroll horizontal plutôt que débordement ── */
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* ── Modales plein écran sur mobile ── */
  .modal { width: 94vw !important; max-width: 94vw !important; max-height: 88vh; }

  /* ── Livraisons : empiler les 3 colonnes verticalement ── */
  .livraisons-grid {
    grid-template-columns: 1fr !important;   /* une seule colonne */
    gap: 14px !important;
  }

  /* ── Assistant IA : empiler chat + suggestions ── */
  .assistant-grid {
    grid-template-columns: 1fr !important;
    height: auto !important;
    gap: 12px !important;
  }

  /* ── Clients : tableau allégé (masquer Encours + bouton Voir redondant) ── */
  .crm-clients-table { display: table !important; width: 100%; white-space: normal; }
  .crm-clients-table th:nth-child(3),   /* Encours autorisé */
  .crm-clients-table td:nth-child(3),
  .crm-clients-table th:nth-child(5),   /* colonne bouton Voir */
  .crm-clients-table td:nth-child(5) {
    display: none;                        /* la ligne entière est déjà cliquable */
  }
  .crm-clients-table td, .crm-clients-table th { padding: 10px 8px; }

  /* ── Kanban : colonnes glissables avec accroche (scroll snap) ── */
  .kanban-board {
    padding: 10px 16px;
    gap: 12px;
    min-height: auto;
    scroll-snap-type: x mandatory;       /* glisse proprement de colonne en colonne */
    -webkit-overflow-scrolling: touch;
    scroll-padding: 0;
  }

  .kanban-col {
    flex: 0 0 calc(100vw - 32px);        /* un écran moins marges board (anti-débordement) */
    width: calc(100vw - 32px);
    max-width: none;
    box-sizing: border-box;
    scroll-snap-align: center;           /* centre la colonne dans l'écran */
    scroll-snap-stop: always;            /* glissement page par page, 1 seule à la fois */
  }

  .kanban-card { padding: 12px; }         /* cibles tactiles plus grandes */
  .kanban-card-title { font-size:13px; }

  /* ── Hauteur du kanban sur mobile (robuste, sans deviner la hauteur de l'en-tête) ──
     Le .main est en flex-column. On fait remplir l'espace disponible par flex,
     et la colonne hérite de cette hauteur. Cible UNIQUEMENT le kanban. */
  .page-content-kanban { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .page-content-kanban .kanban-board { flex: 1; min-height: 0; }
  .page-content-kanban .kanban-col {
    max-height: 100%;
    height: 100%;
  }
  .kanban-col-body { padding-bottom: 16px; }
  /* Indice visuel qu'on peut glisser */
  .kanban-board::after {
    content: '← glisser →';
    position: fixed;
    bottom: 70px; right: 12px; left: auto; transform: none;
    font-size:11px; color: var(--text-muted);
    background: rgba(255,255,255,0.95); padding: 3px 9px; border-radius:12px;
    pointer-events: none; opacity: 0.85; box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    z-index: 5;
  }
}
