:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #8a93a6;
  --line: #e8ecf3;
  --primary: #4f7cff;
  --primary-soft: #eaf0ff;
  --green: #2ecc71;
  --orange: #ff9f43;
  --red: #ff6b6b;
  --radius: 16px;
  --shadow: 0 4px 18px rgba(40, 60, 120, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 24px; }
.title { font-weight: 700; font-size: 17px; }
.subtitle { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 18px; cursor: pointer; color: var(--text);
}
.icon-btn:active { transform: scale(0.94); }

/* 底部标签栏（移动端） + 顶部（桌面） */
.tabbar {
  position: sticky; top: 62px; z-index: 19;
  display: flex; gap: 8px; overflow-x: auto;
  padding: 10px 12px; background: var(--bg);
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--card);
  color: var(--muted); font-weight: 600;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  font-size: 14px;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 主区 */
main { padding: 12px; max-width: 860px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 卡片 */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card .hint { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }

/* 表单控件 */
input, textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-family: inherit;
  background: #fbfcfe; color: var(--text); margin-bottom: 8px;
}
input:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
label { font-size: 13px; color: var(--muted); display: block; margin: 6px 0 2px; }

.btn {
  border: none; background: var(--primary); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-weight: 600;
  cursor: pointer; font-size: 14px;
}
.btn:active { transform: scale(0.97); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: #ffeaea; color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 13px; }

/* 进度条 */
.progress-row { margin-bottom: 14px; }
.progress-row .meta { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.progress-row .meta b { font-size: 14px; }
.bar { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #7ea2ff); border-radius: 999px; transition: width .4s; }
.progress-edit { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.progress-edit input { margin: 0; }
.progress-edit input[type=number] { width: 90px; }

/* 日历 */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head button { border: none; background: var(--primary-soft); color: var(--primary); width: 34px; height: 34px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px; background: #fbfcfe;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 13px; cursor: pointer; position: relative; border: 1px solid transparent;
}
.cal-day.other { color: var(--line); }
.cal-day.today { border-color: var(--primary); font-weight: 700; }
.cal-day.sel { background: var(--primary); color: #fff; }
.cal-day .dot { position: absolute; bottom: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.cal-day.sel .dot { background: #fff; }
/* 月历每日打卡柱状图 */
.cal-day .dnum { position: relative; z-index: 1; }
.cal-day .col { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); width: 8px; background: var(--green); border-radius: 3px; transition: height .3s; }
.cal-day .col.full { background: var(--green); box-shadow: 0 0 0 2px rgba(46,204,113,.25); }
.cal-day.sel .col { background: #fff; }

/* 打卡项管理 */
.manage-box { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.cm-del { margin-left: 3px; font-weight: 700; opacity: .65; font-size: 11px; }
.chip.cm { display: inline-flex; align-items: center; }

/* 打卡项 */
.checkin-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fbfcfe; font-size: 13px; cursor: pointer; user-select: none;
}
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }

/* 列表项 */
.item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: none; }
.item .body { flex: 1; }
.item .del { color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 6px; }
.todo-done { text-decoration: line-through; color: var(--muted); }

/* 时间轴 */
.tl-day { display: flex; gap: 12px; margin-bottom: 6px; }
.tl-axis { width: 56px; text-align: right; font-size: 12px; color: var(--muted); padding-top: 2px; }
.tl-track { flex: 1; position: relative; border-left: 2px solid var(--line); padding-left: 12px; padding-bottom: 8px; min-height: 20px; }
.tl-event { background: var(--primary-soft); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; position: relative; }
.tl-event .bar-color { position: absolute; left: -14px; top: 8px; width: 6px; height: 16px; border-radius: 3px; }
.tl-event .t { font-weight: 600; font-size: 14px; }
.tl-event .time { font-size: 12px; color: var(--muted); }
.tl-event .note { font-size: 12px; color: var(--muted); }

/* 通用 */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row .btn { flex: 0 0 auto; }
.tag { display: inline-block; background: var(--primary-soft); color: var(--primary); padding: 2px 8px; border-radius: 6px; font-size: 11px; margin: 2px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }
.stat { display: flex; gap: 10px; }
.stat .box { flex: 1; background: #fbfcfe; border-radius: 12px; padding: 12px; text-align: center; }
.stat .box b { font-size: 20px; display: block; }
.stat .box span { font-size: 12px; color: var(--muted); }

canvas { width: 100% !important; display: block; }
.img-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }

/* 设置弹层 */
.modal-mask { display: none; position: fixed; inset: 0; background: rgba(20,30,60,.4); z-index: 50; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--card); border-radius: var(--radius); padding: 18px; width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 6px; }
.modal .hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; }

/* 周视图时间轴 */
.week-view { display: flex; overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.week-gutter { width: 40px; flex: 0 0 40px; border-right: 1px solid var(--line); }
.wk-glabel { font-size: 10px; color: var(--muted); text-align: right; padding-right: 4px; box-sizing: border-box; line-height: 1; transform: translateY(-5px); }
.week-grid { display: flex; flex: 1; min-width: 560px; }
.wk-col { flex: 1; border-left: 1px solid var(--line); }
.wk-col:first-child { border-left: none; }
.wk-col.today .wk-col-head { color: var(--primary); font-weight: 700; }
.wk-col.sel .wk-col-head { background: var(--primary-soft); }
.wk-col-head { text-align: center; font-size: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.wk-col-body { position: relative; background-image: repeating-linear-gradient(to bottom, transparent, transparent 29px, var(--line) 29px, var(--line) 30px); }
.tl-ev { position: absolute; left: 2px; right: 2px; border-radius: 7px; color: #fff; font-size: 11px; padding: 2px 5px; overflow: hidden; touch-action: none; cursor: grab; box-sizing: border-box; }
.tl-ev:active { cursor: grabbing; }
.tl-ev-t { font-weight: 600; line-height: 1.2; }
.tl-ev-time { opacity: .9; font-size: 10px; }
.tl-ev-actions { position: absolute; top: 2px; right: 3px; display: flex; gap: 4px; }
.tl-edit, .tl-del { cursor: pointer; font-size: 12px; background: rgba(255,255,255,.25); border-radius: 4px; padding: 0 3px; }
.tl-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 9px; cursor: ns-resize; }
