/* ==========================================================================
   health.css — 健康助手面板样式 + PRD 9.2 建议色值覆盖
   加载顺序必须在 style.css 之后；不修改 style.css 本身。
   色值来源：PRD 9.2（品牌主色 #1F8A5B、辅助色 #2F6FEB、状态色等）
   ========================================================================== */

/* 1) 用 PRD 9.2 的色值覆盖浅色主题变量 */
[data-theme="light"] {
  --bg: #f5f7f6;
  --card-bg: #ffffff;
  --card-border: rgba(31, 138, 91, 0.14);
  --card-shadow: 0 14px 40px rgba(20, 60, 44, 0.08);
  --text: #2b2f33;
  --text-dim: #55605a;
  --text-faint: #8b948e;
  --primary: #1f8a5b;
  --primary-glow: rgba(31, 138, 91, 0.28);
  --success: #1f8a5b;
  --warning: #e8a33d;
  --danger: #d64545;
  --input-bg: #ffffff;
  --input-border: rgba(31, 138, 91, 0.22);
  --dropzone-bg: rgba(31, 138, 91, 0.04);
  --dropzone-border: rgba(31, 138, 91, 0.3);
  --chip-bg: rgba(31, 138, 91, 0.1);
}

/* 2) 健康助手面板 */
.health-card { margin-top: 24px; }
.health-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.health-tab {
  padding: 8px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text-dim); font-size: 0.9rem; transition: all 0.18s ease;
}
.health-tab:hover { transform: var(--hover-raise); }
.health-tab.active {
  background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 600;
}
.health-panel { display: none; }
.health-panel.active { display: block; }

.health-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.health-field { display: flex; flex-direction: column; gap: 6px; }
.health-field label { font-size: 0.82rem; color: var(--text-dim); }
.health-field input, .health-field select {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text); font-size: 0.92rem; font-family: inherit;
}
.health-field input:focus, .health-field select:focus {
  outline: none; border-color: var(--primary);
}
.health-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.health-hint { font-size: 0.82rem; color: var(--text-faint); margin-top: 8px; line-height: 1.6; }
.health-error {
  margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(214, 69, 69, 0.1); color: var(--danger); font-size: 0.86rem;
}
.health-ok {
  margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(31, 138, 91, 0.1); color: var(--primary); font-size: 0.86rem;
}

/* 3) 今日目标与达标率 */
.target-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.target-tile {
  padding: 16px; border-radius: var(--radius); text-align: center;
  border: 1px solid var(--card-border); background: var(--card-bg);
}
.target-tile .value { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.target-tile .label { font-size: 0.78rem; color: var(--text-faint); margin-top: 4px; }
.adherence-bar {
  height: 10px; border-radius: 999px; background: var(--chip-bg);
  overflow: hidden; margin: 10px 0 6px;
}
.adherence-bar > span { display: block; height: 100%; background: var(--primary); }

/* 4) 日历 */
.calendar-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 12px; flex-wrap: wrap;
}
.calendar-grid {
  display: grid;
  /*
   * minmax(0, 1fr) 而不是 1fr：`1fr` 的最小值是格子的 min-content，
   * 手机把字号放大后（日期/符号/🔔 徽标不可断行）轨道无法再压缩，
   * 整行会撑出卡片、最右列跑到屏幕外（2026-09-27 实测反馈）。
   * 写成 minmax(0, 1fr) 才是「真的可以压缩」的 7 等分。
   */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}
.calendar-dow {
  text-align: center; font-size: 0.74rem; color: var(--text-faint); padding: 4px 0;
}
.calendar-cell {
  aspect-ratio: 1 / 1; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  /* 字号带上下限：窄屏随屏宽缩小，宽屏不放大（配合 text-size-adjust 保证 130% 不破版） */
  font-size: clamp(10px, 3.1vw, 12.8px);
  /* 格子可压缩 + 内容不溢出：解决「最下一行被图例压住」 */
  min-width: 0; min-height: clamp(40px, 11.5vw, 56px);
  position: relative; overflow: hidden;
  border: 1px solid transparent; color: var(--text-dim);
}
.calendar-cell .d { font-weight: 600; font-size: clamp(11px, 3.3vw, 13.5px); max-width: 100%; }
.calendar-cell .sym { font-size: clamp(9.5px, 2.9vw, 11px); max-width: 100%; }
.calendar-cell.empty { visibility: hidden; }
/* 状态色（颜色 + 图形符号双编码，避免仅靠颜色区分） */
.cal-red    { background: rgba(214, 69, 69, 0.16); color: #a52828; border-color: rgba(214, 69, 69, 0.35); }
.cal-blue   { background: rgba(47, 111, 235, 0.14); color: #1f4fb0; border-color: rgba(47, 111, 235, 0.32); }
.cal-yellow { background: rgba(232, 163, 61, 0.18); color: #9a6410; border-color: rgba(232, 163, 61, 0.36); }
.cal-grey   { background: var(--chip-bg); color: var(--text-faint); }
.calendar-legend {
  display: flex; column-gap: 14px; row-gap: 6px; flex-wrap: wrap; margin-top: 10px;
  font-size: clamp(10.5px, 3vw, 12.5px); color: var(--text-dim);
}
.calendar-legend .chip { display: inline-flex; align-items: center; gap: 5px; }
.calendar-legend .dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

.health-warning {
  margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(232, 163, 61, 0.12); color: #8a5a12; font-size: 0.85rem;
}
.health-list { margin: 10px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 0.86rem; }
.health-list li { margin-bottom: 6px; line-height: 1.6; }

/* 5) 打卡表单 */
.intake-items { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.intake-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: center; }
/*
 * V3.43（FR-M5-07）：未计入合计的行要**看得出来**。
 * 之前保存后只提示「有 N 项因置信度低未计入」，用户不知道是哪一行、也不知道改哪里。
 */
.intake-row-warn {
  border: 1px solid rgba(217, 83, 79, 0.5);
  background: rgba(217, 83, 79, 0.06);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}
.intake-row-warn .ik-conf {
  border-color: #d9534f;
  box-shadow: 0 0 0 2px rgba(217, 83, 79, 0.15);
}
.ik-pending {
  grid-column: 1 / -1; font-size: 0.82rem; line-height: 1.6; color: #8a5a12;
}
.intake-row input, .intake-row select {
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text); font-size: 0.88rem; font-family: inherit;
}
.intake-remove {
  border: none; background: transparent; color: var(--danger);
  cursor: pointer; font-size: 1.1rem; padding: 10px 12px;
  /* 触控目标不小于 44×44 px（FR-M13-04） */
  min-width: 44px; min-height: 44px;
}
@media (max-width: 560px) {
  .intake-row { grid-template-columns: 1fr 1fr; }
}

/* 6) P3：食谱与计划 */
.recipe-card { transition: transform 0.16s ease, box-shadow 0.16s ease; }
.recipe-card:hover { transform: var(--hover-raise); box-shadow: var(--card-shadow); }
#hr-detail .target-summary { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
#hr-detail .target-tile { padding: 10px; }
#hr-detail .target-tile .value { font-size: 1.15rem; }

/* 7) 今日概览（助手首页） */
.dash-top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 18px;
}
.dash-ring { flex: 0 0 auto; text-align: center; }
.dash-ring-value { font-size: 22px; font-weight: 700; fill: var(--text); }
.dash-ring-label { font-size: 9px; fill: var(--text-faint); }
.dash-ring-caption { font-size: 0.8rem; color: var(--text-dim); margin-top: 4px; }
.dash-metrics {
  flex: 1 1 220px; display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px;
}
.dash-metric {
  padding: 12px 8px; text-align: center; border-radius: var(--radius-sm);
  border: 1px solid var(--card-border); background: var(--card-bg);
}
.dash-metric .v { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.dash-metric .l { font-size: 0.72rem; color: var(--text-faint); margin-top: 2px; }
.nutrient-row { margin-bottom: 10px; }
.nutrient-head {
  display: flex; justify-content: space-between; font-size: 0.82rem;
  color: var(--text-dim); margin-bottom: 4px;
}
.nutrient-head .over { color: var(--danger); font-weight: 600; }
.dash-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.dash-actions .btn { flex: 1 1 140px; justify-content: center; text-align: center; }

/* 8) 响应式加固（FR-M13-01：360–1440px 无横向滚动） */
@media (max-width: 768px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .health-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .health-tabs .health-tab { flex: 0 0 auto; }
}
@media (max-width: 560px) {
  .health-grid { grid-template-columns: 1fr; }
  .target-summary { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .dash-top { flex-direction: column; align-items: stretch; text-align: center; }
  .dash-ring { margin: 0 auto; }
  .calendar-grid { gap: 3px; }
  /* 窄屏同样用 clamp（不要写死 rem，否则会盖掉基础规则里的字号上限） */
  .calendar-cell { font-size: clamp(10px, 3vw, 11.5px); border-radius: 6px; }
  .calendar-cell .d { font-size: clamp(10.5px, 3.2vw, 12.5px); }
  .calendar-cell .sym { font-size: clamp(9px, 2.8vw, 10.5px); }
  .health-list { padding-left: 14px; }
  .dash-actions .btn { flex: 1 1 100%; }
}
@media (max-width: 400px) {
  .health-tab { padding: 10px 14px; font-size: 0.84rem; min-height: 44px; }
  .target-tile { padding: 12px 8px; }
  .target-tile .value { font-size: 1.3rem; }
  .dash-metric .v { font-size: 1.1rem; }
}
/* 防止长内容撑破布局 */
.health-panel, .recipe-card, .calendar-grid, .intake-row { max-width: 100%; }
.recipe-card b, .health-list li, .health-hint { word-break: break-word; }

/* v2.63（FR-M9-65）：食谱制作（我的营养计划）编辑器的 7 个时间段 */
.plan-slot-row {
  border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-top: 8px; background: var(--card-bg);
}
.plan-slot-row .health-hint { font-size: 0.8rem; }
.plan-slot-items {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0;
  min-height: 22px; align-items: center;
}
.plan-slot-items .chip { word-break: break-all; }

/* v2.64（FR-M9-69）：营养库等「字典表」的紧凑只读表格（点行编辑） */
.lib-table { min-width: 520px; }
.lib-table td, .lib-table th { padding: 8px 10px; }
.lib-row { cursor: pointer; }
.lib-row:hover { background: var(--chip-bg); }
.lib-row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.lib-row-hidden { display: none; }
.lib-warn { color: #9a6410; font-weight: 600; }
.lib-row-flag td { background: rgba(232, 163, 61, 0.10); }
/* v2.66（FR-M1-48）：食材营养修改的醒目提醒 */
.nutrition-alert {
  margin: 8px 0 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(232, 163, 61, 0.16); border: 1px solid rgba(232, 163, 61, 0.45);
  color: #7a4c0c; font-size: 0.86rem; line-height: 1.65;
}
.nutrition-alert b { color: #8a5a12; }
.lib-filter {
  padding: 6px 10px; border-radius: var(--radius-sm); font-family: inherit;
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-dim);
}

/* 9) 页面分流用的隐藏类（page.js 控制，不用删除 DOM） */
.aigcoil-hidden { display: none !important; }

/* ==========================================================================
   10) v2.8：5 个 tab 的组件样式（今日 / 历程 / 专项 / 食谱库 / 档案）
   对应 PRD 9.8 与设计方案第 15 章；全部新增，不改动上面的既有类
   ========================================================================== */

/* 10.1 今日：目标达成率卡片 + 两个按钮 + 可展开三段明细 */
.today-goal {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
  padding: 18px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--card-border); background: var(--card-bg);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.today-goal:hover { transform: var(--hover-raise); box-shadow: var(--card-shadow); }
.today-goal:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.goal-left { flex: 0 0 auto; text-align: center; min-width: 132px; }
.goal-rate { font-size: 2.4rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.goal-rate.over { color: var(--danger); }
.goal-rate.short { color: var(--warning); }
.goal-rate.muted { color: var(--text-faint); }
.goal-caption { font-size: 0.8rem; color: var(--text-faint); margin-top: 4px; }
.goal-status { font-size: 0.82rem; color: var(--text-dim); margin-top: 6px; }
.goal-right { flex: 1 1 240px; min-width: 200px; }
.goal-line { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.goal-line .gl-label { flex: 0 0 52px; font-size: 0.82rem; color: var(--text-dim); }
.goal-line .adherence-bar { flex: 1 1 auto; margin: 0; }
.goal-line .gl-value { flex: 0 0 auto; font-size: 0.82rem; color: var(--text); }
.adherence-bar > span.remaining { background: var(--warning); }
.adherence-bar > span.over { background: var(--danger); }
.adherence-bar > span.short { background: var(--warning); }
.nutrient-head .short { color: #9a6410; font-weight: 600; }
.goal-toggle { flex: 1 1 100%; font-size: 0.8rem; color: var(--primary); }
.today-actions .btn { flex: 1 1 160px; justify-content: center; }
.today-detail { margin-top: 16px; padding-top: 4px; border-top: 1px dashed var(--card-border); }

/* 10.2 今日菜谱与建议 */
.menu-block { margin-bottom: 12px; }
.menu-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.88rem; color: var(--text); padding: 6px 0;
  border-bottom: 1px solid var(--card-border);
}
.menu-head span { font-size: 0.8rem; color: var(--primary); font-weight: 600; }
.health-list li.muted { color: var(--text-faint); }
.advice-list { margin: 10px 0 0; padding-left: 18px; }
.advice-list li { margin-bottom: 10px; font-size: 0.88rem; color: var(--text); }
.advice-list li b { color: var(--primary); }

/* 10.3 历程：日历卡片与跨度切换 */
.cal-card {
  padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--card-border); background: var(--card-bg);
}
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.cal-head b { font-size: 1rem; }
.cal-nav { padding: 6px 14px; font-size: 1.1rem; line-height: 1; }
.cal-card .calendar-grid { max-width: 520px; margin: 0 auto; }
.cal-card .calendar-legend { justify-content: center; }
.calendar-cell[role="button"] { cursor: pointer; }
.calendar-cell[role="button"]:hover { border-color: var(--primary); }
.calendar-cell.selected {
  outline: 2px solid var(--primary); outline-offset: -2px; font-weight: 700;
}
.span-switch { display: flex; gap: 8px; margin: 16px 0 12px; }
.chip-btn {
  padding: 8px 18px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text-dim); font-size: 0.86rem; font-family: inherit;
}
.chip-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 10.4 历程：日视图与跨度视图 */
.day-card, .span-card, .scheme-card {
  padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--card-border); background: var(--card-bg);
}
.day-head {
  display: flex; flex-wrap: wrap; justify-content: space-between;
  align-items: baseline; gap: 8px; margin-bottom: 8px;
}
.day-head b { font-size: 1rem; }
.day-head span { font-size: 0.82rem; color: var(--text-dim); }
.weight-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; }
.weight-line b { font-size: 1.3rem; color: var(--primary); }
.weight-line span { font-size: 0.84rem; color: var(--text-dim); }

/* 10.5 SVG 折线图 */
.chart { width: 100%; height: auto; display: block; margin-top: 6px; }
.chart-grid { stroke: rgba(43, 47, 51, 0.08); stroke-width: 1; }
.chart-ref { stroke: var(--primary); stroke-dasharray: 4 4; stroke-width: 1; opacity: 0.6; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2; }
.chart-dot { fill: var(--primary); }
.chart-dot-raw { fill: #fff; stroke: var(--primary); stroke-width: 1.2; opacity: 0.7; }
.chart-axis { font-size: 9px; fill: var(--text-faint); }

/* 10.6 专项 */
.special-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.tag {
  padding: 5px 12px; border-radius: 999px; font-size: 0.8rem;
  border: 1px solid var(--input-border); background: var(--input-bg);
}
.tag-avoid { color: var(--danger); border-color: rgba(214, 69, 69, 0.35); background: rgba(214, 69, 69, 0.08); }
.tag-limit { color: #9a6410; border-color: rgba(232, 163, 61, 0.4); background: rgba(232, 163, 61, 0.1); }
.tag-ok { color: var(--primary); border-color: var(--input-border); background: var(--chip-bg); }

/* 10.7 食谱库 */
.recipe-card {
  padding: 12px; border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer;
}
.recipe-head, .food-head {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.recipe-energy, .food-head span { color: var(--primary); font-weight: 600; font-size: 0.86rem; }
.food-row {
  padding: 10px 12px; border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); margin-bottom: 8px;
}

/* 10.8 档案四档 */
.portfolio {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px;
}
.portfolio-row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  background: var(--card-bg);
}
.portfolio-no {
  flex: 0 0 28px; font-size: 1.1rem; color: var(--primary); text-align: center;
}
.portfolio-main { flex: 1 1 auto; }
.portfolio-main b { font-size: 0.92rem; }
.portfolio-state {
  flex: 0 0 auto; font-size: 0.8rem; color: var(--text-faint); white-space: nowrap;
}
.portfolio-state.done { color: var(--primary); font-weight: 600; }
.check-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.check-item {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.85rem; color: var(--text-dim);
}

/* 10.9 弹窗（打卡 / 营养计划） */
.modal-mask {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(20, 30, 26, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; overflow-y: auto;
}
/*
 * v3.16：两个弹层容器共用 .modal-mask 的 z-index，先出现的会被后出现的盖住——
 * 「食谱收藏」是 sheetModal，「新增/修改食谱」弹窗是 foodModal，而 sheetModal 在
 * DOM 里排在后面，于是「点新增，弹窗出现在当前页面后面」。这里显式分层：
 *   sheetModal（一级弹层）< foodModal（二级弹窗，必须在最前面）
 */
#sheetModal { z-index: 120; }
#foodModal { z-index: 140; }
/*
 * v2.67（FR-M9-73）：「食谱收藏」里搜索结果很多时，滚轮会把整张弹层顶出页面边界，
 * 并继续带动后面的页面一起滚。原因是**滚动链**：结果区没有自己的滚动容器，
 * 滚到 content 末尾后事件继续传给 .modal-body → .modal-mask（position:fixed）→ 文档。
 * 处理：
 *   ① 三个 tab 的结果区共用 `#lib-list`，给它**自己的上下滚动条**（有界高度）；
 *   ② `overscroll-behavior: contain` 掐断滚动链，滚到底不再传给下一层；
 *   ③ `#panel-library` 限高，保证整个面板不会超出弹层边界（页面其余两个面板不受影响）。
 */
#sheetModal, #sheetModal .modal-body { overscroll-behavior: contain; }
/*
 * V2.70：**不再依赖 flex 计算高度**。
 * 手机端出现「接口返回 200、列表却看不见」时，最可疑的是这段 flex 高度链
 * （面板 max-height → flex 子项 → 列表）在部分 WebView 上算出了 0 高度。
 * 改为「普通块级 + 结果区自带上下界与滚动条」的保守写法：
 * 结果区有 min-height（绝不为 0）与 max-height（视口比例），一定看得见、一定可滚。
 */
#panel-library {
  min-height: 0; max-height: calc(88vh - 104px);
  overflow-y: auto; overscroll-behavior: contain;
}
/*
 * V2.69：手机上 `vh` 是**大视口**（不含地址栏），用 88vh 算出来的面板可能比真正可见区域还高，
 * 于是结果区被推到屏幕外，看起来像「没有任何记录」。有 `dvh` 时改用动态视口高度。
 */
@supports (height: 100dvh) {
  #panel-library { max-height: calc(88dvh - 104px); }
  #lib-list { max-height: min(52dvh, 520px); }
  .modal-mask { padding: 16px 12px; }
}
#lib-list {
  /* 结果区：有下界（永不为 0）+ 上界（不撑破弹层）+ 自己的滚动条 */
  min-height: 160px; max-height: min(52vh, 520px);
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;   /* 给滚动条留位，避免压住表格最后一列 */
}
/* 结果下方的「详情 / 编辑器出口」：同样自带滚动条，避免把面板撑出弹层 */
#lib-detail {
  min-height: 0; max-height: 42vh;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* 结果区上方的加载 / 诊断行（V2.70）：永远可见，用来判断「数据没来」还是「没渲染出来」 */
#lib-status { margin: 6px 0 4px; font-size: 0.8rem; color: var(--text-faint); }
#lib-status.lib-status-error { color: #a52828; font-weight: 600; }
@media (max-width: 560px) {
  #panel-library { max-height: calc(88vh - 92px); }
}
.modal-box {
  width: 100%; max-width: 680px; margin: auto;
  background: var(--card-bg); border-radius: var(--radius);
  border: 1px solid var(--card-border); box-shadow: var(--card-shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--card-border);
}
.modal-head b { font-size: 1rem; }
.modal-close {
  border: none; background: transparent; cursor: pointer; font-size: 1.1rem;
  color: var(--text-dim); min-width: 44px; min-height: 44px;
}
.modal-body { padding: 18px; }
body.modal-open { overflow: hidden; }
.ck-upload {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 14px 0 6px;
}
.ck-upload input[type="file"] { flex: 1 1 200px; font-size: 0.86rem; color: var(--text-dim); }
.portion-row { display: flex; gap: 8px; align-items: center; }
.portion-row input { flex: 1 1 auto; min-width: 80px; }
.portion-btn { padding: 8px 10px; white-space: nowrap; }

@media (max-width: 560px) {
  .today-goal { flex-direction: column; align-items: stretch; }
  .goal-left { min-width: 0; }
  .goal-line .gl-label { flex: 0 0 44px; }
  .portfolio-row { flex-wrap: wrap; }
  .modal-mask { padding: 12px 8px; }
  .modal-body { padding: 14px; }
}

/* ==========================================================================
   11) 2026-09-23：多成员档案中心（成员表格 + 四档手风琴 + 文档上传）
   ========================================================================== */

/* 11.1 成员管理 */
.member-panel {
  padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--card-border); background: var(--card-bg); margin-bottom: 16px;
}
.member-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.member-toolbar input {
  flex: 1 1 200px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text); font-size: 0.9rem; font-family: inherit;
}
.member-table-wrap {
  /* 成员表按需求保留横向滚动（窄屏左右拖动查看），
     但滚动容器自身不得把页面撑宽：max-width + overscroll 收窄在容器内 */
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  max-width: 100%; overscroll-behavior-x: contain;
}
.member-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 620px; }
.member-table th, .member-table td {
  padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}
.member-table th { color: var(--text-faint); font-weight: 600; font-size: 0.8rem; }
.member-table tr.active { background: var(--chip-bg); }
.member-table td.member-actions { white-space: normal; }
.tag-default {
  margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 0.7rem;
  color: var(--primary); background: var(--chip-bg); border: 1px solid var(--input-border);
}
.link-btn {
  border: none; background: transparent; color: var(--primary); cursor: pointer;
  font-size: 0.82rem; padding: 6px 4px; font-family: inherit;
}
.link-btn.danger { color: var(--danger); }
.link-btn:hover { text-decoration: underline; }

/* 11.2 四档手风琴 */
.portfolio-panel {
  padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--card-border); background: var(--card-bg);
}
.portfolio-title {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 12px;
}
.portfolio-acc {
  border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  margin-bottom: 10px; overflow: hidden;
}
.portfolio-acc.open { border-color: var(--primary); }
.portfolio-head {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  cursor: pointer; background: var(--card-bg);
}
.portfolio-head:hover { background: var(--chip-bg); }
.portfolio-no { flex: 0 0 28px; font-size: 1.1rem; color: var(--primary); text-align: center; }
.portfolio-main { flex: 1 1 auto; }
.portfolio-main b { font-size: 0.92rem; }
.portfolio-body { padding: 4px 14px 14px; border-top: 1px dashed var(--card-border); }
.portfolio-caret { color: var(--text-faint); font-size: 0.9rem; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.detail-item {
  display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--chip-bg); font-size: 0.86rem;
}
.detail-item span { color: var(--text-faint); }

/* 11.3 三/四档：文档上传与识别结果 */
.doc-item {
  padding: 12px; border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); margin-bottom: 10px;
}
.doc-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.doc-status { font-size: 0.76rem; padding: 2px 10px; border-radius: 999px; background: var(--chip-bg); }
.doc-status.confirmed { color: var(--primary); }
.doc-status.extracted { color: #9a6410; background: rgba(232, 163, 61, 0.14); }
.doc-status.failed { color: var(--danger); background: rgba(214, 69, 69, 0.12); }
.doc-upload { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.doc-upload input[type="file"] { flex: 1 1 220px; font-size: 0.86rem; color: var(--text-dim); }
.doc-detail { margin-top: 10px; }
.doc-raw {
  margin-top: 10px; padding: 10px; border-radius: var(--radius-sm);
  background: var(--chip-bg); color: var(--text-dim); font-size: 0.8rem;
  white-space: pre-wrap; max-height: 180px; overflow: auto;
}
.metric-input {
  width: 110px; padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text); font-size: 0.84rem; font-family: inherit;
}

/* 11.4 目标修改 */
.target-edit {
  margin-top: 12px; padding: 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--primary); background: var(--chip-bg);
}

/* 11.5 KG-1：图谱标签上的剂量阈值（循证等级见 hover 提示） */
.tag .tag-dose {
  margin-left: 6px; font-style: normal; font-size: 0.72rem;
  color: var(--text-faint); white-space: nowrap;
}

/* 11.6 第三批：自测体征与主观感受的录入表单 */
.record-form {
  margin-top: 8px; display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;
}
.record-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.84rem; color: var(--text-dim);
}
.record-form label.record-notes { grid-column: 1 / -1; }
.record-form input, .record-form select {
  padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--text); font-size: 0.84rem; font-family: inherit;
}
.record-form .health-hint { margin: 0; }

/* =====================================================================
 * v3.0 页面重构：日历为主 + 当日仪表盘/明细表 + AI 问答 + 右上角菜单
 * ===================================================================== */

/* ---- 顶部菜单（打卡 / 食谱收藏 / 我的 / 管理） ---- */
/* 菜单文字必须一行显示：不换行、不压缩；窄屏改为整条菜单横向滚动 */
.menu-btn {
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}
body[data-page="member"] .navbar { flex-wrap: nowrap; gap: 12px; }
body[data-page="member"] .nav-actions { flex-wrap: nowrap; }
@media (max-width: 720px) {
  body[data-page="member"] .navbar { padding: 12px 14px; }
  body[data-page="member"] .brand .brand-sub { display: none; }
  body[data-page="member"] .nav-actions {
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  body[data-page="member"] .nav-actions::-webkit-scrollbar { display: none; }
  .menu-btn { padding: 6px 10px; font-size: 0.82rem; }
}

/* ---- 日历工具栏 ---- */
.cal-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.cal-periods { display: inline-flex; gap: 6px; }
.cal-periods .chip-btn { min-width: 44px; }
.cal-nav-wrap { display: inline-flex; align-items: center; gap: 8px; }
.cal-nav-wrap b { min-width: 132px; text-align: center; font-size: 0.98rem; }

/* ---- 日历矩阵（参考手机日历：7 列、日期格带状态色与符号） ---- */
.calendar-head {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px;
  margin-bottom: 4px; width: 100%;
}
.calendar-head span {
  text-align: center; font-size: 0.74rem; color: var(--text-faint); padding: 2px 0;
}
.calendar-grid.week-mode { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-cell.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.calendar-cell.future { opacity: 0.72; }
.calendar-cell .meta {
  font-size: clamp(9.5px, 2.7vw, 10.5px); color: inherit; opacity: 0.85; max-width: 100%;
}
.calendar-cell.week-cell {
  aspect-ratio: auto; min-height: clamp(58px, 16vw, 76px);
}

/* ---- 年视图：12 个迷你月 ---- */
.mini-months {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px;
}
.mini-month {
  border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  padding: 8px 6px; text-align: center; background: var(--card-bg); cursor: pointer;
}
.mini-month.active { border-color: var(--primary); }
.mini-month .m { font-size: 0.78rem; color: var(--text-dim); }
.mini-month .v { font-size: 1.02rem; font-weight: 700; color: var(--primary); margin: 2px 0; }
.mini-month .s { font-size: 0.68rem; color: var(--text-faint); }

/* ---- 当日仪表盘（4 类信息 + 建议） ---- */
.dash-card {
  border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 14px 14px 6px; background: var(--card-bg);
}
.dash-card.dash-clickable { cursor: pointer; }
.dash-card.dash-clickable:hover { border-color: var(--primary); }
.dash-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}
.dash-status { font-size: 0.82rem; }
.dash-metrics.dash-4 { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.dash-metric.muted { opacity: 0.55; }
.dash-metric .u { font-size: 0.7rem; color: var(--text-faint); }
.dash-metric .sub { font-size: 0.68rem; color: var(--text-faint); margin-top: 2px; }
.dash-hint-bar {
  margin-top: 10px; font-size: 0.78rem; color: var(--text-faint);
}

/* ---- 明细表（点击仪表盘后展开；按日期关系决定可否编辑） ---- */
.edit-table .ro { color: var(--text-faint); }
.edit-table input, .edit-table select {
  padding: 4px 6px; border-radius: var(--radius-sm); border: 1px solid var(--input-border);
  background: var(--input-bg); color: var(--text); font-size: 0.82rem; font-family: inherit;
  max-width: 108px;
}
.edit-table input:disabled, .edit-table select:disabled {
  opacity: 0.6; cursor: not-allowed;
}
.edit-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px;
}
.btn[disabled], .btn.btn-disabled {
  opacity: 0.5; cursor: not-allowed; filter: grayscale(0.4);
}
.plan-add-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px; align-items: end; margin-top: 8px;
}
.ro-notice {
  margin-top: 8px; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--chip-bg); color: var(--text-faint); font-size: 0.8rem;
}

/* ---- 打卡：图片预览与大弹窗 ---- */
.ck-preview {
  margin-top: 10px; border: 1px dashed var(--input-border); border-radius: var(--radius-sm);
  padding: 10px; text-align: center; background: var(--chip-bg);
}
.ck-preview img { max-width: 100%; max-height: 240px; border-radius: var(--radius-sm); }
.ck-meals { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.ck-meal {
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--input-border);
  background: var(--card-bg); color: var(--text-dim); cursor: pointer; font-size: 0.86rem;
  font-family: inherit;
}
.ck-meal.active {
  border-color: var(--primary); color: var(--primary); font-weight: 700;
  background: rgba(47, 111, 235, 0.08);
}
.modal-box-lg { max-width: 880px; width: 94vw; max-height: 88vh; }
.modal-box-lg .modal-body { max-height: calc(88vh - 56px); overflow: auto; }

/* ---- AI 问答（内联区域） ---- */
.ask-inline { margin-top: 4px; }
.ask-samples { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

/* ---- 区间视图：可点击曲线 + 多线对比图图例 ---- */
.span-chart {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 4px 6px 0; cursor: pointer;
}
.span-chart:hover { border-color: var(--primary); background: rgba(47, 111, 235, 0.04); }
.span-chart:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.chart-legend {
  display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 4px;
  font-size: 0.78rem; color: var(--text-dim);
}
.chart-legend .chip { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

/* 分面视图（small multiples）：每个营养素一张小图，各自带真实刻度 */
.span-charts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px;
}
.mini-chart {
  border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  padding: 8px 8px 4px; background: var(--card-bg);
}
.mini-chart-title { font-size: 0.84rem; font-weight: 600; color: var(--text-dim); }
.mini-chart .chart-legend { margin: 4px 0 2px; font-size: 0.74rem; }
@media (max-width: 640px) {
  .span-charts { grid-template-columns: 1fr; }
}

/* ---- 日历提醒 ---- */
.calendar-cell .rem-dot {
  /*
   * 提醒徽标从「第三行」改为**右上角角标**：格子是正方形（宽≈44px），
   * 三行内容放不下会把格子内容顶出去（实测「最后一行被备注文字遮挡」）。
   * 移到角上后格子只剩两行内容，同时保留「有提醒」这个信息。
   */
  position: absolute; top: 1px; right: 2px;
  font-size: clamp(8.5px, 2.4vw, 10px); line-height: 1;
  color: #b8860b; max-width: 100%; overflow: hidden; white-space: nowrap;
}
.reminder-form {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px; align-items: end; margin-top: 8px;
}
.reminder-form input, .reminder-form select {
  padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--input-border);
  background: var(--input-bg); color: var(--text); font-size: 0.84rem; font-family: inherit;
}

/* v3.7：日历第 4 类信息的指标选择器（点它不会打开明细表） */
.metric-picker {
  margin-left: 6px; padding: 1px 4px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text);
  font-size: 0.7rem; font-family: inherit; vertical-align: middle; cursor: pointer;
}

/* v3.7：问答栏的「智能体执行过程」（分析 → 解析 → 调用 API → 同步） */
.ask-trace {
  margin-top: 8px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--input-bg); border: 1px solid var(--input-border);
}
.ask-trace summary {
  cursor: pointer; font-size: 0.8rem; color: var(--primary); font-weight: 600;
}
.ask-trace ol { margin: 8px 0 0 18px; padding: 0; }
.ask-trace li { font-size: 0.78rem; color: var(--text-faint); line-height: 1.7; }
.ask-trace li b { color: var(--text); }

/* ============================================================
 * v3.9：AI 问答升级为消息流（参考主流智能体问答形态）
 *   · 头部一行说明 + 「新会话」
 *   · 消息流：用户右侧气泡、助手左侧气泡（含过程 / 工具 / 卡片 / 追问建议）
 *   · 输入区：多行输入（Enter 发送、Shift+Enter 换行）+ 发送 / 停止
 * ============================================================ */
.ask-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.ask-head-main { flex: 1 1 auto; min-width: 0; }
.ask-head-main b { display: block; margin-bottom: 2px; }
.ask-head-ops { flex: 0 0 auto; }

.ask-thread {
  margin-top: 10px; max-height: 460px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; padding: 4px 2px;
}
.ask-msg { display: flex; gap: 8px; align-items: flex-start; }
.ask-msg.from-user { flex-direction: row-reverse; }
.ask-avatar {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; color: #fff; background: var(--primary);
}
.ask-msg.from-user .ask-avatar { background: #6b7280; }
.ask-body { min-width: 0; max-width: 100%; }
.ask-bubble {
  padding: 8px 12px; border-radius: 12px; font-size: 0.86rem; line-height: 1.7;
  border: 1px solid var(--input-border); background: var(--input-bg);
  word-break: break-word;
}
.ask-bubble.user { background: rgba(31, 138, 91, 0.12); }
.ask-bubble.agent { background: var(--card-bg, #fff); }
.ask-bubble.pending { color: var(--text-faint); }
.ask-bubble-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 2px;
}
.ask-intent { font-size: 0.68rem; color: var(--text-faint); }
.ask-dots { display: inline-flex; gap: 3px; margin-right: 6px; }
.ask-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--primary);
  display: inline-block; animation: askDot 1s infinite ease-in-out;
}
.ask-dots i:nth-child(2) { animation-delay: 0.15s; }
.ask-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes askDot { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.ask-tools { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.ask-chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; border: 1px solid var(--input-border);
  background: var(--input-bg); color: var(--text-faint); white-space: nowrap;
}
.ask-chip.error { color: #b91c1c; border-color: rgba(185, 28, 28, 0.35); }
.ask-chip.link { cursor: pointer; color: var(--primary); }
.ask-chip.link:hover { background: rgba(31, 138, 91, 0.1); }
.ask-suggest { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }

/* v3.11：回答里的「相关页面」链接——点一下就地打开对应页面，不点可继续追问 */
.ask-links {
  margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 0.8rem; color: var(--text-faint);
}
.ask-link {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--input-border); background: var(--input-bg);
  color: var(--primary); text-decoration: none; white-space: nowrap;
}
.ask-link:hover { background: rgba(31, 138, 91, 0.12); text-decoration: underline; }
.ask-link::after { content: ' ↗'; font-size: 0.75em; }

.ask-composer {
  margin-top: 10px; border: 1px solid var(--input-border); border-radius: 12px;
  background: var(--input-bg); padding: 8px 10px;
}
.ask-composer textarea {
  width: 100%; border: 0; outline: none; resize: none; background: transparent;
  color: var(--text); font-family: inherit; font-size: 0.88rem; line-height: 1.6;
  max-height: 160px;
}
.ask-composer-ops {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  margin-top: 4px;
}
.ask-composer-ops .health-hint { margin: 0 auto 0 0; }

/* 明细表在窄屏改为换行显示，避免手机上必须左右拖动（档案表仍用横向滚动） */
@media (max-width: 640px) {
  .edit-table { min-width: auto; }
  .edit-table th, .edit-table td { white-space: normal; padding: 8px 6px; }
  .edit-table input, .edit-table select { max-width: 100%; }
  .dash-metrics.dash-4 { grid-template-columns: repeat(2, 1fr); }
  .cal-nav-wrap b { min-width: 96px; font-size: 0.9rem; }
}
