/* ===================================================================
 * admin-mobile.css — Responsive global pour l'espace admin
 * Charge depuis theme.php après les CSS spécifiques
 * v2 — utilise !important pour bypasser les inline styles si cache actif
 * =================================================================== */

/* === WORKFLOW STEPPER (force responsive même si inline CSS pas à jour) === */
@media (max-width: 760px) {
  .vmgr-workflow {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 6px !important;
    padding: 10px !important;
  }
  .vmgr-workflow .wf-label { display: none !important; }
  .vmgr-workflow .step {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
  }
  .vmgr-workflow .step .lbl-text { display: inline !important; }
  .vmgr-workflow .step .num { width: 20px !important; height: 20px !important; font-size: 10px !important; }
  .vmgr-workflow .arrow { flex-shrink: 0 !important; padding: 0 2px !important; }

  .vmgr-subviews {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
  }
  .vmgr-subviews .sv-label { white-space: nowrap !important; flex-shrink: 0 !important; }
  .vmgr-subviews .sv-item { flex-shrink: 0 !important; white-space: nowrap !important; font-size: 12px !important; }

  .filter-pills {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
    padding-bottom: 6px !important;
  }
  .filter-pills .filter-pill { flex-shrink: 0 !important; white-space: nowrap !important; }
}
/* Sur très petits écrans : labels TOUJOURS visibles, mais plus compacts + scroll horizontal */
@media (max-width: 480px) {
  .vmgr-workflow {
    padding: 8px 6px !important;
    gap: 4px !important;
  }
  .vmgr-workflow .step {
    padding: 5px 10px !important;
    font-size: 11px !important;
  }
  .vmgr-workflow .step .lbl-text {
    display: inline !important;
    font-size: 11px !important;
  }
  .vmgr-workflow .step .num {
    width: 18px !important; height: 18px !important; font-size: 9px !important;
    margin-right: 4px !important;
  }
  .vmgr-workflow .arrow {
    display: inline-block !important;
    padding: 0 1px !important;
    font-size: 11px !important;
    opacity: 0.5;
  }
}

/* === NAV ADMIN BAR (top) === */
@media (max-width: 760px) {
  .admin-bar { padding: 8px 12px !important; gap: 8px !important; flex-wrap: wrap !important; }
  .admin-bar a { font-size: 12px !important; padding: 4px 8px !important; }
  .admin-bar .admin-badge { padding: 4px 10px !important; font-size: 11px !important; }
  .admin-content { padding: 12px !important; }
}

/* === HEADERS DES PAGES === */
@media (max-width: 760px) {
  .admin-page-header { flex-direction: column; align-items: flex-start !important; gap: 12px !important; }
  .admin-page-header h1 { font-size: 22px !important; line-height: 1.2; }
  .admin-page-header .subtitle { font-size: 12px !important; flex-wrap: wrap; line-height: 1.5; }
  .admin-page-actions { width: 100%; flex-wrap: wrap; }
  .admin-page-actions .btn { flex: 1; min-width: 0; justify-content: center; }
}

/* === TABLEAUX RESPONSIVE === */
/* On wrappe automatiquement toute admin-mini-table dans un scroll horizontal */
.admin-mini-table {
  width: 100%;
  border-collapse: collapse;
}
@media (max-width: 760px) {
  /* Force le scroll horizontal sur les conteneurs de tableaux */
  .admin-section { overflow-x: auto; }
  .admin-mini-table { min-width: max-content; font-size: 12px; }
  .admin-mini-table th, .admin-mini-table td { padding: 6px 8px !important; white-space: nowrap; }
  /* Sauf colonnes marquées comme wrap */
  .admin-mini-table th[data-wrap="1"], .admin-mini-table td[data-wrap="1"] { white-space: normal; }
}

/* === STATS CARDS === */
@media (max-width: 760px) {
  .admin-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .admin-stats .stat-card { padding: 10px 12px !important; }
  .stat-num-admin { font-size: 20px !important; }
  .stat-label-admin { font-size: 10px !important; }
}
@media (max-width: 480px) {
  .admin-stats { grid-template-columns: 1fr 1fr !important; gap: 6px !important; }
}

/* === SECTIONS === */
@media (max-width: 760px) {
  .admin-section { padding: 14px !important; margin-bottom: 14px !important; border-radius: 10px !important; }
  .admin-section h3 { font-size: 16px !important; }
  .admin-section h4 { font-size: 14px !important; }
}

/* === FILTRES === */
@media (max-width: 760px) {
  .filter-pills { gap: 6px !important; }
  .filter-pill { font-size: 11.5px !important; padding: 6px 12px !important; }
}

/* === FORMS === */
@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .field input, .field select, .field textarea { font-size: 16px !important; /* Évite zoom auto iOS */ }
  /* Inputs/textarea avec font-size >= 16px = pas de zoom auto sur iOS */
  input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
  input[type="password"], input[type="date"], input[type="time"], input[type="datetime-local"],
  input[type="search"], select, textarea {
    font-size: 16px !important;
  }
}

/* === BOUTONS === */
@media (max-width: 760px) {
  .btn { font-size: 13px !important; padding: 10px 14px !important; }
  .btn-sm { font-size: 12px !important; padding: 7px 12px !important; }
}

/* === MODAL POPUP (admin-tables.js + autres) === */
@media (max-width: 760px) {
  #admin-popup-modal, #pelModal { padding: 8px !important; align-items: flex-start !important; }
  #admin-popup-content, #pelModal .modal-content {
    max-width: 100% !important;
    max-height: calc(100vh - 16px) !important;
    border-radius: 10px !important;
  }
  #admin-popup-body { padding: 12px !important; }
}

/* === SIDE BAR / DASHBOARD GRID === */
@media (max-width: 980px) {
  .dashboard-grid, .voyage-grid { grid-template-columns: 1fr !important; gap: 12px !important; }
}

/* === CALENDRIER GANTT (mobile : scroll horizontal) === */
@media (max-width: 760px) {
  .cal-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-row-name { font-size: 11px !important; }
  .cal-th-day { font-size: 9px !important; }
}

/* === GENERAL : éviter le débordement du body === */
body.admin-page { overflow-x: clip; }
.admin-content > * { max-width: 100%; }

/* === Cards d'images (carte temps réel, etc.) === */
@media (max-width: 760px) {
  .map-wrap, #cm-map { height: 50vh !important; min-height: 280px; }
}

/* === DROPDOWNS TOOLBAR voyage.php — drawer plein-écran sur mobile ===
   Fix critique : avant, .vmgr-menu.vmgr-menu-wide était positionné en absolute
   avec right:0 et min-width:580px, ce qui le faisait déborder hors écran
   sur smartphone (visible en partie tronquée à gauche).
   Maintenant : drawer fixé au bas de l'écran avec marges latérales. */
@media (max-width: 760px) {
  .vmgr-dd { position: static !important; }
  .vmgr-menu {
    position: fixed !important;
    left: 12px !important; right: 12px !important;
    top: auto !important; bottom: 12px !important;
    min-width: 0 !important; width: auto !important; max-width: none !important;
    max-height: 70vh !important; overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px !important;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.25) !important;
    z-index: 9000 !important;
  }
  .vmgr-menu.vmgr-menu-wide { padding: 12px !important; }
  .vmgr-menu-wide .vmgr-grid { grid-template-columns: 1fr !important; }
  /* Overlay sombre derrière le drawer */
  .vmgr-dd.dd-open::before {
    content: ''; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 8999;
  }
  /* Touch target : items du menu mieux espacés */
  .vmgr-menu a { padding: 12px 14px !important; min-height: 48px; }
}

/* === TRACKING VOLS (_tab_vols.php) — responsive global === */
@media (max-width: 760px) {
  .tk-filters { grid-template-columns: 1fr 1fr !important; padding: 10px !important; gap: 8px !important; }
  .tk-filters > div:first-child { grid-column: 1 / -1 !important; }
  .tk-check-btn { width: 100% !important; justify-content: center !important; min-height: 46px !important; }
}
@media (max-width: 420px) {
  .tk-filters { grid-template-columns: 1fr !important; }
  .tk-stats { grid-template-columns: 1fr 1fr !important; }
}

/* === BAR D'OUTILS voyage : empêche débordement horizontal === */
.vmgr-toolbar { max-width: 100%; }
.vmgr-toolbar .group { min-width: 0; }
.vmgr-btn { max-width: 100%; }

/* === Prévention overflow horizontal global pour TOUTES les pages admin === */
html, body { max-width: 100vw; overflow-x: clip; }
.admin-content, main { overflow-x: hidden; }

/* ═══════════════════════════════════════════════════════════════════
   iPhone / iOS Safari — optimisations spécifiques
   ═══════════════════════════════════════════════════════════════════ */

/* Safe-area pour iPhone X+ (notch + home indicator) */
@supports (padding: env(safe-area-inset-top)) {
  body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .admin-bar { padding-top: max(8px, env(safe-area-inset-top)) !important; }
  .vmgr-menu, .bc-bottom, .tr-bottom { padding-bottom: max(10px, env(safe-area-inset-bottom)) !important; }
}

/* Désactive le tap highlight bleu de Safari (remplacé par CSS :active) */
* { -webkit-tap-highlight-color: rgba(201, 154, 61, 0.18); }
a, button, [role="button"], .vmgr-btn, .btn, .tr-action, .filter-pill, .tr-pill, .tr-chip {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
/* Mais on garde la sélection sur les zones de texte */
.tr-card, .tr-meta, .admin-section, p, h1, h2, h3, h4, td, th, .field input, .field textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Empêche le rebond élastique gênant en haut/bas (iOS overscroll) */
html { overscroll-behavior-y: none; }
.tr-list, .bc-filters, .vmgr-menu, .tr-sheet-body { overscroll-behavior: contain; }

/* iOS sticky : utilise -webkit-sticky en fallback ancien iOS */
.tr-header, .tr-search, .bc-filters, .vmgr-workflow {
  position: -webkit-sticky;
}

/* Smooth momentum scroll partout */
*[class*="overflow"], .admin-section, .tr-list, .bc-list, .tr-sheet-body {
  -webkit-overflow-scrolling: touch;
}

/* Réduit les ombres sur mobile (économie GPU = scroll plus fluide) */
@media (max-width: 760px) {
  .admin-section { box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important; }
  .stat-card { box-shadow: 0 1px 2px rgba(0,0,0,0.04) !important; }
  .tr-card { box-shadow: 0 1px 4px rgba(0,0,0,0.05) !important; }
  /* Désactive le backdrop-filter (gourmand) sur mobile */
  .vmgr-menu, [class*="backdrop-filter"], .bc-overlay { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
}

/* Hover states inutiles sur touch — désactivés (évite le "sticky hover" iOS) */
@media (hover: none) and (pointer: coarse) {
  .vmgr-btn:hover, .btn:hover, .filter-pill:hover, .tr-pill:hover, .tr-card:hover,
  .vmgr-card:hover, .bc-card:hover { transform: none !important; }
}

/* Touch targets : minimum 44×44px (Apple HIG) */
@media (max-width: 760px) {
  .btn, .vmgr-btn, .tr-action, .filter-pill, .tr-pill,
  button:not(.bc-tpl-btn):not(.tr-clear-all), [role="button"] {
    min-height: 40px;
  }
  /* Icônes cliquables : 36px (un peu plus petit OK) */
  .ic-btn, .vmgr-toolbar [class*="-toggle"] { min-height: 36px; min-width: 36px; }
}

/* Performance : GPU layer pour les éléments animés/sticky */
.tr-header, .vmgr-workflow, .bc-filters, .tr-sheet, .vmgr-menu, .tr-bottom {
  transform: translateZ(0);
  will-change: transform;
}

/* Date picker iOS : taille minimale pour faciliter le tap */
input[type="date"], input[type="time"], input[type="datetime-local"] {
  min-height: 40px;
}

/* Évite le ghost-click sur iOS quand on tape sur un label associé à une checkbox */
label { touch-action: manipulation; cursor: pointer; }

/* Boutons de formulaires : réinitialise le style iOS par défaut */
input[type="submit"], button {
  -webkit-appearance: none;
  appearance: none;
  border-radius: inherit;
}

/* === Performance : skeleton/placeholder rendu plus simple === */
@media (max-width: 480px) {
  /* Sur très petits écrans, on réduit drastiquement les gradients gourmands */
  .vmgr-btn-primary, .vmgr-btn-secondary, .ctx-btn-go,
  .stat-card, .tr-day-head, .tr-card-head {
    background-image: none !important;
  }
  .vmgr-btn-primary { background-color: #1a3d33 !important; color: white; }
  .vmgr-btn-secondary { background-color: #3b82f6 !important; color: white; }
}

/* === Sticky bar : hauteur fixe pour éviter le jump === */
@media (max-width: 760px) {
  .vmgr-toolbar { position: sticky; top: 0; z-index: 50; background: var(--cream, #fefaee); padding: 8px !important; }
  .vmgr-toolbar.scrolled { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
}

/* === Pellerins tab : la table massive en scroll horizontal natif === */
@media (max-width: 760px) {
  .pel-table-wrap, .pel-rows-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pel-table { font-size: 12px !important; }
}

/* === Pull-to-refresh discret (iOS) — désactivé pour éviter les conflits === */
body.admin-page { overscroll-behavior-y: contain; }

