/*
  Calm base style for Mermaid diagrams
  - No !important
  - Minimal, neutral defaults
  - Shared visuals between normal and fullscreen via .mermaid-theme
*/

/* Variables are sourced from static/css/variables.css (root/body.dark) */

/* Container (normal view) */
.mermaid {
  position: relative;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  background: var(--scheme-bg);
  border: 1px solid var(--scheme-border);
  border-radius: var(--scheme-border-radius, 8px);
}

/* Inline fullscreen button in normal view */
.mermaid > .mermaid-fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1;
  color: var(--text-color);
  background: var(--card-bg);
  border: 1px solid var(--scheme-border);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mermaid svg,
.mermaid-fullscreen-svg-container svg {
  display: block;
  margin: 0 auto;
  height: auto;
  overflow: visible;
  max-width: 100%;
}

/* Hide original code block once processed */
.mermaid[data-processed="true"] pre,
.mermaid[data-processed="true"] code {
  display: none;
}

/*
  Shared diagram visuals
  Apply .mermaid-theme to elements that should style the SVG visuals
  (both normal .mermaid and fullscreen svg container receive this class)
*/
.mermaid-theme text {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, 'Inter', Arial, sans-serif;
  font-size: 14px;
  font-weight: 500;
  fill: var(--scheme-text-color);
  white-space: pre-line;
}

.mermaid-theme .node rect,
.mermaid-theme .node polygon,
.mermaid-theme .node path,
.mermaid-theme .node ellipse,
.mermaid-theme .node circle {
  fill: var(--scheme-bg);
  stroke: var(--scheme-branch-color);
  stroke-width: var(--scheme-arrow-width);
  rx: var(--scheme-border-radius, 6px);
  ry: var(--scheme-border-radius, 6px);
}

.mermaid-theme .edgePath path,
.mermaid-theme .edgePaths path,
.mermaid-theme .edgePaths .path,
.mermaid-theme .edgePaths .line,
.mermaid-theme .flowchart-link {
  stroke: var(--scheme-arrow-color);
  stroke-width: var(--scheme-arrow-width);
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.mermaid-theme marker path,
.mermaid-theme marker polygon,
.mermaid-theme .arrowheadPath {
  fill: var(--scheme-arrow-color);
  stroke: var(--scheme-arrow-color);
  stroke-linejoin: round;
}

.mermaid-theme .edgeLabel rect {
  fill: var(--scheme-label-bg);
  stroke: var(--scheme-label-border-color);
  stroke-width: 1px;
  rx: var(--scheme-border-radius, 6px);
  ry: var(--scheme-border-radius, 6px);
}

.mermaid-theme .edgeLabel text {
  font-size: 12.5px;
  font-weight: 500;
  fill: var(--scheme-label-text-color);
}

/* Fullscreen layout */
.mermaid-fullscreen-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: none;
  justify-content: center;
  align-items: center;
}

.mermaid-fullscreen-overlay.active {
  display: flex;
}

.mermaid-fullscreen-container {
  position: relative;
  width: min(1200px, 92vw);
  height: min(90vh, 90vh);
  background: var(--scheme-bg);
  border: 1px solid var(--scheme-border);
  border-radius: var(--scheme-border-radius, 8px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mermaid-fullscreen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--header-footer-bg);
  color: var(--text-color);
  border-bottom: 1px solid var(--border-color);
}

.mermaid-fullscreen-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.mermaid-fullscreen-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.mermaid-fullscreen-btn {
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--scheme-border);
  border-radius: 6px;
  min-width: 32px;
  height: 32px;
  padding: 4px 8px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.mermaid-fullscreen-close {
  /* reserved for any close button tweaks if needed */
}

.mermaid-fullscreen-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--scheme-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mermaid-fullscreen-svg-container {
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mermaid-fullscreen-svg-container:active {
  cursor: grabbing;
}

/* Zoom controls */
.mermaid-zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 1;
}

.mermaid-zoom-btn {
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--scheme-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.mermaid-zoom-info {
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--scheme-border);
  border-radius: 9999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  min-width: 64px;
  text-align: center;
}

@media (max-width: 768px) {
  .mermaid-fullscreen-container {
    width: 95vw;
    height: 95vh;
  }
  .mermaid-fullscreen-title {
    font-size: 0.9rem;
  }
  .mermaid-fullscreen-btn {
    min-width: 28px;
    height: 28px;
    font-size: 13px;
  }
}
