/* 减肥日记 PWA — 与安卓版 v3 扁平版保持同一套设计语言
   底色 #F5F6F8 / 卡片纯白 + #E6E9EE 描边 / 圆角 12px / 唯一强调色墨绿 #0A7F57 */

:root {
  --bg: #f5f6f8;
  --bg-top: #f7f8fa;
  --surface1: #ffffff;
  --surface2: #fafbfc;
  --surface3: #eff1f4;
  --line: #e6e9ee;
  --card-border: #e6e9ee;
  --card-border-strong: #d8dde4;

  --green: #0a7f57;
  --green-light: #dcf3e9;
  --green-deep: #07714c;
  --green-dim: #eaf6f1;

  --meal-breakfast: #b45309;
  --meal-lunch: #0a7f57;
  --meal-dinner: #3f5a8c;
  --meal-snack: #6d5b8c;

  --amber: #a85b00;
  --amber-light: #fdf1e0;
  --coral: #e4572e;
  --red: #dc2626;
  --blue: #2563eb;
  --blue-light: #e8f0fe;

  --text-main: #15181d;
  --text-sub: #4e5765;
  --text-faint: #6e7683;

  --radius: 12px;
  --radius-sm: 8px;

  --nav-h: 58px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
  min-height: 100vh;
  min-height: 100dvh; /* iOS 上 100vh 含地址栏高度，用 dvh 兜底 */
}

button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-main);
}

/* ---------------------------------------------------------------- 布局 */

.view {
  padding: 8px 18px 24px;
  padding-top: calc(8px + var(--safe-top));
  max-width: 560px;
  margin: 0 auto;
  animation: fadeUp .18s ease-out;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  padding: 10px 0 14px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 0;
}

.page-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 4px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  padding: 18px 2px 9px;
}

.section-title .trailing {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- 卡片 */

.card {
  background: var(--surface1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card {
  margin-top: 10px;
}

.card-tight {
  padding: 13px 14px;
}

.card-accent {
  position: relative;
  background: var(--surface1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 16px 16px 19px;
  overflow: hidden;
}

.card-accent::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent, var(--green));
}

.stack-10 > * + * {
  margin-top: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.spacer {
  flex: 1;
}

.muted { color: var(--text-sub); }
.faint { color: var(--text-faint); }
.tiny { font-size: 11px; }
.small { font-size: 12px; }
.bold { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 环 */

.ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0 2px;
}

.ring {
  position: relative;
  width: 200px;
  height: 200px;
}

.ring svg {
  display: block;
  transform: rotate(-90deg);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.ring-label {
  font-size: 11px;
  color: var(--text-sub);
}

.ring-value {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -1.2px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.ring-unit {
  font-size: 11px;
  color: var(--text-faint);
}

.ring-sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.legend {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  width: 100%;
}

.legend.single .legend-item {
  flex: 0 0 auto;
  min-width: 116px;
}

.legend-item {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 7px 8px;
}

.legend-name {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--text-sub);
}

.legend-kcal {
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}

/* ---------------------------------------------------------------- 统计 */

.stats {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.stat {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px 9px;
}

.stat-label {
  font-size: 10.5px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.stat-value {
  font-size: 15px;
  font-weight: 600;
  margin-top: 2px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stat-value .u {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-faint);
  margin-left: 2px;
}

/* ---------------------------------------------------------------- 按钮 */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 46px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: opacity .12s, transform .12s;
}

.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; }

.btn-primary {
  background: var(--green);
  color: #fff;
}

.btn-ghost {
  background: var(--surface3);
  color: var(--text-faint);
  border: 1px solid var(--card-border);
}

.btn-outline {
  white-space: nowrap;
  background: var(--surface1);
  color: var(--text-main);
  border: 1px solid var(--card-border-strong);
  height: 42px;
  font-weight: 500;
  font-size: 13px;
}

.btn-sm {
  white-space: nowrap;
  height: 34px;
  font-size: 12.5px;
  border-radius: 8px;
  width: auto;
  padding: 0 14px;
  font-weight: 500;
}

.inline-action {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface1);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 12.5px;
  transition: background .12s;
}

.inline-action:active { background: var(--surface2); }

.inline-action .v {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-sub);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- Chip */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  background: var(--surface1);
  font-size: 12.5px;
  color: var(--text-sub);
  transition: background .12s, border-color .12s, color .12s;
}

.chip.on {
  background: var(--green-dim);
  border-color: rgba(10, 127, 87, .45);
  color: var(--green);
  font-weight: 500;
}

.chip.amber.on {
  background: var(--amber-light);
  border-color: rgba(168, 91, 0, .45);
  color: var(--amber);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 500;
  background: var(--surface3);
  color: var(--text-sub);
}

.pill.green { background: var(--green-dim); color: var(--green); }
.pill.amber { background: var(--amber-light); color: var(--amber); }
.pill.red { background: #fdeaea; color: var(--red); }

/* ---------------------------------------------------------------- 进度条 */

.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface3);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--green);
  transition: width .35s ease-out;
}

/* ---------------------------------------------------------------- 餐卡 */

.meal {
  background: var(--surface1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.meal + .meal { margin-top: 9px; }

.meal-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 13px;
  width: 100%;
  text-align: left;
}

.meal-thumb {
  width: 52px;
  height: 52px;
  border-radius: 9px;
  background: var(--surface3);
  flex: none;
  object-fit: cover;
  border: 1px solid var(--card-border);
}

.meal-thumb-ph {
  width: 52px;
  height: 52px;
  border-radius: 9px;
  background: var(--surface3);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-faint);
}

.meal-main { flex: 1; min-width: 0; }

.meal-type {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13.5px;
  font-weight: 600;
}

.meal-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-kcal {
  text-align: right;
  flex: none;
}

.meal-kcal .v {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meal-kcal .u {
  font-size: 10px;
  color: var(--text-faint);
  margin-left: 2px;
}

.meal-body {
  border-top: 1px solid var(--card-border);
  padding: 4px 13px 13px;
}

.dish {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid var(--card-border);
}

.dish:last-of-type { border-bottom: none; }

.conf-bar {
  width: 2.5px;
  height: 26px;
  border-radius: 2px;
  flex: none;
  background: var(--green);
}

.dish-main { flex: 1; min-width: 0; }

.dish-name {
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dish-meta {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 1px;
}

.dish-kcal {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.add-dish {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 0 2px;
  font-size: 12.5px;
  color: var(--green);
  font-weight: 500;
}

.warn-line {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 9px;
  padding: 8px 10px;
  background: var(--amber-light);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--amber);
  line-height: 1.45;
}

.err-line {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 9px;
  padding: 8px 10px;
  background: #fdeaea;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--red);
  line-height: 1.45;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 16px;
  text-align: center;
}

.empty-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 17px;
}

.empty-text {
  font-size: 12.5px;
  color: var(--text-faint);
  white-space: pre-line;
  line-height: 1.6;
}

/* ---------------------------------------------------------------- 表单 */

.field + .field { margin-top: 13px; }

.field-label {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 5px;
  line-height: 1.5;
}

.input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--card-border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface1);
  outline: none;
  transition: border-color .12s;
  /* iOS Safari 的规矩：输入框 font-size < 16px 会在聚焦时把整页放大，且不会自动缩回去。
     这里必须写 16px，视觉大小靠 height 控制，不要调小这一行。 */
  font-size: 16px;
}

.input:focus { border-color: var(--green); }

.input-sm {
  height: 38px;
  text-align: right;
  width: 96px;
  flex: none;
}

textarea.input {
  height: auto;
  padding: 10px 12px;
  resize: none;
  line-height: 1.5;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-row > .input {
  flex: 1;
  min-width: 0;
  width: auto;
}

.input-row > .btn {
  flex: none;
  width: auto;
  padding: 0 12px;
}

.input-unit {
  font-size: 12px;
  color: var(--text-faint);
  flex: none;
}

/* ---------------------------------------------------------------- 底栏 */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface1);
  border-top: 1px solid var(--card-border);
  padding-bottom: var(--safe-bottom);
  z-index: 40;
}

.bottom-nav-inner {
  display: flex;
  height: var(--nav-h);
  max-width: 560px;
  margin: 0 auto;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  color: var(--text-faint);
  transition: color .12s;
}

.nav-tab svg { width: 21px; height: 21px; }
.nav-tab.on { color: var(--green); font-weight: 500; }

/* 内联图标默认尺寸：没写 width/height 的 SVG 在 flex 容器里会塌成 0 */
.icon-inline svg,
.dish svg,
.empty-dot svg,
.shot-icon svg,
.legend-name svg {
  width: 18px;
  height: 18px;
  display: block;
}

.shot-icon svg { width: 22px; height: 22px; }
.empty-dot svg { width: 19px; height: 19px; }

/* ---------------------------------------------------------------- 弹窗 */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 28, .38);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .16s ease-out;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface1);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp .2s cubic-bezier(.2, .8, .3, 1);
}

@keyframes slideUp {
  from { transform: translateY(24px); }
  to { transform: none; }
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.sheet-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 16px;
  line-height: 1.5;
}

.sheet-actions {
  display: flex;
  gap: 9px;
  margin-top: 18px;
}

.sheet-actions .btn { flex: 1; }

/* 日期列表 */
.date-list { max-height: 340px; overflow-y: auto; }

.date-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 14px;
}

.date-row:active { background: var(--surface2); }
.date-row.on { background: var(--green-dim); color: var(--green); font-weight: 600; }
.date-row .sub { font-size: 11.5px; color: var(--text-faint); margin-left: auto; }
.date-row.on .sub { color: var(--green); }

/* ---------------------------------------------------------------- 拍照 */

.shot-area {
  position: relative;
  width: 100%;
  height: 250px;
  background: var(--surface1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.shot-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.shot-clear {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.shot-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
}

.picker-btns {
  display: flex;
  gap: 9px;
  margin-top: 2px;
}

.pill-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: 9px;
  background: var(--surface2);
  border: 1px solid var(--card-border-strong);
  font-size: 12.5px;
  font-weight: 500;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.tips {
  background: var(--surface1);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px 14px;
}

.tip {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.55;
}

.tip + .tip { margin-top: 7px; }

.tip-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-faint);
  margin-top: 8px;
  flex: none;
}

/* ---------------------------------------------------------------- 图表 */

.chart {
  width: 100%;
  display: block;
}

.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  font-size: 10.5px;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- 提示条 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  background: rgba(21, 24, 29, .92);
  color: #fff;
  font-size: 12.5px;
  padding: 9px 16px;
  border-radius: 9px;
  z-index: 200;
  max-width: 84vw;
  text-align: center;
  animation: fade .16s ease-out;
}

.progress-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 300;
}

.progress-top > i {
  display: block;
  height: 100%;
  width: 30%;
  background: var(--green);
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* ---------------------------------------------------------------- 工具 */

.hide { display: none !important; }

.loading-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-sub);
  padding: 10px 0;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--card-border-strong);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001s !important;
    transition-duration: .001s !important;
  }
}

/* ---- v6 新增 ---- */

/* 今日活动未填时的提示色 */
.inline-action.amber { background: var(--amber-light); border-color: var(--amber); }
.inline-action.amber .v { color: var(--amber); }

/* 保护线提醒 */
.warn-card { background: var(--amber-light); border-color: #f0dcbc; }
.warn-ico { color: var(--amber); display: flex; margin-top: 2px; }

/* 首页 21 天周期入口 */
.cycle-row {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; text-align: left; margin-top: 10px; padding: 14px;
}
.cycle-row .v { font-size: 12.5px; color: var(--text-sub); flex: none; }

/* 记录页右上角的报告小按钮 */
.mini-report {
  font-size: 10.5px; padding: 3px 8px; border-radius: 5px;
  font-weight: 500; line-height: 1.4;
}
.mini-report:active { opacity: 0.7; }
