:root {
  --bg: #ffffff;
  --sidebar-bg: #f7f7f8;
  --sidebar-border: #e6e6ea;
  --hover: #ececf0;
  --selected: #d9d9e0;
  --text: #1c1c1e;
  --text-2: #8a8a8e;
  --text-3: #b0b0b5;
  --accent: #ffd60a;
  --accent-soft: #fff6cc;
  --line: #ececf0;
  --danger: #ff3b30;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 任何带 hidden 属性的元素都必须隐藏（避免被 display:flex 等覆盖） */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 10px;
}
.sidebar-head h1 {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
  letter-spacing: .2px;
}
.icon-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.new-btn { color: #c79a00; font-weight: 700; }
.menu-btn { display: none; }

.search {
  margin: 4px 14px 10px;
  position: relative;
}
.search-ico {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: .55;
}
.search input {
  width: 100%;
  border: none;
  background: #e9e9ee;
  border-radius: 9px;
  padding: 8px 10px 8px 30px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}
.search input::placeholder { color: var(--text-3); }

.note-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.note-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background .12s;
}
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--selected); }
.note-item .ni-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .ni-snippet {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .ni-date {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--sidebar-border); }
.mode-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #1c1c1e;
  font-weight: 600;
  font-size: 14px;
  padding: 11px;
  border-radius: 11px;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.mode-btn:hover { filter: brightness(.96); }
.mode-btn.editing { background: #ececf0; color: var(--text-2); }

/* ---------- 主编辑区 ---------- */
.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tool {
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  color: #444;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.tool:hover { background: var(--hover); }
.tool.danger { color: var(--danger); margin-left: auto; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.version-mark {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  opacity: 0.7;
  user-select: text;
  padding: 0 4px;
}

.save-status {
  font-size: 12px;
  color: var(--text-3);
  margin-left: 6px;
  min-width: 48px;
}

.note-head {
  padding: 22px 56px 6px;
}
.title-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  font-family: var(--font);
}
.title-input::placeholder { color: var(--text-3); }
.meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

.content-wrap { flex: 1; position: relative; overflow-y: auto; }
.content {
  padding: 8px 56px 80px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  outline: none;
  min-height: 100%;
}
.content[contenteditable="true"] { cursor: text; }

/* 富文本内容样式 */
.content h2 { font-size: 21px; font-weight: 700; margin: 14px 0 6px; }
.content h3 { font-size: 18px; font-weight: 700; margin: 12px 0 5px; }
.content p { margin: 6px 0; }
.content ul, .content ol { margin: 6px 0 6px 24px; }
.content blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin: 10px 0;
  padding: 8px 14px;
  border-radius: 0 8px 8px 0;
  color: #5a4d00;
}
.content img.note-img {
  max-width: 100%;
  border-radius: 10px;
  margin: 8px 0;
  display: block;
  box-shadow: var(--shadow);
}
.content a { color: #0a84ff; }

.empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  text-align: center;
  gap: 10px;
}
.empty.show { display: flex; }
.empty-emoji { font-size: 46px; }
.empty-new {
  margin-top: 8px;
  border: none;
  background: var(--accent);
  color: #1c1c1e;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 11px;
  cursor: pointer;
  font-family: var(--font);
}
.empty-new:hover { filter: brightness(.96); }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.32);
  display: grid; place-items: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.modal {
  background: #fff;
  width: 320px;
  max-width: 88vw;
  border-radius: 16px;
  padding: 22px 20px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.modal input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  font-family: var(--font);
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}
.btn.ghost { background: #f0f0f3; color: var(--text); }
.btn.primary { background: var(--accent); color: #1c1c1e; }
.btn.primary:hover { filter: brightness(.96); }

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    z-index: 30;
    height: 100%;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.18);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .menu-btn { display: grid; }
  .note-head, .content { padding-left: 20px; padding-right: 20px; }
  .new-btn { margin-left: auto; }
}
