/**
 * Blog Academic Styles
 * ====================
 * Styles for code snippets, math formulas, tables, blockquotes,
 * and other academic blog components.
 */

/* ─────────────────────────────────────────────
   1. CODE BLOCKS — macOS Carbon-style window
   ───────────────────────────────────────────── */

/* Base style for ALL code blocks */
.blog-article-content pre,
.cs-preview-body pre,
#cs-preview-body pre,
#math-preview pre {
    position: relative;
    margin: 1.5rem 0;
    padding: 2.5rem 1.25rem 1.25rem 1.25rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.7;
    overflow-x: auto;
    background: #1e1e2e;
    color: #cdd6f4;
}

/* macOS window dots — red, yellow, green (using box-shadow for reliability) */
.blog-article-content pre::after,
.cs-preview-body pre::after,
#cs-preview-body pre::after,
#math-preview pre::after {
    content: '';
    position: absolute;
    top: 13px;
    left: 16px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff5f57;
    box-shadow:
        18px 0 0 #febc2e,
        36px 0 0 #28c840;
    z-index: 2;
    pointer-events: none;
}

/* Top bar background strip */
.blog-article-content pre::before,
.cs-preview-body pre::before,
#cs-preview-body pre::before,
#math-preview pre::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    pointer-events: none;
    z-index: 1;
}

/* Language label badge — repositioned for window chrome */
.blog-article-content pre[data-label]::before,
.cs-preview-body pre[data-label]::before,
#cs-preview-body pre[data-label]::before {
    /* Override the bar — becomes the label instead */
    content: attr(data-label);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 14px;
    font-size: 0.6rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.35);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Prism-themed blocks */
.blog-article-content pre[class*="language-"],
.cs-preview-body pre[class*="language-"],
#cs-preview-body pre[class*="language-"],
#math-preview pre[class*="language-"] {
    padding: 2.5rem 1.25rem 1.25rem 1.25rem;
}

.blog-article-content pre code,
.cs-preview-body pre code,
#cs-preview-body pre code,
#math-preview pre code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.8;
    background: transparent;
    color: inherit;
    padding: 0;
    border: none;
    border-radius: 0;
    white-space: pre;
    word-break: normal;
    word-wrap: normal;
    display: block;
}

/* ─────────────────────────────────────────────
   2. INLINE CODE
   ───────────────────────────────────────────── */

.blog-article-content code:not([class*="language-"]):not(pre code),
.blog-article-content code.inline-code,
.cs-preview-body code:not([class*="language-"]):not(pre code),
.cs-preview-body code.inline-code,
#cs-preview-body code:not([class*="language-"]):not(pre code),
#cs-preview-body code.inline-code,
#math-preview code:not([class*="language-"]):not(pre code),
#math-preview code.inline-code {
    background: #f1f3f5;
    color: #e83e8c;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.875em;
    font-family: 'JetBrains Mono', 'Fira Code', 'Source Code Pro', 'Consolas', monospace;
    white-space: nowrap;
    border: 1px solid #dee2e6;
}

/* Dark mode inline code */
@media (prefers-color-scheme: dark) {

    .blog-article-content code:not([class*="language-"]):not(pre code),
    .blog-article-content code.inline-code {
        background: #2d333b;
        color: #f47067;
        border-color: #444c56;
    }
}

/* Custom scrollbar for code blocks */
.blog-article-content pre::-webkit-scrollbar,
.cs-preview-body pre::-webkit-scrollbar,
#cs-preview-body pre::-webkit-scrollbar {
    height: 6px;
}

.blog-article-content pre::-webkit-scrollbar-track,
.cs-preview-body pre::-webkit-scrollbar-track,
#cs-preview-body pre::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.blog-article-content pre::-webkit-scrollbar-thumb,
.cs-preview-body pre::-webkit-scrollbar-thumb,
#cs-preview-body pre::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.blog-article-content pre::-webkit-scrollbar-thumb:hover,
.cs-preview-body pre::-webkit-scrollbar-thumb:hover,
#cs-preview-body pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ─────────────────────────────────────────────
   3. MATHJAX / MATH FORMULAS
   ───────────────────────────────────────────── */

.blog-article-content .MathJax,
.cs-preview-body .MathJax,
#math-preview .MathJax {
    font-size: 1.1em !important;
}

/* Display math — centered block */
.blog-article-content mjx-container[display="true"],
.cs-preview-body mjx-container[display="true"],
#math-preview mjx-container[display="true"] {
    margin: 1.5rem 0 !important;
    padding: 1rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border-left: 4px solid #6c63ff;
    border-radius: 4px;
    overflow-x: auto;
    max-width: 100%;
}

/* Inline math — seamless */
.blog-article-content mjx-container:not([display="true"]),
.cs-preview-body mjx-container:not([display="true"]),
#math-preview mjx-container:not([display="true"]) {
    display: inline !important;
    margin: 0 2px;
}

/* Math formula wrapper for visual distinction */
.blog-article-content .math-tex,
.cs-preview-body .math-tex,
#math-preview .math-tex {
    /* Preserve the wrapper but don't add extra styling since MathJax handles it */
}

/* ─────────────────────────────────────────────
   4. TABLES (Academic Style)
   ───────────────────────────────────────────── */

.blog-table-wrapper {
    margin: 1.5rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: transparent;
    padding: 2px 3px 6px;
    box-sizing: border-box;
}

.blog-article-content .blog-table-wrapper .blog-academic-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin: 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.blog-article-content .blog-academic-table thead th {
    background: #f8f9fa;
    color: #212529;
    font-weight: 600;
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
    border: 1px solid #dee2e6;
}

.blog-academic-table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: top;
}

.blog-academic-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.blog-academic-table tbody tr:hover {
    background-color: #e8f0fe;
    transition: background-color 0.15s ease;
}

/* Tables in the editor content area */
.blog-article-content table,
.cs-preview-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.9rem;
    border: 1px solid #dee2e6;
}

.blog-article-content table thead th,
.cs-preview-body table thead th {
    background: #f8f9fa;
    color: #212529;
    font-weight: 600;
    padding: 10px 14px;
    border: 1px solid #dee2e6;
    text-align: left;
}

.blog-article-content table tbody td,
.cs-preview-body table tbody td {
    padding: 10px 14px;
    border: 1px solid #dee2e6;
    vertical-align: top;
}

.blog-article-content table tbody tr:nth-child(even),
.cs-preview-body table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

/* ─────────────────────────────────────────────
   5. BLOCKQUOTES (Academic Callout Style)
   ───────────────────────────────────────────── */

.blog-article-content blockquote,
.cs-preview-body blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    border-left: 4px solid #6c63ff;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #495057;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.blog-article-content blockquote::before,
.cs-preview-body blockquote::before {
    content: '\201C';
    position: absolute;
    top: -10px;
    left: 10px;
    font-size: 3rem;
    color: #6c63ff;
    opacity: 0.2;
    font-family: Georgia, serif;
    line-height: 1;
}

.blog-article-content blockquote p:last-child,
.cs-preview-body blockquote p:last-child {
    margin-bottom: 0;
}

/* ─────────────────────────────────────────────
   6. DEFINITION LISTS
   ───────────────────────────────────────────── */

.blog-article-content dl {
    margin: 1.5rem 0;
}

.blog-article-content dt {
    font-weight: 700;
    color: #333;
    margin-top: 0.75rem;
}

.blog-article-content dd {
    margin-left: 1.5rem;
    color: #555;
    margin-bottom: 0.5rem;
}

/* ─────────────────────────────────────────────
   7. KEYBOARD KEYS
   ───────────────────────────────────────────── */

.blog-article-content kbd,
.cs-preview-body kbd {
    background: linear-gradient(180deg, #f8f9fa, #e9ecef);
    border: 1px solid #ced4da;
    border-bottom: 3px solid #adb5bd;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.8em;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    color: #333;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
    white-space: nowrap;
}

/* ─────────────────────────────────────────────
   8. HIGHLIGHTED / MARKED TEXT
   ───────────────────────────────────────────── */

.blog-article-content mark {
    background: linear-gradient(120deg, #fff9c4 0%, #fff176 100%);
    padding: 2px 4px;
    border-radius: 2px;
}

/* ─────────────────────────────────────────────
   9. SUBSCRIPT / SUPERSCRIPT (Chemistry & Math)
   ───────────────────────────────────────────── */

.blog-article-content sub,
.blog-article-content sup {
    font-size: 0.75em;
    line-height: 0;
}

/* ─────────────────────────────────────────────
   10. HORIZONTAL RULES
   ───────────────────────────────────────────── */

.blog-article-content hr {
    margin: 2rem 0;
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, #dee2e6, transparent);
}

/* ─────────────────────────────────────────────
   11. FIGURE & FIGCAPTION
   ───────────────────────────────────────────── */

.blog-article-content figure {
    margin: 2rem 0;
    text-align: center;
}

.blog-article-content figure img {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.blog-article-content figcaption {
    font-size: 0.85rem;
    color: #6c757d;
    margin-top: 0.5rem;
    font-style: italic;
}

/* ─────────────────────────────────────────────
   12. ABBREVIATIONS
   ───────────────────────────────────────────── */

.blog-article-content abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
    border-bottom: none;
}

/* ─────────────────────────────────────────────
   13. ORDERED LIST ACADEMIC STYLES
   ───────────────────────────────────────────── */

.blog-article-content ol {
    counter-reset: list-counter;
    padding-left: 0;
    list-style: none;
    margin: 1rem 0;
}

.blog-article-content ol>li {
    counter-increment: list-counter;
    padding-left: 2.5rem;
    position: relative;
    margin-bottom: 0.5rem;
}

.blog-article-content ol>li::before {
    content: counter(list-counter) ".";
    position: absolute;
    left: 0;
    font-weight: 700;
    color: #6c63ff;
    min-width: 1.5rem;
}

.blog-article-content ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.blog-article-content ul li {
    margin-bottom: 0.35rem;
}

/* ─────────────────────────────────────────────
   14. COPY BUTTON FOR CODE BLOCKS
   ───────────────────────────────────────────── */

div.code-toolbar>.toolbar {
    position: absolute;
    top: 6px;
    right: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 3;
}

div.code-toolbar:hover>.toolbar {
    opacity: 1;
}

div.code-toolbar>.toolbar>.toolbar-item>button,
div.code-toolbar>.toolbar>.toolbar-item>a {
    background: rgba(255, 255, 255, 0.12);
    color: #ccc;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

div.code-toolbar>.toolbar>.toolbar-item>button:hover {
    background: rgba(108, 99, 255, 0.5);
    color: #fff;
    border-color: rgba(108, 99, 255, 0.6);
}

/* Line numbers plugin overrides */
pre.line-numbers {
    padding-left: 3.8rem !important;
    padding-top: 2.5rem !important;
}

.line-numbers .line-numbers-rows {
    top: 2.5rem !important;
    border-right: 1px solid rgba(255, 255, 255, 0.06) !important;
    left: 0 !important;
    padding-top: 0 !important;
}

.line-numbers .line-numbers-rows>span::before {
    color: rgba(255, 255, 255, 0.18) !important;
}

/* ─────────────────────────────────────────────
   15. CONTENT STUDIO EDITOR CUSTOM TOOLBAR STYLES
   ───────────────────────────────────────────── */

.note-toolbar .note-btn-group .cs-code-dropdown,
.note-toolbar .note-btn-group .cs-math-dropdown {
    min-width: 180px;
}

.note-toolbar .note-btn-group .cs-math-dropdown {
    min-width: 360px;
    padding: 0;
}

.note-toolbar .cs-math-quick {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    text-align: left;
}

.note-toolbar .cs-math-quick:hover {
    background: #6c63ff;
    color: #fff;
    border-color: #6c63ff;
}

/* ─────────────────────────────────────────────
   16. RESPONSIVE ADJUSTMENTS
   ───────────────────────────────────────────── */

@media (max-width: 768px) {
    .blog-article-content pre {
        font-size: 0.8rem;
        border-radius: 6px;
        margin: 1rem 0;
    }

    .blog-article-content mjx-container[display="true"] {
        padding: 0.75rem;
        overflow-x: auto;
    }

    .cs-math-dropdown {
        min-width: calc(100vw - 40px) !important;
    }

    .blog-article-content table {
        font-size: 0.8rem;
    }
}

/* ─────────────────────────────────────────────
   17. PRINT STYLES
   ───────────────────────────────────────────── */

@media print {
    .blog-article-content pre {
        box-shadow: none;
        border: 1px solid #ddd;
        background: #f8f9fa !important;
        color: #333 !important;
        page-break-inside: avoid;
    }

    .blog-article-content pre::after {
        background: #ccc !important;
        box-shadow:
            18px 0 0 #ccc,
            36px 0 0 #ccc !important;
    }

    .blog-article-content pre::before {
        background: rgba(0, 0, 0, 0.03) !important;
    }

    .blog-article-content pre code {
        color: #333 !important;
    }

    .blog-article-content mjx-container[display="true"] {
        border-left-color: #333;
        background: #fff;
        page-break-inside: avoid;
    }

    div.code-toolbar>.toolbar {
        display: none;
    }

    .line-numbers .line-numbers-rows {
        display: none;
    }
}

/* ─────────────────────────────────────────────
   18. VIDEO EMBEDS (YouTube & Vimeo)
   ───────────────────────────────────────────── */

.blog-video-container {
    margin: 1.75rem 0;
    width: 100%;
    clear: both;
}

.blog-video-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
    overflow: hidden;
    border-radius: 12px;
    background: #0f172a;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.blog-video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 12px;
}

/* In editor (.note-editable) and live preview */
.note-editable .blog-video-container,
.cs-preview-content .blog-video-container {
    margin: 1.25rem 0;
}

