/* Typst rendering styles */

/* Container for side-by-side display */
.typst-container.side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    margin: 1.5rem 0;
    border: 1px solid #313244;
    border-radius: 8px;
    overflow: hidden;
    background: #1e1e2e;
    align-items: stretch;
}

/* Code section */
.typst-code {
    background: #282c34;
    border-right: 1px solid #313244;
    overflow-x: auto;
    display: flex;
    flex-direction: column;
}

.typst-code pre {
    margin: 0 !important;
    border-radius: 0;
    box-shadow: none !important;
    position: relative;
    flex: 1;
}

.typst-code pre code {
    padding: 1em !important;
    padding-top: 1em !important;
    margin: 0 !important;
    display: block;
}

.typst-code pre code.hljs {
    padding: 1em !important;
    margin: 0 !important;
    box-shadow: none !important;
}

.typst-container.side-by-side .typst-code pre code.hljs {
    box-shadow: none !important;
}

/* Ensure copy button works in side-by-side */
.typst-code .copy-code-button {
    top: 0.5rem;
    right: 0.5rem;
}

/* Output section */
.typst-output {
    /* Blue-gray gradient background for the "desk" */
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    padding: 2rem;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 100%;
    position: relative;
}

.typst-output img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    /* White background and elevated shadow for paper effect */
    background: #ffffff;
    padding: 1rem;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.3),
        0 2px 4px -1px rgba(0, 0, 0, 0.2),
        0 10px 15px -3px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* Placeholder when image is not yet generated */
.typst-placeholder {
    display: none;
    text-align: center;
    color: #6c7086;
    padding: 2rem;
}

.typst-output img[src=""] + .typst-placeholder,
.typst-output img:not([src]) + .typst-placeholder,
.typst-output img[src*="404"] + .typst-placeholder {
    display: block;
}

.typst-output img[src=""]:not([src*="404"]),
.typst-output img:not([src]),
.typst-output img[src*="404"] {
    display: none;
}

.typst-note {
    font-size: 0.875rem;
    color: #6c7086;
    font-style: italic;
    margin-top: 1rem;
}

/* Render-only display */
.typst-render {
    margin: 1.5rem 0;
    /* Blue-gray surface to simulate a desk/background */
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    padding: 2rem;
    border-radius: 12px;
}

.typst-render .typst-output {
    /* Remove double background/padding - parent .typst-render already provides it */
    background: transparent;
    padding: 0;
}

/* Hide code in render mode placeholder */
.typst-render .typst-placeholder pre {
    display: none;
}

/* PDF fallback for browsers that can't embed PDFs */
.pdf-fallback {
    text-align: center;
    padding: 4rem 2rem;
    color: #cdd6f4;
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    border-radius: 8px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.pdf-fallback p {
    font-size: 1rem;
    margin-bottom: 1.5rem;
    color: #bac2de;
}

.pdf-download-btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    background: #89b4fa;
    color: #1e1e2e;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.pdf-download-btn:hover {
    background: #74c7ec;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px -2px rgba(0, 0, 0, 0.4);
}

.pdf-download-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

/* Mobile responsive design */
@media (max-width: 768px) {
    .typst-container.side-by-side {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
    }

    /* Ensure code appears first (top) */
    .typst-code {
        order: 1;
        border-right: none;
        border-bottom: 1px solid #313244;
    }

    /* Render appears second (bottom) */
    .typst-output {
        order: 2;
    }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .typst-output {
        background: #f4f4f4;
    }
}

/* Loading state */
.typst-loading {
    position: relative;
}

.typst-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #89b4fa;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}