/* Typora 风格：窄侧栏 + 居中纸张 + 克制排版。默认浅色纸张，可一键切换深色。 */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-code: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --paper-max: 880px;
  --line-h: 26px;
}

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar-bg: #f6f6f6;
  --sidebar-border: #e5e5e5;
  --text: #333333;
  --heading: #1a1a1a;
  --muted: #8a8a8a;
  --faint: #b8b8b8;
  --accent: #4a76a8;
  --accent-soft: #e9f0f8;
  --border: #e8e8e8;
  --code-bg: #f5f5f5;
  --quote-bg: #fafafa;
  --quote-bar: #d4d4d4;
  --active-line: rgba(0, 0, 0, 0.035);
  --selected: #e8eef6;
  --hover: rgba(0, 0, 0, 0.045);
  --danger: #b34a44;
  --success: #3f8a5c;
  --warn: #a97c1b;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1e1e1e;
  --sidebar-bg: #262626;
  --sidebar-border: #343434;
  --text: #cccccc;
  --heading: #f0f0f0;
  --muted: #8b8b8b;
  --faint: #666666;
  --accent: #7ba7d7;
  --accent-soft: #2c3a4a;
  --border: #383838;
  --code-bg: #2b2b2b;
  --quote-bg: #252525;
  --quote-bar: #555555;
  --active-line: rgba(255, 255, 255, 0.05);
  --selected: #303c4a;
  --hover: rgba(255, 255, 255, 0.055);
  --danger: #df7b73;
  --success: #74b58c;
  --warn: #d3a84e;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ---------- 通用按钮 ---------- */
.primary {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 9px 16px;
  font-weight: 600;
  transition: opacity .15s ease;
}
.primary:hover { opacity: .9; }
.primary:disabled { opacity: .55; cursor: not-allowed; }
.block { width: 100%; }
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- 登录 / 注册 ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 40px 36px 30px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-mark,
.brand-mark,
.empty-mark {
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #ffffff;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}
.auth-mark {
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  border-radius: 8px;
  font-size: 24px;
}
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 600;
  color: var(--heading);
  letter-spacing: .02em;
}
.auth-card .sub { margin: 0 0 28px; color: var(--muted); font-size: 13px; }
.field { display: block; margin-bottom: 16px; color: var(--muted); font-size: 12px; text-align: left; }
.field input {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 10px 11px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  font-size: 14px;
  color: var(--text);
}
.field input:focus { border-color: var(--accent); }
.error { min-height: 18px; margin: 0 0 8px; color: var(--danger); font-size: 12px; }
.switch { margin: 20px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.switch a { text-decoration: none; }

/* ---------- 主框架 ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 258px 1fr;
  height: 100vh;
  transition: grid-template-columns .18s ease;
}
.app-shell.sidebar-collapsed { grid-template-columns: 0 1fr; }
.app-shell.sidebar-collapsed .sidebar { padding-left: 0; padding-right: 0; overflow: hidden; border-right: 0; }

/* ---------- 侧栏 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 12px 12px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
}
.sidebar-head { padding: 0 8px 16px; }
.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 4px; font-size: 14px; flex: none; }
.brand-text { color: var(--heading); font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.brand-text em { font-style: normal; font-weight: 400; color: var(--muted); }
.who { display: block; margin-top: 7px; padding-left: 31px; font-size: 11px; color: var(--muted); }

.new-note {
  width: 100%;
  margin-bottom: 10px;
  padding: 9px 12px;
  text-align: left;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.new-note:hover { color: var(--accent); border-color: var(--accent); background: var(--hover); }
.plus { font-size: 15px; margin-right: 4px; vertical-align: -1px; }

.note-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 2px;
}
.list-hint { color: var(--faint); text-align: center; font-size: 12px; margin-top: 24px; }
.note-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  border-radius: 3px;
  transition: background .12s ease;
}
.note-item:hover { background: var(--hover); }
.note-item.selected { background: var(--selected); border-left-color: var(--accent); }
.note-title {
  display: block;
  color: var(--heading);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-excerpt,
.note-time {
  display: block;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-time { color: var(--faint); font-size: 10px; margin-top: 2px; }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 2px;
  margin-top: 8px;
  border-top: 1px solid var(--sidebar-border);
  white-space: nowrap;
}
.user-dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.logout {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 0;
}
.logout:hover { color: var(--danger); }

/* ---------- 工作区 ---------- */
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.doc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 46px;
  flex: none;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}
.doc-crumb {
  flex: 1;
  min-width: 0;
  color: var(--faint);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-actions { display: flex; align-items: center; gap: 6px; }
.tabs { display: flex; gap: 2px; margin-right: 6px; }
.tab {
  background: transparent;
  border: none;
  border-radius: 3px;
  padding: 5px 11px;
  color: var(--muted);
  font-size: 12px;
}
.tab:hover { background: var(--hover); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.doc-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--faint); }
.empty-mark { width: 52px; height: 52px; margin-bottom: 16px; border-radius: 10px; font-size: 28px; opacity: .45; }
.empty p { font-size: 13px; }

.paper {
  width: 100%;
  max-width: var(--paper-max);
  min-height: 100%;
  margin: 0 auto;
  padding: 58px 56px 90px;
  display: flex;
  flex-direction: column;
}
.title-input {
  width: 100%;
  padding: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--heading);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -.01em;
}
.title-input::placeholder { color: var(--faint); font-weight: 400; }
.paper-divider { height: 1px; margin: 20px 0 26px; background: var(--border); }

.editor-wrap { position: relative; flex: 1; min-height: 58vh; }
.active-line {
  position: absolute;
  top: 0;
  left: -12px;
  right: -12px;
  height: var(--line-h);
  background: var(--active-line);
  pointer-events: none;
  z-index: 0;
  will-change: transform;
}
.content-input {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 58vh;
  padding: 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-code);
  font-size: 14px;
  line-height: var(--line-h);
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  tab-size: 4;
}
.content-input::placeholder { color: var(--faint); }

.preview {
  position: relative;
  z-index: 1;
  min-height: 58vh;
  outline: none;
}

/* ---------- Typora 风格 Markdown 排版 ---------- */
.markdown-body {
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
  word-wrap: break-word;
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--heading);
  font-weight: 700;
  line-height: 1.35;
  margin: 1.6em 0 .7em;
}
.markdown-body h1 { font-size: 2em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 1.55em; padding-bottom: .25em; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 1.3em; }
.markdown-body h4 { font-size: 1.12em; }
.markdown-body p { margin: 0 0 1.1em; }
.markdown-body strong { color: var(--heading); font-weight: 700; }
.markdown-body em { color: var(--text); }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body ul, .markdown-body ol { padding-left: 2em; margin: 0 0 1.1em; }
.markdown-body li { margin: .25em 0; }
.markdown-body li > p { margin: .25em 0; }
.markdown-body blockquote {
  margin: 1.2em 0;
  padding: 8px 16px;
  border-left: 4px solid var(--quote-bar);
  background: var(--quote-bg);
  color: var(--muted);
}
.markdown-body blockquote p:last-child { margin-bottom: 0; }
.markdown-body code {
  font-family: var(--font-code);
  font-size: .88em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}
.markdown-body pre {
  margin: 1.2em 0;
  padding: 15px 18px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow-x: auto;
  line-height: 1.6;
}
.markdown-body pre code { background: none; border: none; padding: 0; font-size: .9em; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 2.2em 0; }
.markdown-body table { width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: 14px; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown-body th { background: var(--code-bg); color: var(--heading); font-weight: 600; }
.markdown-body img { max-width: 100%; border-radius: 4px; }
.markdown-body del { color: var(--muted); }

/* ---------- 搜索 ---------- */
.search-input {
  width: 100%;
  margin-bottom: 10px;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  color: var(--text);
  font-size: 12px;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--faint); }

/* ---------- 分屏：源码 + 实时预览 ---------- */
.editor-wrap.split { display: flex; gap: 24px; }
.editor-wrap.split .content-input { width: 50%; flex: none; }
.editor-wrap.split .active-line { right: calc(50% + 12px); }
.editor-wrap.split .split-preview {
  width: 50%;
  flex: none;
  min-height: 58vh;
  overflow-y: auto;
  padding-left: 20px;
  border-left: 1px solid var(--border);
}

/* ---------- 代码块复制按钮 ---------- */
.markdown-body pre { position: relative; }
.copy-code {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  font-size: 11px;
  opacity: 0;
  transition: opacity .15s ease;
}
.markdown-body pre:hover .copy-code,
.copy-code:focus { opacity: 1; }
.copy-code:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- 状态栏 ---------- */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  flex: none;
  padding: 0 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}
.status { background: none; border: none; padding: 0; color: var(--muted); font-size: 11px; }
.status[data-kind="saving"], .status[data-kind="unsaved"] { color: var(--warn); }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="saved"] { color: var(--success); }
.status-right { display: flex; align-items: center; gap: 16px; }
.hint { color: var(--faint); }

@media (max-width: 900px) {
  .editor-wrap.split { display: block; }
  .editor-wrap.split .content-input,
  .editor-wrap.split .split-preview { width: 100%; }
  .editor-wrap.split .active-line { right: -12px; }
  .editor-wrap.split .split-preview {
    margin-top: 18px;
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
@media (max-width: 860px) {
  .paper { padding: 36px 28px 70px; }
  .title-input { font-size: 28px; }
}
@media (max-width: 680px) {
  .app-shell { grid-template-columns: 0 1fr; }
  .sidebar { position: absolute; z-index: 10; width: 258px; height: 100vh; box-shadow: var(--shadow); }
  .app-shell:not(.sidebar-collapsed) { grid-template-columns: 0 1fr; }
  .doc-crumb { display: none; }
}
