/* ===== 编辑器主题变量 ===== */
:root {
  --accent: #2563eb;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e7ec;
  --text: #1f2937;
  --text-muted: #6b7280;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --ok: #16a34a;
  --danger: #dc2626;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #16181d;
  --surface-2: #1b1e24;
  --border: #2a2e37;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --code-bg: #272822;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  transition: background 0.2s, color 0.2s;
  overflow: hidden;
}

button, input, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }

/* ===== 顶栏 ===== */
.e-topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.e-top-left, .e-top-right { display: flex; align-items: center; gap: 10px; }
.e-brand { font-weight: 700; font-size: 1rem; color: var(--text); text-decoration: none; }
.e-brand:hover { color: var(--accent); }
.e-brand span { font-weight: 500; }

.e-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}
.e-btn:hover { background: var(--surface-2); }
.e-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.e-btn-primary:hover { background: var(--accent); opacity: 0.9; }

.e-icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  width: 34px; height: 34px;
  font-size: 1rem;
  line-height: 1;
}
.e-icon-btn:hover { background: var(--surface-2); }

.e-status { font-size: 0.82rem; color: var(--text-muted); min-width: 64px; text-align: right; }
.e-status.saved { color: var(--ok); }
.e-status.error { color: var(--danger); }

/* ===== 布局 ===== */
.e-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  height: calc(100vh - 54px);
}

/* ===== 侧边栏 ===== */
.e-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.e-side-head { padding: 12px; border-bottom: 1px solid var(--border); }
.e-search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
  outline: none;
}
.e-search:focus { border-color: var(--accent); }

.e-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.e-list-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.12s;
}
.e-list-item:hover { background: var(--surface-2); }
.e-list-item.active { background: var(--accent); color: #fff; }
.e-list-item.active .e-list-meta, .e-list-item.active .e-list-draft { color: rgba(255, 255, 255, 0.8); }
.e-list-title {
  font-size: 0.9rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.e-list-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.e-list-draft {
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
}
.e-list-item.active .e-list-draft { color: #fff; }
.e-list-empty { padding: 20px; color: var(--text-muted); font-size: 0.85rem; }

/* ===== 主区域 ===== */
.e-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.e-meta { padding: 14px 18px 10px; border-bottom: 1px solid var(--border); background: var(--surface); }
.f-title {
  width: 100%;
  border: none;
  outline: none;
  font-size: 1.6rem;
  font-weight: 700;
  background: transparent;
  padding: 0 0 8px;
}
.f-title::placeholder { color: var(--text-muted); }

.e-meta-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-top: 8px; }
.e-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--text-muted); }
.e-field input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.88rem;
  outline: none;
  color: var(--text);
  width: 150px;
}
.e-field-wide input { width: 260px; }
.e-field input:focus { border-color: var(--accent); }

.e-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  padding-bottom: 6px;
  user-select: none;
}
.e-check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ===== 工具栏 ===== */
.e-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.e-toolbar button {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  transition: background 0.12s;
}
.e-toolbar button:hover { background: var(--surface-2); }
.e-sep { width: 1px; height: 18px; background: var(--border); margin: 0 5px; }

/* ===== 编辑 / 预览双栏 ===== */
.e-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
}
.e-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.e-pane + .e-pane { border-left: 1px solid var(--border); }
.e-pane-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 6px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}

.e-editor {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 18px;
  font-family: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.7;
  background: var(--surface);
  color: var(--text);
  tab-size: 2;
}
.e-editor::placeholder { color: var(--text-muted); }

.e-preview {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  background: var(--surface);
}
.e-preview .empty { color: var(--text-muted); }

/* ===== 预览正文排版（与博客一致） ===== */
.post-body { font-size: 0.98rem; }
.post-body h1, .post-body h2, .post-body h3, .post-body h4 { line-height: 1.3; margin: 1.5em 0 0.6em; }
.post-body h1 { font-size: 1.6rem; }
.post-body h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.post-body h3 { font-size: 1.12rem; }
.post-body p { margin: 0.8em 0; }
.post-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.post-body img { max-width: 100%; border-radius: 8px; }
.post-body ul, .post-body ol { padding-left: 1.5em; }
.post-body li { margin: 4px 0; }
.post-body blockquote {
  margin: 1em 0;
  padding: 2px 16px;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}
.post-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.post-body :not(pre) > code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 0.88em;
}
.post-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.55;
  font-size: 0.88rem;
}
.post-body pre code { background: transparent; padding: 0; }
.post-body table { border-collapse: collapse; width: 100%; margin: 1.2em 0; font-size: 0.92rem; }
.post-body th, .post-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.post-body th { background: var(--surface-2); }

/* ===== Toast ===== */
.e-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.e-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 响应式 ===== */
@media (max-width: 860px) {
  .e-layout { grid-template-columns: 1fr; }
  .e-sidebar { display: none; }
  .e-panes { grid-template-columns: 1fr; }
  .e-pane + .e-pane { border-left: none; border-top: 1px solid var(--border); }
  .e-pane { height: 50vh; }
  .e-preview { height: 50vh; }
}
