/* GitHub Markdown 风格（参考 Reference-frontend/src/common/styles/markdown.css） */
/* 聊天气泡容器：.kefu__chat-msg-msg；知识库分段预览：.markdown-body（与 kb-studio__chunk-md 同用） */

/*
 * ── 防泄漏重置（仅聊天气泡）──
 * 页面级 CSS（如 .kefu__panel p/ul/ol/li/h1-h6/img/em/th …）会用后代选择器
 * 把 margin/padding/list-style/font-weight/font-style/display 等属性「泄漏」到
 * 气泡内 v-html 渲染出的同名标签上。此块统一还原为浏览器默认或 Markdown 期望值。
 */
.kefu__chat-msg-msg p,
.kefu__chat-msg-msg ul,
.kefu__chat-msg-msg ol,
.kefu__chat-msg-msg dl,
.kefu__chat-msg-msg dd,
.kefu__chat-msg-msg h1,
.kefu__chat-msg-msg h2,
.kefu__chat-msg-msg h3,
.kefu__chat-msg-msg h4,
.kefu__chat-msg-msg h5,
.kefu__chat-msg-msg h6 {
    margin: revert;
    padding: revert;
}
.kefu__chat-msg-msg ul,
.kefu__chat-msg-msg ol {
    list-style: revert;
}
.kefu__chat-msg-msg li {
    display: list-item !important;
    margin: 4px 0 !important;
}
.kefu__chat-msg-msg h1,
.kefu__chat-msg-msg h2,
.kefu__chat-msg-msg h3,
.kefu__chat-msg-msg h4,
.kefu__chat-msg-msg h5,
.kefu__chat-msg-msg h6 {
    font-weight: 600;
}
.kefu__chat-msg-msg em,
.kefu__chat-msg-msg i {
    font-style: italic;
}
.kefu__chat-msg-msg th {
    font-weight: 600;
}
.kefu__chat-msg-msg img {
    border-radius: 0;
}

/* ── clearfix（与 markdown.css 一致，避免子元素 float 撑破气泡）── */
.kefu__chat-msg-msg::before,
.markdown-body::before {
    display: table;
    content: "";
}
.kefu__chat-msg-msg::after,
.markdown-body::after {
    display: table;
    clear: both;
    content: "";
}

/* ── 根排版 ── */
.kefu__chat-msg-msg,
.markdown-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    color: #24292f;
}

.kefu__chat-msg-msg {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.markdown-body > *:last-child {
    margin-bottom: 0 !important;
}

/* ── 首尾外边距：气泡内避免顶底多空白（仅聊天气泡）── */
.kefu__chat-msg-msg > :first-child {
    margin-top: 0 !important;
}
.kefu__chat-msg-msg > :last-child {
    margin-bottom: 0 !important;
}
.kefu__chat-template-content > :last-child {
    margin-bottom: 0 !important;
}
.kefu__chat-msg-msg > span > :last-child {
    margin-bottom: 0 !important;
}
.kefu__chat-msg-msg > .kefu__chat-msg-html > :first-child {
    margin-top: 0 !important;
}
.kefu__chat-msg-msg > .kefu__chat-msg-html > :last-child {
    margin-bottom: 0 !important;
}
.kefu__chat-msg-translated-content > :last-child {
    margin-bottom: 0 !important;
}

/* ── 链接 ── */
.kefu__chat-msg-msg a,
.markdown-body a {
    color: #0366d6;
    text-decoration: none;
}
.kefu__chat-msg-msg a:hover,
.markdown-body a:hover {
    text-decoration: underline;
}

/* 订单模板整块为 <a.kefu__order-content-link>，不应套用 Markdown 链接下划线 */
.kefu__chat-msg-msg a.kefu__order-content-link,
.kefu__chat-msg-msg a.kefu__order-content-link:hover,
.kefu__chat-msg-msg a.kefu__order-content-link:active,
.kefu__chat-msg-msg a.kefu__order-content-link:focus,
.kefu__chat-msg-msg a.kefu__order-content-link:focus-visible {
    text-decoration: none;
}

.kefu__chat-msg-msg strong,
.markdown-body strong {
    font-weight: 600;
}

/* ── 标题 ── */
.kefu__chat-msg-msg h1,
.kefu__chat-msg-msg h2,
.kefu__chat-msg-msg h3,
.kefu__chat-msg-msg h4,
.kefu__chat-msg-msg h5,
.kefu__chat-msg-msg h6,
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: #24292e;
}

.kefu__chat-msg-msg h1,
.markdown-body h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #eaecef;
}

.kefu__chat-msg-msg h2,
.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #eaecef;
}

.kefu__chat-msg-msg h3,
.markdown-body h3 {
    font-size: 1.25em;
}

.kefu__chat-msg-msg h4,
.markdown-body h4 {
    font-size: 1em;
}

.kefu__chat-msg-msg h5,
.markdown-body h5 {
    font-size: 0.875em;
}

.kefu__chat-msg-msg h6,
.markdown-body h6 {
    font-size: 0.85em;
    color: #6a737d;
}

/* ── 段落 ── */
.kefu__chat-msg-msg p,
.markdown-body p {
    margin-top: 0;
    margin-bottom: 16px;
}

/* ── 引用块 ── */
.kefu__chat-msg-msg blockquote,
.markdown-body blockquote {
    padding: 0 1em;
    color: #6a737d;
    border-left: 0.25em solid #dfe2e5;
    margin: 0 0 16px 0;
}

.kefu__chat-msg-msg blockquote > :first-child,
.markdown-body blockquote > :first-child {
    margin-top: 0;
}
.kefu__chat-msg-msg blockquote > :last-child,
.markdown-body blockquote > :last-child {
    margin-bottom: 0;
}

/* ── 列表 ── */
.kefu__chat-msg-msg ul,
.kefu__chat-msg-msg ol,
.markdown-body ul,
.markdown-body ol {
    padding-left: 2em;
    margin-top: 0;
    margin-bottom: 16px;
}

.kefu__chat-msg-msg ul ul,
.kefu__chat-msg-msg ul ol,
.kefu__chat-msg-msg ol ol,
.kefu__chat-msg-msg ol ul,
.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
    margin-top: 0;
    margin-bottom: 16px;
}

.kefu__chat-msg-msg li,
.markdown-body li {
    word-wrap: break-all;
}

.kefu__chat-msg-msg li + li,
.markdown-body li + li {
    margin-top: 0.25em;
}

/* 覆盖上方防泄漏里 li 的 margin 简写 !important，使列表项间距与 markdown.css 一致 */
.kefu__chat-msg-msg li + li {
    margin-top: 0.25em !important;
}

.kefu__chat-msg-msg li > p {
    margin-top: 8px;
}

/* Task list（GFM，参考外不覆盖 checkbox 布局） */
.kefu__chat-msg-msg input[type="checkbox"] {
    margin: 0 6px 0 -20px;
    vertical-align: middle;
}

/* ── 行内 code ── */
.kefu__chat-msg-msg code,
.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(27, 31, 35, 0.05);
    border-radius: 3px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    color: #24292f;
}

/* ── 代码块 pre ── */
.kefu__chat-msg-msg pre,
.markdown-body pre {
    word-wrap: normal;
    padding: 16px;
    overflow: auto;
    font-size: 90%;
    line-height: 1.45;
    background-color: #f6f8fa;
    border-radius: 3px;
    margin-top: 0;
    margin-bottom: 16px;
}

.kefu__chat-msg-msg pre code,
.markdown-body pre code {
    display: inline;
    max-width: none;
    padding: 0;
    margin: 0;
    overflow: visible;
    line-height: inherit;
    word-wrap: normal;
    white-space: pre;
    background-color: transparent;
    border: 0;
    font-size: 100%;
    color: #24292f;
}

/* ── 表格 ── */
.kefu__chat-msg-msg table,
.markdown-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: auto;
    margin-top: 0;
    margin-bottom: 16px;
    border-spacing: 0;
    border-collapse: collapse;
    font-size: 0.95em;
}

.kefu__chat-msg-msg table th,
.markdown-body table th {
    font-weight: 600;
}

.kefu__chat-msg-msg table th,
.kefu__chat-msg-msg table td,
.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid #dfe2e5;
    text-align: left;
}

.kefu__chat-msg-msg table tr,
.markdown-body table tr {
    background-color: #fff;
    border-top: 1px solid #c6cbd1;
}

.kefu__chat-msg-msg table tr:nth-child(2n),
.markdown-body table tr:nth-child(2n) {
    background-color: #f6f8fa;
}

/* ── 图片 ── */
.kefu__chat-msg-msg img,
.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: #fff;
}

/* 聊天气泡内 Markdown 图：与 .kefu__chat-msg-picture 视觉尺度一致 */
.kefu__md-img {
    max-width: 270px;
    max-height: 270px;
    border-radius: 6px;
    cursor: default;
    display: block;
    margin: 4px 0;
    border: 1px solid #d0d7de;
}

/* ── 分割线 ── */
.kefu__chat-msg-msg hr,
.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: #e1e4e8;
    border: 0;
}

/* ── 高亮 / mark ── */
.kefu__chat-msg-msg mark,
.markdown-body mark {
    background-color: #fff8c5;
    padding: 0 3px;
    border-radius: 3px;
}

/* ── kbd ── */
.kefu__chat-msg-msg kbd,
.markdown-body kbd {
    display: inline-block;
    padding: 3px 7px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.88em;
    line-height: 1;
    color: #24292f;
    background-color: #f6f8fa;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    box-shadow: inset 0 -1px 0 #d0d7de;
}

/* ── 上下标 ── */
.kefu__chat-msg-msg sub,
.kefu__chat-msg-msg sup,
.markdown-body sub,
.markdown-body sup {
    font-size: 0.75em;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}
.kefu__chat-msg-msg sup,
.markdown-body sup {
    top: -0.4em;
}
.kefu__chat-msg-msg sub,
.markdown-body sub {
    bottom: -0.25em;
}

/* ── 删除线 ── */
.kefu__chat-msg-msg del,
.kefu__chat-msg-msg s,
.markdown-body del,
.markdown-body s {
    text-decoration: line-through;
    color: #6a737d;
}

.kefu__chat-msg-msg em,
.markdown-body em {
    font-style: italic;
}

/*
 * highlight.js GitHub 主题（由 highlight.min.js 生成 .hljs 类名；原独立文件 highlight-github.min.css）
 */
pre code.hljs {
    display: block;
    overflow-x: auto;
    padding: 1em;
}

code.hljs {
    padding: 3px 5px;
}

.hljs {
    color: #24292e;
    background: #fff;
}

.hljs-doctag,
.hljs-keyword,
.hljs-meta .hljs-keyword,
.hljs-template-tag,
.hljs-template-variable,
.hljs-type,
.hljs-variable.language_ {
    color: #d73a49;
}

.hljs-title,
.hljs-title.class_,
.hljs-title.class_.inherited__,
.hljs-title.function_ {
    color: #6f42c1;
}

.hljs-attr,
.hljs-attribute,
.hljs-literal,
.hljs-meta,
.hljs-number,
.hljs-operator,
.hljs-selector-attr,
.hljs-selector-class,
.hljs-selector-id,
.hljs-variable {
    color: #005cc5;
}

.hljs-meta .hljs-string,
.hljs-regexp,
.hljs-string {
    color: #032f62;
}

.hljs-built_in,
.hljs-symbol {
    color: #e36209;
}

.hljs-code,
.hljs-comment,
.hljs-formula {
    color: #6a737d;
}

.hljs-name,
.hljs-quote,
.hljs-selector-pseudo,
.hljs-selector-tag {
    color: #22863a;
}

.hljs-subst {
    color: #24292e;
}

.hljs-section {
    color: #005cc5;
    font-weight: 700;
}

.hljs-bullet {
    color: #735c0f;
}

.hljs-emphasis {
    color: #24292e;
    font-style: italic;
}

.hljs-strong {
    color: #24292e;
    font-weight: 700;
}

.hljs-addition {
    color: #22863a;
    background-color: #f0fff4;
}

.hljs-deletion {
    color: #b31d28;
    background-color: #ffeef0;
}

/*
 * fenced 代码块工具栏（safe-markdown 注入 .kb-chunk-*）
 * 对话端、知识库、管理端消息日志等凡引入 chat-markdown + highlight.min.js 即生效
 */
.kb-chunk-code-block {
    position: relative;
    margin-bottom: 12px;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
    background: #fafafa;
    box-sizing: border-box;
}

.kb-chunk-code-block:last-child {
    margin-bottom: 0;
}

.kb-chunk-code-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 36px;
    padding: 6px 12px;
    box-sizing: border-box;
    background: #f6f8fa;
    border-bottom: 1px solid #ebebeb;
}

.kb-chunk-code-lang {
    font-size: 11px;
    line-height: 1.4;
    color: #8c8c8c;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kb-chunk-code-copy {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: background-color 0.15s ease;
}

.kb-chunk-code-copy:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.kb-chunk-code-copy::before {
    content: "";
    position: absolute;
    inset: 3px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 14px 14px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='64 64 896 896' focusable='false' data-icon='copy' width='1em' height='1em' fill='%238c8c8c' aria-hidden='true' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z'%3E%3C/path%3E%3C/svg%3E");
}

.kb-chunk-code-copy:hover::before {
    background-image: url("data:image/svg+xml,%3Csvg viewBox='64 64 896 896' focusable='false' data-icon='copy' width='1em' height='1em' fill='%238c8c8c' aria-hidden='true' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z'%3E%3C/path%3E%3C/svg%3E");
}

.kb-chunk-code-copy.copied::before {
    background-repeat: no-repeat;
    background-position: center;
    background-size: 11px 11px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='64 64 896 896' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%238c8c8c' d='M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 00-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z'/%3E%3C/svg%3E");
}

.kb-chunk-code-block pre {
    margin: 0 !important;
    margin-bottom: 0 !important;
    padding: 10px 12px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.55;
    border: none;
    border-radius: 0;
    background: #fff;
}

.kb-chunk-code-block pre code.hljs {
    padding: 0;
    display: block;
    background: transparent;
    font-size: inherit;
    line-height: inherit;
}
