/*
 * Tout ce qui s'affiche par-dessus la page (fenêtres, confirmations, messages) reste dans la zone sûre :
 * jamais dans la zone de l'heure de l'appli iPhone (iOS 26 y floute tout, voir #ios-statusbar-fill
 * dans base.html), jamais sous la barre d'accueil ni sous le clavier.
 *
 * Zone libre MESURÉE par js/surcouches_mobile.js (bas réel de la bande pétrole du haut, haut réel de la barre
 * de navigation du bas ou du clavier) : --ovl-top, --ovl-bottom, --ovl-centre posés sur <html>.
 * Les valeurs ci-dessous ne servent que si le script n'a pas tourné.
 */
:root {
  --ovl-top: calc(var(--pwa-offset, 0px) + var(--vv-top, 0px) + 12px);
  --ovl-bottom: calc(max(var(--sab, 0px), var(--kb, 0px)) + 12px);
}

/* Fenêtres natives <dialog> ouvertes en modale (clés de connexion rapide, préférences e-mail…) :
   centrées dans la zone sûre. Safari les plaçait en haut de l'écran, sous l'heure. */
html body dialog:modal {
  position: fixed;
  /* Centre de la zone sûre (Safari ignore le centrage par margin:auto d'un <dialog> modal). */
  inset: var(--ovl-centre, calc((100% + var(--ovl-top) - var(--ovl-bottom)) / 2)) 0 auto 0;
  transform: translateY(-50%);
  margin: 0 auto !important; /* une marge haute (16 px) décalait la fenêtre vers le bas */
  max-height: calc(100% - var(--ovl-top) - var(--ovl-bottom));
  overflow: auto;
}

/* Fenêtre de confirmation du site (js/contacto_confirm.js). */
html body .cc-confirm { padding: var(--ovl-top) 16px var(--ovl-bottom); }
html body .cc-confirm__box { max-height: 100%; overflow: auto; }

/* Messages Django affichés par-dessus la page (« Bienvenue sur Contacto ! »…) : sous la bande pétrole. */
html body #flash-messages-globaux { top: max(72px, var(--ovl-top)); }

/* Fenêtres plein écran à carte centrée (cookies, alertes, comptes provisoires, Page Pro, messagerie…) :
   la carte est centrée dans la zone sûre, jamais sous l'heure ni sous la barre d'accueil. */
html body .fixed.inset-0.items-center,
html body .contacto-push-modal-overlay,
html body .ep-pp-modal,
html body .b2r-push-onboard,
html body .b2r-choice-modal-overlay,
html body .faf-dialog-backdrop {
  padding-top: var(--ovl-top) !important;
  padding-bottom: var(--ovl-bottom) !important;
}

/* Menu ouvert + clavier (recherche dans le menu) : le panneau s'arrête au-dessus du clavier,
   la liste défile et le bas du menu (Se déconnecter) reste visible. */
html.clavier-ouvert body .contacto-drawer-panel { padding-bottom: var(--kb) !important; box-sizing: border-box; }

/* La carte d'une fenêtre centrée ne dépasse jamais la zone sûre (clavier ouvert compris) : elle défile. */
html body .fixed.inset-0.items-center > :not(.absolute) { max-height: 100% !important; overflow-y: auto; }
html body .ep-pp-modal__dialog { max-height: 100% !important; }
/* Page Pro « Envoyer un message » : fenêtre centrée sur mobile aussi (plus collée en bas). */
@media (max-width: 639px) {
  html body .ep-pp-modal { align-items: center !important; }
  html body .ep-pp-modal__dialog { border-radius: 18px !important; }
}

/* Feuilles du bas de la messagerie (Réglages, Actions…) : rien sous la barre d'accueil iOS. */
@media (max-width: 767.98px) {
  html body .b2r-options-sheet {
    padding-bottom: calc(var(--sab, 0px) + 12px);
    max-height: calc(100% - var(--ovl-top)) !important;
  }
}

/* Toast « Brouillon enregistré automatiquement » (annonce) : au-dessus de la barre du bas sur mobile, plus posé dessus. */
@media (max-width: 767.98px) {
  html body #autosave-toast { bottom: calc(68px + var(--sab, 0px) + 16px) !important; right: 16px !important; left: 16px; }
}

@media (display-mode: standalone) {
/* ---------------------------------------------------------------------------------------------------------
   Appli iPhone installée : la bande opaque du haut (#ios-statusbar-fill, hauteur --pwa-offset) recouvre le
   haut de l'écran. Toute fenêtre plein écran ou feuille du bas décale son haut de --pwa-offset et limite sa
   hauteur d'autant, pour que titre et croix restent visibles. Sur ordinateur et dans Safari normal,
   --pwa-offset vaut 0 : rien ne change (chaque padding garde au moins sa valeur d'origine).
   --------------------------------------------------------------------------------------------------------- */

/* Fenêtres centrées : le haut de la zone libre commence sous la bande ; « safe center » : si la carte est trop
   haute, elle défile au lieu de monter sous la bande. */
html body .evd-overlay,
html body .cf-refus-fond,
html body .mt-modal,
html body .sv-q-modal,
html body #ep-meet-acces-modal,
html body .meet-preview-overlay,
html body .meet-guard-overlay,
html body .modal-overlay,
html body .prefs-legal-modal,
html body .af-modal-overlay,
html body .abo-modal,
html body .b2r-guide-modal,
html body .b2r-account-overlay {
  padding-top: max(16px, calc(var(--pwa-offset, 0px) + 8px)) !important;
  align-items: safe center;
  overflow-y: auto;
}
html body .ep-modal-overlay,
html body .faf-cat-overlay,
html body .scx,
html body .faf-modal-overlay { padding-top: var(--pwa-offset, 0px) !important; box-sizing: border-box; }
@media (min-width: 640px) {
  html body .ep-modal-overlay,
  html body .faf-cat-overlay,
  html body .scx { padding-top: max(16px, calc(var(--pwa-offset, 0px) + 8px)) !important; }
}
/* Fenêtre de la fiche contact : le conteneur défile, la marge haute descend sous la bande. */
html body .fc-modal__wrap { padding-top: max(16px, calc(var(--pwa-offset, 0px) + 8px)); }
/* Fenêtres Tailwind « relative flex » dans un conteneur fixe (ajouter à une Page Pro, face à face, participants). */
html body .fixed.inset-0 > .relative.flex.min-h-full { padding-top: max(1rem, calc(var(--pwa-offset, 0px) + 8px)); }
html body .fixed.inset-0 > .relative.z-10.flex.h-full { padding-top: var(--pwa-offset, 0px); box-sizing: border-box; }
@media (min-width: 640px) {
  html body .fixed.inset-0 > .relative.z-10.flex.h-full { padding-top: max(1rem, calc(var(--pwa-offset, 0px) + 8px)); }
}

/* Plein écran (recadrage de photo) : la barre du haut commence sous la bande. */
html body .crop-modal-overlay { padding-top: var(--pwa-offset, 0px) !important; box-sizing: border-box; }
@media (max-width: 640px) {
  html body .crop-modal { height: calc(100dvh - var(--pwa-offset, 0px)) !important; max-height: calc(100dvh - var(--pwa-offset, 0px)) !important; }
}

/* Hauteurs maximales : jamais plus haut que l'écran moins la bande (valeur d'origine conservée sinon). */
html body .evd { max-height: calc(100dvh - var(--pwa-offset, 0px) - 32px); }
html body .fc-modal__box--wide { max-height: calc(100dvh - var(--pwa-offset, 0px) - 32px); }
html body .sv-q-modal__box { max-height: min(90vh, calc(100dvh - var(--pwa-offset, 0px) - 32px)); }
html body .ep-meet-acces-dialog { max-height: min(92vh, 900px, calc(100dvh - var(--pwa-offset, 0px) - 32px)); }
html body .meet-preview-dialog { max-height: min(90vh, 820px, calc(100dvh - var(--pwa-offset, 0px) - 32px)); }
html body .abo-modal__panel { max-height: min(90vh, 720px, calc(100dvh - var(--pwa-offset, 0px) - 32px)); }
html body .faf-cat-dialog { max-height: min(90dvh, calc(100dvh - var(--pwa-offset, 0px) - 8px)); }
html body .ep-modal { max-height: min(92vh, calc(100dvh - var(--pwa-offset, 0px) - 8px)); }
html body .faf-bottom-sheet { max-height: min(90dvh, calc(100dvh - var(--pwa-offset, 0px) - 8px)) !important; }
html body .ff-sheet { max-height: min(88dvh, calc(100dvh - var(--pwa-offset, 0px) - 8px)); }
html body .sdash-sheet__panel { max-height: min(88vh, 680px, calc(100dvh - var(--pwa-offset, 0px) - 8px)); }
html body .ep-nav-sheet__panel { max-height: min(78vh, 560px, calc(100dvh - var(--pwa-offset, 0px) - 8px)); }
@media (max-width: 767.98px) { html body .ppf-card { max-height: min(88vh, calc(100dvh - var(--pwa-offset, 0px) - 8px)); } }
}
