
/* PVettese Atelier v41 — modales iPhone : safe-area + fermeture toujours accessible */
@media (max-width: 760px){
  /* Toutes les fenêtres dialog de l'app restent sous l'encoche / barre système. */
  dialog{
    width:calc(100% - 16px) !important;
    max-width:calc(100% - 16px) !important;
    max-height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px) !important;
    margin-top:max(10px, env(safe-area-inset-top, 0px)) !important;
    margin-bottom:max(10px, env(safe-area-inset-bottom, 0px)) !important;
    border-radius:16px !important;
  }

  /* Pop-up fiche œuvre : légèrement plus étroite et moins haute. */
  #pvArtworkViewer,
  #artDialog,
  #formDialog{
    width:calc(100% - 22px) !important;
    max-width:calc(100% - 22px) !important;
    max-height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 28px) !important;
    overflow:auto !important;
  }

  /* En-tête compact : le titre n'écrase plus la croix. */
  dialog .modalHead,
  dialog .dialogHead,
  dialog .pvViewerHead,
  dialog header{
    position:sticky !important;
    top:0 !important;
    z-index:50 !important;
    min-height:48px !important;
    padding:7px 8px !important;
    gap:6px !important;
    background:inherit;
  }

  dialog .modalHead h2,
  dialog .dialogHead h2,
  dialog .pvViewerHead h2,
  dialog header h2,
  dialog header strong{
    min-width:0 !important;
    max-width:calc(100% - 48px) !important;
    font-size:15px !important;
    line-height:1.15 !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
    white-space:nowrap !important;
  }

  /* Boutons de fermeture : toujours dans la zone tactile accessible. */
  dialog .close,
  dialog .closeBtn,
  dialog [data-close],
  #pvArtworkViewer button[aria-label="Fermer"],
  #artDialog button[aria-label="Fermer"],
  #formDialog button[aria-label="Fermer"]{
    position:relative !important;
    flex:0 0 40px !important;
    width:40px !important;
    height:40px !important;
    min-width:40px !important;
    min-height:40px !important;
    top:auto !important;
    right:auto !important;
    margin-left:auto !important;
    z-index:60 !important;
  }

  /* Si une croix utilise un positionnement absolu dans l'ancienne version. */
  #pvArtworkViewer > button:first-child,
  #artDialog > button:first-child,
  #formDialog > button:first-child{
    max-top:none;
  }
}

/* iPhone installé sur écran d'accueil : marge de sécurité supplémentaire. */
@media (max-width: 760px) and (display-mode: standalone){
  dialog{
    margin-top:max(16px, calc(env(safe-area-inset-top, 0px) + 8px)) !important;
  }
}
