/* ===========================================================
   饮食记录 · 样式
   =========================================================== */

:root {
  --bg: #f4f6f8;
  --bg-soft: #eaeef2;
  --card: #ffffff;
  --card-2: #f8fafc;
  --text: #16202b;
  --text-soft: #64748b;
  --text-faint: #94a3b8;
  --line: #e3e8ef;
  --accent: #16a34a;
  --accent-soft: #e8f7ee;
  --accent-2: #f97316;
  --protein: #3b82f6;
  --carbs: #22c55e;
  --fat: #eab308;
  --fiber: #14b8a6;
  --sugar: #a855f7;
  --sodium: #64748b;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 32, 48, .05), 0 8px 24px rgba(16, 32, 48, .06);
  --radius: 16px;
  --radius-sm: 10px;
}

html[data-theme="dark"] {
  --bg: #0e1418;
  --bg-soft: #131c22;
  --card: #161f26;
  --card-2: #1b262e;
  --text: #e8eef3;
  --text-soft: #9fb0bf;
  --text-faint: #77899a;
  --line: #26343e;
  --accent: #34d399;
  --accent-soft: #10302a;
  --accent-2: #fb923c;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;          /* 禁止双击放大，更接近 App 手感 */
}

button, input, select, textarea, label { -webkit-tap-highlight-color: transparent; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 17px; }
p { margin: 0; }

.app { max-width: 1120px; margin: 0 auto; padding: 22px 20px 48px; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  font-size: 24px; background: var(--accent-soft); box-shadow: var(--shadow);
}
.brand-text h1 { font-size: 20px; }
.brand-text p { font-size: 12px; color: var(--text-faint); }

.tabs {
  display: flex; gap: 4px; padding: 4px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--line);
}
.tab {
  appearance: none; border: 0; background: transparent; color: var(--text-soft);
  padding: 8px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: .18s;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---------------- 视图 ---------------- */
.view { display: none; }
.view.is-active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-2 > .card { margin-bottom: 0; }
.grid.grid-2 { margin-bottom: 16px; }

.hint { font-size: 12.5px; color: var(--text-soft); margin-top: 8px; }
.muted { color: var(--text-soft); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------- 按钮 / 输入 ---------------- */
.btn {
  appearance: none; font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent; background: var(--accent); color: #fff;
  transition: .16s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: var(--card-2); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-accent { background: var(--accent-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--card-2);
  color: var(--text); width: 34px; height: 34px; border-radius: 10px;
  cursor: pointer; font-size: 16px; line-height: 1; display: grid; place-items: center;
  transition: .16s; font-family: inherit;
}
.icon-btn:hover { background: var(--bg-soft); }
.link-btn {
  appearance: none; border: 0; background: none; color: var(--accent);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 0;
}

.input {
  font-family: inherit; font-size: 14px; color: var(--text); background: var(--card-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px;
  min-width: 0; transition: .16s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { width: 100%; resize: vertical; line-height: 1.6; }
select.input { cursor: pointer; }
.grow { flex: 1 1 200px; }
.date-input { width: 150px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--text-soft); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.span-2 { grid-column: span 2; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  appearance: none; font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text-soft);
  transition: .16s;
}
.chip:hover { color: var(--text); }
.chip.is-active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip-add { border-style: dashed; }

/* ---------------- 日期条 ---------------- */
.datebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.datebar-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.day-label { font-size: 14px; font-weight: 650; }
.day-label.today { color: var(--accent); }

/* ---------------- 体重卡 ---------------- */
.weight-top { display: flex; align-items: baseline; gap: 10px; }
.weight-big { font-size: 44px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.weight-unit { font-size: 15px; color: var(--text-soft); font-weight: 600; }
.weight-sub { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--text-soft); }
.delta-up { color: var(--danger); font-weight: 650; }
.delta-down { color: var(--accent); font-weight: 650; }
.delta-flat { color: var(--text-faint); font-weight: 650; }
.spark { width: 100%; height: 64px; margin-top: 10px; display: block; }
.weight-quick { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.weight-quick .input { width: 110px; }

/* ---------------- 进度环 ---------------- */
.ring-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.ring { width: 148px; height: 148px; flex: none; }
.ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring .ring-bg { stroke: var(--bg-soft); }
.ring .ring-fg { stroke: var(--accent); transition: stroke-dashoffset .5s ease; }
.ring-center { position: relative; display: grid; place-items: center; }
.ring-text {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; text-align: center;
}
.ring-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.ring-label { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.ring-side { flex: 1 1 190px; min-width: 180px; }
.ring-side-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.ring-side-row:last-child { border-bottom: 0; }
.ring-side-row span:first-child { color: var(--text-soft); font-size: 13px; }
.ring-side-row span:last-child { font-weight: 650; font-variant-numeric: tabular-nums; }
.over { color: var(--danger) !important; }

/* ---------------- 营养条 ---------------- */
.bar-row { margin-bottom: 16px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.bar-name { font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.bar-val { font-size: 13px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.bar-track { height: 9px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .45s ease; }

/* ---------------- 餐次 ---------------- */
.meal { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 12px; overflow: hidden; }
.meal:last-child { margin-bottom: 0; }
.meal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; background: var(--card-2); border-bottom: 1px solid var(--line);
}
.meal-title { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.meal-title small { color: var(--text-faint); font-weight: 600; font-size: 12px; }
.meal-kcal { font-size: 13px; font-weight: 650; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.meal-body { padding: 4px 0; }
.food-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 14px;
  border-bottom: 1px dashed var(--line);
}
.food-item:last-child { border-bottom: 0; }
.food-item-name { flex: 1 1 auto; min-width: 0; }
.food-item-name strong { font-weight: 600; font-size: 14px; }
.food-item-name .sub { font-size: 12px; color: var(--text-faint); }
.food-item-kcal { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14px; }
.item-btn {
  appearance: none; border: 0; background: transparent; color: var(--text-faint);
  cursor: pointer; font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 8px;
}
.item-btn:hover { background: var(--bg-soft); color: var(--text); }
.item-btn.del:hover { color: var(--danger); }
.empty-meal { padding: 12px 14px; color: var(--text-faint); font-size: 13px; }

/* ---------------- 明细表 ---------------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--line); }
.table th { font-size: 12.5px; color: var(--text-soft); font-weight: 650; text-transform: none; }
.table th:first-child, .table td:first-child { text-align: left; }
.table tr:last-child td { border-bottom: 0; }
.table .val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------- 食物库 ---------------- */
.food-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.food-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.food-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.food-card h4 { font-size: 15px; margin: 0; }
.food-card .brandline { font-size: 12px; color: var(--text-faint); }
.badge {
  font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-soft); white-space: nowrap;
}
.food-nutri { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 12px; text-align: center; }
.food-nutri div { background: var(--card-2); border-radius: 8px; padding: 6px 2px; }
.food-nutri b { display: block; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.food-nutri span { color: var(--text-faint); }
.food-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }

/* ---------------- 识别区 ---------------- */
.recognize-box {
  margin: 16px 0; padding: 14px; border: 1px dashed var(--accent);
  border-radius: var(--radius-sm); background: var(--accent-soft);
}
.recognize-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.recognize-head .hint { margin: 0; }
.recognize-box .input { background: var(--card); }
.recognize-result {
  margin-top: 12px; padding: 12px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--line); font-size: 13px;
}
.recognize-result ul { margin: 6px 0 0; padding-left: 18px; }
.recognize-result li { margin: 2px 0; font-variant-numeric: tabular-nums; }
.image-preview { margin-top: 10px; }
.image-preview img { max-width: 100%; border-radius: var(--radius-sm); cursor: zoom-in; border: 1px solid var(--line); }
.warn-line { color: var(--accent-2); font-size: 12.5px; }
.ok-line { color: var(--accent); font-size: 12.5px; }

/* ---------------- 弹窗 ---------------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(9, 15, 20, .5); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative; width: min(720px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 18px; border-top: 1px solid var(--line); background: var(--card-2); flex-wrap: wrap;
}
.modal-foot .row-actions { margin-top: 0; }

/* 导入示例食物：选择面板 */
.import-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 14px 0 12px; }
#importCats { margin-bottom: 12px; max-height: 116px; overflow-y: auto; }
.chip:disabled { opacity: .45; cursor: not-allowed; }
.import-list {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  max-height: 44vh; overflow-y: auto; background: var(--card);
}
.import-cat {
  position: sticky; top: 0; z-index: 1;
  padding: 7px 12px; font-size: 12px; font-weight: 700; color: var(--text-soft);
  background: var(--card-2); border-bottom: 1px solid var(--line);
}
.import-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px dashed var(--line); cursor: pointer; font-size: 14px;
}
.import-item:last-child { border-bottom: 0; }
.import-item:hover { background: var(--bg-soft); }
.import-item input { width: 16px; height: 16px; flex: none; cursor: pointer; accent-color: var(--accent); }
.import-item .nm { flex: 1 1 auto; min-width: 0; }
.import-item .kc { flex: none; color: var(--text-faint); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.import-item.is-on { background: var(--accent-soft); }
.import-item.is-on .nm { font-weight: 600; }
.import-empty { padding: 26px 16px; text-align: center; color: var(--text-faint); font-size: 13.5px; }

/* 选择食物 */
.picker-list { margin-top: 12px; max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.picker-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line); transition: .12s;
}
.picker-item:last-child { border-bottom: 0; }
.picker-item:hover { background: var(--bg-soft); }
.picker-item-name { flex: 1 1 auto; min-width: 0; }
.picker-item-name strong { font-size: 14px; }
.picker-item-name .sub { font-size: 12px; color: var(--text-faint); }
.picker-item-kcal { font-size: 13px; font-weight: 650; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.picker-empty { padding: 26px 16px; text-align: center; color: var(--text-faint); font-size: 13.5px; }

.selected-food {
  display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: var(--radius-sm);
  background: var(--card-2); border: 1px solid var(--line);
}
.gram-row { display: flex; gap: 10px; align-items: center; margin: 16px 0 10px; flex-wrap: wrap; }
.gram-input { width: 130px; font-size: 18px; font-weight: 650; padding: 10px 12px; }
.portion-preview { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.portion-cell { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px; text-align: center; }
.portion-cell b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.portion-cell span { font-size: 11.5px; color: var(--text-faint); }

/* ---------------- 图表 ---------------- */
.chart { width: 100%; display: block; }
.weight-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.weight-form .input[type="number"] { width: 120px; }

/* ---------------- 图片放大 ---------------- */
.lightbox { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .82); }
.lightbox img { position: relative; max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------------- 提示条 / 通知 ---------------- */
.banner {
  background: #fde68a; color: #713f12; padding: 11px 18px; font-size: 13.5px;
  text-align: center; border-bottom: 1px solid #f59e0b;
}
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #16202b; color: #fff; padding: 11px 20px; border-radius: 999px;
  font-size: 13.5px; z-index: 90; box-shadow: 0 12px 30px rgba(0, 0, 0, .3);
  max-width: 80vw;
  display: flex; align-items: center; gap: 14px;
}
.toast-btn {
  appearance: none; border: 0; font-family: inherit; font-size: 13.5px; font-weight: 700;
  background: rgba(255, 255, 255, .16); color: #fff; cursor: pointer;
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
}
.toast-btn:hover { background: rgba(255, 255, 255, .3); }

.footer {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-faint);
}

@media (max-width: 720px) {
  .app {
    padding: calc(14px + env(safe-area-inset-top)) 13px calc(86px + env(safe-area-inset-bottom));
  }
  .topbar { gap: 8px; margin-bottom: 14px; }
  .brand-text p { display: none; }
  .logo { width: 40px; height: 40px; font-size: 21px; }

  /* 手机上把导航放到屏幕底部，方便单手点 */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    width: auto; justify-content: space-around; gap: 4px;
    border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0;
    padding: 5px 8px calc(5px + env(safe-area-inset-bottom));
    background: var(--card);
    box-shadow: 0 -6px 22px rgba(16, 32, 48, .12);
  }
  .tab { flex: 1; padding: 11px 4px; font-size: 13.5px; border-radius: 12px; }

  /* 输入框字号 ≥16px，避免 iPhone 聚焦时页面自动放大 */
  .input, select.input, .textarea { font-size: 16px; }
  .gram-input { font-size: 18px; }
  .btn { padding: 10px 16px; }
  .item-btn { padding: 8px 6px; font-size: 14px; }

  .card { padding: 15px; }
  .span-2 { grid-column: auto; }
  .weight-big { font-size: 38px; }
  .food-item { gap: 8px; padding: 9px 10px; }
  .food-item-kcal { font-size: 13.5px; white-space: nowrap; }
  .food-item-name .sub { font-size: 11.5px; }
  .meal-head { flex-wrap: wrap; }

  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .modal { padding: 0; }
  .modal-panel { max-height: 100vh; height: 100%; border-radius: 0; }
  .modal-head { padding-top: calc(15px + env(safe-area-inset-top)); }
  .modal-body { padding: 15px; padding-bottom: 20px; }
  .modal-foot { padding-bottom: calc(13px + env(safe-area-inset-bottom)); }
  .lightbox {
    padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  }
  #importCats { max-height: 132px; }
  .import-list { max-height: 40vh; }
}
