/* ============================================================
   食物红绿灯 · 设计系统
   语言：暖调中性色阶梯 · 单一品牌绿 · 灯级三色仅用于信号
   参考：OpenNutriTracker 的 calm friendly-flat 体系
   ============================================================ */

:root {
  --canvas: #F7F4EF;
  --surface: #FFFFFF;
  --surface-muted: #F1ECE3;
  --hairline: #E8E2D6;
  --text-strong: #2B2A27;
  --text-muted: #6E685E;
  --text-faint: #A39E94;
  --accent: #0E7A4D;
  --green: #1E9E62;
  --amber: #D97E06;
  --red: #D64545;
  --green-soft: #E4F2EA;
  --amber-soft: #F8EEDB;
  --red-soft: #F9E7E4;
  --shadow-card: 0 1px 2px rgba(64, 58, 46, 0.04), 0 8px 20px rgba(64, 58, 46, 0.05);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--canvas);
  color: var(--text-strong);
  font-size: 18px;
  line-height: 1.6;
}

.page {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 18px 150px;
  min-height: 100vh;
}

/* ===== 品牌头部 ===== */
.app-header {
  padding: 28px 6px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dots {
  display: flex;
  gap: 4px;
}

.brand-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.brand-dots .r { background: var(--red); }
.brand-dots .y { background: var(--amber); }
.brand-dots .g { background: var(--green); }

.app-header h1 {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ===== 搜索框 ===== */
.search-box {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--canvas);
  padding: 6px 0 26px;
}

.search-inner {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 17px;
  top: 50%;
  transform: translateY(-50%);
  width: 19px;
  height: 19px;
  color: var(--text-faint);
  pointer-events: none;
}

#search-input {
  width: 100%;
  font-size: 17px;
  padding: 14px 18px 14px 46px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  color: var(--text-strong);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 122, 77, 0.14);
}

#search-input::placeholder {
  color: var(--text-faint);
}

/* ===== 分类筛选（3×3 等宽网格，右下角「少碰」为特殊入口） ===== */
.chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 4px 2px 8px;
}

/* 放心吃页：8 格（全部+7 类），4 列两行 */
.chips.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.chips.cols-4 .chip {
  padding: 11px 4px;
  font-size: 14px;
}

.chip {
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  text-align: center;
  padding: 11px 8px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: #5A564E;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease,
    color 0.18s ease, background 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .chip:hover {
    transform: translateY(-1px);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 3px 8px rgba(64, 58, 46, 0.1);
  }
}

.chip:active {
  transform: scale(0.96);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  animation: chip-pop 0.25s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}

@keyframes chip-pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* 「少碰」避雷入口 */
.chip.red {
  color: var(--red);
}

.chip.red.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* 首页收藏区已移除：收藏统一走底部「收藏」tab 一键直达 */

/* ===== 分类标题 ===== */
.category-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin: 18px 6px 10px;
}

.category-title .count {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-faint);
}

/* ===== 食物卡片 ===== */
.food-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  padding: 16px 18px;
  margin-bottom: 9px;
  font-size: 18px;
  font-family: inherit;
  color: var(--text-strong);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(64, 58, 46, 0.04);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .food-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-card);
  }
}

.food-item:active {
  transform: scale(0.99);
  background: #FBFAF7;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.dot.green { background: var(--green); box-shadow: 0 0 0 4px rgba(30, 158, 98, 0.14); }
.dot.yellow { background: var(--amber); box-shadow: 0 0 0 4px rgba(217, 126, 6, 0.15); }
.dot.red { background: var(--red); box-shadow: 0 0 0 4px rgba(214, 69, 69, 0.14); }

.food-item .name {
  flex: 1;
  font-weight: 600;
}

.food-item .verdict {
  font-size: 13.5px;
  font-weight: 600;
}

.verdict.green { color: var(--green); }
.verdict.yellow { color: var(--amber); }
.verdict.red { color: var(--red); }

.food-item .chev {
  color: #C9C2B4;
  font-size: 18px;
  font-weight: 600;
  transition: transform 0.18s ease, color 0.18s ease;
}

@media (hover: hover) {
  .food-item:hover .chev {
    transform: translateX(3px);
    color: var(--accent);
  }
}

/* 放心吃清单：名称 + 分量两行 */
.brand-dot {
  width: 12px;
  height: 12px;
}

.brand-star {
  display: inline-flex;
  color: var(--accent);
}

.brand-star svg {
  width: 18px;
  height: 18px;
}

.food-item .name-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.food-item .portion-sub {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
}

/* 详情页收藏按钮 */
.detail-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.fav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.fav-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.fav-btn.active {
  color: var(--accent);
  background: var(--green-soft);
  border-color: var(--green-soft);
}

.fav-btn.active svg {
  fill: currentColor;
}

/* ===== 空结果 ===== */
.empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.8;
  padding: 48px 20px;
}

/* ===== 详情页 ===== */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 15.5px;
  font-family: inherit;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 9px 18px 9px 14px;
  margin: 18px 0 14px 2px;
  box-shadow: 0 1px 2px rgba(64, 58, 46, 0.04);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 28px;
  padding: 22px 20px 24px;
  box-shadow: var(--shadow-card);
}

.detail-category {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-radius: 999px;
  padding: 5px 12px;
}

.detail-name {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-top: 8px;
}

/* hero 信号灯 */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 4px;
}

.lamp {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  position: relative;
}

.lamp::after {
  content: "";
  position: absolute;
  left: 24%;
  top: 16%;
  width: 30%;
  height: 22%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  filter: blur(6px);
}

.lamp.green {
  background: radial-gradient(circle at 32% 28%, #5BC98E, #1E9E62 62%);
  box-shadow:
    0 0 0 9px rgba(30, 158, 98, 0.10),
    0 0 0 19px rgba(30, 158, 98, 0.05),
    0 12px 28px rgba(30, 158, 98, 0.36);
}

.lamp.yellow {
  background: radial-gradient(circle at 32% 28%, #F2B45A, #D97E06 62%);
  box-shadow:
    0 0 0 9px rgba(217, 126, 6, 0.10),
    0 0 0 19px rgba(217, 126, 6, 0.05),
    0 12px 28px rgba(217, 126, 6, 0.38);
}

.lamp.red {
  background: radial-gradient(circle at 32% 28%, #E8837D, #D64545 62%);
  box-shadow:
    0 0 0 9px rgba(214, 69, 69, 0.10),
    0 0 0 19px rgba(214, 69, 69, 0.05),
    0 12px 28px rgba(214, 69, 69, 0.36);
}

.verdict-hero {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-top: 18px;
}

.verdict-hero.green { color: var(--green); }
.verdict-hero.yellow { color: var(--amber); }
.verdict-hero.red { color: var(--red); }

.verdict-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* 建议分量 */
.portion-card {
  background: var(--surface-muted);
  border-radius: 20px;
  padding: 14px 16px;
  margin-top: 16px;
}

.portion-card h3 {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.portion-card p {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.5;
  margin-top: 4px;
}

/* 理由 / 替代 / 备注 */
.detail-block {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--hairline);
}

.detail-block h3 {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.detail-block p {
  font-size: 17.5px;
  line-height: 1.65;
  margin-top: 4px;
}

.alt-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  background: var(--green-soft);
  color: var(--accent);
  font-size: 15.5px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.alt-btn:active {
  background: #D6EADF;
}

.alt-btn .mini-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
}

/* ===== 底部固定区：免责声明 + 导航 ===== */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--hairline);
}

.disclaimer-line {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  padding: 8px 16px 2px;
}

.tabbar {
  position: relative;
  display: flex;
  max-width: 520px;
  margin: 0 auto;
  padding: 2px 12px calc(10px + env(safe-area-inset-bottom));
}

/* 滑动胶囊：选中态背景随 tab 切换滑动 */
.tab-glider {
  position: absolute;
  top: 8px;
  left: 0;
  height: 30px;
  width: 0;
  border-radius: 999px;
  background: var(--green-soft);
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none;
}

.tab {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-faint);
  background: none;
  border: none;
  padding: 8px 0 4px;
  cursor: pointer;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.tab svg {
  width: 22px;
  height: 22px;
}

.tab .icon-wrap {
  display: flex;
  padding: 4px 20px;
  border-radius: 999px;
}

.tab.active {
  color: var(--accent);
}

/* ===== 微动效 ===== */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-card,
.food-list {
  animation: rise 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {
  .detail-card,
  .food-list {
    animation: none;
  }
  .food-item,
  .chip,
  .tab-glider {
    transition: none;
  }
  .chip.active {
    animation: none;
  }
  .chip:hover,
  .food-item:hover {
    transform: none;
  }
}

/* ===== 拍照识别 ===== */
.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-row .search-inner {
  flex: 1;
}

.photo-wrap {
  position: relative;
  flex: 0 0 auto;
  display: flex;
}

.photo-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.photo-btn {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.photo-btn svg {
  width: 24px;
  height: 24px;
}

.photo-btn:active {
  transform: scale(0.94);
}

/* 弹层 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(43, 42, 39, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--canvas);
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  animation: sheet-up 0.25s ease;
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.photo-preview {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 16px;
  display: block;
}

.photo-msg {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  margin: 16px 0 4px;
  line-height: 1.6;
}

.photo-sub {
  text-align: center;
  font-size: 14.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.photo-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.photo-actions .act {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  padding: 14px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.act.primary {
  background: var(--accent);
  color: #fff;
  border: none;
}

.act.secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--hairline);
}

.act:disabled {
  opacity: 0.5;
}

/* 识别中转圈 */
.spinner {
  width: 44px;
  height: 44px;
  margin: 24px auto 8px;
  border-radius: 50%;
  border: 4px solid var(--surface-muted);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== AI 问答兜底 ===== */
.ask-ai {
  text-align: center;
  margin: 6px 0 20px;
}

.ask-ai-btn {
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: var(--accent);
  background: var(--surface);
  border: 1.5px dashed var(--accent);
  border-radius: 999px;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.ask-ai-btn:active {
  transform: scale(0.96);
}

.ask-ai-note {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 8px;
}

.ai-card {
  background: var(--surface);
  border: 1.5px dashed #C9C2B4;
  border-radius: 20px;
  padding: 18px 18px 14px;
  margin-top: 6px;
  text-align: left;
}

.ai-badge {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-radius: 999px;
  padding: 4px 12px;
}

.ai-verdict {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.ai-verdict-text {
  font-size: 19px;
  font-weight: 700;
}

.ai-verdict-text.green { color: var(--green); }
.ai-verdict-text.yellow { color: var(--amber); }
.ai-verdict-text.red { color: var(--red); }

.ai-foot {
  font-size: 13px;
  color: var(--text-faint);
  line-height: 1.6;
  margin-top: 14px;
  border-top: 1px dashed var(--hairline);
  padding-top: 12px;
}
