:root {
  --red: #e00019;
  --green: #059669;
  --ink: #16181d;
  --text: #3f4652;
  --muted: #7c8494;
  --line: #e4e6eb;
  --bg: #f4f5f7;
  --panel: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── 顶栏 ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--ink);
  color: #fff;
  font: 800 14px/1 Menlo, Consolas, monospace;
  letter-spacing: 0.05em;
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* 生成二级标题 + 章节结果：一组，结果为下拉面板 */
.ai-cluster {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.count {
  color: var(--green);
  font-weight: 700;
}

.ai-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: min(480px, calc(100vw - 32px));
  max-height: 420px;
  overflow: auto;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(20, 24, 34, 0.16);
}

/* 章节结果：可直接改标题（同步写回左侧 Markdown）+ 重新生成 */
.result-list td:nth-child(1) {
  width: 44px;
}

.result-list td:nth-child(2) {
  width: 128px;
}

.result-list input.section-title {
  width: 100%;
  min-width: 110px;
  padding: 4px 6px;
  border: 1px solid #e4e6eb;
  border-radius: 4px;
  background: #fafbfc;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 12.5px;
}

.result-list input.section-title:hover {
  border-color: #c7ccd6;
}

.result-list input.section-title:focus {
  outline: none;
  border-color: #a7f3d0;
  background: #fff;
}

.result-list .stale {
  display: block;
  margin-top: 3px;
  color: var(--red);
  font-size: 11px;
}

.ai-panel .warn {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 12px;
  line-height: 1.6;
}

.ai-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ai-panel-hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

.ai-panel[hidden] {
  display: none;
}

.ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.ai-panel .ai-status {
  margin-bottom: 10px;
}

.ai-panel .ai-status:empty {
  display: none;
}

.ai-panel .result-list {
  margin-top: 0;
}

.btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.16s ease;
}

.btn:hover {
  border-color: #c7ccd6;
  background: #fafbfc;
}

.btn.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn.primary:hover {
  background: #c40016;
  border-color: #c40016;
}

/* 生成二级标题：用摸鱼绿与「复制到公众号」区分开 */
.btn.accent {
  border-color: #a7f3d0;
  color: var(--green);
  background: #f2fdf8;
}

.btn.accent:hover {
  border-color: var(--green);
  background: #e7fbf1;
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── 主区域 ───────────────────────────────────────────── */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.editor-pane {
  position: relative;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

/* 把 .md 文件拖到左侧编辑区时的落点提示 */
.editor-pane.is-dragover {
  background: #f4fdf9;
  box-shadow: inset 0 0 0 2px #a7f3d0;
}

.editor-pane.is-dragover::after {
  content: '松开鼠标，导入 Markdown 文件';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(5, 150, 105, 0.28);
}

.preview-pane {
  background: #fff;
}

/* 固定高度：左右两侧面板头等高，「Markdown」与「预览 · 公众号效果」的
   底边框才会落在同一条水平线上（右侧带按钮组时内容更高，不能靠内容撑高） */
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 46px;
  padding: 0 16px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.pane-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.stat {
  font-size: 12px;
  color: var(--muted);
}

.modes {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: #eef0f3;
  border-radius: 6px;
}

.mode {
  padding: 4px 10px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
}

.mode.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

#editor {
  flex: 1;
  min-height: 0;
  padding: 20px;
  border: none;
  outline: none;
  resize: none;
  font-family: 'SF Mono', Menlo, Consolas, 'Courier New', monospace;
  font-size: 13.5px;
  line-height: 1.85;
  color: #22262e;
  background: transparent;
  tab-size: 2;
}

/* 边距对齐原版 md-wechat 的全屏预览：白底铺满、无卡片阴影，
   内边距 26px 14px 56px 与上游 .page 完全一致（正文自身的 12px 14px 26px 由主题容器提供，
   两者相加即公众号后台的观感：左右各 28px、上 38px、下 82px） */
.preview-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 26px 14px 56px;
  background: #fff;
  /* 滚动条常驻留位，内容不会因滚动条出现/消失而左右跳动（上游 .page 同款） */
  scrollbar-gutter: stable;
}

.preview {
  width: 100%;
  max-width: 677px;
  margin: 0 auto;
  background: #fff;
}

/* 手机模式缩到 390px，在白色底上补一圈细边框区隔设备宽度 */
.preview.phone {
  max-width: 390px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* ── AI 抽屉 ──────────────────────────────────────────── */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(18, 22, 30, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 30;
}

.drawer[hidden] {
  display: none;
}

.drawer-panel {
  width: min(420px, 100%);
  height: 100%;
  overflow: auto;
  padding: 20px;
  background: #fff;
  box-shadow: -12px 0 30px rgba(20, 24, 34, 0.16);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 16px;
  color: var(--ink);
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: #f1f2f5;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.hint {
  margin: 0 0 18px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #22262e;
  background: #fafbfc;
}

.field input:focus {
  outline: none;
  border-color: var(--green);
  background: #fff;
}

.row {
  display: flex;
  gap: 8px;
  margin: 18px 0 12px;
}

.ai-status {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-status.ok {
  color: var(--green);
}

.ai-status.err {
  color: var(--red);
}

.result-box {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 12.5px;
}

.result-box summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.result-list {
  margin-top: 10px;
  color: var(--text);
}

.result-list table {
  width: 100%;
  border-collapse: collapse;
}

.result-list td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  font-family: Menlo, Consolas, monospace;
  font-size: 12px;
}

.result-list td:first-child {
  color: var(--green);
  font-weight: 700;
  white-space: nowrap;
}

/* ── 提示条 ───────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: 0.22s ease;
  z-index: 60;
  max-width: min(560px, 88vw);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .editor-pane {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}
