:root {
  --bg: #f5f7f4;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #6b7a72;
  --line: #e3e8e2;
  --primary: #2f6b4f;
  --primary-weak: #e8f0ea;
  --accent: #c9622f;
  --danger: #b3402f;
  --shadow: 0 1px 2px rgba(28, 36, 32, .05), 0 6px 18px rgba(28, 36, 32, .05);
  --tabbar: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131817;
    --card: #1c2321;
    --text: #e9efeb;
    --muted: #9aa9a1;
    --line: #2b3532;
    --primary: #6fbf95;
    --primary-weak: #22362c;
    --accent: #e08a5c;
    --danger: #e08070;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 20px rgba(0, 0, 0, .25);
    --tabbar: #1a201e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button { cursor: pointer; }

h1, h2, h3, p, ul { margin: 0; }

ul { padding: 0; list-style: none; }

.app {
  max-width: 620px;
  margin: 0 auto;
}

.view {
  padding: 18px 14px calc(84px + env(safe-area-inset-bottom));
}

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

.card h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .2px;
}

.muted { color: var(--muted); font-size: 15px; }

.ok { color: var(--primary); font-size: 14px; }

.warn { color: var(--danger); font-size: 14px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 22px 2px 10px;
}

.section-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.btn,
.btn-primary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

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

.btn-ghost {
  background: transparent;
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.btn-mini {
  flex: 0 0 auto;
  min-width: 56px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--primary-weak);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
}

.empty {
  text-align: center;
  padding: 34px 18px;
}

.empty h2 { margin-bottom: 6px; }

.empty .btn-primary { margin-top: 16px; max-width: 240px; margin-left: auto; margin-right: auto; }

/* ---------- 今日 ---------- */
.day-head {
  padding: 2px 2px 14px;
}

.day-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .3px;
}

.day-title .weekday {
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
  margin-left: 6px;
}

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

.meal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
}

.meal-head h2 { font-size: 18px; }

.chip-count {
  font-size: 14px;
  color: var(--primary);
  background: var(--primary-weak);
  border-radius: 999px;
  padding: 2px 10px;
}

.dish-list { margin-top: 4px; }

.dish {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.dish:first-child { border-top: 0; }

.dish-main { min-width: 0; flex: 1 1 auto; }

.dish-name {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
}

.dish-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.meal-foot {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 采购 ---------- */
.aisle { margin-top: 12px; }

.aisle:first-child { margin-top: 4px; }

.aisle-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .6px;
  padding: 4px 2px 6px;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shop-item label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 10px;
}

.shop-item label:active { background: var(--primary-weak); }

.shop-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 1.6px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  position: relative;
}

.shop-item input[type="checkbox"]:checked {
  background: var(--primary) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px 16px no-repeat;
  border-color: var(--primary);
}

.s-name { font-size: 16px; flex: 1 1 auto; min-width: 0; }

.s-qty { font-size: 15px; color: var(--muted); white-space: nowrap; }

.s-day { font-size: 13px; color: var(--muted); }

.shop-item.is-checked .s-name,
.shop-item.is-checked .s-qty,
.shop-item.is-checked .s-day {
  color: var(--muted);
  text-decoration: line-through;
  opacity: .55;
}

.shop-tip {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 一周 ---------- */
.week-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 10px;
  margin: 0 0 6px;
  background: linear-gradient(var(--bg) 76%, rgba(0, 0, 0, 0));
}

.week-toolbar .btn-primary { width: auto; padding: 0 18px; }

.week-toolbar .range { color: var(--muted); font-size: 14px; }

.week-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.week-day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.week-day.is-today {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow);
}

.week-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 12px;
}

.week-row {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 52px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  text-align: left;
  display: block;
}

.wd-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.wd-date { font-size: 16px; font-weight: 700; }

.wd-week {
  font-size: 14px;
  color: var(--muted);
}

.is-today .wd-week { color: var(--primary); }

.wd-summary {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.week-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.week-actions .btn-mini { min-width: 0; font-size: 13px; padding: 0 10px; }

.week-detail {
  padding: 4px 14px 12px;
  border-top: 1px solid var(--line);
}

.wd-meal { margin-top: 10px; }

.wd-meal-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  font-weight: 700;
}

.wd-meal-title .muted { font-weight: 400; font-size: 14px; }

.wd-meal .dish { padding: 7px 0; }

.wd-meal .dish-name { font-size: 16px; }

/* ---------- 分段控件 ---------- */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--primary-weak);
  margin-bottom: 14px;
}

.seg button {
  flex: 1 1 0;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
}

.seg button.is-active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

/* ---------- 设置 ---------- */
.card h2 .sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 6px;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.person-row:first-of-type { border-top: 0; }

.person-info { flex: 1 1 auto; min-width: 0; }

.person-name { font-size: 17px; font-weight: 600; }

.person-meta {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.form-row {
  margin-top: 14px;
}

.form-row > label,
.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px;
}

.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-row .input { flex: 1 1 auto; }

.input-row .btn,
.input-row .btn-ghost {
  flex: 0 0 auto;
  padding: 0 14px;
}

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

.chip {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.chip.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.chip .x {
  margin-left: 4px;
  opacity: .7;
}

.like-group { margin-top: 10px; }

.like-group .field-label { margin-bottom: 4px; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.form-actions .btn,
.form-actions .btn-primary { flex: 1 1 0; width: auto; }

.recipe-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.recipe-item:first-of-type { border-top: 0; }

.recipe-info { flex: 1 1 auto; min-width: 0; }

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

.recipe-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }

.ing-edit-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.ing-edit-row .input { min-width: 0; }
.ing-edit-row .ing-n { flex: 2 1 0; }
.ing-edit-row .ing-q { flex: 1 1 0; }
.ing-edit-row .ing-u { flex: 0 0 62px; padding-left: 8px; padding-right: 4px; }
.ing-edit-row .ing-a { flex: 0 0 100px; padding-left: 6px; padding-right: 6px; }

.kindle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.kindle-item:first-of-type { border-top: 0; }

.kindle-label {
  flex: 0 0 84px;
  font-size: 15px;
  font-weight: 600;
}

.kindle-url {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kindle-item .btn-mini { min-width: 60px; font-size: 14px; }

.card .hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.about p { font-size: 15px; margin-top: 4px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--tabbar);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 14px rgba(28, 36, 32, .06);
}

.tab {
  flex: 1 1 0;
  min-height: 56px;
  padding: 7px 0 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 13px;
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active { color: var(--primary); }

.tab.is-active svg { stroke-width: 2; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 50;
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(28, 36, 32, .9);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 560px) {
  .view { padding-left: 20px; padding-right: 20px; }
}
