/*
 * Build-time mermaid diagrams (sphinx_gp_mermaid).
 *
 * Each diagram is inlined twice — a light and a dark SVG — and this stylesheet
 * shows exactly one. Mermaid bakes literal colours into an id-scoped,
 * !important <style>, so a single SVG cannot be re-themed by CSS; the two
 * variants share identical geometry, so toggling display never shifts layout.
 */

.gp-sphinx-mermaid {
  margin: 1.5rem 0;
  /* Preserve-mode diagrams scroll within the column instead of overflowing it. */
  overflow-x: auto;
}

.gp-sphinx-mermaid__variant svg {
  /* Intrinsic width/height/viewBox are set at build time so the browser can
     reserve geometry before paint. Responsive policy rules below decide
     whether the SVG scales to the column or keeps that intrinsic width. */
  display: block;
  margin: 0 auto;
}

.gp-sphinx-mermaid--fit .gp-sphinx-mermaid__variant svg {
  max-width: 100%;
  height: auto;
}

.gp-sphinx-mermaid--preserve .gp-sphinx-mermaid__variant svg {
  max-width: none;
}

.gp-sphinx-mermaid > figcaption {
  text-align: center;
  font-size: 0.9em;
  margin-top: 0.5rem;
}

/*
 * Three-state theme toggle, mirroring Furo's light/dark logo switching:
 *   - default: light variant,
 *   - explicit dark (body[data-theme="dark"]): dark variant,
 *   - system dark with no explicit choice: dark variant.
 * data-theme is set on <body> before first paint and <body> is never swapped
 * during SPA navigation, so the correct variant shows immediately and stays
 * correct across page swaps with no JavaScript.
 */
.gp-sphinx-mermaid__variant--theme-light {
  display: block;
}

.gp-sphinx-mermaid__variant--theme-dark {
  display: none;
}

body[data-theme="dark"] .gp-sphinx-mermaid__variant--theme-light {
  display: none;
}

body[data-theme="dark"] .gp-sphinx-mermaid__variant--theme-dark {
  display: block;
}

@media (prefers-color-scheme: dark) {
  body:not([data-theme="light"]) .gp-sphinx-mermaid__variant--theme-light {
    display: none;
  }

  body:not([data-theme="light"]) .gp-sphinx-mermaid__variant--theme-dark {
    display: block;
  }
}

/* Shown only when mmdc is unavailable at build time (degraded fallback). */
.gp-sphinx-mermaid__fallback {
  white-space: pre;
  overflow-x: auto;
}
