/*
 * MarginaliaMD - Styles of the rendered document
 *
 * Copyright 2024-2025 Eric Seigne <eric.seigne@cap-rel.fr>
 * License AGPL-3.0-or-later
 *
 * Plain CSS, served as a file rather than inlined in view.php: the page text
 * then starts near the top of the HTML instead of behind 17 kB of styles, and
 * the browser caches it once for the whole portal.
 *
 * Not built by Vite on purpose: the build empties htdocs/assets/, and this
 * sheet must survive a portal running on the CDN fallback.
 *
 * Surfaces, borders and text follow the DaisyUI theme variables (--b1, --b2,
 * --b3, --bc), so a per-instance theme repaints the content along with the rest
 * of the page and the dark variant needs no separate rules. What is specific to
 * a document and has no theme token of its own is declared below as a --mmd-*
 * variable, with the value the portal has always used; data/theme/theme.css
 * overrides those it wants. Every oklch(var(...)) carries a literal fallback, so
 * the sheet still renders if the theme stylesheet fails to load.
 */

:root {
    /* Width of the reading column; an instance may widen it for reference tables */
    --mmd-content-width: 56rem;

    /* Links inside a document: the portal blue, not the theme primary, which is
       free to be any brand colour */
    --mmd-link: #3b82f6;

    /* Code blocks stay dark in both variants, as a code block usually does */
    --mmd-code-bg: #1f2937;
    --mmd-code-text: #e5e7eb;
    --mmd-code-inline-color: inherit;
}

/* Reading column, on the article and on everything aligned with it */
.mmd-content {
    max-width: var(--mmd-content-width);
    margin-left: auto;
    margin-right: auto;
}

/* Document content styling - prose for rendered markdown */
#document-content {
    line-height: 1.7;
}

/* Markdown prose styling */
#document-content h1 { font-size: 2em; font-weight: bold; margin: 1em 0 0.5em; border-bottom: 1px solid oklch(var(--b3, 92% 0 0)); padding-bottom: 0.3em; }
#document-content h2 { font-size: 1.5em; font-weight: bold; margin: 1em 0 0.5em; border-bottom: 1px solid oklch(var(--b3, 92% 0 0)); padding-bottom: 0.3em; }
#document-content h3 { font-size: 1.25em; font-weight: bold; margin: 1em 0 0.5em; }
#document-content h4 { font-size: 1em; font-weight: bold; margin: 1em 0 0.5em; }
#document-content p { margin: 1em 0; }
#document-content ul { margin: 1em 0; padding-left: 2em; list-style: disc; }
#document-content ol { margin: 1em 0; padding-left: 2em; list-style: decimal; }
#document-content ul ul { list-style: circle; }
#document-content ul ul ul { list-style: square; }
#document-content li { margin: 0.25em 0; }
#document-content blockquote { border-left: 4px solid oklch(var(--b3, 92% 0 0)); margin: 1em 0; padding: 0.5em 1em; color: oklch(var(--bc, 21% 0 0) / 0.7); background: oklch(var(--b2, 98% 0 0)); }
#document-content pre { background: var(--mmd-code-bg); color: var(--mmd-code-text); padding: 1em; border-radius: 0.5em; overflow-x: auto; margin: 1em 0; }
#document-content code { background: oklch(var(--b3, 92% 0 0)); color: var(--mmd-code-inline-color); padding: 0.2em 0.4em; border-radius: 0.25em; font-size: 0.9em; }
#document-content pre code { background: transparent; color: inherit; padding: 0; }
#document-content a { color: var(--mmd-link); text-decoration: underline; }
#document-content img { max-width: 100%; max-height: 400px; height: auto; margin: 1em 0; cursor: zoom-in; border-radius: 0.375rem; transition: opacity 0.2s; }
#document-content img:hover { opacity: 0.85; }

/* Lightbox overlay */
.lightbox-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.85);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: zoom-out;
    animation: lightbox-fade-in 0.2s ease;
}
@keyframes lightbox-fade-in { from { opacity: 0; } to { opacity: 1; } }
.lightbox-overlay img {
    max-width: 90vw; max-height: 80vh; object-fit: contain;
    border-radius: 0.5rem; box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    cursor: default;
}
.lightbox-caption {
    color: #e5e7eb; font-size: 0.95rem; margin-top: 0.75rem;
    max-width: 90vw; text-align: center; line-height: 1.4;
}
.lightbox-close {
    position: absolute; top: 1rem; right: 1rem;
    background: rgba(255,255,255,0.15); border: none; color: #fff;
    width: 2.5rem; height: 2.5rem; border-radius: 50%;
    font-size: 1.5rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }
#document-content table { border-collapse: collapse; width: 100%; margin: 1em 0; }
#document-content th, #document-content td { border: 1px solid oklch(var(--b3, 92% 0 0)); padding: 0.5em 1em; text-align: left; }
#document-content th { background: oklch(var(--b2, 98% 0 0)); font-weight: bold; }
#document-content hr { border: none; border-top: 1px solid oklch(var(--b3, 92% 0 0)); margin: 2em 0; }

/*
 * Callouts, from a blockquote opened by a GitHub-style marker:
 *
 *   > [!WARNING]
 *   > Text of the warning.
 *
 * Rendered identically by Parsedown (includes/markdown.php) and by the
 * browser-side pass (view.php).
 *
 * The type colours the left border and tints the background; the title keeps the
 * text colour of the page. A coloured title would have to be checked for
 * contrast against every theme an instance may define, which the border and the
 * 8% tint do not: both sit behind text that stays readable by construction.
 */
#document-content .callout {
    --mmd-callout: var(--bc, 21% 0 0);
    margin: 1.25em 0;
    padding: 0.75em 1em;
    border-left: 4px solid oklch(var(--mmd-callout));
    border-radius: 0.375rem;
    background: oklch(var(--mmd-callout) / 0.08);
}
#document-content .callout-title {
    margin: 0 0 0.35em;
    font-weight: 600;
    font-size: 0.95em;
    letter-spacing: 0.01em;
}
#document-content .callout-body > :first-child { margin-top: 0; }
#document-content .callout-body > :last-child { margin-bottom: 0; }

#document-content .callout-note { --mmd-callout: var(--in, 72% 0.15 240); }
#document-content .callout-tip { --mmd-callout: var(--su, 65% 0.15 155); }
#document-content .callout-important { --mmd-callout: var(--s, 70% 0.19 340); }
#document-content .callout-warning { --mmd-callout: var(--wa, 80% 0.16 85); }
#document-content .callout-caution { --mmd-callout: var(--er, 65% 0.22 25); }

/* Mermaid diagram styling */
#document-content .mermaid { text-align: center; margin: 1rem 0; }
#document-content .mermaid svg { max-width: 100%; height: auto; }

/* Annotation highlight styling */
.annotation-highlight {
    background-color: rgba(255, 235, 59, 0.4);
    cursor: pointer;
    border-radius: 2px;
}

.annotation-highlight:hover {
    background-color: rgba(255, 235, 59, 0.6);
}

.dark .annotation-highlight {
    background-color: rgba(255, 235, 59, 0.3);
}

.dark .annotation-highlight:hover {
    background-color: rgba(255, 235, 59, 0.5);
}

/* Scrollbar styling */
#annotations-sidebar::-webkit-scrollbar {
    width: 6px;
}

#annotations-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#annotations-sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.5);
    border-radius: 3px;
}

.dark #annotations-sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(107, 114, 128, 0.5);
}
