:root {
  --bg: #FAFAF8;
  --sidebar-bg: #1C1C1E;
  --sidebar-text: #AEAEB2;
  --sidebar-hover: #2C2C2E;
  --sidebar-border: #3A3A3C;
  --card-bg: #FFFFFF;
  --accent: #E8533F;
  --accent-hover: #D04430;
  --accent-light: #FCEDEA;
  --text: #2C2C2C;
  --text-muted: #888;
  --text-light: #AAA;
  --border: #E0DCD5;
  --border-light: #EDEAE4;
  --code-bg: #F5F2ED;
  --success: #4CAF50;
  --warning: #FF9800;
  --error: #F44336;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
  --sidebar-w: 340px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== Token Gate ===== */
.token-gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #F3F0EB 0%, #FAFAF8 100%);
}
.token-card {
  text-align: center;
  background: var(--card-bg);
  padding: 48px 40px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 380px; max-width: 90vw;
}
.token-logo { font-size: 48px; margin-bottom: 8px; }
.token-card h1 { font-size: 24px; margin-bottom: 8px; }
.token-card p { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.token-card input {
  width: 100%; padding: 12px 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 15px; margin-bottom: 16px;
  font-family: var(--font);
}
.token-card input:focus { outline: none; border-color: var(--accent); }
.token-error { color: var(--error); font-size: 13px; margin-top: 8px; }

/* ===== Buttons ===== */
.btn-accent {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 20px; border-radius: var(--radius-sm);
  font-size: 14px; cursor: pointer; font-family: var(--font);
  transition: background 0.15s;
}
.btn-accent:hover { background: var(--accent-hover); }
.btn-accent:active { transform: scale(0.97); }
.btn-accent:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-cancel {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 20px; border-radius: var(--radius-sm);
  font-size: 14px; cursor: pointer; font-family: var(--font);
}
.btn-cancel:hover { background: var(--border-light); }
.icon-btn {
  background: none; border: none; font-size: 20px;
  cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--border-light); }

/* ===== App Layout ===== */
.app { display: flex; flex-direction: column; height: 100vh; }
.body { display: flex; flex: 1; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateZ(0);
}
.sidebar-toolbar {
  display: flex; gap: 6px; padding: 10px 12px;
  align-items: center;
}
.sidebar-toolbar input {
  flex: 1; min-width: 0; padding: 7px 10px;
  border: 1px solid var(--sidebar-border); border-radius: var(--radius);
  font-size: 13px; background: #2C2C2E; color: var(--sidebar-text); font-family: var(--font);
}
.sidebar-toolbar input::placeholder { color: #6C6C6E; }
.sidebar-toolbar input:focus { outline: none; border-color: var(--accent); }
.sidebar-toolbar .btn-icon-edit { padding: 6px 8px; font-size: 16px; opacity: 0.6; color: var(--sidebar-text); }
.sidebar-toolbar .btn-icon-edit:hover { opacity: 1; }
.note-list {
  flex: 1; overflow-y: auto;
  padding: 0 8px 8px;
}
.list-loading, .list-empty {
  text-align: center; color: var(--sidebar-text);
  padding: 32px 0; font-size: 14px;
}

/* ===== Tree View ===== */
.tree-header {
  padding: 6px 12px 8px; font-size: 13px; font-weight: 600;
  color: var(--sidebar-text);
  border-bottom: 1px solid var(--sidebar-border); margin-bottom: 4px;
  display: flex; align-items: center; justify-content: space-between;
}
.tree-actions { display: flex; gap: 4px; }
.tree-action-btn {
  background: none; border: none; font-size: 12px; cursor: pointer;
  color: #6C6C6E; padding: 2px 6px; border-radius: 3px;
}
.tree-action-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.tree-pin { font-size: 12px; flex-shrink: 0; }
.tree-folder {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 12px; cursor: pointer; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; margin: 1px 0;
  color: var(--sidebar-text);
  transition: background 0.1s;
}
.tree-folder:hover { background: var(--sidebar-hover); }
.tree-toggle {
  display: inline-block; width: 14px; font-size: 11px;
  color: #6C6C6E; text-align: center;
}
.tree-folder-name { flex: 1; }
.tree-count {
  font-size: 11px; color: #6C6C6E;
  background: var(--sidebar-hover); padding: 0 6px; border-radius: 8px;
}
.tree-folder-add {
  opacity: 0; font-size: 14px; cursor: pointer; color: var(--accent);
  padding: 0 4px; flex-shrink: 0; transition: opacity 0.15s;
}
.tree-folder:hover .tree-folder-add { opacity: 0.7; }
.tree-folder-add:hover { opacity: 1 !important; }
.tree-note {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px; cursor: pointer; border-radius: var(--radius-sm);
  font-size: 14px; margin: 1px 0;
  color: var(--sidebar-text);
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.tree-note:hover { background: var(--sidebar-hover); }
.tree-note.active {
  background: rgba(232,83,63,0.2);
  border-color: var(--accent);
  color: #FFF;
}
.tree-note-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-note-date { font-size: 11px; color: #6C6C6E; flex-shrink: 0; }
.tree-note-tags { display: flex; gap: 3px; flex-shrink: 0; }
.tree-note-tag {
  font-size: 11px; background: var(--sidebar-hover);
  padding: 0 4px; border-radius: 3px; color: #6C6C6E;
}

.load-more { text-align: center; padding: 8px; }
.load-more button {
  background: none; border: 1px solid var(--sidebar-border);
  padding: 6px 16px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-family: var(--font);
  color: var(--sidebar-text);
}
.load-more button:hover { background: var(--sidebar-hover); }

/* ===== Main Panel ===== */
.main-panel {
  flex: 1; overflow-y: auto;
  background: var(--bg);
}
.note-view { max-width: 780px; margin: 0 auto; padding: 32px 40px 80px; }

.empty-state {
  text-align: center; padding: 120px 20px;
  color: var(--text-light);
}
.empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }

.note-header { margin-bottom: 24px; border-bottom: 1px solid var(--border-light); padding-bottom: 16px; }
.note-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.note-title { font-size: 26px; font-weight: 700; margin-bottom: 8px; line-height: 1.3; flex: 1; }
.note-actions { flex-shrink: 0; padding-top: 4px; }
.btn-icon-edit {
  background: none; border: none; font-size: 18px; cursor: pointer;
  padding: 4px 8px; border-radius: var(--radius-sm); opacity: 0.5;
}
.btn-icon-edit:hover { opacity: 1; background: var(--border-light); }
.note-meta {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  font-size: 13px; color: var(--text-muted);
}
.note-meta-tag {
  background: var(--accent-light); color: var(--accent);
  padding: 2px 8px; border-radius: 3px; font-size: 12px;
}
.note-meta-sep { color: var(--border); }

.note-content { font-size: 15px; line-height: 1.75; }
.note-content h1 { font-size: 22px; margin: 24px 0 12px; }
.note-content h2 { font-size: 19px; margin: 20px 0 10px; }
.note-content h3 { font-size: 16px; margin: 16px 0 8px; }
.note-content p { margin-bottom: 12px; }
.note-content ul, .note-content ol { margin: 8px 0 12px 24px; }
.note-content li { margin-bottom: 4px; }
.note-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 16px; margin: 12px 0;
  color: var(--text-muted); background: var(--border-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.note-content code {
  background: var(--code-bg); padding: 2px 6px;
  border-radius: 3px; font-family: var(--mono); font-size: 13px;
}
.note-content pre {
  background: var(--code-bg); padding: 12px 16px;
  border-radius: var(--radius-sm); overflow-x: auto;
  margin: 12px 0; font-size: 13px;
}
.note-content pre code { background: none; padding: 0; }
.note-content a { color: var(--accent); text-decoration: none; }
.note-content a:hover { text-decoration: underline; }
.note-content img { max-width: 100%; border-radius: var(--radius-sm); margin: 8px 0; }
.note-content table {
  border-collapse: collapse; margin: 12px 0; width: 100%;
}
.note-content th, .note-content td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
.note-content th { background: var(--sidebar-bg); font-weight: 600; }
.note-content input[type="checkbox"] { margin-right: 6px; }
.note-content hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ===== Note Outline ===== */
.note-outline {
  margin-bottom: 20px; padding: 12px 16px;
  background: var(--sidebar-bg); border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}
.note-outline-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text-muted); }
.note-outline-item {
  font-size: 13px; padding: 2px 0; cursor: pointer;
  color: var(--accent); display: block;
}
.note-outline-item:hover { text-decoration: underline; }
.note-outline-item.lvl-2 { padding-left: 16px; }
.note-outline-item.lvl-3 { padding-left: 32px; }

/* ===== Footer ===== */
.footer {
  display: flex; justify-content: space-between;
  padding: 6px 20px; font-size: 12px; color: var(--text-light);
  background: var(--sidebar-bg); border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.3);
}
.modal-content {
  position: relative; background: var(--card-bg);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 600px; max-width: 90vw; max-height: 85vh;
  display: flex; flex-direction: column;
}
.modal-content.modal-sm { width: 400px; }
.modal-content.modal-lg { width: 800px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
}
.modal-header h2 { font-size: 18px; }
.modal-close {
  background: none; border: none; font-size: 24px;
  cursor: pointer; color: var(--text-muted); line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border-light);
}
.modal-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

.input-full {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: var(--font);
  margin-bottom: 12px;
}
.input-full:focus { outline: none; border-color: var(--accent); }
.textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
.code-font { font-family: var(--mono); font-size: 13px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--text-muted); }
.checkbox-group { display: flex; gap: 20px; margin-top: 8px; }
.checkbox { font-size: 14px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.checkbox input { margin: 0; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 10px 24px; border-radius: var(--radius);
  font-size: 14px; z-index: 2000;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Loading Spinner ===== */
.loading-dots::after {
  content: ''; display: inline-block;
  width: 16px; text-align: left;
  animation: dots 1.4s steps(4) infinite;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
  100% { content: ''; }
}

/* ===== Scrollbar ===== */
.note-list::-webkit-scrollbar, .main-panel::-webkit-scrollbar { width: 6px; }
.note-list::-webkit-scrollbar-track { background: transparent; }
.note-list::-webkit-scrollbar-thumb {
  background: var(--sidebar-border); border-radius: 3px;
}
.note-list::-webkit-scrollbar-thumb:hover { background: #4A4A4C; }
.main-panel::-webkit-scrollbar-track { background: transparent; }
.main-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.main-panel::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ===== Editor Page (Full Screen) ===== */
.editor-page {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.editor-topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: #F3F0EB;
  flex-shrink: 0;
}
.editor-title-input {
  flex: 1; min-width: 0;
  border: none; background: transparent; outline: none;
  font-size: 16px; font-weight: 600; font-family: var(--font);
  color: var(--text); text-align: center;
}
.editor-title-input::placeholder { color: var(--text-light); font-weight: 400; }
.editor-title-input[readonly] { cursor: default; opacity: 0.6; }
.editor-save-status { font-size: 12px; color: var(--success); flex-shrink: 0; }
.editor-save-status.saving { color: var(--text-muted); }
.tags-selector { position: relative; flex-shrink: 0; }
.tags-btn {
  background: none; border: 1px solid var(--border);
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer; font-family: var(--font);
  color: var(--text-muted);
}
.tags-btn:hover { background: var(--border-light); }
.tags-btn.has-selected { color: var(--accent); border-color: var(--accent); }
.tags-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 8px; max-height: 240px; overflow-y: auto; z-index: 300;
  min-width: 160px;
}
.tags-dropdown-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; cursor: pointer; border-radius: var(--radius-sm);
  font-size: 13px;
}
.tags-dropdown-item:hover { background: var(--border-light); }
.tags-dropdown-item input { margin: 0; }
.editor-textarea {
  flex: 1; width: 100%; max-width: 820px; margin: 0 auto;
  border: none; outline: none; resize: none;
  padding: 32px 32px 80px; font-size: 16px; line-height: 1.85;
  font-family: var(--font); background: var(--bg);
  color: var(--text);
}
.editor-textarea::placeholder { color: var(--text-light); }

/* ===== Draft Recovery ===== */
.draft-options { display: flex; gap: 16px; margin-top: 12px; }
.draft-option {
  flex: 1; padding: 16px; border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.draft-option:hover { border-color: var(--accent); background: var(--accent-light); }
.draft-option-header { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.draft-preview {
  font-size: 13px; color: var(--text-muted); line-height: 1.5;
  max-height: 100px; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
}
.draft-time { font-size: 12px; color: var(--text-light); }

/* ===== Responsive ===== */
.mobile-back { display: none; }
@media (max-width: 700px) {
  .sidebar { width: 100%; }
  .main-panel { display: none; }
  .sidebar.mobile-hidden { display: none; }
  .main-panel.mobile-show { display: block; }
  .mobile-back {
    display: inline-flex; align-items: center; gap: 4px;
    background: none; border: none; font-size: 14px; cursor: pointer;
    color: var(--accent); padding: 8px 12px;
  }
  .note-view { padding: 20px 16px 60px; }
  .modal-content { width: 95vw; max-height: 90vh; }
  .draft-options { flex-direction: column; }
  .editor-textarea { padding: 24px 16px 60px; font-size: 15px; }
  .editor-title-input { font-size: 14px; text-align: left; }
}
