/* ============================================================
 * 饮品食谱小记 - 样式
 * 设计风格：无限暖暖风 — 樱花粉 + 奶油黄，低饱和珠光渐变
 *           大圆角半透明卡片（毛玻璃），柔和阴影，简洁实用
 * ============================================================ */

/* ---------- 主题变量：低饱和珠光调色板（兼顾移动端对比度） ---------- */
:root {
  --pink: #ed8fa3;          /* 樱花粉（加深，按钮/chip 更清晰） */
  --pink-soft: #fbd5df;     /* 浅粉（保留温柔底色） */
  --cream: #ffe8b8;         /* 奶油黄（加深一点，让渐变有层次） */
  --cream-soft: #fff7e0;    /* 浅奶油 */
  --pearl: rgba(255,255,255,0.88);       /* 珠光卡片：0.88，减少发糊 */
  --pearl-strong: rgba(255,255,255,0.96);/* 顶栏/表单底栏更实 */
  --text: #5a3e46;          /* 暖棕文字（由 #6b4a52 加深到 WCAG 合格） */
  --text-soft: #8d6e74;     /* 次级文字（由 #a98b92 加深 ~15%） */
  --line: #efd1d7;          /* 描边色 */
  --danger: #d96474;        /* 删除色（加深，移动端清晰） */
  --ok: #6bb888;            /* 成功色 */
  --shadow: 0 8px 28px rgba(214, 130, 150, 0.22);
  --shadow-sm: 0 4px 14px rgba(214, 130, 150, 0.18);
  --radius: 26px;           /* 大圆角 */
  --radius-sm: 16px;
  /* 安全区域：max(env, 保底值) — 非 iOS env(safe-area-inset-*) 返回 0，
     但 standalone 模式下状态栏 + Home Indicator 需要至少 56px/34px。
     iPhone Home Indicator 实际高度约 34px，回退值必须 ≥34 才能兜底 */
  --safe-top:    max(env(safe-area-inset-top), 56px);
  --safe-bottom: max(env(safe-area-inset-bottom), 34px);
  /* 真实可用视口高度（由 JS 写入）：
     用 window.innerHeight 而非 100vh，避免 iOS Safari/PWA
     把地址栏/工具栏区域算入 vh 导致底部被切 */
  --app-height: 100vh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 强制 hidden 属性生效，防止 display 规则覆盖导致隐藏元素可见 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  /* 樱花粉→奶油黄 珠光渐变背景 */
  background:
    radial-gradient(120% 80% at 0% 0%, var(--pink-soft) 0%, transparent 55%),
    radial-gradient(120% 80% at 100% 10%, var(--cream) 0%, transparent 55%),
    linear-gradient(180deg, #fff8fb 0%, #fffaf0 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 关键：用 --app-height（JS 计算 = innerHeight）替换 100vh，
     确保 PWA standalone / Safari 地址栏收起后不把底部内容推出屏幕外 */
  height: 100%;               /* fallback */
  height: var(--app-height);
  min-height: 100%;
  min-height: var(--app-height);
  width: 100vw;
  /* 不再在 body 加 safe 区 padding — 各组件自行按 --safe-top/--safe-bottom 控制 */
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}
/* body 内主容器滚动：topbar 固定后，main 区域独立滚动 */
body { overflow: hidden; position: relative; }

/* ---------- 顶部栏：fixed + 计算出的 topbar 高度，避免和状态栏重叠 ---------- */
:root {
  /* 由 JS 同步写入，保证列表区避开顶栏底部 */
  --topbar-h: 160px;
}
.topbar {
  position: fixed;
  left: 0; right: 0; top: 0;
  z-index: 30;
  padding: calc(var(--safe-top) + 8px) 16px 12px;
  /* 毛玻璃顶栏（更实，避免文字发糊） */
  background: linear-gradient(180deg, var(--pearl-strong) 0%, rgba(255,248,251,0.92) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-emoji { font-size: 24px; }
.brand-title { font-weight: 800; font-size: 20px; color: var(--text); letter-spacing: 0.2px; }

.search-wrap { margin-top: 12px; }
#searchInput {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--pearl-strong);
  padding: 0 20px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow-sm);
}
#searchInput::placeholder { color: var(--text-soft); }

/* 分类 chips */
.chips {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 9px 18px;
  border-radius: 22px;
  background: var(--pearl-strong);
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.chip.active {
  background: linear-gradient(135deg, var(--pink) 0%, var(--cream) 100%);
  border-color: transparent;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(107,74,82,0.25);
  box-shadow: var(--shadow-sm);
}

/* ---------- 页面主滚动区：避开顶栏上方 / FAB 下方，可独立滚 ---------- */
.page-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-top: calc(var(--topbar-h) + 12px);
  /* 底部留空 = FAB(60+16) + 安全区 + 额外间隙(4) = 80px + safe
     确保滚动到底部时末行文字不被悬浮加号遮挡 */
  padding-bottom: calc(env(safe-area-inset-bottom) + 80px);
}

/* ---------- iOS 添加主屏幕提示横幅 ---------- */
.home-hint {
  margin: 4px 16px 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--pearl-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  animation: dropIn .35s ease;
  max-width: 680px;
  margin-left: auto; margin-right: auto;
}
.home-hint-body { display: flex; align-items: center; gap: 10px; }
.home-hint-icon { font-size: 22px; }
.home-hint-text { flex: 1; font-size: 13px; color: var(--text-soft); font-weight: 500; }
.home-hint-text b { color: var(--text); font-weight: 700; }
.home-hint-close {
  border: none;
  background: transparent;
  font-size: 24px;
  color: var(--text-soft);
  cursor: pointer;
  line-height: 1;
}

/* ---------- 列表 ---------- */
.list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 4px 16px 24px;
  max-width: 680px;
  margin: 0 auto;
}

/* 卡片：大圆角半透珠光 */
.card {
  background: var(--pearl);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fadeUp .35s ease both;
}
.card-top { display: flex; gap: 14px; padding: 16px; }
.card-thumb {
  width: 82px; height: 82px;
  border-radius: 20px;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--cream-soft);
}
.card-thumb-placeholder {
  width: 82px; height: 82px;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  background: linear-gradient(135deg, var(--pink-soft), var(--cream-soft));
  flex: 0 0 auto;
}
.card-body { flex: 1; min-width: 0; }
.card-title {
  font-size: 18px; font-weight: 800; margin: 0 0 6px;
  color: var(--text);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card-cat {
  font-size: 12px; font-weight: 700;
  padding: 3px 12px; border-radius: 12px;
  background: linear-gradient(135deg, var(--pink-soft), var(--cream));
  color: var(--text);
}
.card-snippet {
  font-size: 14px; color: var(--text-soft); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-height: 1.55;
}

/* 同一食谱不同做法（按名字分组）：版本切换条 */
.version-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
}
.version-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 12px; font-weight: 700;
  background: var(--cream-soft);
  color: var(--text);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all .15s;
}
.version-chip.active {
  background: linear-gradient(135deg, var(--pink-soft), var(--cream));
  border-color: transparent;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.version-chip.add-more {
  border-style: dashed;
  border-color: var(--pink);
  color: var(--danger);
  background: #fff;
}
.version-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700; color: var(--text);
  background: linear-gradient(135deg, var(--cream-soft), var(--pink-soft));
  margin-left: 6px;
}

.card-actions {
  display: flex; gap: 10px; padding: 6px 16px 16px; justify-content: flex-end;
}
.card-actions button {
  border: 1px solid transparent;
  background: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 14px; font-weight: 700;
  color: var(--text);
  padding: 9px 16px; border-radius: 14px;
  box-shadow: 0 2px 6px rgba(214,130,150,0.12);
  transition: all .15s;
}
.card-actions button:active { transform: scale(0.96); }
.card-actions button:hover, .card-actions button:focus {
  background: #fff; border-color: var(--line); color: var(--text);
}
.card-actions .del {
  color: #fff;
  background: linear-gradient(135deg, var(--danger), #ec97a3);
  border: none;
}

/* 空状态 */
.empty { text-align: center; color: var(--text-soft); padding: 40px 20px 100px; font-weight: 500; }
.empty-emoji { font-size: 48px; }

/* ---------- 悬浮新增按钮 ---------- */
.fab {
  position: fixed;
  right: 16px;
  /* 基于 iPhone 安全区偏移，不贴底，不被手势横条遮挡 */
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  /* flex 居中：让 ＋ 图标在圆形内完美居中，不同字体/行高都不会歪 */
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  font-size: 34px; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, var(--pink) 0%, #e77b93 100%);
  box-shadow: 0 12px 28px rgba(214,130,150,0.55);
  cursor: pointer;
  z-index: 40;
  transition: transform .15s;
}
.fab:active { transform: scale(0.92); }

/* ---------- 通用按钮 ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 22px;
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  transition: transform .12s, filter .2s;
  letter-spacing: 0.3px;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--pink) 0%, var(--cream) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
  text-shadow: 0 1px 2px rgba(107,74,82,0.25);
}
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: linear-gradient(135deg, var(--danger) 0%, #ec8a95 100%); color: #fff;
  text-shadow: 0 1px 2px rgba(107,74,82,0.2); }

.icon-btn {
  border: none; background: transparent; cursor: pointer;
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 18px; color: var(--text);
}
.mini-btn {
  border: 1px solid var(--line); background: var(--pearl);
  border-radius: 12px; padding: 8px 12px; font-size: 13px;
  color: var(--text); cursor: pointer;
}
.mini-btn:disabled { opacity: .45; }

/* ---------- 弹层 sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-mask {
  position: absolute; inset: 0;
  background: rgba(90, 62, 70, 0.36);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn .2s;
}
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  /* 高度由 JS 直接设置（style="height: Xpx"），避免 iOS Safari 对 CSS 变量/
     min()/max-height 重算的 bug。JS 会在打开 sheet 时、键盘弹起/收起时
     实时更新 height，确保表单底部永远不被键盘遮挡。 */
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--cream-soft) 0%, #fff 30%);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -12px 44px rgba(214,130,150,0.38);
  padding: 0;
  animation: slideUp .3s ease;
  /* 高度平滑过渡 */
  transition: height .22s ease;
  /* flex 子项：sheet-head 和 sheet-foot 固定，sheet-body 滚动 */
  overflow: hidden; /* 防止 panel 自身溢出 */
}
.sheet-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 10px;
}
.sheet-head h2 { margin: 0; font-size: 19px; color: var(--text); font-weight: 800; }
/* 表单/详情主体：可独立滚动，不会把底部按钮推出屏幕 */
.sheet-body {
  flex: 1 1 auto;
  /* min-height:0 让 flex 子项能缩小到内容以下，否则 iOS Safari 会把 sheet-body 撑到内容高度 */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 18px 18px;
}
/* 操作区：固定在弹窗底部，不参与滚动，留足 iPhone 手势横条安全距离 */
.sheet-foot {
  flex-shrink: 0;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, #ffffff 45%);
  border-top: 1px solid var(--line);
}

/* ---------- 表单 ---------- */
.form { display: flex; flex-direction: column; gap: 0; flex: 1 1 auto; min-height: 0; }
.form .sheet-body {
  display: flex; flex-direction: column; gap: 14px;
  /* 确保 sheet-body 在 form 里也能独立滚动 */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 14px; color: var(--text); font-weight: 700; }
.label i { color: var(--danger); font-style: normal; font-weight: 700; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 11px 14px;
  font-size: 15px; color: var(--text);
  outline: none; font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(247,181,196,0.25);
}
textarea { resize: vertical; min-height: 60px; line-height: 1.6; max-height: 200px; overflow-y: auto; }

.cat-row { display: flex; gap: 8px; }
.cat-row select { flex: 1; }
.cat-row input { flex: 1; }

.img-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.upload-btn {
  border: 1px dashed var(--pink);
  border-radius: var(--radius-sm);
  padding: 10px 14px; cursor: pointer;
  color: var(--text); font-size: 14px;
  background: var(--pearl);
}
.preview {
  width: 84px; height: 84px; border-radius: 16px;
  object-fit: cover; border: 1px solid var(--line);
}
.ocr-status {
  margin-top: 6px; font-size: 13px; color: var(--text-soft);
  background: var(--cream-soft); padding: 8px 12px; border-radius: 12px;
}

.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
}
.form-actions .btn { min-width: 104px; font-weight: 700; }

/* ---------- 详情面板 ---------- */
.detail-head { display: flex; gap: 14px; margin-bottom: 14px; align-items: center; }
.detail-head img { width: 92px; height: 92px; border-radius: 18px; object-fit: cover; }
.detail-head .ph { width: 92px; height: 92px; border-radius: 18px; display:flex; align-items:center; justify-content:center; font-size:38px;
  background: linear-gradient(135deg, var(--pink-soft), var(--cream-soft)); }
.detail-sec { margin: 16px 0; }
.detail-sec h3 { margin: 0 0 6px; font-size: 14px; color: var(--text-soft); font-weight: 700; letter-spacing: 0.2px; }
.detail-sec p, .detail-sec pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 15px; color: var(--text); font-weight: 500; line-height: 1.7; }
.detail-title { font-size: 21px; font-weight: 800; margin: 0; color: var(--text); }
.detail-cat { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 10px;
  background: linear-gradient(135deg, var(--pink-soft), var(--cream)); color: var(--text); }
.source-link {
  display: inline-block; margin-top: 6px; padding: 8px 14px;
  background: linear-gradient(135deg, var(--pink), var(--cream));
  color: #fff; border-radius: 14px; text-decoration: none; font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.detail-actions { display: flex; gap: 10px; }
.detail-actions .btn { flex: 1; min-width: 0; font-weight: 700; }

/* ---------- 管理分类面板 ---------- */
.cat-list { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 0; }
.cat-row-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.cat-row-item .cat-name { flex: 1; font-size: 15px; font-weight: 700; color: var(--text); }
.cat-row-item .cat-name .builtin-tag {
  display: inline-block; margin-left: 8px;
  font-size: 11px; font-weight: 700; color: var(--text-soft);
  background: var(--cream-soft); padding: 2px 8px; border-radius: 8px;
}
.cat-row-item .cat-count {
  font-size: 12px; color: var(--text-soft); font-weight: 600;
  margin-right: 4px;
}
.cat-row-item .mini-btn {
  padding: 6px 10px; font-size: 12px; border-radius: 10px;
}
.cat-row-item .mini-btn.rename { color: var(--text); border-color: var(--line); background: var(--cream-soft); }
.cat-row-item .mini-btn.del   { color: #fff; background: linear-gradient(135deg, var(--danger), #ec97a3); border-color: transparent; }
.cat-row-item .mini-btn:disabled { opacity: .4; }
.cat-row-empty { text-align: center; padding: 30px 10px; color: var(--text-soft); font-weight: 500; }
.cat-add-row { display: flex; gap: 8px; margin-top: 14px; }
.cat-add-row input { flex: 1; }
.cat-add-row .mini-btn { padding: 10px 14px; font-size: 14px; border-color: var(--pink); color: #fff;
  background: linear-gradient(135deg, var(--pink), #e77b93); border-color: transparent; }

/* ---------- 数据备份/恢复区域（在管理分类面板底部） ---------- */
.data-io-section {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--pearl-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.data-io-title {
  margin: 0 0 4px;
  font-size: 15px; font-weight: 800; color: var(--text);
}
.data-io-desc {
  font-size: 12px; color: var(--text-soft); font-weight: 500; line-height: 1.6;
  margin-bottom: 14px;
}
.data-io-row {
  display: flex; gap: 10px;
}
.data-io-row .btn {
  flex: 1; min-width: 0;
  padding: 11px 16px; font-size: 14px; font-weight: 700;
}

/* ---------- 确认弹窗 ---------- */
.confirm {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(107,74,82,0.4); backdrop-filter: blur(4px);
  animation: fadeIn .2s; padding: 20px;
}
.confirm-box {
  background: #fff; border-radius: var(--radius);
  padding: 22px; max-width: 320px; width: 100%;
  box-shadow: var(--shadow); text-align: center;
  animation: pop .25s ease;
}
.confirm-box p { margin: 0 0 18px; color: var(--text); font-size: 15px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%;
  /* 避免被 FAB 遮挡：FAB 高度(60) + 距底(16) + 安全区 + 间距 */
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  transform: translateX(-50%);
  background: rgba(90, 62, 70, 0.95); color: #fff;
  padding: 12px 22px; border-radius: 22px; font-size: 14px; font-weight: 600;
  z-index: 90; box-shadow: var(--shadow);
  animation: toastIn .3s ease; max-width: 86%; text-align: center;
}

/* ---------- 动画 ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px);} to { opacity:1; transform:none;} }
@keyframes dropIn { from { opacity:0; transform: translateY(-8px);} to { opacity:1; transform:none;} }
@keyframes fadeIn { from {opacity:0;} to {opacity:1;} }
@keyframes slideUp { from { transform: translateY(100%);} to { transform:none;} }
@keyframes pop { from { opacity:0; transform: scale(.9);} to { opacity:1; transform:none;} }
@keyframes toastIn { from { opacity:0; transform: translate(-50%, 12px);} to { opacity:1; transform: translate(-50%,0);} }

/* 大屏适配：卡片两列 */
@media (min-width: 720px) {
  .list { grid-template-columns: 1fr 1fr; }
}
