:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --danger: #dc4c4c;
  --warn: #e8890c;
  --ok: #16a34a;
  --border: #e4e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
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: 15px;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* 顶部栏 */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sync-status { font-size: 11px; opacity: .85; }

/* 同步状态点 */
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.sync-dot.ok { background: #5fdc8f; }
.sync-dot.offline { background: #ffb020; }
.sync-dot.error { background: #ff5f5f; }

/* 标签页 */
.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 19;
}
.tab {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  position: relative;
}
.tab.active { color: var(--primary); font-weight: 600; border-bottom-color: var(--primary); }
.badge {
  display: inline-block;
  background: #eef2f7;
  color: var(--primary);
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 7px;
  margin-left: 4px;
  vertical-align: 1px;
}

/* 内容区 */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  padding-bottom: 80px;
  -webkit-overflow-scrolling: touch;
}

/* 已完成折叠区 */
.done-section { margin-bottom: 12px; }
.done-toggle {
  width: 100%;
  background: #eef4fb;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  text-align: left;
  font-weight: 600;
}
.done-list { margin-top: 4px; }

/* 待办卡片 */
.todo-list { list-style: none; }
.todo-item {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.priority-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.priority-dot.high { background: #dc4c4c; }
.priority-dot.mid { background: #e8890c; }
.priority-dot.low { background: #9aa0a6; }
.priority-dot.none { background: #e4e7eb; }

.todo-main { flex: 1; min-width: 0; }
.todo-task {
  font-size: 15px;
  line-height: 1.45;
  word-break: break-all;
  color: var(--text);
}
.todo-item.done .todo-task { color: var(--text-muted); text-decoration: line-through; }
.todo-meta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.tag-status { background: #eef2f7; color: #5b6b7c; }
.tag-status.s-待办 { background: #eef2f7; color: #5b6b7c; }
.tag-status.s-进行中 { background: #eaf2fe; color: #2563eb; }
.tag-status.s-已完成 { background: #e8f5ec; color: #16a34a; }
.tag-status.s-已推迟 { background: #fff4e0; color: #b9791a; }
.tag-status.s-已取消 { background: #f2f2f4; color: #a0a0a0; }
.tag-group { background: #f0f4ff; color: #5b6db0; }
.tag-due { background: #fbf0e6; color: #b9791a; }
.tag-due.overdue { background: #fdeaea; color: #d64545; font-weight: 600; }
.todo-note {
  margin-top: 6px;
  font-size: 12px;
  color: #7a8794;
  word-break: break-all;
  background: #f7f8fa;
  border-radius: 6px;
  padding: 5px 8px;
}

.todo-actions { display: flex; gap: 4px; flex-shrink: 0; }
.chip-btn {
  border: none;
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  background: #eef2f7;
  color: var(--text);
  white-space: nowrap;
}
.chip-btn.done-btn { background: #e8f7ef; color: #2e9e5b; }
.chip-btn.more-btn { padding: 6px 9px; }

/* 空状态 */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}
.empty-icon { font-size: 40px; margin-bottom: 10px; }

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 12px rgba(31,78,121,.35);
  cursor: pointer;
  z-index: 25;
}

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
  font-size: 17px; font-weight: 600;
}
.modal-head .icon-btn { color: var(--text); background: #f0f1f3; }
.modal-body label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 6px;
}
.modal-body label em { color: var(--danger); font-style: normal; }
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  outline: none;
  border-color: var(--primary-light);
}
.modal-err { color: var(--danger); font-size: 13px; margin-top: 10px; }

.seg { display: flex; gap: 6px; }
.seg-priority button {
  flex: 1;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 9px 0;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.seg-priority .seg-p-high.active { background: #dc4c4c; color: #fff; border-color: #dc4c4c; }
.seg-priority .seg-p-mid.active { background: #e8890c; color: #fff; border-color: #e8890c; }
.seg-priority .seg-p-low.active { background: #9aa0a6; color: #fff; border-color: #9aa0a6; }

.modal-foot { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 12px 0;
  font-size: 15px;
  cursor: pointer;
}
.btn-ghost { background: #f0f1f3; color: var(--text); }
.btn-primary { background: var(--primary); color: #fff; font-weight: 600; }
.btn-danger { background: var(--danger); color: #fff; }

/* 底部操作菜单 */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 16px 16px 0 0;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}
.sheet .sheet-task {
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}
.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 14px 18px;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid #f4f5f7;
}
.sheet-item:active { background: #f6f8fa; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { text-align: center; color: var(--text-muted); font-size: 14px; }

/* toast */
.toast {
  position: fixed;
  left: 50%; bottom: 100px;
  transform: translateX(-50%);
  background: rgba(0,0,0,.78);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 40;
  max-width: 80vw;
}