/* ===== 主题变量 ===== */
:root {
  --bg: #f4f5fb;
  --bg-soft: #eef0f8;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e6e8f0;
  --text: #1f2330;
  --text-soft: #6b7080;
  --text-faint: #9aa0b4;
  --primary: #4f46e5;
  --primary-soft: #eceafe;
  --primary-hover: #4338ca;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --shadow: 0 4px 20px rgba(31,35,48,.06);
  --shadow-lg: 0 12px 40px rgba(31,35,48,.12);
  --radius: 16px;
  --radius-sm: 10px;
  --c1: #6366f1; --c2: #ec4899; --c3: #06b6d4; --c4: #f59e0b;
  --c5: #10b981; --c6: #8b5cf6; --c7: #ef4444; --c8: #0ea5e9;
}
[data-theme="dark"] {
  --bg: #0f1117;
  --bg-soft: #161a23;
  --surface: #1a1f2b;
  --surface-2: #20263450;
  --border: #2a3140;
  --text: #e7e9f0;
  --text-soft: #9aa1b3;
  --text-faint: #6b7285;
  --primary: #818cf8;
  --primary-soft: #2a2f5a;
  --primary-hover: #a5b0ff;
  --success: #34d399;
  --success-soft: #0f2e22;
  --warn: #fbbf24;
  --warn-soft: #3a2f10;
  --danger: #f87171;
  --danger-soft: #3a1818;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===== 布局 ===== */
#app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  transition: transform .3s;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--c6));
  display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.brand-text strong { font-size: 16px; display: block; letter-spacing: .5px; }
.brand-text small { color: var(--text-faint); font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border-radius: 11px;
  color: var(--text-soft); font-size: 14px; font-weight: 500;
  text-align: left; transition: all .15s; position: relative;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-ico { font-size: 17px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.sidebar-foot { display: flex; flex-direction: column; gap: 10px; padding: 8px; }
.sidebar-foot small { color: var(--text-faint); font-size: 11px; line-height: 1.5; }
.theme-toggle {
  width: 100%; padding: 9px; border-radius: 10px; background: var(--bg-soft);
  color: var(--text-soft); font-size: 13px; font-weight: 500; transition: all .15s;
}
.theme-toggle:hover { color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 60px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.menu-btn { display: none; font-size: 20px; color: var(--text-soft); }
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 16px; color: var(--text-soft); }
.topbar-date { font-size: 13px; }
.topbar-clock { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }

/* ===== 云端同步 ===== */
.sync-btn {
  padding: 7px 13px; border-radius: 10px; background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 600; transition: all .15s; white-space: nowrap;
}
.sync-btn:hover { background: var(--primary); color: #fff; }
.sync-status { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.sync-status.syncing { color: var(--primary); }
.sync-status.ok { color: var(--success); }
.sync-status.error { color: var(--danger); }
.sync-logout {
  padding: 5px 10px; border-radius: 8px; background: transparent; color: var(--text-faint);
  font-size: 12px; border: 1px solid var(--border); transition: all .15s;
}
.sync-logout:hover { color: var(--danger); border-color: var(--danger); }

.sync-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.sync-tab {
  flex: 1; padding: 9px; border-radius: 10px; background: var(--bg-soft); color: var(--text-soft);
  font-size: 14px; font-weight: 600; transition: all .15s;
}
.sync-tab.active { background: var(--primary); color: #fff; }
.sync-form .field { margin-bottom: 14px; }
.sync-form label { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; font-weight: 500; }
.sync-form input {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; box-sizing: border-box;
}
.sync-form input:focus { outline: none; border-color: var(--primary); }
.sync-hint { font-size: 12px; color: var(--text-faint); line-height: 1.6; margin: 4px 0 16px; }
.btn-primary {
  width: 100%; padding: 11px; border-radius: 10px; background: var(--primary); color: #fff;
  font-size: 14px; font-weight: 600; transition: all .15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.view { flex: 1; overflow-y: auto; padding: 24px; display: none; }
.view.active { display: block; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== 通用组件 ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.card-title .sub { font-size: 12px; color: var(--text-faint); font-weight: 400; margin-left: auto; }
.grid { display: grid; gap: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; background: var(--primary); color: #fff;
  font-weight: 600; font-size: 13px; transition: all .15s;
}
.btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn.ghost { background: var(--bg-soft); color: var(--text); }
.btn.ghost:hover { background: var(--border); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 20px; font-size: 12px; font-weight: 500; background: var(--bg-soft); color: var(--text-soft);
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.field input, .field textarea, .field select {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; outline: none; transition: border .15s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 70px; }
.empty { text-align: center; color: var(--text-faint); padding: 40px 10px; font-size: 13px; }
.empty .ico { font-size: 38px; display: block; margin-bottom: 10px; opacity: .6; }

/* ===== 日历 ===== */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.cal-head h2 { font-size: 20px; font-weight: 700; }
.cal-nav { display: flex; gap: 6px; }
.cal-nav button {
  width: 34px; height: 34px; border-radius: 9px; background: var(--bg-soft); color: var(--text-soft);
  font-size: 16px; display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.cal-nav button:hover { background: var(--border); color: var(--text); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--text-faint); font-weight: 600; padding: 6px 0; }
.cal-cell {
  min-height: 92px; border-radius: 12px; padding: 7px 8px; background: var(--surface-2);
  border: 1px solid transparent; cursor: pointer; transition: all .12s; position: relative; overflow: hidden;
}
.cal-cell:hover { border-color: var(--primary); background: var(--surface); }
.cal-cell.sel { border-color: var(--primary); box-shadow: inset 0 0 0 1.5px var(--primary); }
.cal-cell.other { opacity: .4; }
.cal-cell.today { background: var(--primary-soft); }
.cal-cell.today .cal-day { color: var(--primary); font-weight: 800; }
.cal-day { font-size: 13px; font-weight: 600; color: var(--text); }
.cal-events { margin-top: 5px; display: flex; flex-direction: column; gap: 3px; }
.cal-dot {
  font-size: 11px; padding: 2px 6px; border-radius: 6px; color: #fff; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; font-weight: 500;
}
.cal-more { font-size: 10px; color: var(--text-faint); padding-left: 2px; }

/* ===== 列表/任务 ===== */
.list { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--border); transition: all .15s;
}
.task:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.task.done { opacity: .6; }
.task.done .task-title { text-decoration: line-through; }
.check {
  width: 21px; height: 21px; border-radius: 7px; border: 2px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; margin-top: 1px; transition: all .15s; font-size: 13px;
}
.check.on { background: var(--success); border-color: var(--success); color: #fff; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 600; }
.task-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 7px; align-items: center; }
.task-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.task:hover .task-actions { opacity: 1; }
.icon-btn { width: 30px; height: 30px; border-radius: 8px; background: var(--bg-soft); color: var(--text-soft); font-size: 14px; display:flex; align-items:center; justify-content:center; transition: all .15s; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filters .chip { cursor: pointer; transition: all .15s; }
.filters .chip.active { background: var(--primary); color: #fff; }
.prio { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ===== 番茄钟 ===== */
.pomo-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 20px 0; }
.pomo-ring { position: relative; width: 280px; height: 280px; }
.pomo-ring svg { transform: rotate(-90deg); }
.pomo-ring .track { fill: none; stroke: var(--border); stroke-width: 14; }
.pomo-ring .prog { fill: none; stroke: var(--primary); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset .3s linear; }
.pomo-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pomo-time { font-size: 58px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.pomo-mode { font-size: 14px; color: var(--text-soft); font-weight: 600; margin-top: 4px; }
.pomo-controls { display: flex; gap: 12px; }
.pomo-mode-switch { display: flex; gap: 6px; background: var(--bg-soft); padding: 5px; border-radius: 12px; }
.pomo-mode-switch button { padding: 8px 16px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-soft); transition: all .15s; }
.pomo-mode-switch button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.pomo-stats { display: flex; gap: 26px; }
.pomo-stat { text-align: center; }
.pomo-stat b { font-size: 24px; font-weight: 800; display: block; color: var(--primary); }
.pomo-stat span { font-size: 12px; color: var(--text-soft); }

/* ===== 统计 ===== */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card .v { font-size: 30px; font-weight: 800; }
.stat-card .l { font-size: 12px; color: var(--text-soft); margin-top: 4px; }
.stat-card .i { font-size: 22px; margin-bottom: 8px; }
.chart-svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; }

/* ===== 习惯 ===== */
.habit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.habit-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.habit-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.habit-emoji { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.habit-name { font-weight: 700; font-size: 15px; }
.habit-streak { font-size: 12px; color: var(--warn); font-weight: 600; }
.habit-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.habit-day { aspect-ratio: 1; border-radius: 8px; background: var(--bg-soft); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-faint); cursor: pointer; transition: all .12s; border: 1px solid transparent; }
.habit-day.done { color: #fff; font-weight: 700; }
.habit-day.today { border-color: var(--primary); }
.habit-day:hover { transform: scale(1.08); }

/* ===== 便签 ===== */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.note {
  border-radius: 14px; padding: 16px; min-height: 150px; display: flex; flex-direction: column;
  box-shadow: var(--shadow); position: relative; transition: transform .15s;
}
.note:hover { transform: translateY(-3px); }
.note textarea {
  background: transparent; border: none; resize: none; outline: none; color: #3a3320;
  font-size: 14px; flex: 1; line-height: 1.5;
}
.note .note-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 11px; opacity: .7; }
.note-add { border: 2px dashed var(--border); background: var(--surface-2); border-radius: 14px; display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 40px; cursor: pointer; min-height: 150px; transition: all .15s; }
.note-add:hover { border-color: var(--primary); color: var(--primary); }

/* ===== 仪表盘 ===== */
.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.dash-grid > .card { grid-column: span 4; }
.dash-grid > .card.wide { grid-column: span 8; }
.dash-grid > .card.full { grid-column: span 12; }
.dash-todo { display: flex; flex-direction: column; gap: 9px; }
.dash-todo .row { display: flex; align-items: center; gap: 9px; font-size: 13px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.dash-todo .row:last-child { border-bottom: none; }
.mini-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.mini-cal .d { aspect-ratio: 1; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 11px; background: var(--surface-2); color: var(--text-soft); position: relative; }
.mini-cal .d.today { background: var(--primary); color: #fff; font-weight: 700; }
.mini-cal .d.has::after { content: ''; position: absolute; bottom: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }
.mini-cal .d.today.has::after { background: #fff; }

/* ===== 目标倒计时 ===== */
.target { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; }
.target .emoji { font-size: 28px; }
.target .info { flex: 1; }
.target .name { font-weight: 700; }
.target .dday { font-size: 12px; color: var(--text-soft); }
.target .count { font-size: 26px; font-weight: 800; color: var(--primary); }

/* ===== 弹窗 ===== */
#modal-layer { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; }
#modal-layer.show { display: flex; }
.modal-mask { position: absolute; inset: 0; background: rgba(15,17,23,.5); backdrop-filter: blur(3px); }
.modal {
  position: relative; background: var(--surface); border-radius: 18px; padding: 24px;
  width: 440px; max-width: calc(100vw - 32px); max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: pop .2s ease;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 17px; margin-bottom: 18px; display: flex; align-items: center; gap: 8px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.color-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pick button { width: 28px; height: 28px; border-radius: 8px; border: 2px solid transparent; transition: all .12s; }
.color-pick button.sel { border-color: var(--text); transform: scale(1.12); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 22px; border-radius: 12px;
  font-size: 13px; font-weight: 600; z-index: 200; box-shadow: var(--shadow-lg); animation: toastIn .25s;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== 响应式 ===== */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 60; height: 100%; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .menu-btn { display: block; }
  .view { padding: 16px; }
  .dash-grid > .card, .dash-grid > .card.wide, .dash-grid > .card.full { grid-column: span 12; }
}
