:root {
  --bg: #ffffff;
  --bg-side: #fbfbfa;
  --border: #ededec;
  --text: #37352f;
  --text-soft: #787774;
  --hover: #efefee;
  --active: #e8e7e4;
  --accent: #2383e2;
  --shadow: 0 1px 3px rgba(15, 15, 15, 0.08);
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 264px;
  min-width: 264px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-head {
  padding: 12px 14px 8px;
}
.ws { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.ws-icon { font-size: 18px; }
.ws-name { font-size: 14px; }

.search-wrap { padding: 4px 12px 8px; }
#search {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.sidebar-actions { padding: 2px 12px 6px; }
.btn-ghost {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.btn-ghost:hover { background: var(--hover); color: var(--text); }

.tree { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.tree-empty { color: var(--text-soft); font-size: 12px; padding: 8px; }

.node-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  position: relative;
}
.node-row:hover { background: var(--hover); }
.node-row.active { background: var(--active); }
.node-toggle {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  font-size: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.node-toggle:hover { background: var(--active); }
.node-toggle.leaf { visibility: hidden; }
.node-icon { flex: 0 0 auto; font-size: 14px; }
.node-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
.node-actions {
  display: none;
  gap: 2px;
  flex: 0 0 auto;
}
.node-row:hover .node-actions { display: flex; }
.node-actions button {
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 3px;
  width: 20px;
  height: 20px;
  font-size: 13px;
}
.node-actions button:hover { background: var(--active); color: var(--text); }

.sidebar-foot {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-soft);
}
.save-state.saving { color: var(--accent); }

/* ---------- 主区 ---------- */
#main { flex: 1; overflow-y: auto; position: relative; }

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  gap: 10px;
}
.empty-emoji { font-size: 48px; }

.editor { max-width: 820px; margin: 0 auto; padding: 56px 56px 160px; }
.editor.hidden, .empty.hidden, .emoji-pop.hidden { display: none; }

.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.page-icon {
  font-size: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  line-height: 1;
  border-radius: var(--radius);
  padding: 2px 6px;
}
.page-icon:hover { background: var(--hover); }
.page-title {
  flex: 1;
  border: none;
  outline: none;
  font-size: 38px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  font-family: inherit;
}
.page-title::placeholder { color: #c9c8c4; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fcfcfb;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.toolbar button {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  min-width: 30px;
}
.toolbar button:hover { background: var(--hover); }
.toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

.content {
  outline: none;
  min-height: 50vh;
  line-height: 1.7;
  font-size: 16px;
}
.content:empty::before {
  content: "输入正文，或选中文字后使用上方工具栏…";
  color: #c9c8c4;
}
.content h1 { font-size: 28px; margin: 0.6em 0 0.3em; }
.content h2 { font-size: 23px; margin: 0.6em 0 0.3em; }
.content h3 { font-size: 19px; margin: 0.6em 0 0.3em; }
.content p { margin: 0.4em 0; }
.content blockquote {
  border-left: 3px solid var(--border);
  margin: 0.6em 0;
  padding: 2px 14px;
  color: var(--text-soft);
}
.content pre {
  background: #f6f5f4;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}
.content code {
  background: #f1f0ef;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.9em;
}
.content pre code { background: transparent; padding: 0; }
.content ul, .content ol { padding-left: 1.4em; }
.content a { color: var(--accent); text-decoration: underline; }
.content img { max-width: 100%; border-radius: var(--radius); }
.content hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* emoji 面板 */
.emoji-pop {
  position: fixed;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-width: 320px;
}
.emoji-pop button {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
  padding: 4px;
}
.emoji-pop button:hover { background: var(--hover); }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #e0e0de; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #cfcfcd; }

@media (max-width: 720px) {
  #sidebar { width: 200px; min-width: 200px; }
  .editor { padding: 32px 20px 120px; }
  .page-title { font-size: 30px; }
}
