/* ==========================================================================
 * 墨匣 XNote — Vditor 覆盖层
 *
 * Vditor 自带一套固定色值的皮肤。这里不 fork 它的 CSS，而是用 XUI 令牌把它「收编」：
 *   - 背景/文本/边框/强调色全部走 var(--*)
 *   - 编辑区变成无边框、居中阅读列（行宽可调）
 *   - 工具栏改造成 XUI 的按钮密度与 hover 语言
 * 选择器统一用 #vditor 提升优先级，避免和 vendor 里的规则打架。
 * ========================================================================== */

#vditor {
  --xnote-font-size: 16px;
  --xnote-line-width: 780px;
  --xnote-line-height: 1.75;
  height: 100%;
  border: 0 !important;
  background: transparent !important;
  font-family: var(--font-ui) !important;
}

#vditor .vditor-toolbar {
  background: var(--bg-elev-1) !important;
  border-bottom: 1px solid var(--line) !important;
  padding: 2px var(--s-2) !important;
  min-height: calc(var(--btn-h-sm) + 6px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
}

#vditor .vditor-toolbar__item {
  margin: 0 1px !important;
}

#vditor .vditor-toolbar__item button {
  color: var(--text-2) !important;
  border-radius: var(--r-xs) !important;
  height: var(--btn-h-sm);
  min-width: var(--btn-h-sm);
  padding: 0 var(--s-1);
  background: transparent !important;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}

#vditor .vditor-toolbar__item button:hover {
  background: var(--bg-elev-3) !important;
  color: var(--text-1) !important;
}

#vditor .vditor-toolbar__item button.vditor-menu--current {
  background: var(--accent-soft) !important;
  color: var(--accent-on-soft) !important;
}

#vditor .vditor-toolbar__divider {
  border-color: var(--line) !important;
  margin: 0 var(--s-1) !important;
}

#vditor .vditor-toolbar__br {
  flex-basis: 100%;
  height: 0;
}

#vditor .vditor-toolbar svg {
  color: currentColor;
}

#vditor .vditor-toolbar__icon {
  padding: 0 var(--s-1) !important;
}

#vditor .vditor-toolbar__item .vditor-tooltipped::after {
  font-family: var(--font-ui);
}

#vditor .vditor-toolbar__item button svg {
  fill: currentColor;
}

/* 内容区 ---------------------------------------------------------------- */

#vditor .vditor-content {
  background: var(--bg-base) !important;
  flex: 1;
  min-height: 0;
}

#vditor .vditor-ir,
#vditor .vditor-sv,
#vditor .vditor-preview,
#vditor .vditor-wysiwyg {
  background: transparent !important;
  border: 0 !important;
}

/* IR（即时渲染）：一栏、居中、可调行宽。
 * 注意 Vditor 的 IR 结构是 .vditor-ir > pre.vditor-reset（pre 自己就是滚动容器），
 * 不是 .protyle-wysiwyg；左右 padding 用 max() 把正文夹成一条居中的阅读列。 */
#vditor .vditor-ir {
  width: 100% !important;
  overflow: hidden !important;
  padding: 0 !important;
}

#vditor .vditor-ir > .vditor-reset {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: var(--s-5) max(var(--s-6), calc((100% - var(--xnote-line-width)) / 2)) 30vh !important;
  min-height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
}

/* 窄屏时不要再把列宽当成约束 */
@media (max-width: 900px) {
  #vditor .vditor-ir > .vditor-reset {
    padding: var(--s-4) var(--s-4) 26vh !important;
  }
}

/* SV（分屏源码）：左右两栏，中间一条线 */
#vditor .vditor-sv {
  width: 50% !important;
  max-width: none !important;
  padding: var(--s-5) var(--s-4) 30vh !important;
  border-right: 1px solid var(--line) !important;
  overflow: auto;
}

#vditor .vditor-preview {
  width: 50% !important;
  padding: var(--s-5) var(--s-5) 30vh !important;
  overflow: auto;
}

#vditor .vditor-preview > .vditor-reset {
  max-width: var(--xnote-line-width);
  margin: 0 auto;
}

/* 纯预览（阅读模式） */
#vditor.vditor--preview .vditor-preview {
  width: 100% !important;
}

#vditor.vditor--preview .vditor-preview > .vditor-reset {
  max-width: var(--xnote-line-width);
  margin: 0 auto;
  padding: var(--s-5) var(--s-6) 30vh !important;
  background: transparent !important;
}

/* 正文排版 --------------------------------------------------------------- */

#vditor .vditor-reset {
  font-family: var(--font-ui);
  font-size: var(--xnote-font-size);
  line-height: var(--xnote-line-height);
  color: var(--text-1);
  background: transparent;
  word-break: break-word;
}

#vditor .vditor-reset p,
#vditor .vditor-reset ul,
#vditor .vditor-reset ol,
#vditor .vditor-reset dl,
#vditor .vditor-reset table,
#vditor .vditor-reset blockquote {
  margin: 0 0 0.9em;
}

#vditor .vditor-reset h1,
#vditor .vditor-reset h2,
#vditor .vditor-reset h3,
#vditor .vditor-reset h4,
#vditor .vditor-reset h5,
#vditor .vditor-reset h6 {
  color: var(--text-1);
  font-weight: var(--t-weight-semibold);
  line-height: 1.3;
  margin: 1.6em 0 0.6em;
  letter-spacing: -0.01em;
}

#vditor .vditor-reset h1 {
  font-size: 1.9em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--line);
}

#vditor .vditor-reset h2 {
  font-size: 1.5em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--line-subtle);
}

#vditor .vditor-reset h3 { font-size: 1.25em; }
#vditor .vditor-reset h4 { font-size: 1.1em; }
#vditor .vditor-reset h5 { font-size: 1em; color: var(--text-2); }
#vditor .vditor-reset h6 { font-size: 0.92em; color: var(--text-3); }

#vditor .vditor-reset a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
  transition: border-color var(--d-fast) var(--ease);
}

#vditor .vditor-reset a:hover {
  border-bottom-color: var(--accent);
}

#vditor .vditor-reset strong { font-weight: var(--t-weight-semibold); color: var(--text-1); }
#vditor .vditor-reset em { font-style: italic; }
#vditor .vditor-reset del { color: var(--text-3); }

#vditor .vditor-reset blockquote {
  border-left: 3px solid var(--accent);
  background: var(--bg-elev-1);
  color: var(--text-2);
  padding: var(--s-2) var(--s-4);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin-left: 0;
}

#vditor .vditor-reset blockquote > :last-child { margin-bottom: 0; }

#vditor .vditor-reset ul,
#vditor .vditor-reset ol {
  padding-left: 1.6em;
}

#vditor .vditor-reset li { margin: 0.25em 0; }

#vditor .vditor-reset li::marker { color: var(--text-3); }

#vditor .vditor-reset hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2em 0;
}

#vditor .vditor-reset code:not(.hljs):not(.katex) {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-elev-3);
  color: var(--accent-on-soft);
  border-radius: var(--r-xs);
  padding: 0.14em 0.4em;
  border: 1px solid var(--line);
}

#vditor .vditor-reset pre {
  background: var(--surface-code) !important;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4) !important;
  overflow: auto;
  font-size: 0.875em;
  line-height: 1.65;
}

/* IR 里代码块/公式的「源码」是一个 .vditor-ir__marker--pre 的 pre：
 * Vditor 用 width:0 + overflow:hidden 把它折叠起来，只在光标进入时展开。
 * 如果这里也吃到上面的 pre 样式（padding/border），折叠后会留下一个 34×26 的小方块。 */
#vditor .vditor-reset pre.vditor-ir__marker,
#vditor .vditor-reset pre.vditor-ir__marker--pre {
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

#vditor .vditor-reset pre code {
  background: transparent !important;
  border: 0 !important;
  color: var(--text-1);
  font-family: var(--font-mono);
  padding: 0 !important;
  font-size: inherit;
}

#vditor .vditor-reset pre code.hljs {
  background: transparent !important;
  padding: 0 !important;
}

#vditor .vditor-reset table {
  border-collapse: collapse;
  width: 100%;
  display: table;
  font-size: 0.94em;
}

#vditor .vditor-reset table th,
#vditor .vditor-reset table td {
  border: 1px solid var(--line);
  padding: var(--s-1-5) var(--s-2-5);
  text-align: left;
}

#vditor .vditor-reset table th {
  background: var(--bg-elev-2);
  color: var(--text-2);
  font-weight: var(--t-weight-semibold);
}

#vditor .vditor-reset table tr:nth-child(2n) td {
  background: var(--bg-elev-1);
}

#vditor .vditor-reset img {
  border-radius: var(--r-sm);
  max-width: 100%;
}

#vditor .vditor-reset kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-elev-3);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  padding: 0.1em 0.4em;
}

#vditor .vditor-reset mark {
  background: var(--warn-soft);
  color: var(--text-1);
  border-radius: 2px;
  padding: 0 2px;
}

/* 选区：和 XUI 的 surface-selection 同色 */
#vditor .vditor-reset ::selection,
#vditor .vditor-ir > .vditor-reset ::selection {
  background: var(--surface-selection);
}

/* IR 内的块级元素与冲突提示 */
#vditor .vditor-ir > .vditor-reset [data-node-id] {
  border-radius: var(--r-xs);
}

#vditor .vditor-ir > .vditor-reset [data-node-id].vditor-ir__node--expand {
  background: transparent;
}

#vditor .vditor-ir > .vditor-reset .vditor-ir__marker {
  color: var(--text-3);
}

#vditor .vditor-ir > .vditor-reset .vditor-ir__marker--heading {
  color: var(--accent);
}

/* IR 的标题标记（H1/H2…）平时藏起来，悬停/聚焦到那一行再出现：更像成品，而不是源码 */
#vditor .vditor-ir__marker--heading {
  opacity: 0;
  transition: opacity var(--d-fast) var(--ease);
}

#vditor .vditor-ir__node:hover .vditor-ir__marker--heading,
#vditor .vditor-ir__node:focus-within .vditor-ir__marker--heading {
  opacity: 0.75;
}

/* 块级公式与代码块的 marker 也按同样口径收敛 */
#vditor .vditor-ir__node .vditor-ir__marker--info,
#vditor .vditor-ir__node [data-type$="-marker"] {
  opacity: 0;
  transition: opacity var(--d-fast) var(--ease);
}

#vditor .vditor-ir__node:hover .vditor-ir__marker--info,
#vditor .vditor-ir__node:hover [data-type$="-marker"],
#vditor .vditor-ir__node:focus-within .vditor-ir__marker--info,
#vditor .vditor-ir__node:focus-within [data-type$="-marker"] {
  opacity: 0.7;
}

#vditor .vditor-ir > .vditor-reset .vditor-ir__marker--link {
  color: var(--accent);
}

/* 表格编辑控件 */
#vditor .vditor-table {
  color: var(--text-2);
}

#vditor .vditor-reset .vditor-ir__node--expand .vditor-table__panel {
  background: var(--bg-elev-2);
  border-color: var(--line);
}

/* 代码块工具条 */
#vditor .vditor-code {
  color: var(--text-3);
}

#vditor .vditor-copy {
  color: var(--text-2);
}

#vditor .vditor-copy:hover {
  color: var(--accent);
}

/* 数学公式 */
#vditor .katex-display {
  margin: 1em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}

#vditor .katex {
  color: var(--text-1);
}

/* Mermaid / 渲染块 */
#vditor .vditor-reset svg[id^="mermaid"] {
  max-width: 100%;
  height: auto;
}

/* 标题锚点（预览模式下 TOC 链接用） */
#vditor .vditor-reset .vditor-anchor {
  color: var(--text-3);
}

/* 工具栏弹层（插入表格/链接） */
.vditor-hint {
  background: var(--surface-overlay) !important;
  border: 1px solid var(--line-strong) !important;
  border-radius: var(--r-sm) !important;
  box-shadow: var(--shadow-menu) !important;
  color: var(--text-1) !important;
}

.vditor-hint button,
.vditor-hint .vditor-hint__item {
  color: var(--text-2) !important;
}

.vditor-hint button:hover,
.vditor-hint .vditor-hint__item:hover,
.vditor-hint .vditor-hint__item--current {
  background: var(--accent-soft) !important;
  color: var(--accent-on-soft) !important;
}

/* 编辑器内的 tooltip */
.vditor-tooltipped::after {
  background: var(--bg-elev-4) !important;
  color: var(--text-1) !important;
  border-radius: var(--r-xs) !important;
}

/* 上传/加载动画的遮罩 */
#vditor .vditor-panel {
  background: var(--bg-elev-2) !important;
  border-color: var(--line) !important;
  color: var(--text-1) !important;
}

/* 全屏：交给浏览器全屏，去掉 Vditor 自己的 fixed 定位冲突 */
#vditor.vditor--fullscreen {
  background: var(--bg-base) !important;
}

/* 空文档时给一句温和的提示（IR 模式的 placeholder 由 Vditor 渲染） */
#vditor .vditor-ir > .vditor-reset:empty::before {
  content: "开始写点什么…";
  color: var(--text-3);
}

/* 深色主题下 highlight.js 的代码块不额外加底色（已由 pre 提供） */
#vditor .hljs {
  background: transparent !important;
  color: var(--text-1);
}

/* 窄屏：工具栏允许横向滚动，而不是把编辑区挤成两行 */
@media (max-width: 720px) {
  #vditor .vditor-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  #vditor .vditor-toolbar::-webkit-scrollbar {
    display: none;
  }

  #vditor .vditor-ir > .vditor-reset,
  #vditor.vditor--preview .vditor-preview > .vditor-reset {
    padding: var(--s-4) var(--s-3) 30vh;
  }
}
/* Vditor 会在 IR 的标题左侧用 :before 画出 H1/H2 之类的块类型标签。
 * 对写作界面来说它太吵：平时藏起来，悬停到该标题时再以低透明度出现。 */
#vditor .vditor-ir .vditor-reset > :is(h1, h2, h3, h4, h5, h6)::before {
  opacity: 0;
  transition: opacity var(--d-fast) var(--ease);
}

#vditor .vditor-ir .vditor-reset > :is(h1, h2, h3, h4, h5, h6):hover::before {
  opacity: 0.55;
}
