:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --line: #e6eaf1;
  --text: #1c1f26;
  --muted: #8a92a3;
  --blue: #3478f6;
  --blue-soft: #e3edff;
  --carb: #3ecfb2;
  --fat: #9d5ce6;
  --protein: #f6a53c;
  --red: #e5484d;
  --radius: 20px;
  --shadow: 0 4px 18px rgba(31, 45, 80, .06);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100vh; }
/* hidden 属性优先级最高：防止 display:grid/flex 等类覆盖导致"隐藏失效" */
[hidden] { display: none !important; }

.view[hidden] { display: none; }
.muted { color: var(--muted); font-size: 13px; }
i { font-style: normal; }

/* ---------- 登录页 ---------- */
.login-hero {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 32px;
}
.login-hero .logo { font-size: 64px; margin-bottom: 12px; }
.login-hero h1 { font-size: 32px; font-weight: 800; }
.login-hero .sub { color: var(--muted); margin: 14px 0 36px; line-height: 1.7; }
.login-hero .foot { margin-top: 28px; color: var(--muted); font-size: 12px; }

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 14px; cursor: pointer;
  padding: 12px 20px; font-size: 15px; font-weight: 600; color: var(--text);
  background: #f1f4f9; transition: opacity .15s;
}
.btn:active { opacity: .75; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.big { width: 100%; padding: 16px; font-size: 17px; border-radius: 16px; }
.btn.ghost { background: #f1f4f9; color: var(--muted); }
.btn.danger { background: #fdeeec; color: var(--red); }
.btn.small { padding: 8px 14px; font-size: 13px; }
.btn.wide { width: 100%; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; margin: 0 16px 14px; box-shadow: var(--shadow);
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px 4px;
}
.date-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 26px; font-weight: 800; color: var(--text);
  display: flex; align-items: center; gap: 8px; padding: 0;
}
.date-btn .caret { width: 19px; height: 19px; color: var(--muted); margin-top: 4px; }
.more-btn {
  border: none; background: transparent; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 6px 10px; border-radius: 10px;
}
.more-btn:active { background: #e6eaf1; }

/* ---------- 周打卡条 ---------- */
.week-strip {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 22px 6px; gap: 4px;
}
.week-strip .wd { display: flex; flex-direction: column; align-items: center; gap: 7px; flex: 1; }
.week-strip .wd .lb { font-size: 12px; color: var(--muted); }
.week-strip .wd .dot {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid #d4dae4; background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: transparent; cursor: pointer;
}
.week-strip .wd .dot.logged { background: #dce9ff; border-color: #dce9ff; }
.week-strip .wd .dot.sel {
  background: var(--blue); border-color: var(--blue); color: #fff;
}
.page { padding-bottom: 120px; }

/* ---------- 卡路里 / 营养素卡 ---------- */
.kcal-title { color: var(--muted); font-size: 14px; }
.kcal-row { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 0 12px; }
.kcal-now { font-size: 15px; color: var(--muted); }
.kcal-now b { font-size: 30px; font-weight: 800; color: var(--text); margin-right: 4px; }
.kcal-left { color: var(--muted); font-size: 13px; }
.kcal-left b { color: var(--text); font-size: 16px; }
.m-goal { font-size: 12px; color: var(--muted); }
.m-goal i { color: var(--text); font-weight: 600; }
.bar.track {
  height: 8px; border-radius: 5px; background: #edf0f5; overflow: hidden;
}
.bar.fill { height: 100%; border-radius: 5px; width: 0; transition: width .4s ease; }
.bar.fill.kcal { background: var(--blue); }
.bar.fill.carb { background: var(--carb); }
.bar.fill.fat { background: var(--fat); }
.bar.fill.protein { background: var(--protein); }

.macro-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.macro-col .m-name { color: var(--muted); font-size: 13px; }
.macro-col .m-val { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.macro-col .m-val b { font-size: 17px; font-weight: 800; color: var(--text); }

/* ---------- 餐饮 ---------- */
.meals-sec { margin: 20px 16px 0; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; padding: 0 2px; }
.sec-head h2 { font-size: 19px; font-weight: 800; }
.sec-head a { color: var(--blue); font-size: 13.5px; font-weight: 600; text-decoration: none; }
.meal-type-card {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  padding: 15px 16px; margin-bottom: 12px;
}
.mt-head { display: flex; justify-content: space-between; align-items: center; }
.mt-head .mt-name { font-size: 16.5px; font-weight: 800; }
.mt-actions { display: flex; align-items: center; gap: 10px; }
.mt-more { color: var(--muted); border: none; background: transparent; font-size: 16px; cursor: pointer; padding: 2px 6px; }
.mt-add {
  border: none; cursor: pointer; background: var(--blue-soft); color: var(--blue);
  font-size: 13px; font-weight: 700; padding: 7px 16px; border-radius: 999px;
}
.mt-add:active { opacity: .75; }
.mt-meal {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px 2px; cursor: pointer;
}
.mt-meal + .mt-meal { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 12px; }
.mt-thumb { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; background: #f1f4f9; flex-shrink: 0; }
.mt-info { flex: 1; min-width: 0; }
.mt-foods { font-size: 14px; color: var(--text); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mt-kcal { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.mt-empty { color: var(--muted); font-size: 13px; padding-top: 10px; }

/* ---------- 统计 ---------- */
.seg { display: flex; gap: 6px; padding: 5px; }
.seg-btn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 9px; border-radius: 12px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.seg-btn.active { background: var(--blue-soft); color: var(--blue); }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; }
.stat-label { font-weight: 700; }
.stat-macros { display: flex; gap: 18px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.stat-macros b { color: var(--text); }
.card h3 { font-size: 15px; font-weight: 800; margin-bottom: 14px; }
.chart { display: flex; align-items: flex-end; gap: 5px; height: 150px; }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; }
.chart .bar {
  width: 100%; max-width: 26px; border-radius: 6px 6px 3px 3px;
  background: var(--blue); min-height: 3px;
}
.chart .bar.zero { background: #edf0f5; }
.chart .bar-label { color: var(--muted); font-size: 10px; margin-top: 6px; white-space: nowrap; }
.chart .bar-val { color: var(--muted); font-size: 9.5px; margin-bottom: 3px; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.history-item .d { font-weight: 700; font-size: 14.5px; }
.history-item .d small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }
.history-item .t { text-align: right; }
.history-item .t .k { color: var(--blue); font-weight: 800; font-size: 16px; }
.history-item .t .m { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------- 更多 ---------- */
.more-card { display: flex; flex-direction: column; gap: 16px; }
.more-user { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 16px; }
.more-user .avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--blue-soft);
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.more-card .foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 4px; }

/* ---------- 底部导航 ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: center; align-items: center; gap: 14px;
  padding: 0 20px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.nav-pill {
  pointer-events: auto;
  background: #fff; border-radius: 999px; box-shadow: 0 8px 30px rgba(31,45,80,.16);
  display: flex; padding: 8px; flex: 1; max-width: 420px;
}
.nav-btn {
  flex: 1; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
  padding: 7px 0; border-radius: 999px;
}
.nav-btn .ic { width: 23px; height: 23px; }
.nav-btn.active { background: #eaf2ff; color: var(--blue); }

/* ---------- 目标设置 ---------- */
.goal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0 16px; }
.goal-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.goal-field span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.goal-field input {
  background: #f7f9fc; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 10px 12px; font-size: 15px; font-weight: 700; width: 100%;
  min-width: 0; -webkit-appearance: none; appearance: none;
}
/* iOS 原生日期输入统一样式，防止固有宽度撑爆网格 */
input[type="date"] { min-height: 44px; font-weight: 600; font-size: 14px; }
.export-range {
  display: flex; align-items: flex-end; gap: 8px; margin: 12px 0 16px;
}
.export-range .rf { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.export-range .rf span { font-size: 12px; color: var(--muted); font-weight: 600; }
.export-range .rf input {
  background: #f7f9fc; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 10px 10px; width: 100%; min-width: 0;
  -webkit-appearance: none; appearance: none; min-height: 42px;
  font-weight: 600; font-size: 14px;
}
.export-range .rf-sep { color: var(--muted); font-weight: 600; padding-bottom: 11px; }

/* ---------- 日历弹层 ---------- */
.popover { position: fixed; inset: 0; z-index: 60; }
.popover[hidden] { display: none; }
.pop-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .35); }
.cal-card {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  width: min(92vw, 360px); background: #fff; border-radius: 22px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, .22); padding: 18px;
}
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cal-head b { font-size: 16px; }
.cal-nav { display: flex; gap: 6px; }
.cal-nav-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer;
  background: #f1f4f9; color: var(--text); font-size: 17px;
}
.cal-weekrow { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 4px; }
.cal-cell {
  position: relative; height: 40px; display: flex; align-items: center; justify-content: center;
  font-size: 14.5px; cursor: pointer; border-radius: 50%; font-weight: 500;
}
.cal-cell:active { background: #f1f4f9; }
.cal-cell.dim { color: #c3cad6; }
.cal-cell.sel { background: var(--blue); color: #fff; font-weight: 700; }
.cal-cell .rdot {
  position: absolute; bottom: 3px; width: 4px; height: 4px; border-radius: 50%;
  background: var(--blue);
}
.cal-cell.sel .rdot { background: #fff; }

/* ---------- 餐次弹层 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.modal-body {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 0; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 18px 18px calc(26px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.modal-img { width: 100%; max-height: 240px; object-fit: cover; border-radius: 16px; }
.modal-meta { display: flex; gap: 8px; align-items: center; }
.modal-meta select, .modal-meta input {
  background: #fff; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font-size: 14px;
}
#modal-delete { margin-left: auto; }

#modal-items { display: flex; flex-direction: column; gap: 10px; }
.item-row { background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.item-row .line1 { display: flex; justify-content: space-between; gap: 8px; }
.item-row .name { font-weight: 700; flex: 1; min-width: 0; }
.item-row .kcal { color: var(--blue); font-weight: 800; flex-shrink: 0; }
.item-row .portion { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.item-row .macros { display: flex; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 6px; }
.item-row .item-actions { display: flex; gap: 8px; margin-top: 8px; }
.item-row .mini-btn {
  background: #f1f4f9; border: none; color: var(--muted); border-radius: 9px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; font-weight: 600;
}
.item-row .mini-btn.del { color: var(--red); background: #fdeeec; }
.item-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.item-edit input {
  background: #f7f9fc; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; width: 100%;
}
.item-edit input.k { grid-column: 1 / -1; }
.item-edit .act-save { background: #f1f4f9; color: var(--muted); transition: all .15s; }
.item-edit .act-save.dirty { background: var(--blue); color: #fff; }

/* ---------- 记录面板 ---------- */
.sheet-body { gap: 14px; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; }
.sheet-head b { font-size: 18px; font-weight: 800; }
.chip-row { display: flex; gap: 8px; }
.chip {
  flex: 1; border: 1.5px solid var(--line); background: #fff; color: var(--muted);
  padding: 10px 6px; border-radius: 12px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.chip.active { background: var(--blue-soft); border-color: var(--blue-soft); color: var(--blue); }
.time-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow);
}
.time-row span { font-weight: 600; font-size: 15px; }
.time-row input {
  border: none; background: transparent; font-size: 16px; font-weight: 700;
  color: var(--blue); font-family: inherit; text-align: right;
}
.btn.lib { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%);
  background: #262b36; color: #fff; padding: 11px 20px;
  border-radius: 12px; font-size: 14px; z-index: 99; max-width: 86vw; text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
