/* Mermaid figures, click to enlarge (assets/js/mermaid-figures.js, includes/mermaid-figure.php).
   Both themes: colours come from the site tokens; the diagram itself is themed by the script. */

.mf {
    position: relative;
    margin: 1.75rem 0;
    padding: 3rem 1rem 1rem;
    background: var(--surface);
    border: 1px solid rgba(133, 133, 160, 0.28);
    border-radius: 12px;
}
.mf__open {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 1;
    font: 600 0.8rem/1 var(--font-body, Manrope, sans-serif);
    color: var(--text);
    background: var(--bg);
    border: 1px solid rgba(133, 133, 160, 0.45);
    border-radius: 6px;
    padding: 0.45rem 0.7rem;
    cursor: pointer;
}
.mf__open:hover:not(:disabled) { border-color: var(--accent); }
.mf__open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mf__open:disabled { opacity: 0.45; cursor: default; }

.mf__canvas { min-height: 160px; overflow-x: auto; }
.mf--drawn .mf__canvas { cursor: zoom-in; }
.mf__canvas svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
/* Page typography (e.g. .guide-section p { line-height: 1.7 }) must not leak into the
   HTML labels after Mermaid has measured them. */
.mf__canvas foreignObject p,
.mf__canvas foreignObject div,
.mf__canvas foreignObject span {
    margin: 0;
    line-height: 1.35;
    font-size: inherit;
    color: inherit;
}

/* Without JavaScript, or when the diagram cannot be drawn, show the description instead. */
.mf__fallback { color: var(--text); }
.mf__fallback p { margin: 0 0 0.75rem; line-height: 1.6; }
.mf__fallback details { margin-top: 0.5rem; }
.mf__fallback summary { cursor: pointer; color: var(--text-secondary); font-size: 0.85rem; }
.mf__fallback pre {
    margin: 0.5rem 0 0;
    padding: 0.75rem;
    overflow-x: auto;
    white-space: pre-wrap;
    font: 0.78rem/1.5 var(--font-mono, "JetBrains Mono", monospace);
    color: var(--text-secondary);
    background: var(--bg);
    border-radius: 8px;
}
html.js .mf:not(.mf--failed) .mf__fallback { display: none; }
html:not(.js) .mf__canvas,
html:not(.js) .mf__open,
.mf--failed .mf__canvas,
.mf--failed .mf__open { display: none; }
.mf--failed, html:not(.js) .mf { padding-top: 1.25rem; }

.mf figcaption {
    margin-top: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* The enlarge dialog. The site's global reset removes the dialog's default margin:auto. */
dialog.mf-dialog {
    margin: auto;
    padding: 0.75rem 1rem 1rem;
    width: min(1280px, 96vw);
    max-width: 96vw;
    max-height: 92vh;
    background: var(--surface);
    color: var(--text);
    border: 1px solid rgba(133, 133, 160, 0.35);
    border-radius: 14px;
}
dialog.mf-dialog::backdrop { background: rgba(5, 5, 8, 0.72); }
.mf-dialog__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.mf-dialog__cap { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
.mf-dialog__close {
    font: 600 0.85rem/1 var(--font-body, Manrope, sans-serif);
    color: var(--text);
    background: var(--bg);
    border: 1px solid rgba(133, 133, 160, 0.45);
    border-radius: 6px;
    padding: 0.5rem 0.85rem;
    cursor: pointer;
}
.mf-dialog__close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mf-dialog__body { overflow: auto; max-height: calc(92vh - 4.5rem); }
.mf-dialog__body svg { display: block; width: 100%; height: auto; max-width: none; }

@media (max-width: 640px) {
    .mf { padding: 2.8rem 0.6rem 0.75rem; }
    dialog.mf-dialog { padding: 0.5rem; }
    /* On a phone the dialog is no wider than the page, so enlarging must mean bigger:
       keep a readable width and let the diagram scroll sideways inside the dialog. */
    .mf-dialog__body svg { width: max(100%, 720px); }
}
@media (prefers-reduced-motion: reduce) {
    .mf__open, .mf-dialog__close { transition: none; }
}
