/*
 * article-content.css
 *
 * Shared stylesheet for:
 *   - public article detail page (.it-article-content wrapper)
 *   - TinyMCE editor content preview (via tinymce init content_css)
 *
 * Goal: editor WYSIWYG matches the rendered public page. Loaded by both.
 * No TinyMCE runtime deps: safe to include on any public page.
 *
 * Scope selector preference:
 *   - Prefer .it-article-content ...  so public page selectors are namespaced
 *   - TinyMCE loads this file inside the editor iframe (no wrapper), selectors
 *     without .it-article-content also apply; that's fine, they're article-safe
 */

/* ---- Base typography ---- */
.it-article-content {
    font-size: 16px;
    line-height: 1.75;
    color: #2c3e50;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
body {
    /* TinyMCE iframe body inherits this; public pages already have their own */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.it-article-content p,
body > p {
    margin: 0 0 1em;
}

.it-article-content h1,
.it-article-content h2,
.it-article-content h3,
.it-article-content h4,
.it-article-content h5,
.it-article-content h6 {
    margin: 1.5em 0 0.6em;
    font-weight: 600;
    line-height: 1.3;
    color: #1a242f;
}

.it-article-content h1 { font-size: 1.8em; }
.it-article-content h2 { font-size: 1.5em; border-bottom: 1px solid #eaecef; padding-bottom: 0.3em; }
.it-article-content h3 { font-size: 1.25em; }
.it-article-content h4 { font-size: 1.1em; }
.it-article-content h5 { font-size: 1em; color: #566573; }
.it-article-content h6 { font-size: 0.95em; color: #7f8c8d; }

/* ---- Links ---- */
.it-article-content a {
    color: #1e87d8;
    text-decoration: none;
}
.it-article-content a:hover {
    text-decoration: underline;
}

/* ---- Lists ---- */
.it-article-content ul,
.it-article-content ol {
    margin: 0 0 1em;
    padding-left: 2em;
}
.it-article-content li {
    margin: 0.2em 0;
}

/* ---- Blockquote ---- */
.it-article-content blockquote {
    margin: 1em 0;
    padding: 0.6em 1em;
    border-left: 4px solid #dfe4ea;
    color: #566573;
    background: #f8f9fa;
}
.it-article-content blockquote p:last-child { margin-bottom: 0; }

/* ---- Images ---- */
/* body img 规则覆盖"编辑器 iframe 里图片没有 .it-article-content 包裹"的场景：
   TinyMCE content_css 加载本文件到 iframe，里面 img 直挂在 <body> 下。
   前台页面有 .it-article-content 包裹层，两条选择器同特异性，后者源码在后覆盖前者。 */
body img,
.it-article-content img {
    max-width: 100%;
    height: auto;
}
.it-article-content img {
    display: inline-block;
}
.it-article-content figure {
    margin: 1em 0;
    text-align: center;
}
.it-article-content figure img {
    display: block;
    margin: 0 auto;
}
.it-article-content figcaption {
    margin-top: 0.4em;
    color: #7f8c8d;
    font-size: 0.9em;
    text-align: center;
}

/* ---- Tables ---- */
.it-article-content .it-article-table-wrap,
.it-article-content {
    /* Allow tables to scroll horizontally on mobile rather than break layout */
}
.it-article-content table {
    border-collapse: collapse;
    margin: 1em 0;
    max-width: 100%;
    display: block;
    overflow-x: auto;
}
.it-article-content th,
.it-article-content td {
    border: 1px solid #dfe4ea;
    padding: 6px 10px;
    vertical-align: top;
}
.it-article-content th {
    background: #f8f9fa;
    font-weight: 600;
}

/* ---- Inline and block code ---- */
.it-article-content code {
    font-family: Consolas, "Courier New", Menlo, Monaco, monospace;
    font-size: 0.92em;
    background: #f6f8fa;
    padding: 1px 5px;
    border-radius: 3px;
    color: #c0392b;
}
.it-article-content pre {
    margin: 1em 0;
    padding: 12px 14px;
    background: #2b2b2b;
    color: #f8f8f2;
    border-radius: 4px;
    overflow-x: auto;
    line-height: 1.5;
    font-family: Consolas, "Courier New", Menlo, Monaco, monospace;
    font-size: 0.9em;
}
.it-article-content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-size: inherit;
    border-radius: 0;
}

/* .blogread-code is the canonical class produced by normalize_code_blocks.
   Full styling moved here from it/tmpl/header.html so modern templates
   (which don't share that inline <style>) render line-numbers / copy /
   wrap buttons and language label identically. Old header.html still
   carries its inline copy — harmless duplication, removed when the old
   template retires. */

.blogread-code {
    display: block !important;
    overflow-x: auto !important;
    /* 顶部 padding 预留 34px 给右上角常驻按钮组；右侧 12px 给按钮本身。
       见 openspec/specs/it-code-block-actions/spec.md */
    padding: 34px 12px 10px 12px !important;
    white-space: pre !important;
    word-wrap: normal !important;
    font-family: Consolas, "Courier New", monospace !important;
    background: #f7f7f7;  /* Prism 没加载时的 fallback */
    line-height: 1.5;
    font-size: 16px;
    position: relative;  /* 让 .code-actions 和 ::before 能绝对定位 */
    max-width: 100% !important;
    box-sizing: border-box !important;
}
.blogread-code code {
    font-family: Consolas, "Courier New", monospace !important;
    white-space: pre !important;
    background: transparent !important;
    padding: 0 !important;
}
/* Prism line-numbers 插件：给 <pre> 加 line-numbers class，左侧让出 3.8em 放行号列。 */
.blogread-code.line-numbers {
    padding-left: 3.8em !important;
}
/* 换行模式：点右上角"换行"按钮时切换 .wrap class。 */
.blogread-code.wrap {
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
    overflow-x: hidden !important;
}
.blogread-code.wrap code {
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
}
/* 左上角语言标签：从 data-lang 属性读取；纯 CSS 不依赖 JS。
   视觉：亮色文字无框（像轻量水印），不抢代码本身的视觉焦点。 */
.blogread-code::before {
    content: attr(data-lang);
    position: absolute;
    top: 9px;
    left: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 11px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.92);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    pointer-events: none;
    user-select: none;
    z-index: 1;
}
.blogread-code[data-lang="plaintext"]::before,
.blogread-code:not([data-lang])::before,
.blogread-code[data-lang=""]::before {
    content: "代码块";
    text-transform: none;
}
/* 右上角按钮组：换行切换 + 复制。常驻但视觉低调 —— 透明底、淡灰文字，hover 才点亮。
   见 openspec/specs/it-code-block-actions/spec.md */
.blogread-code .code-actions {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    gap: 6px;
    z-index: 2;
}
.blogread-code .code-actions button {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 12px;
    line-height: 1.4;
    padding: 3px 10px;
    min-height: 24px;
    background: transparent;
    color: rgba(216, 216, 216, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    box-shadow: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.blogread-code .code-actions button:hover,
.blogread-code .code-actions button:focus {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.92);
    outline: none;
    border-color: rgba(255, 255, 255, 0.22);
}
.blogread-code .code-actions button:active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}
@media (max-width: 640px) {
    .blogread-code::before { top: 12px; font-size: 12px; }
    .blogread-code .code-actions button {
        font-size: 13px;
        padding: 6px 12px;
        min-height: 32px;
    }
    .blogread-code {
        padding-top: 44px !important;
    }
}

/* ---- Horizontal rule ---- */
.it-article-content hr {
    margin: 1.5em 0;
    border: none;
    border-top: 1px solid #eaecef;
}

/* ---- Prevent overflow from long URLs / identifiers ---- */
.it-article-content p,
.it-article-content li,
.it-article-content td,
.it-article-content th {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ---- 方案 C (2026-05-12)：遮住老 Crayon / WP-Syntax 双 <pre> 表格的左列（gutter）----
 *
 * 历史上一些文章的代码块是 div.highlight > table > tr > td.gutter[<pre.blogread-code>] +
 * td.'code'[<pre.blogread-code>] 结构：左列 <pre> 内容是 "1\n2\n3" 纯行号，右列 <pre>
 * 是代码正文。两个 <pre> 都被 normalize_code_blocks 贴上了 blogread-code，前端 JS
 * 的 line-numbers 又给**两个**都自动生成了行号，于是视觉上"行号重复"（见 /it/article/5716）。
 *
 * 正确做法（方案 A，后续 normalize_code_blocks 增强时再做）：识别这种双列结构把
 * gutter <pre> 从 DB content 里移除；届时 .highlight 结构消失，这一组规则自动变 no-op
 * 可安全删除。当前先做 CSS 层遮挡以解决视觉问题。
 */
.it-article-content .highlight table td.gutter {
    display: none;
}
/* 外层 table / highlight 已只剩 code 一列 <pre>，把 table/cell 默认 padding 压扁，
 * 让代码块视觉上与普通的 <pre.blogread-code> 一致。 */
.it-article-content .highlight,
.it-article-content .highlight > table,
.it-article-content .highlight > table > tbody,
.it-article-content .highlight > table > tbody > tr,
.it-article-content .highlight > table > tbody > tr > td {
    display: block;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    width: auto;
}
