/* Markdown 正文 & 编辑预览 */

.md-editor {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.md-editor-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(26, 46, 42, 0.03);
}

.md-editor-tabs button {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.md-editor-tabs button.active {
  color: var(--teal-deep);
  border-bottom-color: var(--teal);
}

.md-editor-hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: auto;
  padding: 0.55rem 0.85rem;
  align-self: center;
}

.md-editor [data-md-input] {
  display: block;
  width: 100%;
  min-height: 160px;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  resize: vertical;
  padding: 0.85rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  background: transparent;
  color: var(--ink);
}

.md-editor [data-md-input]:focus {
  outline: none;
}

.md-preview {
  min-height: 160px;
  padding: 0.85rem 1rem 1.1rem;
  overflow: auto;
  cursor: default;
}

.md-preview-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

/* 编写 / 预览互斥：用 class 覆盖，避免 display 盖掉 hidden */
.md-editor.is-write [data-md-input],
.md-editor:not(.is-preview) [data-md-input] {
  display: block !important;
}
.md-editor.is-write [data-md-preview],
.md-editor:not(.is-preview) [data-md-preview],
.md-editor [data-md-preview][hidden] {
  display: none !important;
}
.md-editor.is-preview [data-md-input],
.md-editor [data-md-input][hidden] {
  display: none !important;
}
.md-editor.is-preview [data-md-preview] {
  display: block !important;
}


/* —— 正文排版 —— */
.md-body {
  font-size: 1.02rem;
  line-height: 1.75;
  color: var(--ink-soft);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.md-body > *:first-child {
  margin-top: 0;
}

.md-body > *:last-child {
  margin-bottom: 0;
}

.md-body p,
.md-body ul,
.md-body ol,
.md-body blockquote,
.md-body pre,
.md-body table,
.md-body .md-table-wrap {
  margin: 0.75em 0;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
  color: var(--ink);
  font-weight: 700;
  line-height: 1.35;
  margin: 1.1em 0 0.5em;
}

.md-body h1 { font-size: 1.35em; }
.md-body h2 { font-size: 1.2em; }
.md-body h3 { font-size: 1.08em; }

.md-body ul,
.md-body ol {
  padding-left: 1.4em;
}

.md-body li + li {
  margin-top: 0.25em;
}

.md-body blockquote {
  border-left: 3px solid var(--teal);
  padding: 0.15em 0 0.15em 0.9em;
  color: var(--muted);
  margin-left: 0;
}

.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(26, 46, 42, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.md-body pre {
  background: rgba(26, 46, 42, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  overflow-x: auto;
}

.md-body pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}

.md-body a {
  color: var(--teal-deep);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.25em 0;
}

.md-body img {
  max-width: 100%;
  border-radius: 4px;
}

/* —— 表格友好 —— */
.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.md-body table {
  width: 100%;
  min-width: 280px;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.92em;
}

.md-body thead th {
  background: rgba(42, 157, 143, 0.1);
  color: var(--ink);
  font-weight: 700;
  text-align: left;
}

.md-body th,
.md-body td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.75rem;
  vertical-align: top;
}

.md-body tbody tr:nth-child(even) td {
  background: rgba(26, 46, 42, 0.025);
}

.md-body tbody tr:last-child td {
  border-bottom: none;
}

.md-body th[align="center"],
.md-body td[align="center"] {
  text-align: center;
}

.md-body th[align="right"],
.md-body td[align="right"] {
  text-align: right;
}

/* 详情 / 回复内容区去掉白字预格式化冲突 */
.detail-body.md-body,
.reply-content.md-body {
  white-space: normal;
}

.reply-content.md-body {
  font-size: 0.98rem;
}

.admin-item-body.md-body {
  max-height: none;
  white-space: normal;
  font-size: 0.92rem;
}

html[data-theme="apple-black"] .md-editor,
html[data-theme="nvidia"] .md-editor {
  background: #2a2a2a;
}

html[data-theme="apple-black"] .md-editor-tabs,
html[data-theme="nvidia"] .md-editor-tabs {
  background: rgba(255, 255, 255, 0.04);
}

html[data-theme="apple-black"] .md-body code,
html[data-theme="nvidia"] .md-body code,
html[data-theme="apple-black"] .md-body pre,
html[data-theme="nvidia"] .md-body pre {
  background: rgba(255, 255, 255, 0.08);
}

html[data-theme="apple-black"] .md-body thead th,
html[data-theme="nvidia"] .md-body thead th {
  background: rgba(42, 157, 143, 0.2);
}
