/* ============================================
   冰箱管家 — 移动优先、明亮厨房风
   ============================================ */

:root {
  --green: #4caf50;
  --green-dark: #388e3c;
  --green-light: #c8e6c9;
  --orange: #ff9800;
  --orange-light: #ffe0b2;
  --red: #f44336;
  --red-light: #ffcdd2;
  --blue: #2196f3;
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-400: #bdbdbd;
  --gray-500: #9e9e9e;
  --gray-700: #616161;
  --gray-900: #212121;
  --bg: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 2px 6px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --tabbar-h: 64px;
  --header-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ============ 顶部 ============ */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--green);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 16px;
  box-shadow: var(--shadow);
  z-index: 100;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.app-header .header-status {
  font-size: 13px;
  opacity: 0.95;
  padding: 4px 10px;
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
}

/* ============ 主体 ============ */
.app-main {
  padding: calc(var(--header-h) + 12px) 12px calc(var(--tabbar-h) + 24px);
  max-width: 720px;
  margin: 0 auto;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s; }
@keyframes fadeIn { from {opacity:0;transform:translateY(6px);} to {opacity:1;transform:none;} }

/* ============ 卡片 ============ */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-title .badge {
  background: var(--green-light);
  color: var(--green-dark);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}

/* ============ 统计网格 ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-cell {
  text-align: center;
  padding: 12px 4px;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
}

.stat-cell .num {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.1;
}

.stat-cell .label {
  font-size: 12px;
  color: var(--gray-700);
  margin-top: 2px;
}

.stat-cell.warn .num { color: var(--orange); }
.stat-cell.danger .num { color: var(--red); }
.stat-cell.ok .num { color: var(--green-dark); }

/* ============ 列表 ============ */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: white;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  gap: 10px;
}

.list-item .icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--green-light);
  color: var(--green-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.list-item .info { flex: 1; min-width: 0; }
.list-item .name {
  font-weight: 500;
  color: var(--gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .meta {
  font-size: 12px;
  color: var(--gray-700);
  margin-top: 2px;
}

.list-item .status-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
  flex-shrink: 0;
}
.tag-fresh { background: var(--green-light); color: var(--green-dark); }
.tag-soon { background: var(--orange-light); color: var(--orange); }
.tag-expired { background: var(--red-light); color: var(--red); }
.tag-frozen { background: #bbdefb; color: #1565c0; }
.tag-room { background: #e1bee7; color: #6a1b9a; }

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--gray-500);
  font-size: 14px;
}

.empty .emoji {
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: opacity 0.15s, transform 0.05s;
  min-height: 40px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--green); color: white; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-900); }
.btn-danger { background: var(--red); color: white; }
.btn-outline {
  background: white;
  border: 1px solid var(--gray-300);
  color: var(--gray-900);
}
.btn-small { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn-block { width: 100%; }
.btn-icon {
  padding: 8px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-700);
  width: 36px; height: 36px;
  flex-shrink: 0;
}

/* ============ 浮动添加按钮 ============ */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + 16px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 28px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}

/* ============ 底部 Tab Bar ============ */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tabbar-h);
  background: white;
  border-top: 1px solid var(--gray-200);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  font-size: 11px;
  gap: 2px;
  text-decoration: none;
}

.tab .icon { font-size: 22px; }
.tab.active { color: var(--green-dark); }

/* ============ 表单 ============ */
.form-group { margin-bottom: 12px; }
.form-label {
  display: block;
  font-size: 13px;
  color: var(--gray-700);
  margin-bottom: 4px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: white;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--green);
}
.form-textarea { resize: vertical; min-height: 100px; font-family: var(--font); }
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 16px 24px;
  animation: slideUp 0.25s;
}
@keyframes slideUp { from {transform:translateY(100%);} to {transform:none;} }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--gray-200);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions .btn { flex: 1; }

/* ============ 选择列表 ============ */
.search-box {
  position: relative;
  margin-bottom: 12px;
}
.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: white;
  outline: none;
}
.search-box::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.6;
}

.pick-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
}

.pick-item {
  padding: 8px 6px;
  text-align: center;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  border: 2px solid transparent;
  user-select: none;
}
.pick-item:hover { background: var(--gray-200); }
.pick-item.selected {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
  font-weight: 500;
}

/* ============ 菜谱卡片 ============ */
.recipe-card {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.1s;
}
.recipe-card:active { transform: scale(0.98); }

.recipe-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.recipe-name {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.recipe-match {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  flex-shrink: 0;
}
.match-full { background: var(--green-light); color: var(--green-dark); }
.match-partial { background: var(--orange-light); color: var(--orange); }
.match-low { background: var(--gray-200); color: var(--gray-700); }

.recipe-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.recipe-tag {
  font-size: 11px;
  padding: 2px 7px;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: 999px;
}

.recipe-coverage {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-700);
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--gray-200);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}

/* ============ 菜谱详情 ============ */
.recipe-detail h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.recipe-detail .recipe-meta { margin-bottom: 16px; }

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin: 16px 0 8px;
  padding-left: 8px;
  border-left: 3px solid var(--green);
}

.ingredient-row {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
  gap: 8px;
}
.ingredient-row:last-child { border: none; }
.ingredient-row .check {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}
.ingredient-row.have .check { background: var(--green); color: white; }
.ingredient-row.miss .check { background: var(--gray-300); color: var(--gray-700); }
.ingredient-row .name { flex: 1; }
.ingredient-row .qty { font-size: 13px; color: var(--gray-700); }
.ingredient-row.miss .name { color: var(--gray-700); }
.ingredient-row.miss .qty { color: var(--orange); }

.step {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}
.step:last-child { border: none; }
.step-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.step-text { flex: 1; line-height: 1.6; }

.tip-box {
  background: #fff8e1;
  border-left: 3px solid #ffc107;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #5d4037;
  margin-top: 8px;
}
.tip-box ul { padding-left: 18px; }
.tip-box li { margin-bottom: 2px; }

/* ============ 补货 ============ */
.restock-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: white;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  box-shadow: var(--shadow-sm);
  gap: 10px;
}
.restock-item .name { flex: 1; font-weight: 500; }
.restock-item .source {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: 999px;
}
.restock-item .check-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.restock-item.checked { opacity: 0.4; }
.restock-item.checked .name { text-decoration: line-through; }
.restock-item.checked .check-btn {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

/* ===== 补货：按菜谱分组 ===== */
.restock-recipe-group {
  background: white;
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.restock-recipe-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
  border-bottom: 1px solid var(--gray-200);
  gap: 8px;
}

.restock-recipe-header .recipe-emoji { font-size: 20px; }
.restock-recipe-header .recipe-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.restock-recipe-header .recipe-count {
  font-size: 12px;
  padding: 2px 8px;
  background: rgba(76, 175, 80, 0.15);
  color: var(--green-dark);
  border-radius: 999px;
  font-weight: 500;
  flex-shrink: 0;
}

.restock-recipe-items {
  padding: 4px 0;
}

.restock-sub-item {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  gap: 8px;
  border-bottom: 1px solid var(--gray-100);
}
.restock-sub-item:last-child { border-bottom: none; }
.restock-sub-item.checked .sub-name {
  text-decoration: line-through;
  color: var(--gray-500);
}
.restock-sub-item .sub-name {
  flex: 1;
  font-size: 14px;
}
.check-btn-small {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  cursor: pointer;
}
.restock-sub-item.checked .check-btn-small {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 24px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(33,33,33,0.92);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ============ 工具类 ============ */
.row-between { display: flex; justify-content: space-between; align-items: center; }
.row-gap { display: flex; gap: 6px; flex-wrap: wrap; }
.muted { color: var(--gray-500); }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.text-small { font-size: 12px; }
.divider { height: 1px; background: var(--gray-200); margin: 12px 0; }

/* ============ 链接解析提示卡 ============ */
.api-hint {
  background: #e3f2fd;
  border-left: 3px solid var(--blue);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #0d47a1;
  margin-bottom: 12px;
  line-height: 1.6;
}
.api-hint code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

/* ============ Loading ============ */
.loading {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }