:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --subtle: #f0f2f5;
  --text: #1c2535;
  --muted: #637087;
  --border: #dde2e9;
  --accent: #385bc4;
  --accent-soft: #eaf0ff;
  --danger: #b53440;
  --warning-bg: #fff4e3;
  --warning-text: #845215;
  --shadow: 0 16px 48px #17233b16;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141923; --surface: #1c2330; --subtle: #242d3c; --text: #e5ebf5; --muted: #a2b0c5;
    --border: #344156; --accent: #92acff; --accent-soft: #2b3859; --danger: #ff9ba4; --warning-bg: #382d1e; --warning-text: #f6cd89;
    --shadow: 0 16px 48px #0003;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141923; --surface: #1c2330; --subtle: #242d3c; --text: #e5ebf5; --muted: #a2b0c5;
  --border: #344156; --accent: #92acff; --accent-soft: #2b3859; --danger: #ff9ba4; --warning-bg: #382d1e; --warning-text: #f6cd89;
  --shadow: 0 16px 48px #0003;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { padding: 7px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); line-height: 1.5; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--subtle); border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(.92); background: var(--accent); }
button.danger { color: var(--danger); }
input, select { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 24px; line-height: 1.4; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.eyebrow { font-size: 11px; letter-spacing: .18em; font-weight: 700; color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(100%, 400px); padding: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.login-card label { display: block; margin: 14px 0 6px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin: 22px 0 16px; }
.login-card > p:last-child { margin: 0; }
.notice { overflow-wrap: anywhere; color: var(--danger); }
.app { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.app-header { display: flex; align-items: center; gap: 6px; height: 46px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--surface); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 5px; flex-shrink: 0; border: 0; border-radius: 5px; background: transparent; }
.icon-button svg, .footer-controls svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.action-menu { position: relative; flex-shrink: 0; }
/* Native details menus stall Chromium's large textarea replacement paste. */
.action-menu > .menu-toggle[aria-expanded="true"] { background: var(--subtle); color: var(--accent); }
.menu-panel { position: absolute; top: calc(100% + 5px); right: 0; z-index: 10; display: flex; flex-direction: column; gap: 5px; width: 220px; max-width: calc(100vw - 20px); padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.menu-panel button { display: flex; align-items: center; justify-content: space-between; border: 0; text-align: left; }
.menu-panel label, .menu-panel kbd { font: inherit; font-size: 12px; color: var(--muted); }
.menu-meta { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 0; margin-top: 3px; border-top: 1px solid var(--border); }
.workspace { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.workspace[data-sidebar="true"] { grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { display: none; flex-direction: column; min-height: 0; padding: 8px; background: var(--surface); border-right: 1px solid var(--border); }
.workspace[data-sidebar="true"] .sidebar { display: flex; }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 4px; margin-bottom: 5px; }
.sidebar-heading h2 { font-size: 12px; font-weight: 500; color: var(--muted); margin: 0; }
#search { flex-shrink: 0; width: 100%; height: 32px; margin-bottom: 8px; padding: 5px 10px; font-size: 13px; background: var(--surface); }
#list-status { margin: 6px 4px; overflow-wrap: anywhere; }
#list-status:empty { display: none; }
#refresh-list { margin-bottom: 8px; }
.folder-toolbar { display: flex; margin: 0 0 5px; }
.folder-toolbar button { width: 100%; text-align: left; }
#folder-tree { flex: 0 1 auto; max-height: 42%; overflow-y: auto; min-height: 36px; border-bottom: 1px solid var(--border); padding-bottom: 5px; margin-bottom: 5px; }
.folder-select { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border: 0; background: transparent; text-align: left; padding: 5px 8px; }
.folder-expand { width: 20px; flex: 0 0 20px; border: 0; padding: 2px; background: transparent; color: var(--muted); font-size: 11px; }
.folder-row > .folder-select { padding-left: 4px; }
.folder-select[aria-current="true"] { background: var(--subtle); color: var(--accent); }
.folder-row { display: flex; align-items: center; gap: 2px; min-width: 0; padding-left: 8px; }
.folder-actions { display: flex; gap: 1px; }
.folder-actions button { border: 0; padding: 3px 4px; font-size: 10px; }
.folder-children { margin-left: 7px; border-left: 1px solid var(--border); }
#note-list { flex: 1; overflow-y: auto; min-height: 0; }
.note-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; margin: 2px 0; padding: 8px 10px; border-radius: 5px; }
.note-item::before { content: ''; flex-shrink: 0; width: 9px; height: 12px; border: 1px solid var(--muted); border-radius: 2px; }
.note-item[aria-current="true"] { background: var(--subtle); }
.note-item-title { display: block; min-width: 0; font-size: 13px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.main { min-height: 0; min-width: 0; background: var(--surface); }
.empty-state { height: 100%; display: grid; place-items: center; text-align: center; padding: 24px; }
.empty-state h2 { font-size: 22px; }
.note-workspace { height: 100%; min-height: 0; display: flex; flex-direction: column; }
#note-title { flex: 1; width: 0; min-width: 0; font-size: 16px; font-weight: 600; line-height: 1.5; border: 0; border-radius: 0; padding: 2px 0; background: transparent; text-overflow: ellipsis; }
#save-status[data-state="error"] { color: var(--danger); }
#save-status[data-state="saving"], #save-status[data-state="dirty"] { color: var(--accent); }
.editor-panes { display: grid; grid-template-columns: minmax(0, 1fr); flex: 1; min-height: 0; overflow: hidden; }
.edit-pane, .preview-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#editor { flex: 1; min-height: 0; width: 100%; resize: none; padding: 12px 14px; border: 0; outline: none; background: transparent; font: 14px/1.85 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; tab-size: 2; }
#rich-editor { flex: 1; min-height: 0; width: 100%; border: 0; border-radius: 0; background: var(--surface); color: var(--text); }
#rich-editor .vditor-content, #rich-editor .vditor-ir { min-height: 0; }
#rich-editor .vditor-ir { flex: 1; overflow: auto; }
#rich-editor .vditor-ir .vditor-reset { min-height: 100%; padding: 12px 14px !important; color: var(--text); font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
#rich-editor .vditor-toolbar { display: none; }
#rich-editor .vditor-reset pre, #rich-editor .vditor-reset code { background: var(--subtle); color: var(--text); }
#rich-editor .vditor-reset pre { max-width: 100%; overflow-x: auto; }
#rich-editor .vditor-reset blockquote { color: var(--muted); border-color: var(--border); }
#rich-editor .vditor-reset hr { border-color: var(--border); }
#rich-editor[aria-busy="true"]::before { content: '正在加载即时渲染… 可手动切换纯文本'; display: block; padding: 12px 14px; color: var(--muted); font-size: 12px; }
.markdown { flex: 1; overflow: auto; padding: 12px 14px; font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; min-height: 0; }
.markdown > :first-child { margin-top: 0; }
.markdown h1 { font-size: 26px; }
.markdown h2 { font-size: 21px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 18px; }
.markdown a { color: var(--accent); }
.markdown pre { overflow-x: auto; padding: 14px; border-radius: 7px; background: var(--subtle); max-width: 100%; }
.markdown code { background: var(--subtle); padding: 2px 4px; border-radius: 3px; font-size: .9em; }
.markdown pre code { padding: 0; background: transparent; white-space: pre; overflow-wrap: normal; }
.markdown blockquote { margin-left: 0; padding-left: 16px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown img { max-width: 100%; height: auto; }
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin-bottom: 16px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.markdown .task-checkbox { margin-right: 7px; accent-color: var(--accent); }
.markdown .task-item { list-style: none; }
.markdown li > p { margin-bottom: 8px; }
.main[data-view="edit"] .preview-pane, .main[data-view="preview"] .edit-pane { display: none; }
.editor-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; height: 38px; flex-shrink: 0; border-top: 1px solid var(--border); padding: 4px 10px 4px 14px; background: var(--surface); }
#save-status { min-width: 0; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.footer-controls { display: flex; align-items: center; flex-shrink: 0; gap: 4px; }
.footer-controls button { display: inline-flex; align-items: center; gap: 5px; border: 0; font-size: 12px; padding: 4px 8px; }
#toggle-preview[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.problem { flex-shrink: 0; margin: 12px 20px 0; padding: 12px 16px; background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--border); border-radius: 8px; overflow-wrap: anywhere; max-height: 40dvh; overflow: auto; }
.problem h2 { font-size: 14px; margin-bottom: 4px; }
.problem p { font-size: 13px; margin-bottom: 8px; }
.problem-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.problem-actions button { white-space: normal; }
.remote-notice { background: var(--warning-bg); color: var(--warning-text); padding: 8px 28px; margin: 0; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: calc(100vw - 24px); padding: 10px 18px; border-radius: 8px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); overflow-wrap: anywhere; }
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: min(440px, calc(100vw - 32px)); padding: 24px; box-shadow: var(--shadow); }
dialog::backdrop { background: #0006; }
dialog p { overflow-wrap: anywhere; }
#folder-dialog form > label { display: block; margin: 12px 0 4px; }
#folder-dialog input, #folder-dialog select { display: block; width: 100%; margin-bottom: 14px; }
#folder-dialog input:read-only { background: var(--subtle); cursor: default; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 700px) {
  .app { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
  .app-header { display: grid; grid-template-columns: 44px 44px minmax(44px, 1fr) 44px 44px; gap: 4px; height: auto; padding: 4px 12px 8px; }
  .app-header > .icon-button, .app-header > .action-menu { grid-row: 1; }
  #note-menu { justify-self: end; }
  .icon-button { width: 44px; height: 44px; padding: 12px; border-radius: 8px; }
  #note-title { grid-row: 2; grid-column: 1 / -1; width: 100%; min-height: 40px; padding: 4px 8px; border-radius: 6px; background: var(--subtle); font-size: 17px; }
  input, select, textarea { font-size: 16px; }
  button, input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
  .menu-panel { position: fixed; top: calc(env(safe-area-inset-top) + 56px); right: calc(env(safe-area-inset-right) + 12px); left: calc(env(safe-area-inset-left) + 12px); width: auto; max-width: none; max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 72px); overflow-y: auto; padding: 12px; border-radius: 12px; }
  .menu-panel button { white-space: normal; gap: 8px; }
  .menu-panel label { padding: 4px 10px 0; }
  .workspace[data-sidebar="true"] { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; padding: 8px 12px max(12px, env(safe-area-inset-bottom)); }
  .sidebar-heading { padding: 0; margin-bottom: 8px; }
  .sidebar-heading h2 { font-size: 16px; color: var(--text); }
  #search { height: 44px; padding: 8px 12px; font-size: 16px; }
  .folder-toolbar { margin-bottom: 8px; }
  .folder-toolbar button { font-size: 14px; }
  #folder-tree, #note-list, .markdown, #rich-editor .vditor-ir { overscroll-behavior: contain; }
  .folder-select { font-size: 14px; padding: 10px 8px; }
  .folder-expand { width: 44px; flex: 0 0 44px; font-size: 13px; }
  .folder-row { flex-wrap: wrap; gap: 0; padding-left: 0; }
  .folder-actions { flex-basis: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding-left: 44px; margin-bottom: 4px; }
  .folder-actions button { min-width: 44px; padding: 6px 4px; font-size: 12px; }
  .note-item { min-height: 48px; padding: 10px 12px; border-radius: 8px; }
  .note-item-title { font-size: 15px; }
  .workspace[data-sidebar="true"] .main { display: none; }
  #editor { padding: 16px; font-size: 16px; line-height: 1.8; }
  #rich-editor .vditor-ir .vditor-reset { padding: 16px !important; font-size: 16px; line-height: 1.8; }
  #rich-editor .vditor-reset table { display: block; max-width: 100%; overflow-x: auto; }
  #rich-editor .vditor-reset img { max-width: 100%; height: auto; }
  .markdown { padding: 16px; font-size: 16px; line-height: 1.8; }
  .markdown h1 { font-size: 24px; }
  .editor-footer { height: auto; flex-wrap: wrap; gap: 2px; padding: 6px 12px max(6px, env(safe-area-inset-bottom)); }
  #save-status { flex: 1 0 100%; font-size: 12px; line-height: 20px; }
  .footer-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 4px; }
  .footer-controls button { justify-content: center; min-width: 0; font-size: 14px; padding: 8px 4px; }
  .problem { margin: 8px 12px 0; padding: 10px 12px; }
  .remote-notice { padding: 8px 16px; }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 88px); pointer-events: none; }
  .login-screen { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .login-card { padding: 24px; }
  dialog { width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px); overflow-y: auto; padding: 20px; }
}
@media (max-width: 700px) and (max-height: 500px) {
  .sidebar { overflow-y: auto; overscroll-behavior: contain; }
  .sidebar-heading, .folder-toolbar { flex-shrink: 0; }
  #folder-tree { flex: none; max-height: none; overflow: visible; }
  #note-list { flex: none; overflow: visible; }
}
