/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* Ensure the mermaid pre block is a positioning context for the expand button */
.content pre.mermaid {
    position: relative;
}

.content pre.mermaid svg {
    display: block;
    margin: 0 auto;
}

/* Expand button (upper-right corner of each diagram) */
.mermaid-expand-button {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--icons);
    border-radius: 4px;
    background: var(--bg);
    color: var(--icons);
    cursor: pointer;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, border-color 0.15s;
    z-index: 1;
}

pre.mermaid:hover .mermaid-expand-button,
.mermaid-expand-button:focus-visible {
    opacity: 1;
}

.mermaid-expand-button:hover,
.mermaid-expand-button:focus-visible {
    background: var(--sidebar-bg);
    border-color: var(--sidebar-active);
    color: var(--sidebar-active);
}

.mermaid-expand-button svg {
    width: 16px;
    height: 16px;
}

/* Modal overlay */
.mermaid-modal-open {
    overflow: hidden;
}

.mermaid-modal[hidden] {
    display: none;
}

.mermaid-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
}

.mermaid-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
}

.mermaid-modal__panel {
    position: relative;
    margin: min(4vh, 24px) auto;
    width: min(96vw, 1600px);
    height: 92vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--icons);
    background: var(--bg);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.mermaid-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--icons);
}

.mermaid-modal__title {
    color: var(--fg);
    font-size: 16px;
}

.mermaid-modal__close {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--icons);
    border-radius: 4px;
    background: var(--bg);
    color: var(--icons);
    cursor: pointer;
    padding: 0;
}

.mermaid-modal__close:hover,
.mermaid-modal__close:focus-visible {
    background: var(--sidebar-bg);
    border-color: var(--sidebar-active);
    color: var(--sidebar-active);
}

.mermaid-modal__close svg {
    width: 14px;
    height: 14px;
}

.mermaid-modal__help {
    position: absolute;
    right: calc((100vw + min(96vw, 1600px)) / 2 + 10px);
    top: min(4vh, 24px);
    z-index: 1;
    width: max-content;
    max-width: 300px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--icons);
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
    color: var(--sidebar-fg);
    font-size: 13px;
    font-weight: 600;
}

.mermaid-modal__help strong {
    color: var(--fg);
    font-size: 14px;
}

.mermaid-modal__help span {
    white-space: nowrap;
}

.mermaid-modal__help kbd {
    border: 1px solid var(--icons);
    border-radius: 4px;
    padding: 1px 5px;
    background: var(--sidebar-bg);
    color: var(--fg);
    font: inherit;
}

.mermaid-modal__help span kbd:last-of-type {
    margin-right: 0.35em;
}

@media (max-width: 2240px) {
    .mermaid-modal__panel {
        margin-bottom: 0;
        height: calc(92vh - 84px);
    }

    .mermaid-modal__help {
        position: relative;
        inset: auto;
        width: min(96vw, 1600px);
        margin: 10px auto 0;
        max-width: 96vw;
        box-sizing: border-box;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .mermaid-modal__help strong {
        margin-right: 8px;
    }

    .mermaid-modal__help span {
        border-left: 1px solid var(--icons);
        padding-left: 14px;
    }
}

.mermaid-modal__content {
    overflow: auto;
    padding: 20px;
    flex: 1;
    min-height: 0;
}

.mermaid-modal__content svg {
    display: block;
    width: 100%;
    height: auto;
    max-width: none;
}

.mermaid-modal__svg-wrapper {
    display: block;
    margin: 0 auto;
}
