:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #16181d;
  --sub: #8a8f9a;
  --line: #eceef2;
  --green: #22c55e;
  --green-soft: #e8f8ee;
  --orange: #f97316;
  --blue: #3b82f6;
  --purple: #8b5cf6;
  --red: #ef4444;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

#app { padding-bottom: calc(72px + var(--safe-b)); max-width: 560px; margin: 0 auto; }
.hidden { display: none !important; }
.muted { color: var(--sub); font-size: 13px; font-weight: 400; }

/* ---- 顶栏 ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 18px 12px;
}
.topbar .date { font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.topbar .sub { font-size: 13px; color: var(--sub); margin-top: 2px; }
.ghost-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
}

/* ---- 目标进度卡 ---- */
.goal-card {
  background: var(--card); border-radius: var(--radius);
  margin: 0 14px 14px; padding: 18px;
  box-shadow: 0 1px 3px rgba(16,24,40,.04);
}
.goal-top { display: flex; justify-content: space-between; align-items: flex-start; }
.goal-title { font-size: 13px; color: var(--sub); }
.goal-sub { font-size: 24px; font-weight: 700; margin-top: 3px; }
.streak { text-align: right; }
.streak b { display: block; font-size: 22px; color: var(--orange); line-height: 1.1; }
.streak i { font-style: normal; font-size: 11px; color: var(--sub); }

.progress-bar {
  height: 9px; background: #f0f2f5; border-radius: 999px;
  margin: 14px 0 8px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, #4ade80, #22c55e);
  transition: width .5s cubic-bezier(.3,.9,.4,1);
}
.goal-marks { display: flex; justify-content: space-between; font-size: 11px; color: var(--sub); }
.goal-marks span:last-child { color: var(--green); font-weight: 600; }

.week-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 16px; }
.wd { text-align: center; }
.wd .box {
  height: 30px; border-radius: 8px; background: #f0f2f5;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #aeb3bd; font-weight: 600;
}
.wd .box.has { color: #fff; }
.wd .box.today { outline: 2px solid var(--text); outline-offset: 1px; }
.wd .lb { font-size: 10px; color: var(--sub); margin-top: 4px; }
.wd .lb.now { color: var(--text); font-weight: 700; }

.estimate {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--sub); text-align: center; line-height: 1.5;
}

/* ---- 卡片 ---- */
.ring-card, .list-card {
  background: var(--card); border-radius: var(--radius);
  margin: 0 14px 14px; padding: 18px;
  box-shadow: 0 1px 3px rgba(16,24,40,.04);
}

/* ---- 环形进度 ---- */
.ring-wrap { position: relative; width: 160px; height: 160px; margin: 4px auto 14px; }
#ringCanvas { width: 160px; height: 160px; }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.ring-num { font-size: 30px; font-weight: 700; line-height: 1.1; }
.ring-label { font-size: 12px; color: var(--sub); margin-top: 3px; }

.ring-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { text-align: center; }
.stat b { display: block; font-size: 16px; font-weight: 700; }
.stat i { font-style: normal; font-size: 11px; color: var(--sub); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-bottom: 4px; }
.dot.in { background: var(--orange); }
.dot.base { background: var(--blue); }
.dot.out { background: var(--green); }
.dot.gap { background: var(--purple); }

/* ---- 快捷按钮 ---- */
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 14px 14px; }
.qbtn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 14px 10px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 0 1px 3px rgba(16,24,40,.04);
}
.qbtn:active { transform: scale(.97); }
.qbtn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.qbtn .ico { font-size: 17px; }

/* ---- 列表 ---- */
.list-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 15px; font-weight: 600; margin-bottom: 10px;
}
.rec-list { display: flex; flex-direction: column; gap: 8px; }
.rec {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
}
.rec .r-ico { font-size: 18px; width: 24px; text-align: center; }
.rec .r-main { flex: 1; min-width: 0; }
.rec .r-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .r-meta { font-size: 12px; color: var(--sub); margin-top: 2px; }
.rec .r-cal { font-weight: 700; font-size: 15px; color: var(--orange); white-space: nowrap; }
.rec .r-cal.burn { color: var(--green); }
.rec .r-del { border: none; background: none; color: var(--sub); font-size: 17px; padding: 0 2px; }
.empty-tip { color: var(--sub); font-size: 13px; text-align: center; padding: 18px 0; }

/* ---- 拍照页 ---- */
.cam-body { padding: 0 14px; }
.empty-state { text-align: center; padding: 34px 16px; }
.empty-ico { font-size: 54px; margin-bottom: 10px; }
.empty-state p { margin: 3px 0; font-weight: 600; }
.empty-state p.sub { font-weight: 400; font-size: 13px; color: var(--sub); margin-bottom: 22px; }
.big-btn {
  display: block; width: 100%; border: none; background: var(--green); color: #fff;
  padding: 15px; border-radius: 14px; font-size: 16px; font-weight: 600; margin-top: 10px;
}
.big-btn:active { opacity: .88; }
.big-btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.big-btn.danger { background: var(--card); color: var(--red); border: 1px solid #fecaca; }
/* 拍照 / 相册 两个入口并排等宽 */
.cam-actions { display: flex; gap: 10px; }
.cam-actions .big-btn { flex: 1; min-width: 0; padding: 15px 6px; font-size: 15px; }
.or-line { position: relative; text-align: center; margin: 22px 0 14px; color: var(--sub); font-size: 12px; }
.or-line::before {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  border-top: 1px solid var(--line); z-index: 0;
}
.or-line span { position: relative; background: var(--bg); padding: 0 12px; }
.kw-row { display: flex; gap: 8px; }
.kw-row input {
  flex: 1; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px 14px; font-size: 15px; color: var(--text);
}
.mini-btn {
  border: none; background: var(--text); color: #fff;
  border-radius: 12px; padding: 0 18px; font-size: 14px; font-weight: 600;
}

.preview-wrap { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
#previewImg { width: 100%; max-height: 300px; object-fit: cover; display: block; background: #ddd; }
.retake {
  position: absolute; right: 10px; bottom: 10px;
  background: rgba(0,0,0,.6); color: #fff; border: none;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
}

.result-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 3px rgba(16,24,40,.04); margin-bottom: 14px;
}
.result-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.result-head .t { font-weight: 700; font-size: 15px; }
.result-head .total { color: var(--orange); font-weight: 700; font-size: 18px; }
.channel-tag {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--green-soft); color: #16a34a; font-weight: 600; margin-left: 6px;
}
.channel-tag.warn { background: #fff7ed; color: #c2410c; }
.res-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-bottom: 9px;
}
.res-item .ri-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.res-item .ri-name { font-weight: 600; flex: 1; }
.res-item .ri-cal { font-weight: 700; color: var(--orange); }
.res-item .ri-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.res-item label { font-size: 11px; color: var(--sub); display: block; margin-bottom: 3px; }
.res-item input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font-size: 14px; background: #fafbfc; color: var(--text);
}
.res-item .ri-nut { font-size: 11px; color: var(--sub); margin-top: 7px; }
.res-item.off { opacity: .45; }
.conf-low { color: #c2410c; font-size: 11px; margin-left: 4px; }

.loading-state { text-align: center; padding: 60px 0; color: var(--sub); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 16px;
  border: 3px solid var(--line); border-top-color: var(--green);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 图表 ---- */
.chart-wrap { width: 100%; height: 170px; }
.chart-wrap canvas { width: 100%; height: 170px; }
.tip { font-size: 12px; color: var(--sub); margin-top: 10px; text-align: center; }

/* ---- 三大营养素卡 ---- */
.macro-card {
  background: var(--card); border-radius: var(--radius);
  margin: 0 14px 14px; padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(16,24,40,.04);
}
.macro-row { margin-top: 12px; }
.macro-row:first-of-type { margin-top: 8px; }
.macro-label { font-size: 13px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.macro-label b { font-weight: 700; color: var(--text); }
.macro-label .muted { margin-left: auto; font-weight: 400; }
.mdot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.mdot.p { background: var(--green); }
.mdot.f { background: var(--orange); }
.mdot.c { background: var(--blue); }
.macro-bar { height: 9px; background: #f0f2f5; border-radius: 999px; overflow: hidden; }
.macro-fill { height: 100%; width: 0; border-radius: 999px; transition: width .5s cubic-bezier(.3,.9,.4,1); }
.macro-fill.p { background: var(--green); }
.macro-fill.f { background: var(--orange); }
.macro-fill.c { background: var(--blue); }
.macro-fill.over { background: var(--red); }

/* ---- 拍照页模式切换 ---- */
.cam-tabs { display: flex; gap: 8px; margin: 4px 0 14px; }
.cam-tab {
  flex: 1; border: 1px solid var(--line); background: #fafbfc; color: var(--sub);
  padding: 11px; border-radius: 12px; font-size: 14px; font-weight: 600; font-family: inherit;
}
.cam-tab.on { background: var(--text); color: #fff; border-color: var(--text); }
.label-tip { text-align: left; margin-top: 14px; line-height: 1.55; }

/* ---- 标签识别结果 ---- */
.lb-info {
  font-size: 12px; color: var(--sub); background: #fafbfc; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; line-height: 1.55;
}
.calc-box .neg { color: var(--red); }

/* ---- 表单 ---- */
.form { display: flex; flex-direction: column; gap: 13px; }
.form label { font-size: 13px; color: var(--sub); display: block; }
.form input, .form select {
  width: 100%; border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px; font-size: 15px; margin-top: 5px;
  background: #fafbfc; color: var(--text); font-family: inherit;
}
.seg { display: flex; gap: 8px; margin-top: 5px; }
.seg button {
  flex: 1; border: 1px solid var(--line); background: #fafbfc; color: var(--text);
  padding: 10px; border-radius: 11px; font-size: 14px;
}
.seg button.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.calc-box {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  background: #fafbfc; border-radius: 12px; padding: 14px 8px; text-align: center;
}
.calc-box b { display: block; font-size: 17px; }
.calc-box i { font-style: normal; font-size: 11px; color: var(--sub); }

/* ---- 底部导航 ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar .tab {
  flex: 1; border: none; background: none; color: var(--sub);
  padding: 8px 0 9px; font-size: 11px; display: flex;
  flex-direction: column; align-items: center; gap: 3px; font-family: inherit;
}
.tabbar .tab span { font-size: 20px; }
.tabbar .tab.on { color: var(--green); font-weight: 600; }

/* ---- 弹层 ---- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0 } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(22px + var(--safe-b));
  max-height: 82vh; overflow-y: auto;
  animation: up .25s cubic-bezier(.2,.8,.3,1);
}
@keyframes up { from { transform: translateY(100%) } }
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0 14px; font-size: 16px; font-weight: 700;
  position: sticky; top: 0; background: var(--card);
}
.sheet-head button { border: none; background: none; font-size: 19px; color: var(--sub); padding: 0 4px; }
.sheet-body { padding-bottom: 8px; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-b)); z-index: 60;
  background: rgba(22,24,29,.92); color: #fff;
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  max-width: 80%; text-align: center; animation: fade .2s ease;
}
