/**
 * Mermaid Diagram Zoom Styles
 * Add to Sphinx _static/ folder and include in conf.py
 */

/* Container for mermaid diagrams */
.mermaid-container {
    position: relative;
    cursor: zoom-in;
    display: block;
    width: 100%;
    max-width: 100%;
    transition: opacity 0.2s;
}

.mermaid-container pre.mermaid,
.mermaid-container div.mermaid {
    width: 100%;
    display: block;
}

.mermaid-container svg {
    width: 100%;
    height: auto;
    display: block;
}

/* Specific styling for Furo theme */
#furo-main-content .mermaid-container {
    width: 100%;
    max-width: 100%;
}

.mermaid-container:hover {
    opacity: 0.9;
}

.mermaid-container.zoomed {
    cursor: zoom-out;
}

/* Overlay for zoomed view */
.mermaid-zoom-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    cursor: zoom-out;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    box-sizing: border-box;
}

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

.mermaid-zoom-overlay svg {
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
    height: auto;
    cursor: zoom-out;
    background: white;
    padding: 1rem;
    border-radius: 4px;
}

/* Prevent child elements from blocking clicks on the overlay */
.mermaid-container svg * {
    pointer-events: none;
}

.mermaid-container svg {
    pointer-events: auto;
}

/* IMPORTANT: Allow clicks through to overlay background */
.mermaid-zoom-overlay svg {
    pointer-events: none;
}

.mermaid-zoom-overlay {
    pointer-events: auto;
}

/* Close button */
.mermaid-zoom-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: white;
    font-size: 2rem;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 10000;
    line-height: 1;
    font-family: Arial, sans-serif;
    pointer-events: auto;
}

.mermaid-zoom-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.mermaid-zoom-close:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Zoom hint */
.mermaid-container::after {
    content: '🔍 Click to zoom';
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.mermaid-container:hover::after {
    opacity: 1;
}

/* Animations */
@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes zoomOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

.mermaid-zoom-overlay.active {
    animation: zoomIn 0.2s ease-out;
}

.mermaid-zoom-overlay.closing {
    animation: zoomOut 0.2s ease-out;
}

.mermaid-zoom-overlay.active svg {
    animation: zoomIn 0.2s ease-out;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .mermaid-zoom-overlay {
        padding: 1rem;
    }

    .mermaid-zoom-overlay svg {
        max-width: 98vw;
        max-height: 98vh;
        padding: 0.5rem;
    }

    .mermaid-zoom-close {
        top: 0.5rem;
        right: 0.5rem;
        width: 36px;
        height: 36px;
        font-size: 1.5rem;
    }
}

/* Print: hide zoom controls */
@media print {
    .mermaid-zoom-overlay,
    .mermaid-zoom-close,
    .mermaid-container::after {
        display: none !important;
    }

    .mermaid-container svg {
        width: 100%;
    }
}