:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-soft: #d1fae5;
  --accent: #0ea5e9;
  --warn: #f59e0b;
  --danger: #ef4444;
  --bg: #f3f7f6;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --shadow: 0 6px 20px rgba(16, 185, 129, .08);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { 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", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 18px 12px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #34d399, #059669);
  color: #fff; font-size: 16px; line-height: 1;
}
.brand-text { font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.page-subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; }
.sync-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: #f3f4f6; color: var(--muted); font-size: 11px; white-space: nowrap;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; }
.sync-badge.online { background: var(--primary-soft); color: var(--primary-dark); }
.sync-badge.online .sync-dot { background: var(--primary); }
.sync-badge.offline { background: #fef3c7; color: #92400e; }
.sync-badge.offline .sync-dot { background: var(--warn); }
.sync-badge.error { background: #fee2e2; color: #991b1b; }
.sync-badge.error .sync-dot { background: var(--danger); }

/* 主区域与底部导航 */
.view { padding: 16px 16px calc(92px + var(--safe-bottom)); max-width: 680px; margin: 0 auto; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 9px 0 8px; color: var(--muted); font-size: 11px;
  transition: color .18s;
}
.tab-icon { font-size: 19px; line-height: 1; }
.tab.active { color: var(--primary-dark); font-weight: 700; }
.tab.active .tab-icon { transform: translateY(-1px); }

/* 通用卡片与排版 */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
  border: 1px solid rgba(229, 231, 235, .7);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.card-title .dot { width: 6px; height: 18px; border-radius: 4px; background: var(--primary); }
.card-sub { font-size: 12px; color: var(--muted); }
.section-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 2px 10px; }
.greeting { font-size: 21px; font-weight: 800; margin: 4px 0 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.text-right { text-align: right; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 11px; font-size: 13px; font-weight: 600;
  background: #f3f4f6; color: var(--text); transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(16,185,129,.25); }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--text); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 9px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: #f3f4f6; color: var(--muted); font-size: 15px;
}
.icon-btn.danger { color: var(--danger); background: #fee2e2; }

/* 今日进度 */
.hero {
  background: linear-gradient(135deg, #10b981 0%, #059669 60%, #047857 100%);
  color: #fff; border-radius: 20px; padding: 18px;
  box-shadow: 0 10px 24px rgba(5, 150, 105, .22); margin-bottom: 14px;
}
.hero .between { align-items: center; }
.hero-title { font-size: 13px; opacity: .88; }
.hero-sub { font-size: 12px; opacity: .78; margin-top: 3px; }
.ring-wrap { position: relative; width: 88px; height: 88px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-label {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 20px; font-weight: 800;
}
.ring-label small { font-size: 10px; font-weight: 500; opacity: .85; }

/* 指标网格 */
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric {
  background: var(--card); border-radius: 14px; padding: 12px;
  border: 1px solid rgba(229,231,235,.7);
}
.metric-label { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.metric-value { font-size: 20px; font-weight: 800; margin-top: 4px; }
.metric-value span { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 2px; }

/* 计划/打卡行 */
.plan-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
.plan-row:last-child { border-bottom: 0; }
.plan-icon {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 18px;
  background: var(--primary-soft);
}
.plan-name { font-weight: 650; font-size: 14px; }
.plan-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.plan-value { font-size: 12px; font-weight: 700; color: var(--primary-dark); }
.check-btn {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid #d1d5db; display: grid; place-items: center;
  color: transparent; font-size: 15px; font-weight: 800;
  transition: all .16s;
}
.check-btn.done { background: var(--primary); border-color: var(--primary); color: #fff; }
.step-group { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.step-btn {
  width: 28px; height: 28px; border-radius: 9px; background: var(--primary-soft);
  color: var(--primary-dark); font-weight: 800; font-size: 16px; line-height: 1;
}
.step-btn:disabled { opacity: .35; }
.mini-progress { height: 5px; background: #eef2f1; border-radius: 99px; margin-top: 6px; overflow: hidden; }
.mini-progress > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .25s; }

/* 筛选 chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip {
  padding: 6px 13px; border-radius: 999px; background: #fff; border: 1px solid var(--line);
  font-size: 12px; white-space: nowrap; color: var(--muted);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* 表单 */
.form-row { margin-bottom: 13px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%; border: 1px solid #d9ded9; border-radius: 11px;
  padding: 10px 12px; background: #fff; outline: none; font-size: 14px;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(16,185,129,.12); }
.textarea { min-height: 76px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.week-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.week-picker button {
  padding: 8px 0; border-radius: 9px; background: #f3f4f6; font-size: 12px; color: var(--muted);
}
.week-picker button.on { background: var(--primary); color: #fff; font-weight: 700; }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 26px; height: 26px; border-radius: 50%; border: 3px solid transparent; }
.color-dot.on { border-color: #111827; transform: scale(1.08); }
.switch {
  width: 44px; height: 25px; border-radius: 99px; background: #d1d5db; position: relative;
  transition: background .2s; flex-shrink: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(19px); }

/* 弹窗 */
.modal-root {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(17, 24, 39, .45); backdrop-filter: blur(2px);
}
.modal {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: #fff; border-radius: 20px 20px 0 0; padding: 18px 18px calc(20px + var(--safe-bottom));
  animation: slideUp .22s ease-out;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 17px; font-weight: 800; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translate(-50%, 12px);
  background: rgba(17,24,39,.92); color: #fff; padding: 9px 16px; border-radius: 10px;
  font-size: 13px; z-index: 80; opacity: 0; pointer-events: none; transition: all .2s;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 统计图表 */
.chart { display: flex; align-items: flex-end; gap: 5px; height: 130px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.chart-bar {
  width: 100%; max-width: 22px; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #34d399, #059669); min-height: 3px;
  transition: height .3s;
}
.chart-label { font-size: 9px; color: var(--muted); white-space: nowrap; }
.bar-row { margin-bottom: 11px; }
.bar-track { height: 8px; background: #eef2f1; border-radius: 99px; overflow: hidden; margin-top: 5px; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .3s; }
.weight-chart { width: 100%; height: 120px; overflow: visible; }
.weight-chart polyline { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.weight-chart circle { fill: #fff; stroke: var(--primary); stroke-width: 2; }
.weight-chart text { fill: var(--muted); font-size: 8px; }

/* 空状态 */
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty-icon { font-size: 34px; opacity: .45; }
.empty p { margin: 8px 0 14px; font-size: 13px; }

/* 日期切换 */
.date-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.date-nav .current { font-weight: 700; font-size: 15px; }
.date-nav input[type="date"] {
  border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px; background: #fff; font-size: 12px;
}

/* 个人资料 */
.avatar {
  width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, #34d399, #059669); color: #fff; font-size: 24px; font-weight: 800;
}
.bmi-badge { padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--primary-soft); color: var(--primary-dark); }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: #f3f4f6; }
.list-arrow { color: #9ca3af; }

@media (min-width: 600px) {
  .view { padding-left: 24px; padding-right: 24px; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-root { align-items: center; }
  .modal { border-radius: 20px; padding-bottom: 20px; }
}
