:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --ink: #2b2a27;
  --ink-2: #6e6b64;
  --ink-3: #a19d94;
  --line: #e7e2d9;
  --accent: #7c6f5a;
  --accent-soft: #efe9dc;
  --teal: #4a8f7b;
  --teal-soft: #e6f2ed;
  --red: #c2574a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(43, 42, 39, .04), 0 8px 24px rgba(43, 42, 39, .04);
}

* { box-sizing: border-box; }
/* [hidden] 只是浏览器默认的 display:none,类上写了 display 就会盖掉它
   (.login-view/.todo-list 都中招了),这里统一压一道,别让隐藏元素还占着位置。 */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--ink-2); font-size: 12px; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand h1 { font-size: 22px; letter-spacing: .04em; }
.login-brand p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.brand-mark { width: 48px; height: 48px; border-radius: 14px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 600; flex: none; }
.brand-mark.small { width: 32px; height: 32px; border-radius: 9px; font-size: 15px; }
.login-tabs { display: flex; gap: 6px; padding: 4px; background: var(--surface-2); border-radius: 10px; margin-bottom: 20px; }
.login-tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px; color: var(--ink-2); }
.login-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.login-card form label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--ink-2); }
.login-card form input { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; }
.login-card form input:focus { border-color: var(--accent); }
.form-error { color: var(--red); font-size: 12px; min-height: 18px; }
.primary-btn { border: 0; background: var(--accent); color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 500; }
.primary-btn:active { opacity: .8; }
.login-card .primary-btn { width: 100%; margin-top: 4px; }
.login-hint { font-size: 12px; color: var(--ink-3); text-align: center; margin: 18px 0 0; line-height: 1.5; }

.topbar { position: sticky; top: 0; z-index: 20; background: rgba(247,245,240,.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 12px; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong { display: block; font-size: 15px; line-height: 1.2; }
.topbar-title span { display: block; font-size: 11px; color: var(--ink-3); }
.scope-switch { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 9px; }
.scope-btn { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-size: 12px; color: var(--ink-2); }
.scope-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.icon-btn { width: 34px; height: 34px; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; display: grid; place-items: center; color: var(--ink-2); }
.tabbar { max-width: 1080px; margin: 0 auto; padding: 8px 20px 0; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; background: transparent; padding: 9px 14px; border-radius: 9px 9px 0 0; color: var(--ink-2); white-space: nowrap; font-size: 13px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.content { max-width: 1080px; margin: 0 auto; padding: 16px 20px 60px; }
.panel { display: none; }
.panel.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font-size: 15px; }

.hero { background: var(--accent-soft); border-color: #e3d9c5; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.eyebrow { font-size: 12px; color: var(--ink-2); letter-spacing: .08em; }
.hero h2 { font-size: 40px; line-height: 1.1; margin: 6px 0; font-weight: 500; }
.hero-unit { font-size: 15px; color: var(--ink-2); font-weight: 400; }
.hero-sub { margin: 0; color: var(--ink-2); font-size: 13px; }
.hero-ring { width: 76px; height: 76px; border-radius: 50%; border: 5px solid var(--accent); display: grid; place-items: center; font-size: 11px; color: var(--ink-2); background: var(--surface); flex: none; }
.score-control { display: flex; align-items: center; gap: 12px; margin: 18px 0 12px; }
.score-control input { flex: 1; accent-color: var(--accent); }
.score-control span { width: 32px; text-align: right; font-variant-numeric: tabular-nums; }
.note-box textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--surface); resize: vertical; outline: none; }
.note-box textarea:focus { border-color: var(--accent); }
.autosave { text-align: right; font-size: 11px; color: var(--ink-3); margin-top: 4px; min-height: 16px; }

.habit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.habit { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); text-align: left; }
.habit.done { background: var(--teal-soft); border-color: #c5dfd4; }
.habit-name { font-weight: 500; }
.habit-goal { font-size: 11px; color: var(--ink-2); }
.habit-streak { font-size: 11px; color: var(--teal); margin-top: 6px; }
.habit-stats { display: flex; gap: 40px; margin: 18px 0 8px; }
.habit-stats div { display: flex; flex-direction: column; }
.stat-num { font-size: 22px; font-weight: 500; }
.stat-label { font-size: 11px; color: var(--ink-2); }
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; width: max-content; }
.heatmap i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); display: block; }
.heatmap i.l1 { background: #d7e9e1; } .heatmap i.l2 { background: #a9d3c2; }
.heatmap i.l3 { background: #6fb49b; } .heatmap i.l4 { background: var(--teal); }
.heatmap-note { font-size: 11px; color: var(--ink-3); margin-top: 8px; }

.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric { background: var(--bg); border-radius: 12px; padding: 14px; }
.metric-label { display: block; font-size: 11px; color: var(--ink-2); }
.metric strong { font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.field label, .field > label { display: block; font-size: 11px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.field.wide { grid-column: 1 / -1; }
.field.align-end { display: flex; align-items: flex-end; }
.field.align-end .primary-btn { width: 100%; }
.budget-row { display: flex; gap: 8px; }
.budget-row input { flex: 1; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); outline: none; }
.ghost-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 14px; border-radius: 9px; }
.danger-btn { border: 1px solid #e6c3bd; background: #fff4f2; color: var(--red); padding: 9px 14px; border-radius: 9px; }
.text-btn { border: 0; background: transparent; color: var(--teal); font-size: 12px; padding: 0; }
.progress { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 12px 0 6px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .3s; }
.progress-fill.teal { background: var(--teal); }
.budget-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); }
.category-bars { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: grid; grid-template-columns: 64px 1fr 60px; align-items: center; gap: 10px; font-size: 12px; }
.cat-bar { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.cat-bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.cat-amount { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.record-list { display: flex; flex-direction: column; }
.record { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.record:last-child { border-bottom: 0; }
.record-main { flex: 1; min-width: 0; }
.record-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { font-size: 11px; color: var(--ink-3); }
.record-value { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.record-value.income { color: var(--teal); }
.record-value.expense { color: var(--red); }
.record-actions { display: flex; gap: 6px; }
.mini-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 5px 8px; font-size: 11px; color: var(--ink-2); }
.mini-btn.danger { color: var(--red); }

.pri { display: inline-block; font-size: 10px; line-height: 1.6; padding: 0 7px; border-radius: 6px; margin-left: 6px; vertical-align: 1px; font-weight: 400; }
.pri-high { background: #f7e4e0; color: var(--red); }
.pri-mid { background: var(--accent-soft); color: var(--accent); }
.pri-low { background: var(--surface-2); color: var(--ink-2); }
.due.overdue { color: var(--red); }
.overdue-text { color: var(--red); }
.todo-done .record-title { color: var(--ink-3); text-decoration: line-through; }
.idea-title { white-space: normal; }
.idea-tag { display: inline-block; font-size: 10px; padding: 0 7px; border-radius: 6px; margin-left: 6px; background: var(--teal-soft); color: var(--teal); vertical-align: 1px; }
.empty { color: var(--ink-3); text-align: center; padding: 28px 10px; font-size: 13px; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; background: var(--surface-2); border-radius: 9px; margin-bottom: 12px; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; font-size: 12px; color: var(--ink-2); }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }

.goal-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); }
.goal-line b { color: var(--ink); font-weight: 500; }
.chart-wrap { width: 100%; overflow-x: auto; }
canvas { display: block; width: 100%; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.day-chip { text-align: center; padding: 8px 2px; border-radius: 9px; background: var(--bg); font-size: 11px; color: var(--ink-2); }
.day-chip.today { background: var(--accent-soft); color: var(--ink); }
.day-chip b { display: block; font-size: 15px; font-weight: 500; color: var(--ink); }
.day-chip i { display: block; font-style: normal; color: var(--teal); font-size: 10px; }

.stream-day { margin-bottom: 18px; }
.stream-date { font-size: 12px; color: var(--ink-2); padding: 6px 0; border-bottom: 1px solid var(--line); }
.stream-item { display: flex; gap: 10px; padding: 9px 0; font-size: 13px; border-bottom: 1px dashed var(--line); }
.stream-kind { flex: none; width: 44px; font-size: 11px; color: var(--teal); padding-top: 2px; }
.stream-body { flex: 1; min-width: 0; }
.stream-detail { font-size: 11px; color: var(--ink-3); }
.stream-right { font-size: 13px; color: var(--ink-2); white-space: nowrap; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.modal { position: fixed; inset: 0; background: rgba(43,42,39,.35); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 16px; padding: 24px; width: min(420px, 100%); }
.modal-card h3 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

.todo-list { display: flex; flex-direction: column; }
.todo-row { display: flex; align-items: flex-start; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.todo-row:last-child { border-bottom: 0; }
.todo-check { flex: none; width: 28px; height: 28px; display: grid; place-items: center; margin-top: -2px; }
.todo-check input { width: 17px; height: 17px; accent-color: var(--teal); }
.todo-main { flex: 1; min-width: 0; }
.todo-line { display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
.todo-title { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0; text-align: left; font-size: 14px; line-height: 1.5; white-space: normal; overflow: visible; text-overflow: clip; word-break: break-word; }
.todo-line .pri { margin-left: 0; }
.todo-meta { font-size: 11px; color: var(--ink-3); margin-top: 2px; white-space: normal; overflow: visible; text-overflow: clip; word-break: break-word; }
.tag { flex: none; font-size: 10px; line-height: 1.7; padding: 0 7px; border-radius: 6px; margin-top: 1px; }.todo-attach { flex: none; max-width: 108px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; line-height: 1.7; padding: 0 7px; margin-top: 1px; border-radius: 6px; border: 1px dashed var(--line); background: transparent; color: var(--ink-3); }
.todo-attach:hover { color: var(--ink-2); border-style: solid; background: var(--surface-2); }

/* 工作台顶部搜索:收起时只剩一个放大镜 */
.work-search { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.work-search .search-input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--ink); outline: none; }
.work-search .search-input:focus { border-color: var(--accent); }
.work-search .search-input::-webkit-search-cancel-button { cursor: pointer; }
.work-search .search-info { flex: none; font-size: 11px; white-space: nowrap; }
.work-search .search-btn { flex: none; margin-left: auto; width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 9px; }
.work-search .search-btn:active { background: var(--surface-2); }

/* 命中的行高亮关键词,其余行变淡但仍在原位(不影响排序) */
.todo-row.search-dim { opacity: .34; }
.todo-row.search-hit mark.hl { background: #f7e6a8; color: inherit; padding: 0 1px; border-radius: 2px; }
.tag-time { background: var(--surface-2); color: var(--ink-2); }
.tag-overdue { background: #f7e4e0; color: var(--red); }
.todo-row.striking .todo-title, .todo-row.todo-done .todo-title { color: var(--ink-3); text-decoration: line-through; }
.todo-done-wrap { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.done-bar { display: flex; align-items: center; gap: 8px; }
.done-toggle { flex: 1; min-width: 0; display: flex; justify-content: space-between; border: 0; background: transparent; padding: 4px 0; font-size: 12px; color: var(--ink-2); }
.done-toggle b { font-weight: 500; color: var(--ink); }
.done-all-btn { flex: none; border: 1px solid var(--line); background: var(--bg); color: var(--ink-2); border-radius: 8px; padding: 3px 9px; font-size: 11px; white-space: nowrap; }
.done-all-btn b { font-weight: 500; color: var(--ink); }
#doneAllModal .modal-card { max-height: 80vh; overflow-y: auto; }
.quick-add { position: sticky; bottom: 8px; display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 1px 2px rgba(43,42,39,.04), 0 8px 24px rgba(43,42,39,.06); }
.quick-input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 4px; font-size: 16px; outline: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--bg); color: var(--ink-2); border-radius: 8px; padding: 5px 9px; font-size: 12px; }
.chip:active { background: var(--surface-2); }

@media (max-width: 640px) {
  .topbar-inner { padding: 10px 14px; }
  .tabbar { padding: 6px 14px 0; }
  .content { padding: 12px 14px 50px; }
  .card { padding: 16px; border-radius: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
  .hero h2 { font-size: 34px; }
  .hero-ring { width: 64px; height: 64px; }
  .metric strong { font-size: 17px; }
  .topbar-title span { display: none; }
}

/* ===== 灵感:可展开的 Markdown 笔记 ===== */
.md-level { margin-left: auto; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); font-size: 11px; padding: 2px 9px; border-radius: 999px; cursor: pointer; }
.md-level:hover { border-color: var(--accent); color: var(--accent); }

.idea-editor { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.idea-title-input, .idea-body { width: 100%; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); padding: 8px 10px; outline: none; font-size: 13.5px; }
.idea-title-input { font-weight: 600; }
.idea-title-input:focus, .idea-body:focus { border-color: var(--accent); }
.idea-body { resize: vertical; line-height: 1.65; min-height: 38px; }
.idea-editor.collapsed .idea-title-input,
.idea-editor.collapsed .idea-tools { display: none; }
.idea-editor.collapsed .idea-body { min-height: 38px; height: 38px; resize: none; overflow: hidden; }
.idea-editor.expanded .idea-body { min-height: 96px; }
.idea-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.idea-tag-field { font-size: 11px; color: var(--ink-3); display: flex; align-items: center; gap: 4px; }
.idea-tag-field input { width: 108px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 7px;
  background: var(--surface); font-size: 12px; outline: none; }
.idea-hint { font-size: 11px; margin-right: auto; }
.idea-editor.drag-over .idea-body { border-color: var(--accent); background: var(--accent-soft); }

/* 渲染结果:标题压小,别把卡片撑爆 */
.md-body { font-size: 13.5px; color: var(--ink); line-height: 1.7; }
.md-body > *:first-child { margin-top: 0; }
.md-body > *:last-child { margin-bottom: 0; }
.md-h { margin: 10px 0 4px; line-height: 1.4; }
.md-h1 { font-size: 17px; } .md-h2 { font-size: 15.5px; } .md-h3 { font-size: 14.5px; }
.md-h4, .md-h5, .md-h6 { font-size: 13.5px; color: var(--ink-2); }
.md-p { margin: 4px 0; }
.md-list { margin: 4px 0; padding-left: 20px; }
.md-list li { margin: 2px 0; }
.md-task-item { list-style: none; margin-left: -20px; }
.md-task-item label { display: flex; gap: 7px; align-items: flex-start; cursor: pointer; }
.md-task-item input.md-task { margin-top: 4px; accent-color: var(--accent); cursor: pointer; flex: none; }
.md-task-item input.md-task:checked + .md-task-text { color: var(--ink-3); text-decoration: line-through; }
.md-quote { margin: 6px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--line); color: var(--ink-2); }
.md-code { margin: 6px 0; padding: 9px 11px; background: var(--surface-2); border-radius: 9px;
  overflow-x: auto; font-size: 12.5px; line-height: 1.55; }
.md-code code { font-family: Consolas, "SF Mono", Menlo, monospace; white-space: pre; }
.md-inline-code { background: var(--surface-2); border-radius: 5px; padding: 1px 5px;
  font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.md-link { color: var(--teal); }
.md-hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md-img { display: block; max-width: 100%; border-radius: 10px; margin: 6px 0; }
.md-img-fail { display: inline-block; font-size: 11.5px; color: var(--ink-3);
  background: var(--surface-2); border-radius: 7px; padding: 3px 8px; }
.md-plain { white-space: pre-wrap; word-break: break-word; }
