/* ============================================
   MERMAID FIT PAGE - Export PDF Obsidian
   ============================================ */

/* ---------- MODE LECTURE & ÉDITION ---------- */
.mermaid {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  width: 100% !important;
  overflow: hidden !important;
}

.mermaid svg {
  max-width: 100% !important;
  max-height: 100% !important;
  width: 100% !important;
  height: auto !important;
  object-fit: contain !important;
}

/* ---------- EXPORT PDF (PRINT) ---------- */
@media print {

  /* Empêche la découpe du diagramme sur 2 pages */
  .mermaid {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    display: flex !important;
    justify-content: center !important;
  }

  /* Force le SVG à tenir dans la largeur de la page */
  .mermaid svg {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    max-height: 25cm !important; /* Hauteur max A4 paysage */
    object-fit: contain !important;
    page-break-inside: avoid !important;
  }

  /* Réduit automatiquement les grands diagrammes */
  .mermaid svg[style*="width"] {
    width: 100% !important;
  }

  /* Ajuste la taille du texte dans les nœuds */
  .mermaid text {
    font-size: 12px !important;
  }

  /* Marges de page optimisées pour Mermaid */
  @page {
    margin: 1cm;
    size: A4 landscape; /* Paysage pour plus d'espace */
  }
}

/* ---------- DIAGRAMMES TRÈS LARGES ---------- */
/* Si un diagramme déborde encore, on le réduit */
@media print and (max-width: 1000px) {
  .mermaid svg {
    transform: scale(0.85);
    transform-origin: center top;
  }
}

/* ---------- MODE PAYSAGE FORCÉ ---------- */
@page landscape {
  size: A4 landscape;
}

/* ---------- HAUTEUR MAX SELON ORIENTATION ---------- */
@media print and (orientation: portrait) {
  .mermaid svg {
    max-height: 22cm !important; /* A4 portrait */
  }
}

@media print and (orientation: landscape) {
  .mermaid svg {
    max-height: 16cm !important; /* A4 paysage */
  }
}
