:root {
  --dark-bg: #1a1d24;
  --dark-2: #252830;
  --dark-3: #2d313b;
  --border-dark: #363b47;
  --text-light: #e6e8eb;
  --text-dim: #9aa1ac;
  --accent: #5b8bff;
  --accent-hover: #7aa4ff;

  --content-bg: #ffffff;
  --content-text: #22272e;
  --content-border: #e2e5ea;
  --placeholder: #9ca3af;

  --radius: 6px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---- base ---- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--dark-bg);
  color: var(--text-light);
  font-size: 14px; -webkit-font-smoothing: antialiased; overflow: hidden;
}
.app { display: flex; flex-direction: column; height: 100vh; }

/* ====== DARK HEADER ====== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; height: 44px; background: var(--dark-bg);
  border-bottom: 1px solid var(--border-dark); user-select: none; gap: 10px; flex-shrink: 0;
}
.topbar-left {
  display: flex; align-items: center; gap: 6px; min-width: 200px; white-space: nowrap;
}
.brand { font-size: 15px; font-weight: 500; letter-spacing: .3px; }
.brand-bold { font-weight: 700; }
.sep-v { color: var(--text-dim); margin: 0 2px; }
.doc-title-input {
  border: none; background: transparent; color: var(--accent);
  font-size: 14px; font-weight: 600; outline: none; width: 160px;
}
.doc-title-input::placeholder { color: var(--text-dim) !important; }

/* toolbar icons in header */
.toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: nowrap; overflow-x: auto; }
.toolbar button,
.toolbar select {
  background: transparent; border: none; color: var(--text-light);
  cursor: pointer; padding: 0 12px; border-radius: 6px; font-size: 16px; line-height: 1;
  min-width: 40px; height: 38px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.toolbar button:hover,
.toolbar select:hover { background: var(--dark-2); }
.toolbar button b, .toolbar button i, .toolbar button s { font-style: normal; text-decoration: none; }
/* active format painter */
.toolbar button.active { background: var(--accent); color: #fff; box-shadow: 0 0 0 1px var(--accent) inset; }
body.painter-active #editor,
body.painter-active .visual-editor { cursor: crosshair; }
.toolbar select { appearance: auto; color: var(--text-light); background: transparent; font-size: 12px; padding-right: 4px; }
.toolbar .sep { width: 1px; height: 18px; background: var(--border-dark); margin: 0 3px; flex-shrink: 0; }

/* ====== TAB BAR ====== */
.tabbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 38px; background: var(--dark-2);
  border-bottom: 1px solid var(--border-dark); padding: 0 10px;
  user-select: none; flex-shrink: 0; gap: 8px;
}
.tabbar-left { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.tabbar-right { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; flex-shrink: 0; white-space: nowrap; }

.tabbar-stats {
  display: flex; align-items: center; gap: 2px;
  padding: 2px 6px; background: var(--dark-3);
  border: 1px solid var(--border-dark); border-radius: 6px;
}

.stat-item { padding: 0 4px; min-width: 42px; text-align: center; }
.stat-sep { width: 1px; height: 14px; background: var(--border-dark); margin: 0 2px; }

.mode-switcher { display: flex; align-items: center; overflow: hidden; border-radius: 4px; border: 1px solid var(--border-dark); background: var(--dark-bg); }
.mode-opt { cursor: pointer; padding: 2px 10px; font-size: 12px; color: var(--text-dim); transition: background .15s, color .15s; }
.mode-opt:hover { background: var(--dark-2); color: var(--text-light); }
.mode-opt.active { background: var(--accent); color: #fff; font-weight: 600; }
.sep-t { display: none; }

.new-tab-btn {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 2px 8px; border-radius: 4px;
}
.new-tab-btn:hover { background: var(--dark-3); color: var(--text-light); }

.tab-tool-btn {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 12px; cursor: pointer; padding: 4px 10px; border-radius: 4px;
  display: inline-flex; align-items: center; gap: 3px; white-space: nowrap;
}
.tab-tool-btn:hover { background: rgba(229,72,77,.15); color: #f87171; }

.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; margin-left: 6px; }

.tab {
  display: flex; align-items: center; gap: 6px; padding: 5px 12px;
  border-radius: 6px 6px 0 0; cursor: pointer; font-size: 13px;
  max-width: 180px; background: var(--dark-3); color: var(--text-dim);
}
.tab:hover { background: var(--border-dark); }
.tab.active { background: var(--content-bg); color: var(--content-text); }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .tab-close {
  font-size: 11px; opacity: .45; border-radius: 50%; padding: 1px 4px;
}
.tab .tab-close:hover { opacity: 1; background: rgba(229,72,77,.35); color: #fff; }

.status-badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.status-badge.draft   { background: rgba(91,139,255,.18); color: #8eb4ff; } /* 草稿 */
.status-badge.saved  { background: rgba(46,158,91,.18); color: #4ade80; } /* 已保存 */
.status-badge.dirty   { background: rgba(229,72,77,.18); color: #f87171; } /* 未保存 */

.mode-switcher { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.mode-opt { cursor: pointer; }
.mode-opt.active { color: var(--accent); font-weight: 600; }
.sep-t { color: var(--text-dim); }

/* ====== CONTENT AREA ====== */
.content {
  flex: 1; position: relative; min-height: 0; background: var(--content-bg); color: var(--content-text);
}

#editor {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  width: 100%; height: 100%;
  border: none; outline: none; resize: none;
  padding: 24px 32px; font-family: var(--mono); font-size: 14px; line-height: 1.75;
  background: var(--content-bg); color: var(--content-text);
  tab-size: 2; overflow-y: auto;
}
#editor::placeholder { color: var(--placeholder); }

/* ====== VISUAL EDITOR ====== */
.visual-editor {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  width: 100%; height: 100%;
  border: none; outline: none;
  padding: 24px 32px; font-family: var(--sans); font-size: 14px; line-height: 1.78;
  background: var(--content-bg); color: var(--content-text);
  overflow-y: auto;
}
.visual-editor:empty::before {
  content: attr(placeholder);
  color: var(--placeholder);
  pointer-events: none;
}
.content.split .visual-editor {
  right: 50%; width: 50%; border-right: 1px solid var(--content-border);
}
.visual-editor img { max-width: 100%; min-width: 40px; min-height: 40px; height: auto; border-radius: 6px; display: block; margin: .6em 0; }
.visual-editor h1, .visual-editor h2, .visual-editor h3, .visual-editor h4 { line-height: 1.3; margin: 1.1em 0 .5em; }
.visual-editor h1 { font-size: 1.85em; border-bottom: 2px solid var(--content-border); padding-bottom: .28em; }
.visual-editor h2 { font-size: 1.48em; border-bottom: 1px solid var(--content-border); padding-bottom: .22em; }
.visual-editor h3 { font-size: 1.22em; }
.visual-editor p { margin: .65em 0; }
.visual-editor a { color: var(--accent); text-decoration: none; }
.visual-editor a:hover { text-decoration: underline; }
.visual-editor code {
  font-family: var(--mono); background: #f1f3f5; padding: .15em .4em;
  border-radius: 4px; font-size: .88em;
}
.visual-editor pre {
  background: #f5f7f9; padding: 16px 18px; border-radius: 8px;
  overflow-x: auto; border: 1px solid var(--content-border);
}
.visual-editor pre code { background: transparent; padding: 0; }
.visual-editor blockquote {
  margin: .75em 0; padding: .4em 1em; border-left: 4px solid var(--accent);
  color: #606876; background: #f7f8fa; border-radius: 0 6px 6px 0;
}
.visual-editor ul, .visual-editor ol { padding-left: 1.6em; }
.visual-editor li { margin: .28em 0; }
.visual-editor table { border-collapse: collapse; width: 100%; margin: .8em 0; }
.visual-editor th, .visual-editor td { border: 1px solid var(--content-border); padding: 8px 10px; }
.visual-editor th { background: #f5f7fa; font-weight: 600; }
.visual-editor hr { border: none; border-top: 1px solid var(--content-border); margin: 1.5em 0; }

.preview {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  padding: 24px 40px; line-height: 1.78;
  overflow-y: auto; font-family: var(--sans);
  max-width: 900px; margin: 0 auto;
}
.preview.hidden { display: none; }
.editor-hidden { display: none !important; }

/* split view: editor + preview side by side */
.content.split #editor {
  right: 50%; width: 50%; border-right: 1px solid var(--content-border);
}
.content.split .preview {
  left: 50%; right: 0; max-width: none; margin: 0;
  border-left: 1px solid var(--content-border); background: var(--content-bg);
}

/* ====== DARK FOOTER ====== */
.botbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 34px; padding: 0 16px; background: var(--dark-bg);
  border-top: 1px solid var(--border-dark);
  color: var(--text-dim); font-size: 12px; flex-shrink: 0;
}
.brand-footer { font-weight: 700; }

/* ====== FIND / REPLACE BAR ====== */
.find-bar {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 12px; background: var(--dark-2);
  border-top: 1px solid var(--border-dark); flex-shrink: 0;
}
.find-bar[hidden] { display: none; }
.find-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.find-input {
  flex: 1 1 200px; min-width: 160px; height: 34px; padding: 0 10px;
  background: var(--dark-bg); color: var(--text-light);
  border: 1px solid var(--border-dark); border-radius: 6px; font-size: 13px; outline: none;
}
.find-input:focus { border-color: var(--accent); }
.find-chk {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-dim); font-size: 12px; cursor: pointer; user-select: none;
}
.find-chk input { accent-color: var(--accent); }
.find-count { color: var(--text-dim); font-size: 12px; min-width: 56px; text-align: center; }
.find-btn {
  height: 30px; padding: 0 12px; border: 1px solid var(--border-dark);
  background: var(--dark-3); color: var(--text-light); border-radius: 6px;
  cursor: pointer; font-size: 13px; line-height: 1;
}
.find-btn:hover { background: var(--border-dark); }
.find-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.find-btn.primary:hover { background: var(--accent-hover); }

/* ====== MARKDOWN PREVIEW TYPOGRAPHY ====== */
.preview h1, .preview h2, .preview h3, .preview h4 { line-height: 1.3; margin: 1.2em 0 .55em; }
.preview h1 { font-size: 1.85em; border-bottom: 2px solid var(--content-border); padding-bottom: .28em; }
.preview h2 { font-size: 1.48em; border-bottom: 1px solid var(--content-border); padding-bottom: .22em; }
.preview h3 { font-size: 1.22em; }
.preview p { margin: .65em 0; }
.preview a { color: var(--accent); text-decoration: none; }
.preview a:hover { text-decoration: underline; }
.preview code {
  font-family: var(--mono); background: #f1f3f5; padding: .15em .4em;
  border-radius: 4px; font-size: .88em;
}
.preview pre {
  background: #f5f7f9; padding: 16px 18px; border-radius: 8px;
  overflow-x: auto; border: 1px solid var(--content-border);
}
.preview pre code { background: transparent; padding: 0; }
.preview blockquote {
  margin: .75em 0; padding: .4em 1em; border-left: 4px solid var(--accent);
  color: #606876; background: #f7f8fa; border-radius: 0 6px 6px 0;
}
.preview ul, .preview ol { padding-left: 1.6em; }
.preview li { margin: .28em 0; }
.preview table { border-collapse: collapse; width: 100%; margin: .8em 0; }
.preview th, .preview td { border: 1px solid var(--content-border); padding: 8px 10px; }
.preview th { background: #f5f7fa; font-weight: 600; }
.preview img { max-width: 100%; min-width: 40px; min-height: 40px; height: auto; border-radius: 6px; display: block; margin: .6em 0; }
.preview hr { border: none; border-top: 1px solid var(--content-border); margin: 1.5em 0; }

/* fullscreen mode */
.app.fullscreen .topbar, .app.fullscreen .tabbar, .app.fullscreen .botbar { display: none; }
.app.fullscreen .content { height: 100vh; }

@media (max-width: 720px) {
  .toolbar { display: none; }
  .tabbar-stats .stat-item,
  .tabbar-stats .stat-sep { display: none; }
  .tabbar-stats { padding: 0; background: transparent; border: none; }
  #closeAllBtn span { display: none; }
}

/* ====== EMOJI PICKER ====== */
.emoji-panel {
  position: fixed; z-index: 10000; display: none; flex-direction: column;
  width: 320px; max-height: 360px;
  background: var(--dark-2); border: 1px solid var(--border-dark);
  border-radius: 10px; box-shadow: 0 10px 36px rgba(0,0,0,.45);
  overflow: hidden; color: var(--text-light);
}
.emoji-search { padding: 8px; border-bottom: 1px solid var(--border-dark); }
.emoji-search input {
  width: 100%; box-sizing: border-box; padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--border-dark); background: var(--dark-bg); color: var(--text-light);
  outline: none; font-size: 13px;
}
.emoji-search input:focus { border-color: var(--accent); }
.emoji-search input::placeholder { color: var(--text-dim); }
.emoji-tabs {
  display: flex; gap: 2px; padding: 6px 8px; overflow-x: auto;
  border-bottom: 1px solid var(--border-dark);
}
.emoji-tab {
  flex: 0 0 auto; padding: 4px 10px; border: none; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-dim); font-size: 12px;
}
.emoji-tab:hover { background: var(--dark-3); color: var(--text-light); }
.emoji-tab.active { background: var(--accent); color: #fff; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 8px; overflow-y: auto;
}
.emoji-cell {
  border: none; background: transparent; cursor: pointer; border-radius: 6px;
  font-size: 20px; line-height: 1; padding: 6px 0; text-align: center;
}
.emoji-cell:hover { background: var(--dark-3); }
.emoji-empty {
  grid-column: 1 / -1; text-align: center; color: var(--text-dim);
  font-size: 13px; padding: 24px 0;
}

/* ====== TASK LIST (复选框任务列表) ====== */
.task-list-item {
  list-style: none;
  position: relative;
}
.task-list-item::marker { content: ""; }
.task-list-label {
  display: inline-flex; align-items: center; gap: .45em;
  cursor: pointer; user-select: none;
}
.task-list-item input[type="checkbox"] {
  width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer;
}
/* 可视化编辑器内的任务项同样去圆点、对齐复选框 */
.visual-editor .task-list-item { list-style: none; }
.visual-editor .task-list-item::marker { content: ""; }

/* ====== PREVIEW 图片缩放 ====== */
.preview img { cursor: pointer; }
.preview img.img-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.img-resize-handle {
  position: fixed;
  width: 14px; height: 14px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  cursor: nwse-resize;
  z-index: 99998;
  display: none;
}
.img-resize-handle:hover { background: var(--accent-hover); }

/* ====== DRAG & DROP 拖放遮罩 ====== */
.drop-overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(26,29,36,.55);
  z-index: 99990;
  pointer-events: none;
}
.drop-overlay.show { display: flex; }
.drop-overlay-inner {
  padding: 28px 48px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: rgba(37,40,48,.92);
  color: var(--text-light);
  font-size: 18px; font-weight: 600;
  letter-spacing: .04em;
}

