/* jotbox 样式：Joplin 风格三栏布局，浅色主题 */

:root {
  --bg: #f7f7f7;
  --pane-bg: #ffffff;
  --sidebar-bg: #f0f0f0;
  --border: #d9d9d9;
  --text: #222222;
  --muted: #777777;
  --accent: #2d6cdf;
  --accent-hover: #1f56c4;
  --danger: #c0392b;
  --hover: #e8eefb;
  --selected: #dbe7fd;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---- 通用按钮 ---- */
.btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #e5b4ae; }
.btn.danger:hover { background: #fdecea; }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn.icon-btn { padding: 6px 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---- 锁屏 ---- */
.lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.lock-card {
  width: 100%;
  max-width: 420px;
  background: var(--pane-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}
.lock-title { margin: 0 0 4px; font-size: 26px; text-align: center; }
.lock-sub { margin: 0 0 20px; text-align: center; color: var(--muted); }
.lock-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.lock-form input,
.dialog-body input[type="text"],
.dialog-body input[type="password"],
.dialog-body input[type="url"],
.dialog-body select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.lock-hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.warning {
  background: #fff7e6;
  border: 1px solid #f5d98a;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
}
.form-error { color: var(--danger); font-size: 13px; }
.lock-form .btn.primary { width: 100%; padding: 10px; margin-top: 4px; }

/* ---- 顶栏 ---- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--pane-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-title { font-weight: 600; font-size: 16px; }
.topbar-spacer { flex: 1; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 4px;
  z-index: 50;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 4px;
}
.menu button:hover { background: var(--hover); }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---- 三栏 ---- */
.panes { display: flex; flex: 1; min-height: 0; }
.pane { min-height: 0; overflow-y: auto; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
}
.sidebar.collapsed { display: none; }
.sidebar-section { margin-bottom: 18px; }
.sidebar-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 6px 6px;
}
.sidebar-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  margin-top: 2px;
  border: none;
  background: none;
  border-radius: var(--radius);
}
.sidebar-link:hover, .sidebar-link.active { background: var(--selected); }

.tree, .tag-list, .note-list, .attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tree li { margin: 1px 0; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px;
  border-radius: var(--radius);
  cursor: pointer;
}
.tree-row:hover { background: var(--hover); }
.tree-row.selected { background: var(--selected); }
.tree-row .tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .tree-actions { display: none; gap: 2px; }
.tree-row:hover .tree-actions { display: flex; }
.tree-actions button {
  border: none;
  background: none;
  padding: 1px 4px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 3px;
}
.tree-actions button:hover { background: #fff; color: var(--text); }
.tree-children { padding-left: 16px; }

.tag-list li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  border-radius: var(--radius);
  cursor: pointer;
}
.tag-list li:hover { background: var(--hover); }
.tag-list li.selected { background: var(--selected); }
.tag-list .tag-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-list .tag-actions { display: none; }
.tag-list li:hover .tag-actions { display: block; }
.tag-actions button {
  border: none; background: none; padding: 1px 4px;
  font-size: 12px; color: var(--muted);
}
.tag-actions button:hover { color: var(--danger); }

/* ---- 笔记列表 ---- */
.note-list-pane {
  width: 280px;
  flex-shrink: 0;
  background: var(--pane-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.search-input {
  margin: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.note-list { overflow-y: auto; flex: 1; }
.note-list li {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.note-list li:hover { background: var(--hover); }
.note-list li.selected { background: var(--selected); }
.note-item-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.note-item-title.todo-done { text-decoration: line-through; color: var(--muted); }
.note-item-snippet {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-item-date { font-size: 11px; color: #aaa; margin-top: 3px; }
.note-list .empty-hint { padding: 16px; color: var(--muted); text-align: center; cursor: default; }
.note-list .empty-hint:hover { background: none; }

/* ---- 编辑器 ---- */
.editor-pane { flex: 1; display: flex; flex-direction: column; background: var(--pane-bg); }
.editor-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.note-title {
  flex: 1;
  min-width: 160px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  outline: none;
  padding: 4px 0;
}
.todo-toggle, .todo-done { font-size: 13px; color: var(--muted); white-space: nowrap; }
.editor-spacer { flex: 1; }
.save-status { font-size: 12px; color: var(--muted); min-width: 60px; text-align: right; }
.view-toggle { display: flex; gap: 0; }
.view-toggle .btn { border-radius: 0; }
.view-toggle .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.view-toggle .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.view-toggle .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.editor-body { flex: 1; display: flex; min-height: 0; }
.note-body {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
}
.note-preview {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  border-left: 1px solid var(--border);
}
.note-body.hidden, .note-preview.hidden { display: none; }
.editor-body.split .note-body { width: 50%; flex: none; border-right: 1px solid var(--border); }
.editor-body.split .note-preview { width: 50%; flex: none; border-left: none; }

.editor-tags, .editor-attachments {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}
.editor-tags label { font-size: 13px; color: var(--muted); }
.editor-tags input {
  margin-top: 4px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--selected);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
}
.tag-chip button { border: none; background: none; color: var(--muted); padding: 0 2px; }
.tag-chip button:hover { color: var(--danger); }

.attachment-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
}
.attachment-list .att-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-list .att-size { color: var(--muted); font-size: 12px; }
.attachment-list button { border: none; background: none; color: var(--accent); padding: 2px 4px; }
.attachment-list button:hover { text-decoration: underline; }
.attachment-list button.att-del { color: var(--danger); }

/* ---- 预览 Markdown ---- */
.markdown-body { line-height: 1.75; word-break: break-word; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: 1em 0 0.5em;
  line-height: 1.4;
}
.markdown-body h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.35em; border-bottom: 1px solid #eee; padding-bottom: 0.25em; }
.markdown-body p { margin: 0.6em 0; }
.markdown-body pre {
  background: #f5f5f5;
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
}
.markdown-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 3px;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  margin: 0.8em 0;
  padding: 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.markdown-body table { border-collapse: collapse; margin: 0.8em 0; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
}
.markdown-body th { background: #f5f5f5; }
.markdown-body img { max-width: 100%; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* ---- 回收站 ---- */
.trash-view { flex: 1; overflow-y: auto; padding: 16px 20px; }
.trash-view h2 { margin: 0 0 4px; }
.trash-item-actions { display: flex; gap: 8px; margin-top: 6px; }

/* ---- 对话框 ---- */
.dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  width: min(560px, 92vw);
  max-height: 88vh;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog.small-dialog { width: min(420px, 92vw); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-body { padding: 16px 18px; overflow-y: auto; }
.dialog-body section { margin-bottom: 22px; }
.dialog-body section h3 { margin: 0 0 8px; font-size: 15px; }
.dialog-body label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.dialog-body label.inline-check { display: flex; align-items: center; gap: 6px; }
.dialog-body label.inline-check input { width: auto; margin: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---- Agent Token 列表 ---- */
.agent-token-list { list-style: none; margin: 0 0 10px; padding: 0; }
.agent-token-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 13px;
}
.agent-token-list .att-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.agent-token-list .att-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.agent-token-list button { border: none; background: none; color: var(--danger); padding: 2px 4px; }
.agent-token-list button:hover { text-decoration: underline; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 100;
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* ---- 移动端 ---- */
@media (max-width: 900px) {
  .sidebar { width: 180px; }
  .note-list-pane { width: 220px; }
}
@media (max-width: 640px) {
  .panes { flex-direction: column; }
  .sidebar, .note-list-pane {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 32vh;
  }
  .editor-body.split { flex-direction: column; }
  .editor-body.split .note-body,
  .editor-body.split .note-preview { width: 100%; flex: 1; }
  .topbar { flex-wrap: wrap; }
}

/* ---- 帮助页（help.html）样式：从 help.html 的内联 <style> 移入此处，
   因为 worker 的 CSP 是 style-src 'self'，内联样式会被浏览器拦截。
   全部以 body.help-page 为作用域，避免影响主应用。 ---- */
body.help-page { font-family: -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; line-height: 1.7; color: #1f2937; background: #f8fafc; margin: 0; padding: 0; }
body.help-page main { max-width: 720px; margin: 0 auto; padding: 24px 20px 64px; background: #fff; }
body.help-page a { color: #2563eb; }
body.help-page h1 { font-size: 1.5rem; border-bottom: 1px solid #e5e7eb; padding-bottom: 12px; }
body.help-page h2 { font-size: 1.2rem; margin-top: 36px; border-left: 4px solid #2563eb; padding-left: 10px; }
body.help-page h3 { font-size: 1.05rem; margin-top: 24px; }
body.help-page code { background: #f1f5f9; padding: 1px 6px; border-radius: 4px; font-size: 0.92em; word-break: break-all; }
body.help-page pre { background: #0f172a; color: #e2e8f0; padding: 12px 16px; border-radius: 8px; overflow-x: auto; font-size: 0.9em; }
body.help-page pre code { background: none; color: inherit; padding: 0; }
body.help-page .warn { background: #fef3c7; border: 1px solid #f59e0b; border-radius: 8px; padding: 12px 16px; margin: 16px 0; }
body.help-page .note { background: #eff6ff; border: 1px solid #93c5fd; border-radius: 8px; padding: 12px 16px; margin: 16px 0; }
body.help-page .back { display: inline-block; margin-bottom: 8px; }
body.help-page ol li, body.help-page ul li { margin: 6px 0; }
body.help-page table { border-collapse: collapse; width: 100%; margin: 12px 0; }
body.help-page th, body.help-page td { border: 1px solid #e5e7eb; padding: 8px 10px; text-align: left; font-size: 0.95em; }
body.help-page th { background: #f8fafc; }
