:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e6e9f2;
  --text: #1f2430;
  --text-soft: #6b7280;
  --text-faint: #9aa1b2;
  --primary: #5b6cff;
  --primary-strong: #4a5af0;
  --primary-soft: #eef0ff;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(30, 41, 99, 0.08);
  --shadow-lg: 0 20px 50px rgba(30, 41, 99, 0.16);
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- 按钮 ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
  font-family: inherit;
}
.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 16px rgba(91, 108, 255, 0.28);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(91, 108, 255, 0.38); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f3f4f8; color: var(--text); }
.btn-ghost.danger { color: var(--danger); border-color: #f3d1d1; }
.btn-ghost.danger:hover { background: var(--danger-soft); }
.btn-ghost.on { color: var(--primary-strong); border-color: var(--primary); background: var(--primary-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.icon-btn {
  border: none; background: transparent;
  color: var(--text-faint); font-size: 16px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: all .15s; line-height: 1;
}
.icon-btn:hover { background: #f0f1f6; color: var(--text); }

/* ---------- 登录界面 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, #e0e4ff 0%, transparent 60%),
              radial-gradient(1000px 600px at 90% 10%, #f3e8ff 0%, transparent 55%),
              var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-logo { font-size: 44px; }
.auth-brand h1 { font-size: 24px; margin-top: 8px; }
.auth-sub { color: var(--text-soft); font-size: 13px; margin-top: 4px; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; font-weight: 500; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s; font-family: inherit;
  background: #fafbfe;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: #fff; }

.auth-error {
  min-height: 20px; font-size: 13px; color: var(--danger);
  margin-bottom: 8px; text-align: center;
}

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 260px; min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 16px;
}
.sidebar-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.brand-logo { font-size: 24px; }
.brand-name { font-size: 18px; font-weight: 700; }

.cat-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: .05em;
  color: var(--text-faint); margin: 20px 4px 8px;
}
.cat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.cat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 9px; cursor: pointer;
  color: var(--text-soft); font-size: 14px; font-weight: 500;
  transition: all .15s; border: none; background: transparent; text-align: left; font-family: inherit;
  user-select: none;
}
.cat-item[draggable="true"] { -webkit-user-drag: element; }
.cat-item:hover { background: #f3f4f8; }
.cat-item.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
.cat-item .cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .cat-count { font-size: 12px; color: var(--text-faint); }
.cat-item.active .cat-count { color: var(--primary); }
.cat-item.dragging { opacity: 0.4; }
.sidebar-footer { margin-top: 12px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search {
  width: 100%; max-width: 420px; padding: 11px 16px 11px 40px;
  border: 1px solid var(--border); border-radius: 30px; font-size: 14px;
  background: #f5f6fa url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa1b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 14px center;
  transition: border-color .15s, box-shadow .15s; font-family: inherit;
}
.search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background-color: #fff; }

.workspace { flex: 1; display: flex; min-height: 0; }

.note-list {
  width: 320px; min-width: 320px;
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px; background: #fafbfe;
  display: flex; flex-direction: column; gap: 8px;
}
.note-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px; cursor: pointer;
  transition: all .15s; display: flex; align-items: flex-start; gap: 10px;
}
.note-item:hover { box-shadow: var(--shadow); border-color: #d9ddf0; }
.note-item.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.note-item.checked { border-color: var(--primary); background: var(--primary-soft); }
.note-item .note-item-body { flex: 1; min-width: 0; }
.note-check {
  width: 18px; height: 18px; min-width: 18px; margin-top: 2px;
  border: 2px solid var(--border); border-radius: 5px;
  display: none; transition: all .15s;
}
.note-item.selectable .note-check { display: block; }
.note-item.checked .note-check { background: var(--primary); border-color: var(--primary); }
.note-item.checked .note-check::after {
  content: ''; display: block; width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg); margin: 1px 0 0 5px;
}
.note-item .note-item-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .note-item-snippet { font-size: 13px; color: var(--text-soft); margin-bottom: 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; }
.note-item .note-item-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-faint); }
.badge { background: var(--primary-soft); color: var(--primary-strong); padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.empty-list { text-align: center; color: var(--text-faint); font-size: 14px; padding: 40px 16px; }

.editor { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.editor-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-faint); gap: 12px; }
.empty-icon { font-size: 48px; }
.editor-content { flex: 1; display: flex; flex-direction: column; padding: 24px 28px; min-height: 0; }
.title-input {
  border: none; font-size: 26px; font-weight: 700; padding: 6px 0;
  margin-bottom: 12px; font-family: inherit; width: 100%; color: var(--text);
}
.title-input:focus, .content-input:focus { outline: none; }
.editor-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.cat-select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 13px; background: #fafbfe; color: var(--text-soft);
  font-family: inherit; cursor: pointer;
}
.meta { font-size: 12px; color: var(--text-faint); }
.spacer { flex: 1; }
.content-input {
  flex: 1; border: none; resize: none; font-size: 16px; line-height: 1.7;
  padding: 8px 2px; font-family: inherit; color: var(--text); min-height: 0;
}

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(31, 36, 48, 0.4); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: 100%; max-width: 420px; max-height: 80vh;
  background: var(--surface); border-radius: 16px; padding: 24px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h2 { font-size: 18px; }
.add-cat { display: flex; gap: 8px; margin-bottom: 16px; }
.add-cat input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
}
.add-cat input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.cat-manage { list-style: none; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.cat-manage li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #f7f8fc; border-radius: 9px; }
.cat-manage .cm-name { flex: 1; font-size: 14px; }
.cat-manage input {
  flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; font-family: inherit;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2430; color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .3s ease; z-index: 100;
  box-shadow: var(--shadow-lg); max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #16a34a; }
.toast.error { background: var(--danger); }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .note-list { width: 260px; min-width: 260px; }
}
@media (max-width: 720px) {
  .sidebar { width: 76px; min-width: 76px; padding: 16px 8px; }
  .sidebar .brand-name, .sidebar .cat-title span, .sidebar .cat-item .cat-name,
  .sidebar .cat-item .cat-count, .sidebar-footer .btn { display: none; }
  .sidebar .cat-item { justify-content: center; }
  .note-list { display: none; }
}