/* 食记 · 移动端优先样式 */

:root {
  --bg: #f2f5f4;
  --card: #ffffff;
  --card-2: #f7f9f8;
  --text: #16212b;
  --muted: #6b7c8c;
  --line: #e3e9e6;
  --accent: #2f9e6e;
  --accent-soft: #e6f4ee;
  --carb: #ef9b3d;
  --protein: #3d8bd4;
  --fat: #d15f8c;
  --danger: #d9534f;
  --shadow: 0 1px 2px rgba(16, 32, 26, 0.06), 0 6px 18px rgba(16, 32, 26, 0.05);
  --radius: 16px;
  --tabbar-h: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #171c23;
    --card-2: #1e242c;
    --text: #e7edf3;
    --muted: #8b9aa8;
    --line: #262d36;
    --accent: #3fbd87;
    --accent-soft: #14352a;
    --danger: #e5645f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei',
    'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── 顶栏 ─────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 8px;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.date-nav button {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.date-nav .label {
  min-width: 118px;
  text-align: center;
  font-weight: 650;
  font-size: 16px;
}

.date-nav .label small {
  display: block;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  margin-top: -2px;
}

.topbar .appname {
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
}

/* ── 底部标签栏 ───────────────────────────────────── */
.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
  border: 0;
  background: none;
  padding: 7px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}

.tabbar button .ti {
  font-size: 19px;
  line-height: 1.1;
  filter: grayscale(1) opacity(0.65);
}

.tabbar button.active {
  color: var(--accent);
  font-weight: 600;
}

.tabbar button.active .ti {
  filter: none;
}

/* ── 主体 ─────────────────────────────────────────── */
.view {
  flex: 1;
  padding: 12px 12px calc(var(--tabbar-h) + 24px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.card-head .sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

/* ── 三大营养素环 ─────────────────────────────────── */
.nutri {
  display: flex;
  align-items: center;
  gap: 16px;
}

.ring-wrap {
  position: relative;
  width: 132px;
  height: 132px;
  flex: none;
}

.ring-wrap svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ring-center b {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}

.ring-center span {
  font-size: 10px;
  color: var(--muted);
}

.nutri-legend {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.nutri-item .row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.nutri-item .name {
  font-weight: 600;
  width: 30px;
  flex: none;
}

.nutri-item .val {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.nutri-item .pct {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.bar {
  height: 6px;
  border-radius: 4px;
  background: var(--card-2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin-top: 4px;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 4px;
}

.bar.carb > i { background: var(--carb); }
.bar.protein > i { background: var(--protein); }
.bar.fat > i { background: var(--fat); }
.bar.kcal > i { background: var(--accent); }

.nutri-foot {
  display: flex;
  gap: 14px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

.nutri-foot b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── 餐次 / 条目 ──────────────────────────────────── */
.slot {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 10px;
}

.slot:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.slot-head .slot-name {
  font-weight: 650;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.slot-head .slot-sum {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entries li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}

.entries li:last-child {
  border-bottom: 0;
}

.entries .name {
  flex: 1;
  min-width: 0;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.entries .qty {
  color: var(--muted);
  font-size: 12px;
}

.entries .kcal {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.entries .macros {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

.row-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  border: 0;
  background: var(--card-2);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.chev {
  flex: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  width: 10px;
  text-align: right;
}

.icon-btn:hover { color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

.icon-btn.fav {
  color: var(--muted);
  opacity: 0.45;
}

.icon-btn.fav.on {
  color: var(--carb);
  opacity: 1;
}

/* ── 快捷区（最近常吃 / 常用） ─────────────────────── */
.quick-head {
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
  margin: 2px 0 7px;
}

.quick-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.quick-row::-webkit-scrollbar { display: none; }

.quick-item {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 12px;
  padding: 7px 12px;
  text-align: left;
  cursor: pointer;
  min-width: 104px;
  max-width: 160px;
}

.quick-item:active { background: var(--accent-soft); }

.quick-item .qn {
  display: block;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-item .qk {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quick-item.fav { border-color: color-mix(in srgb, var(--carb) 45%, var(--line)); }
.quick-item.fav .qn { color: var(--carb); }

.btn-mini {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
  background: transparent;
}

.btn.block { width: 100%; }

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn { flex: 1; }

/* ── 表单 ─────────────────────────────────────────── */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card-2);
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── 食物库列表 ───────────────────────────────────── */
.food-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.food-item:last-child { border-bottom: 0; }

.food-item .info { flex: 1; min-width: 0; }

.food-item .fname {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.food-item .fmeta {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.tag {
  display: inline-block;
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
  margin-left: 6px;
  vertical-align: 1px;
}

.search-input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  outline: none;
  margin-bottom: 10px;
}

.search-input:focus { border-color: var(--accent); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 26px 10px;
}

/* ── 体重图表 ─────────────────────────────────────── */
.chart {
  width: 100%;
  height: 190px;
  display: block;
}

.weight-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.stat {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.stat .k {
  font-size: 11.5px;
  color: var(--muted);
}

.stat .v {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.stat .v small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 3px;
}

.down { color: var(--accent); }
.up { color: var(--danger); }

/* ── 底部弹层 ─────────────────────────────────────── */
.sheet-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}

.sheet-root.open { display: block; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 16, 22, 0.45);
  animation: fade 0.18s ease;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25);
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
  max-width: 720px;
  margin: 0 auto;
}

@keyframes rise {
  from { transform: translateY(16%); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  flex: 1;
  text-align: center;
}

.sheet-head .spacer { width: 34px; }

.sheet-body {
  overflow-y: auto;
  padding: 12px 14px;
  -webkit-overflow-scrolling: touch;
}

.sheet-foot {
  padding: 12px 14px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--line);
  background: var(--card);
}

.qty-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 6px 0 2px;
}

.qty-box .food-title {
  font-weight: 650;
  font-size: 16px;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 18px;
}

.qty-row button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card-2);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.qty-val {
  min-width: 96px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.nutrient-preview {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}

.nutrient-preview .n {
  font-size: 11px;
  color: var(--muted);
}

.nutrient-preview .v {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── 提示条 ───────────────────────────────────────── */
.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(20, 28, 34, 0.94);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  animation: rise 0.18s ease;
  max-width: 90%;
  text-align: center;
}

.toast.err { background: var(--danger); }

/* ── 锁屏 / 安装引导 ──────────────────────────────── */
.lock {
  text-align: center;
  padding: 40px 20px;
}

.lock h2 { font-size: 18px; margin: 0 0 6px; }
.lock p { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

.lock input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  margin-bottom: 10px;
  text-align: center;
  letter-spacing: 1px;
}

.install-tip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

.install-tip .grow { flex: 1; }

.link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
}

.list-row:last-child { border-bottom: 0; }

.list-row .lk {
  font-size: 14px;
  font-weight: 550;
}

.list-row .ld {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.section-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ── 桌面端微调 ───────────────────────────────────── */
@media (min-width: 760px) {
  .view { padding: 18px 18px 60px; }
  .tabbar {
    position: static;
    order: -1;
    top: auto;
    bottom: auto;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 150px));
    justify-content: center;
  }
  .tabbar button { padding: 10px 0; }
  .tabbar button .ti { font-size: 17px; }
  .topbar { position: static; }
  .sheet { border-radius: 20px; bottom: 24px; max-width: 520px; }
  .weight-stats { grid-template-columns: repeat(4, 1fr); }
}
