/* ============ 云笺 · 记事本 ============ */
:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --ink: #2b2f3a;
  --ink-soft: #6b7280;
  --ink-faint: #9ca3af;
  --accent: #6d5ae8;
  --accent-2: #4f8cff;
  --accent-soft: #efecff;
  --danger: #e5484d;
  --border: #e7e9f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 24, 60, .06), 0 8px 24px rgba(20, 24, 60, .06);
  --shadow-lg: 0 12px 40px rgba(20, 24, 60, .14);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; }

/* ============ 登录页 ============ */
.login-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f6f4ff 0%, #eef4ff 50%, #fdf0f6 100%);
  z-index: 100;
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(600px 300px at 15% 20%, rgba(109, 90, 232, .10), transparent 60%),
    radial-gradient(500px 300px at 85% 75%, rgba(79, 140, 255, .10), transparent 60%);
  pointer-events: none;
}
.login-card {
  position: relative;
  width: min(360px, calc(100vw - 48px));
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 24px;
  padding: 44px 36px 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  width: 68px; height: 68px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(109, 90, 232, .35);
}
.login-card h1 { font-size: 26px; font-weight: 700; letter-spacing: 2px; }
.login-sub { color: var(--ink-soft); font-size: 13px; margin: 6px 0 28px; }
#loginForm { display: flex; flex-direction: column; gap: 12px; }
#loginPassword {
  height: 48px; padding: 0 16px;
  border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 15px; background: #fff; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#loginPassword:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#loginBtn {
  height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 15px; font-weight: 600; letter-spacing: 4px;
  transition: transform .15s, box-shadow .15s;
}
#loginBtn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(109, 90, 232, .3); }
#loginBtn:active { transform: translateY(0); }
#loginBtn:disabled { opacity: .6; cursor: wait; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 2px; }

/* ============ 主界面布局 ============ */
.app { display: flex; height: 100%; }

/* 侧栏 */
.sidebar {
  width: 320px; min-width: 280px; height: 100%;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px;
}
.brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand span { background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--ink-soft);
  transition: background .15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.sidebar-actions { padding: 6px 16px 12px; display: flex; flex-direction: column; gap: 10px; }
.search-box {
  position: relative; display: flex; align-items: center;
  background: var(--bg); border: 1.5px solid transparent; border-radius: 12px;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.search-box:focus-within { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { padding-left: 12px; font-size: 13px; opacity: .5; }
#searchInput {
  flex: 1; height: 40px; padding: 0 8px;
  background: none; border: none; outline: none; font-size: 14px;
}
.search-clear { padding: 0 10px; font-size: 12px; color: var(--ink-faint); }
.search-clear:hover { color: var(--ink); }
.new-btn {
  height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 12px rgba(109, 90, 232, .25);
  transition: transform .15s, box-shadow .15s;
}
.new-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(109, 90, 232, .35); }
.new-btn:active { transform: translateY(0); }

.note-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.note-list::-webkit-scrollbar { width: 5px; }
.note-list::-webkit-scrollbar-thumb { background: #d5d8e2; border-radius: 4px; }
.note-item {
  padding: 12px 14px; margin-bottom: 4px;
  border-radius: 12px; cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
}
.note-item:hover { background: var(--bg); }
.note-item.active { background: var(--accent-soft); border-color: rgba(109, 90, 232, .25); }
.note-item .ni-top { display: flex; align-items: center; gap: 6px; }
.note-item .ni-title {
  flex: 1; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note-item .ni-pin { font-size: 11px; }
.note-item .ni-excerpt {
  font-size: 12px; color: var(--ink-soft); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note-item .ni-time { font-size: 11px; color: var(--ink-faint); margin-top: 5px; }
.list-empty { text-align: center; color: var(--ink-faint); font-size: 13px; padding: 40px 0; }

.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--ink-faint);
}
.link-btn { font-size: 12px; color: var(--accent); }
.link-btn:hover { text-decoration: underline; }

/* 编辑器 */
.editor { flex: 1; height: 100%; display: flex; flex-direction: column; background: var(--panel); position: relative; }
.editor-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--ink-faint); gap: 10px;
}
.empty-icon { font-size: 46px; opacity: .7; }
.editor-empty p { font-size: 14px; }

.editor-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-topbar {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.back-btn { display: none; font-size: 26px; line-height: 1; }
.save-state { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-faint); }
.save-state .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.save-state.saving .dot { background: #f59e0b; animation: pulse 1s infinite; }
.save-state.error .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.tool-btn {
  height: 32px; padding: 0 12px; border-radius: 9px;
  font-size: 13px; color: var(--ink-soft);
  border: 1px solid var(--border); background: #fff;
  transition: all .15s;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tool-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.tool-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: #fef1f1; }

.note-title {
  padding: 18px 24px 6px;
  font-size: 24px; font-weight: 700;
  border: none; outline: none; background: none; color: var(--ink);
}
.editor-meta { display: flex; gap: 16px; padding: 0 24px 10px; font-size: 12px; color: var(--ink-faint); }
.editor-content-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.note-content {
  flex: 1; padding: 6px 24px 32px;
  border: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.8; color: var(--ink);
  background: none;
}
.preview {
  flex: 1; overflow-y: auto; padding: 6px 28px 40px;
  font-size: 15px; line-height: 1.85;
}
.preview::-webkit-scrollbar, .note-content::-webkit-scrollbar { width: 6px; }
.preview::-webkit-scrollbar-thumb, .note-content::-webkit-scrollbar-thumb { background: #d5d8e2; border-radius: 4px; }
.preview h1, .preview h2, .preview h3 { margin: 1.2em 0 .5em; line-height: 1.35; }
.preview h1 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.preview h2 { font-size: 1.3em; }
.preview h3 { font-size: 1.1em; }
.preview p { margin: .6em 0; }
.preview ul, .preview ol { margin: .6em 0; padding-left: 1.6em; }
.preview li { margin: .25em 0; }
.preview blockquote {
  margin: .8em 0; padding: .4em 1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 8px 8px 0;
  color: var(--ink-soft);
}
.preview code {
  background: #f0f1f6; border-radius: 5px; padding: .12em .4em;
  font-size: .9em; font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
.preview pre {
  background: #1e2230; color: #e6e8f0;
  border-radius: 10px; padding: 14px 16px; overflow-x: auto;
  margin: .8em 0;
}
.preview pre code { background: none; padding: 0; color: inherit; }
.preview a { color: var(--accent); }
.preview img { max-width: 100%; border-radius: 10px; }
.preview hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.preview table { border-collapse: collapse; margin: .8em 0; }
.preview th, .preview td { border: 1px solid var(--border); padding: 6px 12px; }
.preview th { background: var(--bg); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(20, 24, 60, .4);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  width: min(340px, calc(100vw - 48px));
  background: #fff; border-radius: 18px; padding: 26px 24px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 10px;
}
.modal h3 { font-size: 17px; }
.modal input {
  height: 42px; padding: 0 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; outline: none; transition: border-color .2s, box-shadow .2s;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-tip { font-size: 13px; color: var(--ink-soft); }
.modal-error { font-size: 12px; color: var(--danger); min-height: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.btn-ghost {
  height: 38px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--border); font-size: 14px; color: var(--ink-soft);
  transition: background .15s;
}
.btn-ghost:hover { background: var(--bg); }
.btn-primary {
  height: 38px; padding: 0 18px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px; font-weight: 600;
}
.btn-danger {
  height: 38px; padding: 0 18px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 14px; font-weight: 600;
}

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(30, 34, 48, .92); color: #fff;
  padding: 10px 22px; border-radius: 999px; font-size: 13px;
  z-index: 300; box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============ 移动端适配 ============ */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 0; }
  .editor { display: none; }
  .editor.open { display: flex; position: fixed; inset: 0; z-index: 50; }
  .back-btn { display: flex; }
  .note-title { font-size: 20px; padding: 14px 16px 4px; }
  .editor-meta { padding: 0 16px 8px; }
  .note-content { padding: 4px 16px 28px; font-size: 15px; }
  .preview { padding: 4px 18px 32px; }
  .editor-topbar { padding: 10px 12px; }
  .tool-btn { padding: 0 10px; }
}
