:root {
  --bg: #f4f5f4; --card: #ffffff; --card2: #f0f2f0; --text: #17201b; --muted: #6f7b75; --faint: #a3ada7; --line: #e6e9e7;
  --accent: #1f7a4d; --accent-soft: #e3f1e9; --good: #1f7a4d; --good-soft: #e3f1e9; --warn: #b7791f; --warn-soft: #fbf1dc; --danger: #b93a2f; --danger-soft: #fae6e3; --info: #3b6b8f; --info-soft: #e5eef5;
  --pill: #eef1ef; --pill-on: #17201b; --pill-on-text: #ffffff; --cell-empty: #e6e9e7;
  --radius: 16px; --tab-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1310; --card: #171d19; --card2: #1f2722; --text: #e8ece9; --muted: #98a39d; --faint: #626c66; --line: #262e29;
    --accent: #4fbf86; --accent-soft: #163224; --good: #4fbf86; --good-soft: #163224; --warn: #e0b04f; --warn-soft: #33290f; --danger: #ef6e60; --danger-soft: #3a1c18; --info: #7fb0d6; --info-soft: #172733;
    --pill: #232b26; --pill-on: #e8ece9; --pill-on-text: #0e1310; --cell-empty: #262e29;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1310; --card: #171d19; --card2: #1f2722; --text: #e8ece9; --muted: #98a39d; --faint: #626c66; --line: #262e29;
  --accent: #4fbf86; --accent-soft: #163224; --good: #4fbf86; --good-soft: #163224; --warn: #e0b04f; --warn-soft: #33290f; --danger: #ef6e60; --danger-soft: #3a1c18; --info: #7fb0d6; --info-soft: #172733;
  --pill: #232b26; --pill-on: #e8ece9; --pill-on-text: #0e1310; --cell-empty: #262e29;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans CJK SC", sans-serif; font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
.ic svg, .iconbtn svg, .tabbar button svg, .thumb > svg, .st svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button { font-family: inherit; }

/* 顶栏 */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); }
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 600; }
.topactions { display: flex; gap: 2px; }
.iconbtn { width: 38px; height: 38px; border: 0; background: none; color: var(--muted); border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.iconbtn:active { background: var(--card2); }

/* 横幅 */
#banner { padding: 4px 16px 10px; max-width: 640px; margin: 0 auto; }
.datenav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.datenav b { font-size: 15px; font-weight: 600; }
.datenav .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.datenav button { width: 34px; height: 34px; border: 0; background: var(--card); color: var(--text); border-radius: 50%; font-size: 18px; }
.datenav button:disabled { opacity: .3; }
.hero { display: flex; align-items: baseline; gap: 8px; }
.hero .n { font-size: 36px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.hero .n.empty { color: var(--faint); font-weight: 500; }
.hero .u { color: var(--muted); font-size: 13px; }
.chip { margin-left: auto; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card2); color: var(--muted); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.prog { margin-top: 8px; }
.prog .bar { height: 6px; border-radius: 3px; background: var(--card2); position: relative; margin: 6px 6px 0; }
.prog .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 3px; }
.prog .bar b { position: absolute; top: -4px; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 3px solid var(--accent); margin-left: -7px; box-sizing: border-box; }
.prog .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 4px; }

/* 主体 */
main { padding: 0 16px 24px; max-width: 640px; margin: 0 auto; }
.sec { margin: 14px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .3px; display: flex; justify-content: space-between; align-items: center; }
.sec small { font-weight: 400; }
.card { background: var(--card); border-radius: var(--radius); padding: 2px 14px; margin-bottom: 10px; }
.card.pad { padding: 14px; }
.card h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }

/* 行 */
.row { border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-h { display: flex; align-items: center; gap: 12px; padding: 12px 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.row-h .ic { color: var(--muted); display: inline-flex; flex: 0 0 22px; }
.row-h .lbl { flex: 1; font-size: 15px; }
.row-h .val { color: var(--muted); font-size: 14px; text-align: right; max-width: 55%; font-variant-numeric: tabular-nums; }
.row-h .val .tag { font-size: 11px; color: var(--faint); margin-left: 4px; }
.row-h .st { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line); flex: 0 0 22px; display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.row-h .st svg { width: 14px; height: 14px; stroke-width: 2.6; }
.row-h .st.done { background: var(--good); border-color: var(--good); }
.row-h .st.bad { background: var(--danger); border-color: var(--danger); font-size: 12px; }
.row-h .st.na { border-style: dashed; }
.row-b { display: none; padding: 0 0 12px 34px; }
.row.open .row-b { display: block; }
.row.toggle .row-h { cursor: default; }
.row.toggle input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); margin: 0; }

/* 控件 */
label.chk { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 15px; }
label.chk input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
label.num { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 14px; color: var(--muted); }
label.num input, .bp input, input[type=date], input[type=text], input[type=password], textarea { font-size: 16px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card2); color: var(--text); font-family: inherit; }
label.num input { width: 120px; text-align: right; }
label.num input:focus, .bp input:focus, textarea:focus, input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.bp { display: grid; grid-template-columns: 30px 1fr 1fr 1fr; gap: 6px; align-items: center; padding: 4px 0; font-size: 13px; color: var(--muted); }
.bp input { width: 100%; text-align: center; padding: 8px 4px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; }
.seg button { border: 0; background: var(--pill); color: var(--text); border-radius: 999px; padding: 8px 13px; font-size: 14px; }
.seg button.on { background: var(--pill-on); color: var(--pill-on-text); }
.seg button.bad.on { background: var(--danger); color: #fff; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper b { min-width: 76px; text-align: center; font-size: 16px; font-variant-numeric: tabular-nums; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--pill); color: var(--text); font-size: 20px; line-height: 1; }
textarea { width: 100%; min-height: 64px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn { border: 0; background: var(--pill-on); color: var(--pill-on-text); border-radius: 12px; padding: 11px 16px; font-size: 15px; font-weight: 600; }
.btn.secondary { background: var(--pill); color: var(--text); font-weight: 500; }
.btn.danger { background: var(--danger-soft); color: var(--danger); font-weight: 500; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btns label.btn { display: inline-block; cursor: pointer; }
.btns label.btn input { display: none; }
.field { padding: 6px 0; }
.field .lbl { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type=password], .field input[type=text], .field input[type=date] { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* 照片与识别 */
.photo-line { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0 8px; }
.thumb { width: 64px; height: 64px; border-radius: 12px; background: var(--card2); flex: 0 0 64px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--faint); position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: none; }
.thumb img.has { display: block; }
.thumb label { position: absolute; inset: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.thumb input { display: none; }
.thumb.busy::after { content: ''; position: absolute; inset: 0; background: rgba(255,255,255,.55); }
.ai { flex: 1; font-size: 13px; color: var(--muted); line-height: 1.4; }
.ai b { color: var(--text); font-weight: 600; }
.ai .kcal { color: var(--accent); font-weight: 600; }

/* 指标块 */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tiles.four { grid-template-columns: repeat(4, 1fr); }
.tile { background: var(--card); border-radius: 14px; padding: 10px 12px; }
.tile small { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile b em { font-style: normal; font-size: 12px; color: var(--faint); font-weight: 500; }
.tile .mini { height: 4px; border-radius: 2px; background: var(--card2); margin-top: 6px; overflow: hidden; }
.tile .mini i { display: block; height: 100%; background: var(--accent); }
.tile.ok b { color: var(--good); }

/* 提示 */
.alerts { margin: 8px 0 2px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; font-size: 13px; background: var(--info-soft); color: var(--text); }
.alert b { display: block; font-size: 14px; margin-bottom: 1px; }
.alert p { margin: 0; color: var(--muted); }
.alert.danger { background: var(--danger-soft); } .alert.danger b { color: var(--danger); }
.alert.warn { background: var(--warn-soft); } .alert.warn b { color: var(--warn); }
.alert.info { background: var(--info-soft); } .alert.info b { color: var(--info); }
.alert.good { background: var(--good-soft); } .alert.good b { color: var(--good); }
.suggest { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; border-left: 4px solid var(--accent); }
.suggest b { display: block; font-size: 15px; margin-bottom: 4px; }
.suggest p { margin: 0; font-size: 13px; color: var(--muted); }
.suggest.gout { border-color: var(--danger); }
.suggest.done { border-color: var(--good); }

/* 图表 */
.chart { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; }
.chart .hline { stroke: var(--faint); stroke-dasharray: 3 3; stroke-width: 1; }
.chart .hlabel { fill: var(--muted); font-size: 10px; }
.chart .chart-empty { fill: var(--muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.strip { display: flex; gap: 3px; }
.strip .cell { flex: 1; height: 14px; border-radius: 3px; }
.range { display: flex; gap: 4px; background: var(--card2); border-radius: 10px; padding: 3px; margin-bottom: 8px; }
.range button { flex: 1; border: 0; background: none; color: var(--muted); border-radius: 8px; padding: 6px; font-size: 13px; }
.range button.on { background: var(--card); color: var(--text); font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 10px 0; list-style: none; display: flex; justify-content: space-between; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: '›'; transform: rotate(90deg); color: var(--faint); }
details[open] summary::after { transform: rotate(-90deg); }
details ul { margin: 0 0 8px; padding-left: 18px; font-size: 13px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list li:last-child { border-bottom: 0; }
.list li span:last-child { color: var(--muted); text-align: right; }
table.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.kv td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 40%; }
table.kv tr:last-child td { border-bottom: 0; }
.score { font-size: 26px; font-weight: 700; }
.kv-inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--line); }
.kv-inline:last-child { border-bottom: 0; }
.kv-inline code { font-size: 11px; word-break: break-all; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }

/* 标签栏 */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 5; }
.tabbar button { flex: 1; border: 0; background: none; color: var(--faint); font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
body.page .tabbar { display: none; }
body.page { padding-bottom: 24px; }

/* 登录门、提示 */
.gate { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate .box { width: 100%; max-width: 360px; background: var(--card); border-radius: var(--radius); padding: 22px 20px; }
.gate h2 { margin: 0 0 6px; font-size: 20px; }
.gate p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.gate input { width: 100%; margin-bottom: 10px; }
.gate .btn { width: 100%; padding: 12px; font-size: 16px; }
.gate .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; max-width: 90vw; }
