/**
 * zai_editor · 内容样式
 * 编辑器内部与前台展示共用同一份，保证「所见即所得」。
 * 前台渲染时给容器加上 class="zai-content" 即可。
 */

.zai-content {
  font-size: 15px;
  line-height: 1.8;
  color: var(--zai-text);
  word-wrap: break-word;
}

.zai-content > *:first-child { margin-top: 0; }
.zai-content > *:last-child { margin-bottom: 0; }

/* ---------------- 标题 ---------------- */
.zai-content h1,
.zai-content h2,
.zai-content h3,
.zai-content h4 {
  font-weight: 600;
  line-height: 1.4;
  margin: 1.6em 0 0.6em;
  color: var(--zai-text);
}
.zai-content h1 { font-size: 26px; padding-bottom: .3em; border-bottom: 1px solid var(--zai-border); }
.zai-content h2 { font-size: 22px; padding-bottom: .3em; border-bottom: 1px solid var(--zai-border); }
.zai-content h3 { font-size: 18px; }
.zai-content h4 { font-size: 16px; }

/* ---------------- 段落与行内 ---------------- */
.zai-content p { margin: 0 0 1em; }
.zai-content p:last-child { margin-bottom: 0; }
.zai-content strong { font-weight: 600; }
.zai-content em { font-style: italic; }
.zai-content u { text-decoration: underline; }
.zai-content s { text-decoration: line-through; color: var(--zai-text-light); }
.zai-content a { color: var(--zai-info); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--zai-info) 35%, transparent); }
.zai-content a:hover { border-bottom-color: var(--zai-info); }

.zai-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .88em;
  background: var(--zai-surface-sunken);
  border-radius: 4px;
  padding: .15em .4em;
  color: var(--zai-primary);
}

.zai-content mark {
  background: var(--zai-gold);
  color: inherit;
  border-radius: 3px;
  padding: .1em .2em;
}

/* ---------------- 列表 ---------------- */
.zai-content ul,
.zai-content ol { margin: 0 0 1em; padding-left: 1.6em; }
.zai-content ul { list-style: disc; }
.zai-content ol { list-style: decimal; }
.zai-content li { margin: .3em 0; }
.zai-content li > p { margin: 0 0 .4em; }
.zai-content li > p:last-child { margin-bottom: 0; }
.zai-content ul ul { list-style: circle; }
.zai-content ul ul ul { list-style: square; }

/* ---------------- 待办清单 ---------------- */
.zai-content ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0;
  margin: 0 0 1em;
}
.zai-content ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: .35em 0;
}
.zai-content ul[data-type="taskList"] li > label {
  flex: 0 0 auto;
  margin-top: .45em;
  display: inline-flex;
  gap: 4px;
}
.zai-content ul[data-type="taskList"] li > label input[type="checkbox"] {
  width: 15px; height: 15px; margin: 0; cursor: pointer;
  accent-color: var(--zai-primary);
}
.zai-content ul[data-type="taskList"] li > div { flex: 1 1 auto; min-width: 0; }
.zai-content ul[data-type="taskList"] li[data-checked="true"] > div {
  color: var(--zai-text-light);
  text-decoration: line-through;
}

/* ---------------- 引用 ---------------- */
.zai-content blockquote {
  margin: 1em 0;
  padding: .5em 0 .5em 1em;
  border-left: 3px solid var(--zai-border-strong);
  color: var(--zai-text-mid);
  background: transparent;
}
.zai-content blockquote p:last-child { margin-bottom: 0; }

/* ---------------- 代码块 ---------------- */
.zai-content pre {
  margin: 1.2em 0;
  padding: 14px 16px;
  background: var(--zai-surface-sunken);
  border: 1px solid var(--zai-border);
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.6;
}
.zai-content pre code {
  background: none;
  padding: 0;
  color: var(--zai-text);
  font-size: 13.5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  white-space: pre;
}

/* highlight.js 精简配色（浅色） */
.hljs-comment, .hljs-quote { color: var(--zai-text-light); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section { color: var(--zai-error); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--zai-info); }
.hljs-number, .hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: var(--zai-info); }
.hljs-title, .hljs-title.class_, .hljs-title.function_, .hljs-name { color: var(--zai-partner-r); }
.hljs-built_in, .hljs-type, .hljs-symbol, .hljs-bullet { color: var(--zai-warning); }
.hljs-deletion { color: var(--zai-error); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ---------------- 表格 ---------------- */
.zai-content table {
  border-collapse: collapse;
  margin: 1.2em 0;
  width: 100%;
  display: block;
  overflow-x: auto;
  font-size: 14px;
}
.zai-content table p { margin: 0; }
.zai-content th,
.zai-content td {
  border: 1px solid var(--zai-border-strong);
  padding: 8px 12px;
  vertical-align: top;
  min-width: 80px;
}
.zai-content th { background: var(--zai-surface-sunken); font-weight: 600; text-align: left; }
.zai-content tr:nth-child(n+2) td { background: var(--zai-surface); }

/* ---------------- 图片 ---------------- */
.zai-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: .4em 0;
  display: block;
}
.zai-content img[data-zai-fetching="1"] {
  min-height: 60px;
  background: var(--zai-surface-sunken) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='12' cy='12' r='8' fill='none' stroke='%23B4B2A9' stroke-width='2'/%3E%3C/svg%3E") center no-repeat;
}
.zai-content img[data-zai-fetching="fail"] {
  border: 1px dashed var(--zai-error);
  min-height: 48px;
}

/* ---------------- 分割线 ---------------- */
.zai-content hr {
  border: none;
  border-top: 1px solid var(--zai-border);
  margin: 1.8em 0;
}

/* ---------------- 高亮块 Callout ---------------- */
.zai-content .zai-callout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 1.2em 0;
  padding: 12px 14px;
  border-radius: 8px;
  border-left: 3px solid var(--zai-info);
  background: color-mix(in srgb, var(--zai-info) 14%, var(--zai-surface));
}
.zai-content .zai-callout[data-emoji]::before {
  content: attr(data-emoji);
  font-size: 16px;
  line-height: 1.6;
  flex: 0 0 auto;
}
.zai-content .zai-callout > * { margin: 0; min-width: 0; flex: 1 1 auto; }
.zai-content .zai-callout p:last-child { margin-bottom: 0; }
.zai-content .zai-callout[data-color="blue"] { background: color-mix(in srgb, var(--zai-info) 14%, var(--zai-surface)); border-left-color: var(--zai-info); }
.zai-content .zai-callout[data-color="yellow"] { background: color-mix(in srgb, var(--zai-warning) 16%, var(--zai-surface)); border-left-color: var(--zai-warning); }
.zai-content .zai-callout[data-color="red"] { background: color-mix(in srgb, var(--zai-error) 12%, var(--zai-surface)); border-left-color: var(--zai-error); }
.zai-content .zai-callout[data-color="green"] { background: color-mix(in srgb, var(--zai-success) 14%, var(--zai-surface)); border-left-color: var(--zai-success); }
.zai-content .zai-callout[data-color="orange"] { background: color-mix(in srgb, var(--zai-primary) 12%, var(--zai-surface)); border-left-color: var(--zai-primary); }
.zai-content .zai-callout[data-color="purple"] { background: color-mix(in srgb, var(--zai-partner-r) 14%, var(--zai-surface)); border-left-color: var(--zai-partner-r); }
.zai-content .zai-callout[data-color="gray"],
.zai-content .zai-callout[data-color="grey"] { background: var(--zai-surface-sunken); border-left-color: var(--zai-text-light); }
.zai-content .zai-callout[data-color="turquoise"] { background: color-mix(in srgb, var(--zai-partner-t) 14%, var(--zai-surface)); border-left-color: var(--zai-success); }
.zai-content .zai-callout[data-color="carmine"] { background: color-mix(in srgb, var(--zai-error) 10%, var(--zai-surface)); border-left-color: var(--zai-error); }

/* ---------------- 折叠块 ---------------- */
.zai-content .zai-details {
  margin: 1.2em 0;
  border: 1px solid var(--zai-border);
  border-radius: 8px;
  background: var(--zai-surface-sunken);
  overflow: hidden;
}
.zai-content .zai-details > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  list-style: none;
  background: var(--zai-surface-sunken);
  user-select: none;
}
.zai-content .zai-details > summary::-webkit-details-marker { display: none; }
.zai-content .zai-details > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  transition: transform .15s;
  color: var(--zai-text-mid);
}
.zai-content .zai-details[open] > summary::before { transform: rotate(90deg); }
.zai-content .zai-details > .zai-details-content { padding: 12px 14px; }
.zai-content .zai-details > .zai-details-content > *:last-child { margin-bottom: 0; }

/* ---------------- 链接卡片 ---------------- */
.zai-content .zai-bookmark { margin: 1.2em 0; }
.zai-content .zai-bm-link {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--zai-border);
  border-radius: 8px;
  text-decoration: none;
  border-bottom: 1px solid var(--zai-border);
  background: var(--zai-surface);
  transition: background .15s;
}
.zai-content .zai-bm-link:hover { background: var(--zai-surface-sunken); }
.zai-content .zai-bm-icon {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 6px;
  background: var(--zai-surface-sunken);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--zai-text-mid);
  overflow: hidden;
}
.zai-content .zai-bm-icon img { width: 100%; height: 100%; margin: 0; border-radius: 0; object-fit: cover; }
.zai-content .zai-bm-body { flex: 1 1 auto; min-width: 0; display: block; }
.zai-content .zai-bm-title {
  display: block; font-weight: 600; color: var(--zai-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.zai-content .zai-bm-desc {
  display: block; font-size: 13px; color: var(--zai-text-light);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------- 分栏 ---------------- */
.zai-content .zai-columns { display: flex; gap: 16px; margin: 1.2em 0; }
.zai-content .zai-column { flex: 1 1 0; min-width: 0; }

/* ---------------- 对齐 ---------------- */
.zai-content [style*="text-align: center"],
.zai-content [style*="text-align:center"] { text-align: center; }
.zai-content [style*="text-align: right"],
.zai-content [style*="text-align:right"] { text-align: right; }

/* ---------------- 空状态提示 ---------------- */
.zai-content p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--zai-text-light);
  pointer-events: none;
  height: 0;
}

/* ================================================================
 * 图片展示增强
 * ================================================================ */

/* 单图独占一行（p 内仅一张图 / 块内仅一张图）→ 居中且撑满内容宽度 */
.zai-content p:has(> img:only-child) {
  text-align: center;
  margin-left: 0;
  margin-right: 0;
}
.zai-content p:has(> img:only-child) img,
.zai-content div:has(> img:only-child) img,
.zai-content .zai-column:has(> img:only-child) img {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* 其余图片居中展示，可点击放大 */
.zai-content img {
  cursor: zoom-in;
  margin-left: auto;
  margin-right: auto;
}
.zai-content img[data-zai-fetching="fail"] {
  cursor: not-allowed;
}

/* ---------------- 灯箱 ---------------- */
.zai-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  background: rgba(8, 8, 10, 0.92);
  -webkit-user-select: none;
  user-select: none;
}
.zai-lightbox.is-open { display: block; }

.zai-lightbox-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.zai-lightbox.is-dragging .zai-lightbox-stage { cursor: grabbing; }

/* 图片默认 contain 撑满（至少适配屏幕，宽图/高图完整可见，不裁切） */
.zai-lightbox-img {
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  display: block;
  transform-origin: center center;
  will-change: transform;
  transition: transform 0.12s ease-out;
}
/* 未赋值的灯箱占位图不显示（避免被识别为破图图标） */
.zai-lightbox-img[src=""] {
  display: none;
}
.zai-lightbox.is-dragging .zai-lightbox-img { transition: none; }

.zai-lightbox-toolbar {
  position: absolute;
  right: 16px;
  top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
}
.zai-lightbox-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.zai-lightbox-btn:hover { background: rgba(255, 255, 255, 0.2); }
.zai-lightbox-zoom {
  min-width: 56px;
  text-align: center;
  color: #fff;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 8px 10px;
}
.zai-lightbox-lock { overflow: hidden; }

/* 移动端：工具按钮沉底，避免遮挡图片 */
@media (max-width: 640px) {
  .zai-lightbox-toolbar {
    right: auto;
    left: 50%;
    top: auto;
    bottom: 18px;
    transform: translateX(-50%);
  }
}


/* 图片持续加载：重试中的占位观感（zai-img-keepload.js） */
.zai-content img.zai-img-retrying,
.zai-article-body img.zai-img-retrying {
  min-height: 64px;
  background:
    linear-gradient(100deg, rgba(120,130,150,.08) 30%, rgba(120,130,150,.18) 50%, rgba(120,130,150,.08) 70%)
    var(--zai-surface-sunken, #eef0f5);
  background-size: 200% 100%;
  animation: zai-img-loading 1.2s linear infinite;
  border-radius: 6px;
}
@keyframes zai-img-loading {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
