/* 全局样式：移动端优先 */
:root {
  --primary: #2e7dd7;
  --primary-dark: #1f5fa8;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #222;
  --muted: #777;
  --border: #e2e6ec;
  --green: #27ae60;
  --orange: #f39c12;
  --red: #c0392b;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

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

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

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .user { font-size: 13px; opacity: 0.95; }
.topbar .link { color: #fff; text-decoration: none; font-size: 13px; margin-left: 12px; }

/* 内容区 */
.content { flex: 1; padding: 16px; padding-bottom: 76px; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }

/* 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 60px; }
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 按钮 */
.btn {
  display: inline-block;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { background: var(--primary-dark); }
.btn.secondary { background: #eef2f7; color: var(--primary); }
.btn.danger { background: var(--red); }
.btn.small { width: auto; padding: 8px 14px; font-size: 14px; }
.btn-row { display: flex; gap: 12px; }

/* 结果提示 */
.result {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  border-left: 4px solid var(--muted);
  background: #f8f9fb;
  font-size: 14px;
}
.result .level { font-weight: 700; font-size: 16px; }
.result .advice { margin-top: 6px; color: #444; }

.msg { font-size: 13px; margin-top: 10px; }
.msg.error { color: var(--red); }
.msg.success { color: var(--green); }

/* 记录列表 */
.rec-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.rec-item:last-child { border-bottom: none; }
.rec-main { flex: 1; }
.rec-val { font-size: 20px; font-weight: 700; }
.rec-unit { font-size: 12px; color: var(--muted); margin-left: 2px; }
.rec-meta { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; align-items: center; gap: 8px; }
.rec-note { font-size: 13px; color: #555; margin-top: 4px; }
.period-tag { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.rec-time { font-size: 13px; color: #444; font-weight: 600; }

/* 日期分组标题 */
.day-head {
  position: sticky;
  top: 0;
  background: var(--card);
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  padding: 10px 2px 8px;
  margin-top: 6px;
  border-bottom: 2px solid var(--primary);
  z-index: 1;
}
.day-head:first-child { margin-top: 0; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  color: #fff;
  margin-left: 8px;
}
.rec-actions { display: flex; flex-direction: column; gap: 6px; margin-left: 10px; }
.rec-actions button {
  border: none; background: none; color: var(--primary);
  font-size: 13px; cursor: pointer; padding: 2px 4px;
}
.rec-actions button.del { color: var(--red); }

/* 底部导航 */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 640px;
  margin: 0 auto;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tabbar a {
  flex: 1;
  text-align: center;
  padding: 9px 0 7px;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
}
.tabbar a .ic { display: block; font-size: 20px; line-height: 1.1; }
.tabbar a.active { color: var(--primary); }

/* 图表分段切换 */
.segment { display: flex; background: #eef2f7; border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.segment button {
  flex: 1; border: none; background: none; padding: 8px; border-radius: 6px;
  font-size: 14px; cursor: pointer; color: var(--muted);
}
.segment button.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

/* 图表时间段前后导航 */
.period-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.period-nav button {
  width: 40px; height: 36px; border: 1px solid var(--border); background: #fff;
  border-radius: 8px; font-size: 22px; line-height: 1; color: var(--primary); cursor: pointer;
}
.period-nav button:disabled { color: #ccc; cursor: not-allowed; }
.period-nav #range-title { flex: 1; text-align: center; font-size: 15px; font-weight: 700; color: var(--text); }

/* 图表自定义时间区间 */
.custom-range { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 12px; }
.custom-range .cr-field { flex: 1; }
.custom-range .cr-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.custom-range .cr-field input {
  width: 100%; padding: 9px 8px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 15px; background: #fff; color: var(--text);
}
.custom-range #apply-range { flex: 0 0 auto; white-space: nowrap; }

/* 登录页 */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #2e7dd7, #1f5fa8);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.auth-card .logo { text-align: center; font-size: 44px; margin-bottom: 4px; }
/* 🏃 emoji 默认朝左，水平翻转为朝右 */
.auth-card .logo .runner { display: inline-block; transform: scaleX(-1); }
.auth-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.auth-tabs { display: flex; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.auth-tabs button {
  flex: 1; border: none; background: none; padding: 10px; font-size: 15px;
  cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent;
}
.auth-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #444; margin-bottom: 14px; }
.checkbox-row input { width: auto; }

/* 知识说明页 */
.kb h3 { font-size: 15px; margin: 18px 0 8px; color: var(--primary-dark); }
.kb p { font-size: 14px; color: #444; margin: 6px 0; }
.kb table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.kb th, .kb td { border: 1px solid var(--border); padding: 7px 8px; text-align: left; }
.kb th { background: #f4f6f9; }
.kb .tip { background: #fff8e6; border-left: 4px solid var(--orange); padding: 10px 12px; border-radius: 6px; font-size: 13px; margin: 10px 0; }

/* GI 食物查询 */
.gi-tools { margin: 10px 0 4px; }
.gi-tools #gi-search {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; margin-bottom: 10px;
}
.gi-tools .chip { font-size: 13px; padding: 6px 11px; }
.gi-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px;
  max-height: 460px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.gi-item {
  border: 1px solid var(--border); border-left: 4px solid #999;
  border-radius: 8px; padding: 9px 10px; background: #fff;
}
.gi-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.gi-nums { display: flex; flex-direction: column; gap: 4px; }
.gi-badge { display: inline-block; padding: 2px 7px; border-radius: 8px; font-size: 12px; font-weight: 600; width: fit-content; }
.gi-carb { font-size: 12px; color: var(--muted); }
@media (max-width: 360px) { .gi-list { grid-template-columns: 1fr; } }

.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
