/* ===== 主题变量 ===== */
:root {
  --bg: #fff7ed;
  --surface: #ffffff;
  --surface-2: #ffedd5;
  --text: #1c1917;
  --text-2: #78716c;
  --text-3: #a8a29e;
  --primary: #f97316;
  --primary-dark: #ea580c;
  --danger: #dc2626;
  --ok: #16a34a;
  --border: #f5e6d6;
  --shadow: 0 1px 3px rgba(120, 53, 15, 0.08), 0 4px 16px rgba(120, 53, 15, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --tabbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
[data-theme="dark"] {
  --bg: #14120f;
  --surface: #211d19;
  --surface-2: #2b2620;
  --text: #f5f0ea;
  --text-2: #b3a99e;
  --text-3: #7d746a;
  --primary: #fb923c;
  --primary-dark: #f97316;
  --border: #332c25;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* ===== 基础 ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-dark); text-decoration: none; }
img { max-width: 100%; }
input, textarea, select, button { font: inherit; color: inherit; }
.hidden-input { display: none; }
.muted { color: var(--text-3); font-size: 12px; margin-left: 4px; }
.hint { color: var(--text-2); font-size: 13px; line-height: 1.6; }
.hint.warn { color: var(--primary-dark); }
.hint.center { text-align: center; padding: 8px 0; }
.link { word-break: break-all; }
.pre-line { white-space: pre-wrap; word-break: break-word; }

/* ===== 布局 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.app-title { margin: 0; font-size: 18px; font-weight: 700; }
.view {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 14px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-3);
  font-size: 11px;
}
.tab .tab-icon { font-size: 19px; line-height: 1; }
.tab.active { color: var(--primary-dark); font-weight: 600; }

/* ===== 通用控件 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  transition: transform 0.05s ease, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); border-color: transparent; background: transparent; }
.btn-small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-icon {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-2);
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn-icon:disabled { opacity: 0.3; }
.btn-icon-only { padding: 8px 12px; font-size: 18px; }
.input, .search-input, .sort-select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 15px;
  outline: none;
}
.input:focus, .search-input:focus, .sort-select:focus, .textarea:focus { border-color: var(--primary); }
.input-qty { max-width: 110px; }
.search-input { background: var(--surface-2); border-color: transparent; }
.sort-select { width: auto; }
.textarea { resize: vertical; min-height: 60px; }
.check-label { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; color: var(--text); margin: 2px 10px 2px 0; cursor: pointer; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 12px 0 6px; }

/* ===== 卡片与工具条 ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.card-link { font-size: 13px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar .search-input { flex: 1; }
.toolbar-wrap { flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 8px; margin-left: auto; }
.add-row { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.add-row .input { flex: 1; min-width: 120px; }
.week-nav { display: flex; gap: 8px; }
.summary { color: var(--text-2); font-size: 13px; margin: 6px 2px 8px; }

/* ===== 首页 ===== */
.meal-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.meal-row:last-child { border-bottom: none; }
.meal-label { font-size: 13px; color: var(--text-2); width: 34px; flex-shrink: 0; }
.meal-value { font-weight: 600; }
.meal-empty { color: var(--text-3); font-weight: 400; }
.meal-note { font-size: 12px; color: var(--text-2); margin-left: auto; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.quick-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text);
  box-shadow: var(--shadow);
  position: relative;
}
.quick-icon { font-size: 24px; }
.quick-name { font-size: 12px; color: var(--text-2); text-align: center; }
.quick-badge {
  position: absolute; top: 6px; right: 8px;
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; line-height: 18px;
  border-radius: 9px; text-align: center; padding: 0 5px;
}
.quick-badge-plain { background: var(--text-3); }
.quick-badge-warn { background: var(--danger); }
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item { display: flex; align-items: center; gap: 10px; color: var(--text); }
.recent-cover { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.recent-cover-empty { display: flex; align-items: center; justify-content: center; font-size: 22px; }
.recent-name { font-weight: 600; }
.recent-time { font-size: 12px; color: var(--text-3); }

/* ===== 菜谱列表 ===== */
.recipe-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.recipe-cover-wrap { aspect-ratio: 4/3; background: var(--surface-2); }
.recipe-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.recipe-cover-empty { display: flex; align-items: center; justify-content: center; font-size: 40px; }
.recipe-card-body { padding: 9px 11px 11px; }
.recipe-name { font-weight: 700; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-meta { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-filter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip-active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.chip-small { padding: 2px 8px; font-size: 11px; cursor: default; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }

/* ===== 菜谱详情 ===== */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-cover { width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--radius); margin-bottom: 12px; }
.detail-title { margin: 0 0 8px; font-size: 22px; }
.detail-people { color: var(--text-2); font-size: 14px; margin-bottom: 10px; }
.detail-section { padding: 14px; }
.ingredient-list { display: flex; flex-direction: column; }
.ingredient-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 2px; border-bottom: 1px dashed var(--border); }
.ingredient-group { font-weight: 700; color: var(--text-2); border-bottom: none; padding-top: 10px; }
.ingredient-prop { color: var(--text-2); }
.step-list { display: flex; flex-direction: column; gap: 12px; }
.step-row { display: flex; gap: 10px; }
.step-index {
  width: 24px; height: 24px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.step-img { border-radius: 10px; margin-top: 6px; max-height: 220px; object-fit: cover; }

/* ===== 计划 ===== */
.week-title { font-size: 15px; margin: 4px 0 10px; color: var(--text-2); }
.plan-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; overflow-x: auto; }
.plan-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  min-width: 92px;
}
.plan-day-today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.plan-day-head { text-align: center; margin-bottom: 6px; }
.plan-day-date { font-weight: 700; font-size: 13px; }
.plan-day-week { font-size: 11px; color: var(--text-2); }
.plan-slot {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 6px 5px;
  margin-bottom: 6px;
  min-height: 52px;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--surface-2);
}
.plan-slot-filled { border-style: solid; background: var(--surface); }
.plan-slot-cover { width: 100%; height: 42px; object-fit: cover; border-radius: 6px; }
.plan-slot-body { flex: 1; }
.plan-slot-name { font-size: 12px; font-weight: 600; line-height: 1.3; }
.plan-slot-note { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.plan-slot-label { font-size: 11px; color: var(--text-3); }
.plan-slot-text { font-size: 11px; color: var(--text-2); }
.plan-slot-menu { position: absolute; top: 1px; right: 1px; width: 22px; height: 22px; font-size: 13px; }
.picker-list { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.picker-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}
.picker-cover { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.picker-cover-empty { display: flex; align-items: center; justify-content: center; font-size: 18px; }
.picker-name { font-weight: 600; }
.menu-item {
  display: block; width: 100%;
  padding: 12px 14px;
  border: none; background: transparent;
  border-bottom: 1px solid var(--border);
  text-align: left; font-size: 15px;
  cursor: pointer;
}
.menu-item:last-child { border-bottom: none; }
.menu-item-danger { color: var(--danger); }
.meal-checks { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== 采购 / 库存 ===== */
.shopping-list, .inventory-list { display: flex; flex-direction: column; gap: 6px; }
.shopping-row, .inventory-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.shopping-check { width: 20px; height: 20px; accent-color: var(--primary); flex-shrink: 0; }
.shopping-info, .inventory-info { flex: 1; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; min-width: 0; }
.shopping-name, .inventory-name { font-weight: 600; }
.shopping-qty, .inventory-qty { color: var(--primary-dark); font-size: 13px; }
.shopping-note, .inventory-note { color: var(--text-3); font-size: 12px; }
.shopping-done .shopping-name { text-decoration: line-through; color: var(--text-3); }
.shopping-done .shopping-qty { color: var(--text-3); }

/* ===== 我的 ===== */
.data-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.data-row:last-child { border-bottom: none; }
.data-info { flex: 1; min-width: 0; }
.data-label { font-weight: 600; font-size: 14px; }
.data-desc { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.tags-manage { display: flex; flex-direction: column; gap: 6px; }
.tag-manage-row { display: flex; align-items: center; gap: 8px; padding: 7px 2px; }
.tag-manage-name { font-weight: 600; }
.tag-manage-count { color: var(--text-3); font-size: 12px; flex: 1; }
.mode-select { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.sample-names { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; align-items: center; }
.import-warnings { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }

/* ===== 编辑表单 ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.editable-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.editable-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px;
}
.editable-row .input { background: var(--surface); }
.editable-row-steps { align-items: flex-start; }
.step-no {
  width: 22px; height: 22px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-top: 8px;
}
.row-actions { display: flex; gap: 2px; }
.step-thumb-wrap { position: relative; }
.step-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; display: block; }
.step-thumb-del {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px;
  background: var(--danger); color: #fff;
  border-radius: 50%; font-size: 11px;
}
.cover-edit { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.edit-cover-preview { width: 110px; height: 82px; object-fit: cover; border-radius: 10px; display: none; }
.sticky-save { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px); background: var(--bg); padding: 8px 0; }

/* ===== 弹窗 / 提示 ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column;
  padding: 14px 16px calc(16px + var(--safe-bottom));
  overflow: hidden;
}
.modal-wide { max-width: 700px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-title { font-weight: 700; font-size: 16px; }
.modal-body { overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.confirm-text { line-height: 1.7; }
.plan-pick-grid { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0; }
.plan-pick-col { flex-shrink: 0; width: 84px; text-align: center; }
.plan-pick-date { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.plan-pick-slot {
  display: block; width: 100%;
  padding: 8px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 6px;
}
.plan-pick-slot:active { background: var(--primary); color: #fff; }

.toast-box {
  position: fixed;
  top: calc(var(--safe-top) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(28, 25, 23, 0.92);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 86vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: var(--ok); }
.toast-warn { background: var(--primary-dark); }
.toast-error { background: var(--danger); }

/* ===== 空状态 ===== */
.empty-state { text-align: center; padding: 44px 16px; color: var(--text-2); }
.empty-icon { font-size: 44px; margin-bottom: 10px; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-hint { font-size: 13px; margin-top: 6px; }
.error-card { color: var(--danger); }

@media (min-width: 560px) {
  .recipe-grid { grid-template-columns: repeat(3, 1fr); }
  .modal { border-radius: 18px; margin-bottom: 4vh; }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { --bg: #14120f; --surface: #211d19; --surface-2: #2b2620; --text: #f5f0ea; --text-2: #b3a99e; --text-3: #7d746a; --primary: #fb923c; --primary-dark: #f97316; --border: #332c25; --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.3); }
}
