/* ==========================================================================
   IAFA Mobile Adapter CSS (iPhone iOS Safari & Android Chrome) — v1.8.5
   GARANTIE STRICTE : 100 % des règles sont confinées sous `body.iafa-mobile-ux`.
   Sur PC (sans `body.iafa-mobile-ux`), AUCUNE règle ci-dessous ne s'applique.
   ========================================================================== */

/* Par défaut (sur PC), masquer intégralement tout élément injecté pour mobile */
body:not(.iafa-mobile-ux) .iafa-mobile-only,
body:not(.iafa-mobile-ux) #iafaMobileTopBar,
body:not(.iafa-mobile-ux) #iafaMobileDrawerBackdrop,
body:not(.iafa-mobile-ux) #iafaMobileBottomNav,
body:not(.iafa-mobile-ux) #iafaGradinTouchConfirmBar,
body:not(.iafa-mobile-ux) .iafa-mobile-cards-wrapper,
body:not(.iafa-mobile-ux) .iafa-mobile-view-switcher,
body:not(.iafa-mobile-ux) #iafaEmailMobileBackBar,
body:not(.iafa-mobile-ux) #iafaGradinMobileQuickBar {
  display: none !important;
}

/* Bouton flottant discret uniquement si un smartphone a forcé le mode PC */
#iafaReturnToMobileFloatingBtn {
  display: none;
}
body.iafa-desktop-forced-on-phone #iafaReturnToMobileFloatingBtn {
  display: inline-flex !important;
}

/* ==================== 1. FONDATIONS iOS SAFARI & ANDROID ==================== */
body.iafa-mobile-ux {
  min-height: 100dvh;
  padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(251, 191, 36, 0.2);
}

/* Anti-zoom automatique iOS Safari : police >= 16px sur tous les champs de saisie */
body.iafa-mobile-ux input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
body.iafa-mobile-ux select,
body.iafa-mobile-ux textarea {
  font-size: 16px !important;
  line-height: 1.35 !important;
}

/* Barres de défilement fines et fluides sur mobile (remplace le 16px PC) */
body.iafa-mobile-ux ::-webkit-scrollbar {
  width: 4px !important;
  height: 4px !important;
}
body.iafa-mobile-ux ::-webkit-scrollbar-track {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
body.iafa-mobile-ux ::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.55) !important;
  border: none !important;
  min-width: 20px !important;
  min-height: 20px !important;
  box-shadow: none !important;
}

body.iafa-mobile-ux .overflow-x-auto,
body.iafa-mobile-ux .overflow-y-auto {
  -webkit-overflow-scrolling: touch;
}

/* ==================== 2. PORTAIL DE CONNEXION (#authLandingScreen) & 2FA ==================== */
body.iafa-mobile-ux #authLandingScreen {
  padding: max(10px, env(safe-area-inset-top, 10px)) 10px max(12px, env(safe-area-inset-bottom, 12px)) 10px !important;
  align-items: flex-start !important;
  min-height: 100dvh !important;
}

body.iafa-mobile-ux #authLandingScreen > div {
  border-radius: 20px !important;
  display: flex !important;
  flex-direction: column !important;
  margin-top: auto !important;
  margin-bottom: auto !important;
}

/* Bandeau d'affiche compact en haut sur smartphone (dépliable au toucher) pour garder le login visible sans scroller */
body.iafa-mobile-ux #authLandingScreen > div > div:first-child {
  padding: 12px 14px !important;
}
body.iafa-mobile-ux #authLandingScreen:not(.iafa-poster-expanded) #authPosterFrame {
  max-width: 135px !important;
  max-height: 175px !important;
  border-radius: 12px !important;
}
body.iafa-mobile-ux #authLandingScreen:not(.iafa-poster-expanded) #authPosterImage {
  max-height: 171px !important;
  width: auto !important;
  object-fit: contain !important;
}
body.iafa-mobile-ux #authLandingScreen #authPosterCaption {
  margin-top: 6px !important;
  font-size: 10px !important;
}

/* Colonne formulaire de connexion compacte et sans débordement sur iPhone 375px */
body.iafa-mobile-ux #authLandingScreen > div > div:last-child {
  padding: 16px !important;
}
body.iafa-mobile-ux #authLandingScreen h2,
body.iafa-mobile-ux #authLandingScreen h2 + div {
  white-space: normal !important;
  font-size: 15px !important;
  line-height: 1.25 !important;
}
body.iafa-mobile-ux #authLandingScreen h2 + div {
  font-size: 12px !important;
}
body.iafa-mobile-ux #authLandingScreen > div > div:last-child p {
  font-size: 11px !important;
  line-height: 1.35 !important;
}

/* Modale 2FA adaptée aux écrans iPhone / Android */
body.iafa-mobile-ux #iafa2FAModal {
  padding: 8px !important;
  align-items: flex-end !important;
}
body.iafa-mobile-ux #iafa2FAModal > div {
  max-height: calc(94dvh - env(safe-area-inset-top, 0px)) !important;
  overflow-y: auto !important;
  border-radius: 22px !important;
  margin-bottom: env(safe-area-inset-bottom, 0px) !important;
}
body.iafa-mobile-ux #iafa2FAModalBody {
  padding: 14px !important;
}

/* ==================== 3. EN-TÊTE COMPACT (1 LIGNE) & RUBAN D'ONGLETS ==================== */
body.iafa-mobile-ux > header {
  padding-top: env(safe-area-inset-top, 0px);
}
/* Masquer l'en-tête multi-boutons PC au profit de #iafaMobileTopBar */
body.iafa-mobile-ux > header > div:first-child {
  display: none !important;
}

#iafaMobileTopBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #1e1b4b;
  border-bottom: 1px solid rgba(99, 102, 241, 0.35);
}

/* Ruban d'onglets supérieur épuré pour glissement naturel au pouce */
body.iafa-mobile-ux #navTabsBarWrapper > div {
  padding: 4px 8px !important;
}
body.iafa-mobile-ux #navTabsBarWrapper .ergo-only-helper {
  display: none !important;
}
body.iafa-mobile-ux #navTabs {
  gap: 6px !important;
  scroll-snap-type: x proximity;
  padding-bottom: 2px !important;
}
body.iafa-mobile-ux #navTabs .nav-tab {
  scroll-snap-align: start;
  padding: 6px 10px !important;
  font-size: 11px !important;
  border-radius: 10px !important;
}

/* Conteneur principal plus aéré sur petit écran */
body.iafa-mobile-ux > main {
  padding: 10px 10px 20px 10px !important;
}

/* ==================== 4. BARRE DE NAVIGATION BASSE (STYLE APP NATIVE iOS / ANDROID) ==================== */
#iafaMobileBottomNav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  background: rgba(15, 23, 42, 0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 2px solid #f59e0b;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px)) 4px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.45);
}
body.iafa-mobile-ux.iafa-auth-open #iafaMobileBottomNav {
  display: none !important;
}
.iafa-bnav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 2px;
  border-radius: 10px;
  color: #cbd5e1;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.1;
  position: relative;
  transition: all 0.15s ease;
}
.iafa-bnav-btn .iafa-bnav-ico {
  font-size: 16px;
  line-height: 1.15;
  margin-bottom: 2px;
}
.iafa-bnav-btn.active {
  background: linear-gradient(135deg, #fde047 0%, #f59e0b 100%);
  color: #0f172a;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.45);
}
.iafa-bnav-badge {
  position: absolute;
  top: 2px;
  right: 6px;
  background: #f43f5e;
  color: #ffffff;
  font-size: 9px;
  font-weight: 900;
  padding: 0 4px;
  border-radius: 9999px;
  line-height: 14px;
  min-width: 14px;
  text-align: center;
}

/* ==================== 5. TIROIR MENU MOBILE (☰ COMPTE, OUTILS & TOUS LES MODULES) ==================== */
#iafaMobileDrawerBackdrop {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  justify-content: flex-end;
}
#iafaMobileDrawerBackdrop.open {
  display: flex;
}
#iafaMobileDrawerPanel {
  width: min(88vw, 350px);
  height: 100dvh;
  background: linear-gradient(180deg, #1e1b4b 0%, #0f172a 100%);
  border-left: 2px solid #f59e0b;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px calc(18px + env(safe-area-inset-bottom, 0px)) 14px;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.6);
}

/* ==================== 6. TABLEAU DE BORD & ÉCHELLE DE TEMPS SUR MOBILE ==================== */
@media screen and (min-width: 355px) {
  body.iafa-mobile-ux #dashboardFinancialCards {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
}
body.iafa-mobile-ux #dashboardFinancialCards > div {
  padding: 10px 11px !important;
}
body.iafa-mobile-ux #dashboardFinancialCards .text-xl {
  font-size: 16px !important;
}

/* Fenêtre flottante d'étape de l'échelle de temps convertie en Bottom-Sheet stable sur mobile */
body.iafa-mobile-ux #timelineStepDynamicWindow {
  left: 8px !important;
  right: 8px !important;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  top: auto !important;
  width: auto !important;
  max-width: none !important;
  max-height: 72dvh !important;
  overflow-y: auto !important;
  z-index: 90 !important;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.55) !important;
}

/* ==================== 7. BOÎTE MAIL MAÎTRE / DÉTAIL (STYLE MAIL iOS / GMAIL) ==================== */
body.iafa-mobile-ux #tab-emails.iafa-email-detail-open #emailListContainer {
  display: none !important;
}
body.iafa-mobile-ux #tab-emails.iafa-email-detail-open > div.grid > div:first-child {
  display: none !important;
}
body.iafa-mobile-ux #tab-emails:not(.iafa-email-detail-open) #emailDetailPane {
  display: none !important;
}

/* ==================== 8. FILTRES PLEINE LARGEUR, FICHES MOBILE & TABLEAUX À 1re COLONNE FIGÉE ==================== */
body.iafa-mobile-ux #searchEntityInput,
body.iafa-mobile-ux #filterEntityType,
body.iafa-mobile-ux #filterEntityStatus,
body.iafa-mobile-ux #searchContactInput,
body.iafa-mobile-ux #filterContactCategory,
body.iafa-mobile-ux #searchSoireeInput,
body.iafa-mobile-ux #filterSoireeAssigne,
body.iafa-mobile-ux #filterSoireeDate,
body.iafa-mobile-ux #spectacleSelector,
body.iafa-mobile-ux #gradinPlanSelector {
  width: 100% !important;
  max-width: 100% !important;
}

/* Masquer la barre horizontale PC à 8 boutons sur smartphone (le swipe tactile au doigt est natif) */
body.iafa-mobile-ux .iafa-hscroll-bar {
  display: none !important;
}

/* En mode Fiches Mobile actif, masquer le conteneur du grand tableau correspondant */
body.iafa-mobile-ux .iafa-table-hidden-on-mobile {
  display: none !important;
}

/* En mode Tableau sur smartphone : figer la 1re colonne d'identification à gauche pendant le swipe horizontal */
body.iafa-mobile-ux .iafa-sticky-col-table th:first-child,
body.iafa-mobile-ux .iafa-sticky-col-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 6;
  max-width: 145px;
}
body.iafa-mobile-ux .iafa-sticky-col-table tbody td:first-child {
  background-color: #ffffff;
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.08);
}
body.iafa-mobile-ux .iafa-sticky-col-table thead th:first-child {
  background-color: #1e293b;
  z-index: 12;
}

/* ==================== 9. STUDIO PLACEMENT GRADINS 2D SUR SMARTPHONE ==================== */
/* Masquer le suiveur de curseur souris flottant sur mobile (remplacé par la barre tactile fixe en bas) */
body.iafa-mobile-ux #gradinCursorFollower {
  display: none !important;
}

#iafaGradinTouchConfirmBar {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  z-index: 65;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  border: 2px solid #fbbf24;
  border-radius: 16px;
  padding: 10px 12px;
  color: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
}

/* Sous-menus Référentiels & Administration défilables horizontalement sur 1 ligne ou empilés proprement */
body.iafa-mobile-ux #refSubMenuBar,
body.iafa-mobile-ux #adminSubTabsBar {
  flex-wrap: nowrap !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  padding: 8px !important;
  gap: 6px !important;
}
body.iafa-mobile-ux #refSubMenuBar button,
body.iafa-mobile-ux #adminSubTabsBar button {
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  font-size: 11px !important;
  padding: 7px 10px !important;
}

/* ==================== 10. LES 13 FENÊTRES MODALES ADAPTÉES AUX PETITS ÉCRANS & CLAVIERS VIRTUELS ==================== */
body.iafa-mobile-ux #adminGenericModal,
body.iafa-mobile-ux #adminImportModal,
body.iafa-mobile-ux #entityModal,
body.iafa-mobile-ux #docPreviewModal,
body.iafa-mobile-ux #newEmailModal,
body.iafa-mobile-ux #contactModal,
body.iafa-mobile-ux #excelInjectModal,
body.iafa-mobile-ux #jalonModal,
body.iafa-mobile-ux #initNewYearModal,
body.iafa-mobile-ux #copyFromPastYearModal,
body.iafa-mobile-ux #gradinExcel2DModal,
body.iafa-mobile-ux #posterFramingModal,
body.iafa-mobile-ux #auditInspectModal,
body.iafa-mobile-ux #aboutModal,
body.iafa-mobile-ux #bcChoixInspectModal {
  padding: 6px !important;
  align-items: flex-end !important;
}

body.iafa-mobile-ux #adminGenericModal > div,
body.iafa-mobile-ux #adminImportModal > div,
body.iafa-mobile-ux #entityModal > div,
body.iafa-mobile-ux #docPreviewModal > div,
body.iafa-mobile-ux #newEmailModal > div,
body.iafa-mobile-ux #contactModal > div,
body.iafa-mobile-ux #excelInjectModal > div,
body.iafa-mobile-ux #jalonModal > div,
body.iafa-mobile-ux #initNewYearModal > div,
body.iafa-mobile-ux #copyFromPastYearModal > div,
body.iafa-mobile-ux #gradinExcel2DModal > div,
body.iafa-mobile-ux #posterFramingModal > div,
body.iafa-mobile-ux #auditInspectModal > div,
body.iafa-mobile-ux #aboutModal > div,
body.iafa-mobile-ux #bcChoixInspectModal > div {
  padding: 14px !important;
  border-radius: 20px !important;
  max-height: calc(92dvh - env(safe-area-inset-top, 0px)) !important;
  overflow-y: auto !important;
  margin-bottom: env(safe-area-inset-bottom, 0px) !important;
}

/* Replier les grilles 2 colonnes étroites dans les formulaires modaux sur téléphone portrait (< 480px) */
@media screen and (max-width: 480px) {
  body.iafa-mobile-ux #entityModalBody .grid-cols-2,
  body.iafa-mobile-ux #contactModalBody .grid-cols-2,
  body.iafa-mobile-ux #newEmailModal .grid-cols-2,
  body.iafa-mobile-ux #admPanel_droits_mail .grid-cols-2 {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Toast centré au-dessus de la barre de navigation mobile */
body.iafa-mobile-ux #toastBox {
  left: 12px !important;
  right: 12px !important;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
  justify-content: center;
}
