/* ==========================================================================
   Wiki 富文本文档统一排版（所见即所得）
   --------------------------------------------------------------------------
   同一套样式同时作用于：
   1. 编辑器正文：.editor-inner.rt-content
   2. 公开知识库前台：.pub-content.rt-content
   只作用于 .rt-content，不影响 Markdown 文档（.md-content）
   ========================================================================== */

/* ------------------------------ 基础排版 ------------------------------ */
.rt-content {
    font-size: 15.5px;
    /* 默认行高 1.5：编辑器与前台一致，行高工具默认识别为 1.5 */
    line-height: 1.5;
    color: #374151;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.nb-content,
.rt-content{
    min-height: calc(100vh - 478px);
}
.rt-content > *:first-child {
    margin-top: 0;
}

/* ------------------------------ 标题 ------------------------------ */
.rt-content :is(h1, h2, h3, h4, h5, h6) {
    color: #111827;
    /* line-height: 1.4; */
    margin: 30px 0 12px;
    letter-spacing: -.2px;
    font-weight: 700;
}

.rt-content h1 { font-size: 24px; }
.rt-content h2 { font-size: 21px; }
.rt-content h3 { font-size: 18px; }
.rt-content h4 { font-size: 16px; }
.rt-content h5 { font-size: 15.5px; }
.rt-content h6 { font-size: 15px; color: #6b7280; }

/* ------------------------------ 段落 / 链接 ------------------------------ */
/* 行高用 inherit：在段落层级设过的行高（如外层 div 上设的 2.5）能继续传给段落，
   编辑器与前台表现一致，不会出现同一段内容行高忽大忽小 */
.rt-content p {
    /* margin: 0 0 14px; */
    margin: 7px 0;
    line-height: inherit;
}

.rt-content a {
    color: #1F8FDF;
    text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, #1F8FDF 35%, transparent);
}

.rt-content a:hover {
    color: #1273B7;
    text-decoration: none;
}

/* ------------------------------ 列表 ------------------------------ */
.rt-content :is(ul, ol) {
    padding-left: 24px;
    margin: 0 0 14px;
}

.rt-content li {
    margin-bottom: 6px;
    line-height: inherit;
}

.rt-content li > :is(ul, ol) {
    margin: 6px 0 0;
}

/* ------------------------------ 引用 ------------------------------ */
.rt-content blockquote {
    margin: 16px 0;
    padding: 2px 15px;
    border-left: 3px solid #9aa1ad;
    background: #fafbfc;
    color: #4b5563;
    border-radius: 5px;
    /* 引用里的长文本/长链接同样自动换行，不出现横向滚动条 */
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* .rt-content blockquote > :last-child {
    margin-bottom: 0;
} */
.rt-content blockquote > :last-child p{
    margin: 0;
}

/* ------------------------------ 列表 ------------------------------ */
/* 列表项被设为居中/居右时，让项目符号（点或数字）跟随文字一起移动 */
.rt-content li[style*="text-align: center"],
.rt-content li[style*="text-align:center"],
.rt-content li[style*="text-align: right"],
.rt-content li[style*="text-align:right"] {
    list-style-position: inside;
}

/* ------------------------------ 待办事项 ------------------------------ */
/* 兼容历史文档里 wangEditor 留下的 data-w-e-type 标记 */
.rt-content [data-w-e-type="todo"] {
    margin: 5px 0;
}

.rt-content [data-w-e-type="todo"] input[type="checkbox"] {
    margin-right: 0.5em;
    vertical-align: middle;
}

/* ------------------------------ 分割线 ------------------------------ */
.rt-content hr {
    border: 0;
    border-top: 1px solid #e5e7eb;
    margin: 26px 0;
}

/* ------------------------------ 图片 ------------------------------ */
.rt-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    border: 1px solid #e5e7eb;
}

/* 兼容历史文档里的图片容器 */
.rt-content .w-e-image-container {
    display: inline-block;
    margin: 0 3px;
}

/* ------------------------------ 行内代码 ------------------------------ */
.rt-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 5px;
    /* font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    font-size: 13px;
    color: #374151;
}

/* ------------------------------ 代码块 ------------------------------ */
.rt-content pre {
    background: #f8f9fb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 22px 16px;
    margin: 0 0 16px;
    overflow: auto;
    position: relative;
}

.rt-content pre > code {
    display: block;
    margin: 0;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    color: #24292f;
    /* font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    font-size: 13px;
    line-height: 2;
    white-space: pre;
    word-break: normal;
    overflow-x: auto;
    text-shadow: none;
    -webkit-hyphens: none;
    hyphens: none;
    tab-size: 4;
}

/* 粘贴进来的预格式化文本块（white-space: pre）：同样自动换行，不出现横向滚动条 */
.rt-content :is(div, p, span, li)[style*="white-space: pre"] {
    max-width: 100%;
    white-space: pre-wrap !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* 粘贴内容里带 nowrap 的块也强制换行，避免撑出横向滚动条 */
.rt-content :is(div, p, span, li)[style*="white-space: nowrap"] {
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* 代码块行高锁死：编辑器与前台使用同一个值，保证所见即所得 */
/* .rt-content pre,
.rt-content pre > code {
    line-height: 1.8 !important;
} */

/* 可横向滚动的块统一用细滚动条，避免默认滚动条又粗又占地方 */
.rt-content pre,
.rt-content pre > code {
    scrollbar-width: thin;
    scrollbar-color: rgba(17, 24, 39, .22) transparent;
}

.rt-content pre::-webkit-scrollbar,
.rt-content pre > code::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.rt-content pre::-webkit-scrollbar-track,
.rt-content pre > code::-webkit-scrollbar-track {
    background: transparent;
}

.rt-content pre::-webkit-scrollbar-thumb,
.rt-content pre > code::-webkit-scrollbar-thumb {
    background: rgba(17, 24, 39, .22);
    border-radius: 3px;
}

.rt-content pre::-webkit-scrollbar-thumb:hover,
.rt-content pre > code::-webkit-scrollbar-thumb:hover {
    background: rgba(17, 24, 39, .38);
}

.rt-content pre::-webkit-scrollbar-button,
.rt-content pre > code::-webkit-scrollbar-button {
    display: none;
}

/* 前台代码块：语言标签 + 复制按钮（仅公开站，编辑器内由语言下拉替代） */
.pub-content.rt-content pre:has(> .code-head) {
    padding: 0;
    overflow: hidden;
}

.pub-content.rt-content pre:has(> .code-head) > code {
    padding: 5px 16px 14px;
    /* padding: 14px 16px; */
    overflow-x: auto;
}

.pub-content.rt-content .code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px 0 15px;
    /* padding: 6px 12px; */
    /* background: #f1f3f6; */
    /* border-bottom: 1px solid #e5e7eb; */
    font-size: 12px;
    line-height: 1.6;
    color: #6b7280;
    user-select: none;
}

.pub-content.rt-content .code-lang {
    letter-spacing: .3px;
}

.pub-content.rt-content .code-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
}

.pub-content.rt-content .code-copy:hover {
    background: #e5e7eb;
    color: #111827;
}

.pub-content.rt-content .code-copy.is-copied {
    color: #16a34a;
}

.pub-content.rt-content .code-copy svg {
    display: block;
}

/* 代码块语法高亮：GitHub 浅色主题（编辑器与前台同一套 token 配色） */
.rt-content pre code :is(.token.comment, .token.prolog, .token.doctype, .token.cdata) {
    color: #6a737d;
    font-style: italic;
}

.rt-content pre code .token.punctuation {
    color: #24292f;
}

.rt-content pre code :is(.token.property, .token.tag, .token.constant, .token.symbol, .token.deleted, .token.boolean, .token.number) {
    color: #005cc5;
}

.rt-content pre code :is(.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted) {
    color: #22863a;
}

.rt-content pre code :is(.token.operator, .token.entity, .token.url, .token.atrule, .token.attr-value, .token.keyword) {
    color: #d73a49;
}

.rt-content pre code :is(.token.function, .token.class-name) {
    color: #6f42c1;
}

.rt-content pre code :is(.token.regex, .token.important, .token.variable) {
    color: #e36209;
}

.rt-content pre code :is(.token.important, .token.bold) {
    font-weight: 700;
}

.rt-content pre code .token.italic {
    font-style: italic;
}

.rt-content pre code .token.entity {
    cursor: help;
}

/* ------------------------------ 表格 ------------------------------ */
.rt-content table {
    width: auto;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0 0 16px;
    font-size: 14px;
}

/* 没有滚动容器的表格（历史内容兜底）：限制在内容宽度内，避免撑出页面横向滚动条 */
.rt-content table {
    max-width: 100%;
}

/* 表格横向滚动容器：表格比内容区宽时只出现左右滚动条（不出现上下滚动条） */
.rt-content .rt-table-wrap {
    position: relative;
    max-width: 100%;
    margin: 0 0 16px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(17, 24, 39, .22) transparent;
}

/* 容器内的表格按实际宽度展示，超出部分由外层容器横向滚动，列宽保持原样 */
.rt-content .rt-table-wrap > table {
    max-width: none;
    margin: 0;
}

.rt-content .rt-table-wrap::-webkit-scrollbar {
    width: 0;
    height: 5px;
}

.rt-content .rt-table-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.rt-content .rt-table-wrap::-webkit-scrollbar-thumb {
    background: rgba(17, 24, 39, .22);
    border-radius: 3px;
}

.rt-content .rt-table-wrap::-webkit-scrollbar-thumb:hover {
    background: rgba(17, 24, 39, .38);
}

.rt-content .rt-table-wrap::-webkit-scrollbar-button {
    display: none;
}

.rt-content :is(th, td) {
    border: 1px solid #e5e7eb;
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
    line-height: inherit;
    min-width: 30px;
}

.rt-content th {
    background: #fafbfc;
    color: #111827;
    font-weight: 600;
    text-align: left;
}

.rt-content tbody tr:nth-child(even) {
    background: #fcfcfd;
}

/* ------------------------------ 图文混排 / 多列图文 ------------------------------ */
/* 浮动图片后自动清除，避免影响后续段落 */
.rt-content::after {
    content: "";
    display: block;
    clear: both;
}

.rt-content img.rt-img-left {
    float: left;
    max-width: 50%;
    margin: 4px 18px 12px 0;
}

.rt-content img.rt-img-right {
    float: right;
    max-width: 50%;
    margin: 4px 0 12px 18px;
}

.rt-content img.rt-img-center {
    display: block;
    margin: 8px auto;
}

.rt-content img.rt-img-full {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 8px 0;
}

/* 多列图文：用无边框表格承载，结构稳定；移动端自动堆叠 */
.rt-content table.rt-cols {
    width: calc(100% + 32px);
    max-width: none;
    margin: 0 -16px 16px;
    border: 0;
    border-collapse: separate;
    border-spacing: 16px 0;
    background: none;
    font-size: inherit;
}

.rt-content table.rt-cols > tbody > tr > td {
    width: 50%;
    border: 0;
    padding: 0;
    vertical-align: top;
    background: none;
}

.rt-content table.rt-cols > tbody > tr > td > :last-child {
    margin-bottom: 0;
}

.rt-content table.rt-cols img {
    margin: 0;
}

.rt-content table.rt-cols-3 > tbody > tr > td {
    width: 33.33%;
}

.rt-content table.rt-cols-img > tbody > tr > td.rt-col-media {
    width: 42%;
}

.rt-content table.rt-cols-img > tbody > tr > td.rt-col {
    width: 58%;
}

/* 图注（TinyMCE 图片说明） */
.rt-content figure {
    margin: 16px 0;
}

.rt-content figure img {
    margin: 0;
}

.rt-content figcaption {
    margin-top: 6px;
    font-size: 13px;
    color: #6b7280;
    text-align: center;
}

/* 待办事项：新结构（p.rt-todo，勾选框由 CSS 绘制，没有 input 节点） */
.rt-content p.rt-todo {
    position: relative;
    margin: 7px 0;
    padding-left: 26px;
    min-height: 22px;
}

.rt-content p.rt-todo::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 0.4em;
    width: 14px;
    height: 14px;
    box-sizing: border-box;
    border: 1.5px solid #c3c8d2;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
}

.rt-content p.rt-todo.is-done::before {
    background: #9aa1ad;
    border-color: #9aa1ad;
}

.rt-content p.rt-todo.is-done::after {
    content: "";
    position: absolute;
    left: 5px;
    top: calc(0.4em + 4px);
    width: 7px;
    height: 3px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg);
    pointer-events: none;
}

/* 已完成的待办：勾选后整行变灰 + 删除线（编辑器与前台一致）；
   内部元素可能自带内联颜色 / 链接样式，这里一并强制覆盖 */
.rt-content p.rt-todo.is-done,
.rt-content p.rt-todo.is-done * {
    color: #9aa1ad !important;
    text-decoration: line-through !important;
}

/* 待办事项：旧结构（div.rt-todo + input），用于公开站里尚未迁移的历史文档 */
.rt-content div.rt-todo {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 6px 0;
}

.rt-content div.rt-todo input[type="checkbox"] {
    flex: none;
    width: 15px;
    height: 15px;
    margin: 4px 0 0;
}

.rt-content div.rt-todo > span {
    flex: 1 1 auto;
    min-width: 0;
}

/* ------------------------------ 附件下载卡片 ------------------------------ */
/* 编辑器正文与前台浏览共用：非图片附件统一显示为“图标 + 文件名 + 大小 + 下载”卡片 */
.rt-content .rt-file-link,
.md-content .rt-file-link {
    display: flex;
    align-items: center;
    gap: 12px;
    /* 卡片按内容自适应宽度，不再通栏铺满正文 */
    width: fit-content;
    min-width: min(240px, 100%);
    max-width: min(460px, 100%);
    margin: 10px 0;
    padding: 10px 12px;
    background: #fafbfc;
    border: 0;
    border-radius: 5px;
    color: #232d47;
    text-decoration: none;
    transition: background-color .15s ease, border-color .15s ease;
}

.rt-content .rt-file-link:hover,
.md-content .rt-file-link:hover {
    background: #fafbfc;
    /* border-color: #e3e7ea; */
    color: #232d47;
}

/* 左侧文件类型图标：用扩展名文字代替图片，编辑器与前台渲染一致 */
.rt-content .rt-file-icon,
.md-content .rt-file-icon {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 5px;
    background: #e8f2fb;
    color: #2384d1;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .3px;
    line-height: 1;
    text-transform: uppercase;
}

.rt-content .rt-file-icon-pdf,
.md-content .rt-file-icon-pdf { background: #fdeceb; color: #e04f45; }
.rt-content .rt-file-icon-doc,
.md-content .rt-file-icon-doc { background: #e8f2fb; color: #2384d1; }
.rt-content .rt-file-icon-xls,
.md-content .rt-file-icon-xls { background: #e7f7ef; color: #1f9d63; }
.rt-content .rt-file-icon-ppt,
.md-content .rt-file-icon-ppt { background: #fdf1e6; color: #d98324; }
.rt-content .rt-file-icon-zip,
.md-content .rt-file-icon-zip { background: #f0edfb; color: #7a63d6; }
.rt-content .rt-file-icon-txt,
.md-content .rt-file-icon-txt,
.rt-content .rt-file-icon-file,
.md-content .rt-file-icon-file { background: #eef0f3; color: #6b7280; }

.rt-content .rt-file-meta,
.md-content .rt-file-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1 1 auto;
    min-width: 0;
}

.rt-content .rt-file-name,
.md-content .rt-file-name {
    font-size: 14px;
    font-weight: 500;
    color: #232d47;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rt-content .rt-file-size,
.md-content .rt-file-size {
    font-size: 12px;
    color: #8a94a6;
    line-height: 1.3;
}

/* 右侧下载按钮：悬停时用主题色填充 */
.rt-content .rt-file-dl,
.md-content .rt-file-dl {
    flex: none;
    padding: 5px 12px;
    border: 1px solid #dfe4e8;
    border-radius: 6px;
    background: #fff;
    color: #3c4759;
    font-size: 12px;
    line-height: 1.4;
    user-select: none;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.rt-content .rt-file-link .rt-file-dl:hover,
.md-content .rt-file-link .rt-file-dl:hover {
    background: #448AFF;
    border-color: #448AFF;
    color: #fff;
}

/* ------------------------------ 移动端 ------------------------------ */
@media (max-width: 680px) {
    .rt-content img.rt-img-left,
    .rt-content img.rt-img-right {
        float: none;
        display: block;
        max-width: 100%;
        margin: 8px 0;
    }

    .rt-content table.rt-cols {
        display: block;
        width: 100%;
        margin: 0 0 16px;
        border-spacing: 0;
    }

    .rt-content table.rt-cols > tbody,
    .rt-content table.rt-cols > tbody > tr {
        display: block;
    }

    .rt-content table.rt-cols > tbody > tr > td {
        display: block;
        width: auto !important;
        padding: 0 0 12px;
    }

    /* 附件卡片：小屏收紧内边距与图标尺寸 */
    .rt-content .rt-file-link,
    .md-content .rt-file-link {
        gap: 10px;
        padding: 9px 10px;
    }

    .rt-content .rt-file-icon,
    .md-content .rt-file-icon {
        width: 34px;
        height: 34px;
    }

    .rt-content .rt-file-dl,
    .md-content .rt-file-dl {
        padding: 5px 10px;
    }
}

@media (max-width: 820px) {
    .rt-content {font-size: 15px;}
    .nb-content,
    .rt-content {
        min-height: calc(100vh - 438px);
    }
}
@media (max-width: 560px) {
    .nb-content,
    .rt-content {
        min-height: calc(100vh - 510px);
    }
}
