/* ==========================================================================
   Mermaid Viewer - diagram zoom button & fullscreen pan/zoom modal
   ========================================================================== */

/* Container: allow horizontal scroll when SVG overflows,
   and anchor the absolute-positioned zoom button. */
pre.mermaid {
  position: relative;
  max-height: 70vh; /* cap the in-page diagram height */
  overflow: hidden; /* no scrollbars: rely on svg max-width/max-height to fit */
  text-align: center;
}

pre.mermaid.mermaid-has-viewer {
  cursor: zoom-in;
}

pre.mermaid > svg {
  max-width: 100%; /* keep the in-page diagram within article width */
  max-height: 70vh; /* keep the in-page diagram within viewport height */
  width: auto;
  height: auto;
  display: inline-block;
  margin: 0 auto;
}

/* ---------------------- Fullscreen Viewer Modal ---------------------- */

html.mmv-open,
html.mmv-open body {
  overflow: hidden;
}

.mermaid-viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
}

.mermaid-viewer-modal[aria-hidden='false'] {
  display: block;
}

.mermaid-viewer-modal .mmv-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 15, 0.88);
  backdrop-filter: blur(2px);
}

.mermaid-viewer-modal .mmv-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.mermaid-viewer-modal .mmv-stage.is-dragging {
  cursor: grabbing;
}

.mermaid-viewer-modal .mmv-content {
  transform-origin: center center;
  transition: transform 0.04s linear;
  will-change: transform;
  user-select: none;
  pointer-events: none;
  display: inline-block;
}

.mermaid-viewer-modal .mmv-content svg {
  display: block;
  max-width: none !important;
  max-height: none !important;
  width: auto;
  height: auto;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
  background: #fff;
  border-radius: 6px;
  padding: 16px;
}

.mermaid-viewer-modal .mmv-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.92);
  color: #222;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  pointer-events: auto;
}

.mermaid-viewer-modal .mmv-close:hover {
  background: #fff;
  color: #d93025;
}

.mermaid-viewer-modal .mmv-toolbar {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 3;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}

.mermaid-viewer-modal .mmv-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #333;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.mermaid-viewer-modal .mmv-btn:hover {
  background: rgba(26, 115, 232, 0.1);
  color: #1a73e8;
}

.mermaid-viewer-modal .mmv-scale {
  min-width: 48px;
  text-align: center;
  font-size: 13px;
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;
  user-select: none;
}

@media (max-width: 640px) {
  .mermaid-viewer-modal .mmv-close {
    top: 10px;
    right: 10px;
  }
  .mermaid-viewer-modal .mmv-toolbar {
    bottom: 14px;
  }
}
