:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --bg: #f2f5f7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 16px;
  --tabbar-h: 60px;
  --header-h: 54px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* 顶部 */
.app-header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
  padding-top: env(safe-area-inset-top, 0px);
}
.header-brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.header-logo { font-size: 20px; }

.icon-btn {
  background: none; border: none; color: inherit;
  font-size: 20px; width: 40px; height: 40px;
  border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.app-header .icon-btn:active { background: rgba(255,255,255,.2); }

main {
  padding: 16px 14px;
  padding-bottom: calc(var(--tabbar-h) + 90px + var(--safe-bottom));
  max-width: 560px; margin: 0 auto;
}

/* 日期横幅 */
.date-banner { text-align: center; padding: 8px 0 14px; }
.date-big { font-size: 22px; font-weight: 700; }
.date-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* 汇总卡片 */
.summary-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 16px;
}
.summary-cell {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.summary-cell .sc-value { font-size: 24px; font-weight: 800; line-height: 1.1; }
.summary-cell .sc-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.summary-cell .sc-badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; margin-top: 4px;
}

/* 快捷按钮 */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.quick-btn {
  border: none; border-radius: var(--radius);
  padding: 18px 10px; font-size: 17px; font-weight: 700; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; box-shadow: var(--shadow);
}
.quick-btn .qi { font-size: 30px; }
.quick-btn.meal { background: linear-gradient(135deg, #f59e0b, #f97316); }
.quick-btn.stool { background: linear-gradient(135deg, #14b8a6, #0ea5e9); }
.quick-btn:active { transform: scale(.97); }

/* 分区标题 */
.section-title { font-size: 15px; font-weight: 700; color: var(--muted); margin: 6px 0 10px; }

/* 记录列表 */
.entry-list { display: flex; flex-direction: column; gap: 10px; }
.entry {
  background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 12px;
  position: relative;
}
.entry-emoji { font-size: 24px; flex-shrink: 0; margin-top: 2px; }
.entry-body { flex: 1; min-width: 0; }
.entry-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-main { font-size: 16px; font-weight: 600; word-break: break-word; }
.entry-time { font-size: 12px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.entry-tag {
  font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: #ecfdf5; color: var(--primary-dark);
}
.entry-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.entry-del {
  background: none; border: none; color: #cbd5e1; font-size: 18px;
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer; flex-shrink: 0;
  margin: -4px -8px 0 0;
}
.entry-del:active { background: #fee2e2; color: var(--danger); }

.empty-tip {
  text-align: center; color: #b0b8c1; font-size: 14px;
  padding: 30px 10px;
}

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  max-width: 560px; margin: 0 auto;
}
.tab {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 6px 14px;
}
.tab .ti { font-size: 22px; line-height: 1; }
.tab.active { color: var(--primary); font-weight: 700; }

/* 悬浮按钮 */
.fab {
  position: fixed; right: 20px;
  bottom: calc(var(--tabbar-h) + 20px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 30px; font-weight: 400;
  border: none; box-shadow: 0 4px 14px rgba(16,185,129,.45);
  cursor: pointer; z-index: 25;
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.94); }

/* 弹出层 */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30;
}
.action-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 12px 12px calc(16px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 4px;
  max-width: 560px; margin: 0 auto;
}
.sheet-item {
  background: none; border: none; padding: 16px; font-size: 17px;
  text-align: center; cursor: pointer; border-radius: 12px; color: var(--text);
}
.sheet-item:active { background: var(--bg); }
.sheet-item.sheet-cancel { color: var(--muted); margin-top: 6px; border-top: 1px solid var(--border); border-radius: 0; }

/* 模态框 */
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0;
  max-height: 88vh; overflow-y: auto;
  padding-bottom: var(--safe-bottom);
}
.modal-card-sm { border-radius: 20px; margin: 0 16px 16px; width: calc(100% - 32px); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 6px;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-head .modal-close { color: var(--muted); }
.modal-body { padding: 8px 18px 16px; }
.modal-foot { display: flex; gap: 12px; padding: 12px 18px 20px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text);
}
.field input:focus { outline: none; border-color: var(--primary); background: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* 布里斯托 */
.bristol { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bristol-item {
  border: 2px solid var(--border); background: #fff; border-radius: 12px;
  padding: 8px 4px; text-align: center; cursor: pointer;
}
.bristol-item .b-emoji { font-size: 26px; }
.bristol-item .b-num { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 2px; }
.bristol-item .b-name { font-size: 11px; color: var(--muted); }
.bristol-item.active { border-color: var(--primary); background: #ecfdf5; }
.bristol-item.active .b-num { color: var(--primary-dark); }

.normal-indicator {
  font-size: 14px; font-weight: 700; text-align: center;
  padding: 10px; border-radius: 12px; margin-top: 10px;
}

/* 按钮 */
.btn {
  flex: 1; border: none; border-radius: 14px; padding: 14px;
  font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { flex: none; padding: 8px 16px; font-size: 14px; border-radius: 10px; }

/* 历史日期导航 */
.date-nav { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.date-nav-center { text-align: center; }
.nav-arrow { color: var(--text); font-size: 30px; width: 48px; height: 48px; }
.date-picker {
  display: block; width: 100%; padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card);
  font-size: 16px; color: var(--text);
}

/* 统计卡片 */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.stat-label { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.stat-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.stat-row:last-child { border-bottom: none; }
.stat-row b { color: var(--primary-dark); }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart-bar {
  width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #34d399, #10b981);
  min-height: 2px;
}
.chart-bar.stool { background: linear-gradient(180deg, #5eead4, #14b8a6); }
.chart-val { font-size: 10px; color: var(--muted); margin-bottom: 3px; }
.chart-day { font-size: 10px; color: var(--muted); margin-top: 5px; }

/* 设置 */
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.settings-row:last-of-type { border-bottom: none; }
.settings-hint { font-size: 12px; color: var(--muted); margin-top: 12px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; z-index: 60;
  white-space: nowrap;
}

/* 热量目标卡片 */
.goal-card {
  background: linear-gradient(135deg, #10b981, #0d9488);
  color: #fff; border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 4px 14px rgba(16,185,129,.3);
}
.goal-top { display: flex; align-items: center; justify-content: space-between; }
.goal-label { font-size: 14px; font-weight: 700; opacity: .95; }
.goal-target { font-size: 13px; opacity: .9; }
.goal-big { font-size: 30px; font-weight: 800; margin: 6px 0 2px; line-height: 1.15; }
.goal-big small { font-size: 15px; font-weight: 600; opacity: .85; }
.progress { height: 8px; border-radius: 999px; background: rgba(255,255,255,.25); overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; border-radius: 999px; background: #fff; transition: width .3s; }
.goal-status { font-size: 13px; margin-top: 8px; opacity: .95; }

/* 食物搜索 */
.food-search-wrap { position: relative; }
.autocomplete {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 6;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 240px; overflow-y: auto;
}
.suggest-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; cursor: pointer; border-bottom: 1px solid #f1f5f9;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:active { background: #f0fdf4; }
.si-name { font-size: 15px; font-weight: 600; }
.si-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.food-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.food-meta-cell { display: flex; flex-direction: column; gap: 4px; }
.food-meta-cell span { font-size: 12px; color: var(--muted); font-weight: 600; }
.food-meta-cell input {
  width: 100%; padding: 11px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text);
}
.food-meta-cell input:focus { outline: none; border-color: var(--primary); background: #fff; }

.btn-add {
  width: 100%; margin-top: 12px; background: #ecfdf5; color: var(--primary-dark);
  border: 1px dashed #6ee7b7; border-radius: 12px; padding: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-add:active { background: #d1fae5; }

.meal-items { display: flex; flex-direction: column; gap: 8px; }
.meal-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;
}
.mi-info { flex: 1; min-width: 0; }
.mi-name { font-size: 15px; font-weight: 600; word-break: break-word; }
.mi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mi-del { background: none; border: none; color: #cbd5e1; font-size: 18px; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.mi-del:active { background: #fee2e2; color: var(--danger); }

.meal-total {
  display: flex; align-items: center; justify-content: space-between;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px;
}
.meal-total span { font-size: 14px; color: #92400e; font-weight: 600; }
.meal-total b { font-size: 18px; color: #b45309; }

.empty-tip.small { padding: 14px 8px; font-size: 13px; }

/* 设置里的热量目标 */
.goal-set { display: flex; align-items: center; gap: 8px; }
.goal-set input {
  width: 100px; padding: 8px 10px; font-size: 15px; text-align: center;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
.goal-set input:focus { outline: none; border-color: var(--primary); background: #fff; }

@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; margin: 0 16px; width: calc(100% - 32px); }
  .action-sheet { bottom: 20px; border-radius: 20px; }
  .sheet-backdrop { align-items: center; }
}
