/* Personal Knowledge Base · approved paper-minimalist system */
:root {
  color-scheme: light;
  --bg: #fbfaf7;
  --side: #f3f1eb;
  --paper: #fffefa;
  --line: #e5e1d8;
  --line-soft: #eeebe4;
  --text: #292a27;
  --muted: #6f716a;
  --hover: #eeece6;
  --active: #e9f0f8;
  --accent: #3567a8;
  --accent-hi: #28578f;
  --accent-soft: #e9f0f8;
  --danger: #b64740;
  --danger-soft: #f8e9e6;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(46, 43, 35, .06);
  --shadow-md: 0 14px 36px rgba(38, 39, 35, .16);
  --ease: cubic-bezier(.2, .7, .25, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1d20;
  --side: #17181b;
  --paper: #222428;
  --line: #34363b;
  --line-soft: #2a2c30;
  --text: #eeeeea;
  --muted: #a3a49e;
  --hover: #292b30;
  --active: #26384d;
  --accent: #8db6ed;
  --accent-hi: #a5c7f3;
  --accent-soft: #26384d;
  --danger: #f08c83;
  --danger-soft: #3a2525;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .18);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: color .18s var(--ease), background .18s var(--ease);
  touch-action: manipulation;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { color: var(--text); background: var(--accent-soft); }

/* Navigation */
.sidebar {
  position: relative;
  z-index: 2;
  width: 276px;
  min-width: 276px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(14px + var(--safe-top)) 14px calc(14px + var(--safe-bottom));
  overflow: hidden;
  background: var(--side);
  border-right: 1px solid var(--line);
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .22s var(--ease);
}

.brand {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  padding: 2px 2px 14px;
}
.brand-row {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 9px;
}
.brand-logo svg { width: 17px; height: 17px; }
.brand h1 {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
}
.brand-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.brand-tools .icon-btn { width: 36px; height: 36px; }

.icon-btn, .mobile-nav-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color .16s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
}
.icon-btn:hover, .mobile-nav-btn:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--line);
}
.icon-btn:active, .mobile-nav-btn:active { transform: scale(.96); }
.icon-btn svg, .mobile-nav-btn svg { width: 17px; height: 17px; }
.icon-btn .i-sun { display: none; }
[data-theme="dark"] .icon-btn .i-sun { display: block; }
[data-theme="dark"] .icon-btn .i-moon { display: none; }

.side-top { display: flex; flex-direction: column; gap: 9px; padding: 0 2px 16px; }
.search {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 13px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
.search::placeholder { color: var(--muted); opacity: .85; }
.search:focus, .auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search::-webkit-search-cancel-button { display: none; }

.btn-primary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .16s var(--ease), border-color .16s var(--ease), transform .16s var(--ease), box-shadow .16s var(--ease);
}
.btn-primary:hover {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
  box-shadow: var(--shadow-sm);
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; cursor: wait; box-shadow: none; }
.btn-primary svg { width: 16px; height: 16px; flex: none; }
[data-theme="dark"] .btn-primary { color: #111820; }
#newBtn { width: 100%; justify-content: flex-start; }

.doc-list {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 0 12px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.sidebar:hover .doc-list { scrollbar-color: var(--line) transparent; }
.doc-item {
  position: relative;
  min-height: 58px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background .14s var(--ease), border-color .14s var(--ease), color .14s var(--ease);
}
.doc-item:hover { background: var(--hover); }
.doc-item:active { transform: scale(.99); }
.doc-item:focus-visible { outline-offset: -2px; }
.doc-item.on {
  background: var(--active);
  border-color: color-mix(in srgb, var(--accent) 16%, transparent);
}
.doc-item.on::before {
  position: absolute;
  inset: 10px auto 10px 0;
  width: 3px;
  content: "";
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.doc-item .txt { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.doc-item .t {
  overflow: hidden;
  color: inherit;
  font-size: 13px;
  font-weight: 560;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-item .d { flex: none; color: var(--muted); font-size: 11px; }
.doc-item .snip {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}
mark { color: inherit; background: #f2e4ad; border-radius: 2px; }
[data-theme="dark"] mark { background: #65572c; }
.doc-empty {
  padding: 18px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
}
.doc-act {
  position: absolute;
  z-index: 1;
  right: 8px;
  top: 50%;
  display: none;
  align-items: center;
  gap: 5px;
  transform: translateY(-50%);
}
.doc-item:hover .doc-act, .doc-item:focus-within .doc-act { display: flex; }
.doc-item:hover .d, .doc-item:focus-within .d { visibility: hidden; }
.doc-act button {
  min-height: 30px;
  padding: 3px 8px;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 11px;
  cursor: pointer;
}
.doc-act button:hover { color: var(--accent); border-color: var(--accent); }
.doc-act button.danger:hover { color: var(--danger); border-color: var(--danger); }
.doc-menu-btn { display: none; }
.doc-menu-btn svg { width: 16px; height: 16px; fill: currentColor; }

.side-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}
.mobile-tools { display: none; align-items: center; gap: 3px; }
.trash-toggle {
  min-width: 0;
  min-height: 40px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 9px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  transition: color .16s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
}
.trash-toggle:hover, .trash-toggle.on { color: var(--text); background: var(--hover); }
.trash-toggle.on { border-color: var(--line); }
.trash-toggle svg { width: 16px; height: 16px; flex: none; }
.trash-toggle span { min-width: 0; flex: 1; }
.trash-toggle em {
  min-width: 22px;
  padding: 1px 6px;
  color: var(--muted);
  background: var(--hover);
  border-radius: 999px;
  font-size: 10px;
  font-style: normal;
  text-align: center;
}
.trash-toggle em[data-n="0"] { opacity: .65; }

/* Workspace */
.main {
  min-width: 0;
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg);
}

/* 回收站独立页面：不显示笔记导航和编辑器，地址可刷新与前进/后退。 */
html[data-view="trash"] .sidebar,
html[data-view="trash"] .main,
html[data-view="trash"] .sidebar-backdrop { display: none !important; }
.trash-page {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.trash-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: calc(22px + var(--safe-top)) clamp(24px, 4vw, 58px) 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.trash-head-title { min-width: 0; display: flex; align-items: center; gap: 18px; }
.trash-head-title .btn-trash-back { flex: none; }
.trash-hero-icon {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 15px;
}
.trash-hero-icon svg { width: 23px; height: 23px; }
.trash-heading-copy { min-width: 0; }
.trash-kicker { margin: 0 0 1px; color: var(--accent); font-size: 11px; font-weight: 650; letter-spacing: .08em; }
.trash-heading-copy h1 { margin: 0; color: var(--text); font-size: 24px; line-height: 1.3; font-weight: 650; }
.trash-heading-copy h1:focus { outline: none; }
.trash-heading-copy > p:last-child { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.trash-head-actions { flex: none; display: flex; align-items: center; gap: 14px; }
.trash-total { color: var(--muted); font-size: 12px; white-space: nowrap; }
.trash-total strong { color: var(--text); font-size: 16px; font-weight: 650; }
.mini-btn svg { width: 15px; height: 15px; flex: none; }
.trash-page-body {
  width: min(100%, 1120px);
  min-height: 0;
  flex: 1;
  margin: 0 auto;
  padding: 30px clamp(24px, 4vw, 58px) calc(30px + var(--safe-bottom));
  overflow: auto;
  overscroll-behavior: contain;
}
.trash-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 15px;
}
.trash-section-title h2 { margin: 0; font-size: 15px; font-weight: 650; }
.trash-section-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.trash-count-chip {
  flex: none;
  padding: 4px 9px;
  color: var(--muted);
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 11px;
}
.trash-list { display: grid; gap: 8px; }
.trash-list .doc-item {
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(92px, auto) auto;
  gap: 16px;
  padding: 13px 16px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}
.trash-list .doc-item:hover { border-color: var(--line); }
.trash-list .doc-item .txt { min-width: 0; }
.trash-list .doc-item .d,
.trash-list .doc-item:hover .d,
.trash-list .doc-item:focus-within .d { visibility: visible; }
.trash-list .doc-item .d { position: static; min-width: 96px; color: var(--muted); font-size: 11px; text-align: right; }
.trash-list .doc-item .doc-menu-btn { display: none; }
.trash-list .doc-item .doc-act {
  position: static;
  display: flex !important;
  align-items: center;
  gap: 7px;
  transform: none;
}
.trash-list .doc-act button { min-height: 36px; padding: 5px 11px; font-size: 12px; }
.trash-empty {
  min-height: min(48vh, 360px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
  color: var(--muted);
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 16px;
  text-align: center;
}
.trash-empty-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--side);
  border-radius: 17px;
}
.trash-empty-icon svg { width: 25px; height: 25px; }
.trash-empty h2 { margin: 14px 0 3px; color: var(--text); font-size: 17px; font-weight: 650; }
.trash-empty p { margin: 0 0 16px; font-size: 12px; }
.trash-empty .btn-trash-back { min-height: 38px; }
.trash-flight {
  position: fixed;
  z-index: 140;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 12px;
  overflow: hidden;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  white-space: nowrap;
}
.trash-flight svg { width: 17px; height: 17px; flex: none; color: var(--danger); }
.trash-flight span { overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.trash-toggle.receiving { color: var(--accent); background: var(--accent-soft); animation: trash-receive .52s var(--ease); }
@keyframes trash-receive {
  0%, 100% { transform: scale(1); }
  42% { transform: scale(1.07); }
  72% { transform: scale(.97); }
}
.pane-head {
  min-height: 88px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 17px clamp(24px, 4vw, 58px) 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}
.mobile-nav-btn { display: none; }
.pane-title-wrap { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.doc-title {
  width: 100%;
  min-width: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  font-size: clamp(21px, 2vw, 25px);
  font-weight: 630;
  letter-spacing: -.025em;
  line-height: 1.3;
}
.doc-title::placeholder { color: var(--muted); opacity: .8; font-weight: 500; }
.doc-title:disabled { cursor: default; }
.doc-title:focus-visible { outline: none; }
.pane-title-wrap:focus-within .doc-title:not(:disabled) { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 5px; }
.saved {
  min-height: 17px;
  color: var(--muted);
  font-size: 11px;
  opacity: 0;
  transition: opacity .16s var(--ease);
}
.saved.show { opacity: 1; }
.pane-right {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.hint { color: var(--muted); font-size: 13px; }

.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.seg button {
  min-height: 30px;
  padding: 4px 10px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: color .14s var(--ease), background .14s var(--ease), box-shadow .14s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.on {
  color: var(--text);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}
.btn-save, .btn-trash-back, .mini-btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 11px;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: color .14s var(--ease), background .14s var(--ease), border-color .14s var(--ease), transform .14s var(--ease);
}
.btn-save svg, .btn-trash-back svg { width: 15px; height: 15px; flex: none; }
.btn-save:hover, .btn-trash-back:hover, .mini-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn-save:active, .btn-trash-back:active, .mini-btn:active { transform: scale(.97); }
.btn-save.saving { color: var(--accent); opacity: .7; cursor: wait; }
.mini-btn.danger { color: var(--danger); }
.mini-btn.danger:hover { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }

.editor {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
  padding: 14px clamp(24px, 4vw, 58px) calc(26px + var(--safe-bottom));
  background: var(--paper);
}
.editor.editing.split {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.editor:not(.editing) .doc-body,
.editor:not(.editing) .doc-preview { display: none; }
.doc-body {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  max-width: 820px;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  padding: 24px 8px 54px;
  resize: none;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 0;
  outline: none;
  font-size: 16px;
  line-height: 1.82;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: opacity .16s var(--ease);
}
.doc-body:hover { scrollbar-color: var(--line) transparent; }
.doc-body::placeholder { color: var(--muted); opacity: .72; }
.doc-body:disabled { opacity: .68; }
.doc-body:focus-visible { outline: none; }
.editor.editing.split .doc-body {
  max-width: none;
  margin: 0;
  padding: 22px 26px 54px 8px;
  border-right: 1px solid var(--line-soft);
}
.editor.loading .doc-body { cursor: wait; opacity: .45; }
.doc-preview {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  padding: 22px 8px 54px 28px;
  color: var(--text);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.doc-preview:hover { scrollbar-color: var(--line) transparent; }
.doc-count {
  position: absolute;
  z-index: 1;
  right: clamp(24px, 4vw, 58px);
  bottom: 8px;
  padding: 3px 0;
  color: var(--muted);
  background: var(--paper);
  font-size: 11px;
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  color: var(--text);
  text-align: center;
}
.empty-state[hidden] { display: none; }
.empty-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 18px;
}
.empty-mark svg { width: 34px; height: 34px; }
.empty-kicker {
  margin: 22px 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .12em;
}
.empty-state h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 28px);
  font-weight: 590;
  letter-spacing: -.035em;
}
.empty-copy {
  max-width: 360px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.empty-state .hint { color: var(--muted); }
.empty-new { margin-top: 24px; }

.markdown { font-size: 15px; line-height: 1.8; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 {
  margin: 1.35em 0 .55em;
  color: var(--text);
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -.015em;
}
.markdown h1 { font-size: 1.65em; }
.markdown h2 { font-size: 1.38em; }
.markdown h3 { font-size: 1.18em; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 1em; }
.markdown p { margin: .72em 0; }
.markdown a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.markdown a:hover { text-decoration-color: currentColor; }
.markdown ul, .markdown ol { margin: .65em 0; padding-left: 1.55em; }
.markdown li { margin: .28em 0; }
.markdown blockquote {
  margin: 1em 0;
  padding: 2px 0 2px 14px;
  color: var(--muted);
  border-left: 3px solid var(--accent);
}
.markdown code {
  padding: .16em .42em;
  color: var(--text);
  background: var(--side);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: .88em;
}
.markdown pre {
  padding: 14px 16px;
  color: var(--text);
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: auto;
}
.markdown pre code { padding: 0; background: none; border: 0; font-size: 12.8px; }
.markdown hr { margin: 1.6em 0; border: 0; border-top: 1px solid var(--line); }
.markdown img { max-width: 100%; border-radius: var(--radius-sm); }
.markdown del { color: var(--muted); }
.markdown table { width: 100%; border-collapse: collapse; font-size: 13px; }
.markdown th, .markdown td { padding: 7px 10px; border: 1px solid var(--line); text-align: left; }
.markdown th { background: var(--side); font-weight: 650; }
.markdown tbody tr:hover { background: var(--hover); }
.markdown li.task { list-style: none; margin-left: -1.35em; }
.markdown li.task input { margin-right: 7px; accent-color: var(--accent); }
.markdown li.task.done { color: var(--muted); text-decoration: line-through; }

/* Shared overlays and feedback */
.sidebar-backdrop { display: none; }
body.dropping::after {
  position: fixed;
  z-index: 50;
  inset: 12px;
  display: grid;
  place-items: center;
  content: "松开鼠标即可导入 Markdown 文件";
  color: var(--accent);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}
.toast {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  max-width: min(90vw, 520px);
  padding: 10px 16px;
  color: var(--paper);
  background: var(--text);
  border: 1px solid color-mix(in srgb, var(--text) 76%, transparent);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.doc-menu {
  position: fixed;
  z-index: 100;
  min-width: 184px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}
.doc-menu[hidden] { display: none; }
.doc-menu button {
  min-height: 40px;
  padding: 7px 10px;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.doc-menu button:hover, .doc-menu button:focus-visible { background: var(--hover); }
.doc-menu button.danger { color: var(--danger); }

/* Scrollbars */
.doc-list::-webkit-scrollbar, .doc-preview::-webkit-scrollbar, .doc-body::-webkit-scrollbar { width: 8px; }
.doc-list::-webkit-scrollbar-thumb, .doc-preview::-webkit-scrollbar-thumb, .doc-body::-webkit-scrollbar-thumb {
  background: transparent;
  border: 2px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
}
.sidebar:hover .doc-list::-webkit-scrollbar-thumb,
.editor:hover :is(.doc-preview, .doc-body)::-webkit-scrollbar-thumb { background-color: var(--line); }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted) !important; }

/* Authentication */
[data-auth]:not([data-auth="ready"]) body > :not(#authMask) { display: none; }
.auth-mask {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--side) 78%, transparent);
  backdrop-filter: blur(8px);
}
[data-auth="login"] #authMask,
[data-auth="init"] #authMask,
[data-auth="error"] #authMask { display: grid; }
[data-auth="ready"] #authMask { display: none; }
.auth-card {
  width: min(100%, 380px);
  padding: 30px;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.auth-brand { margin-bottom: 22px; text-align: center; }
.auth-brand svg {
  width: 38px;
  height: 38px;
  padding: 8px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
}
.auth-brand h2 { margin: 12px 0 4px; font-size: 19px; font-weight: 650; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-fields { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }
.auth-fields[hidden] { display: none; }
.auth-fields label { color: var(--text); font-size: 12px; font-weight: 600; }
.auth-fields label span { margin-left: 4px; color: var(--muted); font-weight: 400; }
.auth-input {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 13px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.auth-err {
  margin: 12px 0 4px;
  padding: 9px 11px;
  color: #a4342d;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.auth-submit { width: 100%; margin-top: 16px; }
.auth-submit[disabled] { opacity: .58; cursor: wait; }
.auth-tiny {
  display: block;
  margin: 13px auto 0;
  padding: 3px 6px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 12px;
  cursor: pointer;
}
.auth-tiny:hover { color: var(--accent); }
[data-auth]:not([data-auth="ready"]) #logoutBtn { display: none; }

/* Tablet: keep navigation visible, move secondary tools into the footer */
@media (min-width: 720px) and (max-width: 1023px) {
  .sidebar { width: 232px; min-width: 232px; padding-right: 11px; padding-left: 11px; }
  .brand h1 { font-size: 13px; }
  .brand-tools .icon-btn { width: 40px; height: 40px; }
  .brand #importBtn, .brand #exportBtn { display: none; }
  .mobile-tools { display: flex; }
  .mobile-tools .icon-btn { width: 40px; height: 40px; }
  .side-foot > #backupBtn { width: 40px; height: 40px; }
  .side-foot { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px; }
  .trash-toggle { grid-column: 1 / -1; padding-right: 5px; padding-left: 5px; gap: 5px; }
  .trash-toggle span { white-space: nowrap; }
  .trash-toggle em { min-width: 19px; padding-right: 4px; padding-left: 4px; }
  .mobile-tools { grid-column: 1; justify-self: start; }
  #backupBtn { grid-column: 2; justify-self: end; }
  .pane-head { gap: 10px; padding-right: 22px; padding-left: 28px; }
  .editor { padding-right: 28px; padding-left: 28px; }
  .editor.editing.split .doc-body { padding-right: 17px; }
  .doc-preview { padding-left: 18px; }
}

/* Stack the preview before the columns become too narrow */
@media (min-width: 720px) and (max-width: 900px) {
  .editor.editing.split {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(220px, 1fr) minmax(180px, .85fr);
  }
  .editor.editing.split .doc-body {
    padding-right: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }
  .editor.editing.split .doc-preview { grid-column: 1; grid-row: 2; padding: 18px 8px 44px; }
}

/* Mobile: full writing surface plus an accessible navigation drawer */
@media (max-width: 719px) {
  body { display: block; }
  .sidebar {
    position: fixed;
    z-index: 82;
    inset: 0 auto 0 0;
    width: min(88vw, 328px);
    min-width: 0;
    padding: calc(14px + var(--safe-top)) 14px calc(12px + var(--safe-bottom) + var(--safe-left));
    box-shadow: var(--shadow-md);
    transform: translateX(-105%);
    transition: transform .22s var(--ease), background .18s var(--ease);
  }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    z-index: 80;
    inset: 0;
    display: none;
    background: rgba(23, 24, 27, .36);
    backdrop-filter: blur(2px);
  }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .main { width: 100%; height: 100%; }
  .pane-head {
    min-height: 82px;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 6px 10px;
    padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  }
  .mobile-nav-btn {
    width: 40px;
    height: 40px;
    display: grid;
    grid-column: 1;
    grid-row: 1;
    color: var(--text);
    background: var(--paper);
    border-color: var(--line);
  }
  .pane-title-wrap { grid-column: 2; grid-row: 1; }
  .doc-title { font-size: 20px; }
  .saved { min-height: 14px; font-size: 10px; }
  .pane-right {
    grid-column: 1 / -1;
    grid-row: 2;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .pane-right::-webkit-scrollbar { display: none; }
  .hint { display: none; }
  .editor {
    padding: 10px calc(16px + var(--safe-right)) calc(26px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }
  .editor.editing.split {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(220px, 1fr) minmax(180px, .72fr);
  }
  .editor.editing.split .doc-body {
    padding: 12px 2px 30px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }
  .doc-body { padding: 14px 2px 40px; font-size: 16px; line-height: 1.75; }
  .doc-preview { grid-column: 1; grid-row: 2; padding: 16px 2px 42px; font-size: 14px; }
  .doc-count { right: calc(16px + var(--safe-right)); bottom: calc(7px + var(--safe-bottom)); }
  .empty-state { padding: 24px 18px; }
  .empty-mark { width: 52px; height: 52px; border-radius: 16px; }
  .empty-kicker { margin-top: 18px; }
  .empty-state h2 { font-size: 24px; }
  .empty-copy { max-width: 300px; font-size: 13px; }
  .brand #importBtn, .brand #exportBtn { display: none; }
  .brand-tools .icon-btn { width: 40px; height: 40px; }
  .side-top { padding-bottom: 12px; }
  .doc-item .doc-act { display: none !important; }
  .doc-menu-btn {
    width: 40px;
    height: 40px;
    display: grid;
    flex: none;
    place-items: center;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
  }
  .doc-menu-btn:hover, .doc-menu-btn[aria-expanded="true"] { color: var(--text); background: var(--hover); border-color: var(--line); }
  .side-foot { gap: 5px; }
  .mobile-tools { display: flex; gap: 4px; }
  .mobile-tools .icon-btn { width: 40px; height: 40px; }
  .side-foot > #backupBtn { width: 40px; height: 40px; }
  .trash-page { width: 100%; height: 100vh; height: 100dvh; min-height: 0; }
  .trash-head {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
    padding: calc(14px + var(--safe-top)) calc(16px + var(--safe-right)) 15px calc(16px + var(--safe-left));
  }
  .trash-head-title { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 9px 12px; }
  .trash-head-title .btn-trash-back { grid-column: 1 / -1; justify-self: start; }
  .trash-hero-icon { width: 42px; height: 42px; border-radius: 13px; }
  .trash-heading-copy { align-self: center; }
  .trash-heading-copy h1 { font-size: 22px; }
  .trash-heading-copy > p:last-child { max-width: 42ch; font-size: 11px; }
  .trash-head-actions { width: 100%; justify-content: space-between; gap: 8px; }
  .trash-head-actions .mini-btn,
  .trash-head-title .btn-trash-back { min-height: 40px; }
  .trash-page-body {
    width: 100%;
    padding: 20px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }
  .trash-section-title { align-items: flex-start; margin-bottom: 12px; }
  .trash-section-title h2 { font-size: 14px; }
  .trash-section-title p { max-width: 32ch; font-size: 11px; }
  .trash-list .doc-item {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
    min-height: 0;
    padding: 13px;
  }
  .trash-list .doc-item .d { grid-column: 1; min-width: 0; text-align: left; }
  .trash-list .doc-item .doc-act { grid-column: 1; width: 100%; gap: 7px; padding-top: 5px; }
  .trash-list .doc-act button { flex: 1; min-width: 116px; min-height: 40px; }
  .trash-empty { min-height: min(42vh, 300px); }
  .toast { bottom: calc(16px + var(--safe-bottom)); }
  .auth-card { padding: 25px 22px; }
}

/* Small phones */
@media (max-width: 380px) {
  .pane-head { padding-right: calc(12px + var(--safe-right)); padding-left: calc(12px + var(--safe-left)); }
  .pane-right { gap: 4px; }
  .seg button { padding-right: 8px; padding-left: 8px; }
  .btn-save, .btn-trash-back, .mini-btn { padding-right: 8px; padding-left: 8px; }
  .editor { padding-right: calc(12px + var(--safe-right)); padding-left: calc(12px + var(--safe-left)); }
}

/* Motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

