:root {
  --bg: #f4f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ee;
  --text: #14261c;
  --text-soft: #5a6b60;
  --line: #dde6df;
  --brand: #166534;
  --brand-2: #22a05a;
  --brand-ink: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(16, 40, 26, .06), 0 8px 24px rgba(16, 40, 26, .06);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1512;
    --surface: #16211b;
    --surface-2: #1d2b23;
    --text: #e8f0ea;
    --text-soft: #9fb2a6;
    --line: #293a30;
    --brand: #34c476;
    --brand-2: #2fb872;
    --brand-ink: #07130c;
    --warn: #f0b357;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }

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

button { cursor: pointer; }

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(76px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(12px);
  -webkit-backdrop-filter: saturate(1.2) blur(12px);
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--text-soft);
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -.01em;
}

.month-pill {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
}

.view {
  flex: 1;
  padding: 4px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- 通用组件 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card.tight { padding: 12px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.card-head .sub {
  font-size: 12px;
  color: var(--text-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}

.btn:active { transform: scale(.98); }

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.btn.ghost {
  background: transparent;
  color: var(--text-soft);
}

.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

.btn.block { width: 100%; }

.btn.sm { padding: 7px 10px; font-size: 13px; border-radius: 9px; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 11px;
  line-height: 18px;
  white-space: nowrap;
}

.muted { color: var(--text-soft); }

.empty {
  padding: 26px 12px;
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.7;
}

.empty strong { color: var(--text); display: block; margin-bottom: 4px; font-size: 15px; }

/* ---------- 清单 ---------- */

.budget-strip {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.budget-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.budget-amount { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.budget-amount small { font-size: 14px; font-weight: 500; color: var(--text-soft); }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  transition: width .3s ease;
}

.progress.over > i { background: linear-gradient(90deg, #f59e0b, var(--danger)); }

.quick-add { display: flex; flex-direction: column; gap: 8px; }

.quick-add .main-row { display: flex; gap: 8px; }

.quick-add input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px;
}

.quick-add input[type="text"]:focus,
.field input:focus,
.field select:focus,
.meta-select:focus {
  outline: 2px solid color-mix(in srgb, var(--brand-2) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--brand-2);
}

.quick-add .meta-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.quick-add .meta-row input,
.quick-add .meta-row select,
.meta-select {
  min-width: 0;
  padding: 8px 9px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
}

.quick-add .meta-row input[type="number"] { width: 68px; }
.quick-add .meta-row select { flex: 1; }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px dashed var(--line);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 13px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:active { background: var(--surface-2); }
.chip .plus { color: var(--brand-2); font-weight: 700; margin-right: 3px; }

.list { display: flex; flex-direction: column; }

.item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}

.item:last-child { border-bottom: 0; }

.check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 2px solid color-mix(in srgb, var(--text-soft) 45%, transparent);
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  color: transparent;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
}

.check[aria-pressed="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.item-body { flex: 1; min-width: 0; cursor: pointer; }

.item-name {
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}

.item.is-done .item-name { text-decoration: line-through; color: var(--text-soft); }

.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-soft);
  flex-wrap: wrap;
}

.item-price { font-variant-numeric: tabular-nums; }
.item-price.auto { color: var(--text-soft); }

.item-del {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  font-size: 17px;
  line-height: 1;
}

.item-del:hover { background: var(--surface-2); color: var(--danger); }

.shop-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.shop-actions .btn { flex: 1 1 30%; }

.details-toggle {
  border: 0;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  padding: 8px 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.details-toggle .caret { transition: transform .15s ease; }
.details-toggle[aria-expanded="true"] .caret { transform: rotate(90deg); }

/* ---------- 统计 ---------- */

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.kpi .label { font-size: 11px; color: var(--text-soft); }
.kpi .value { font-size: 18px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .value.sm { font-size: 15px; }

.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav button {
  width: 30px; height: 30px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 15px; color: var(--text-soft);
}
.month-nav .label { font-size: 14px; font-weight: 600; min-width: 92px; text-align: center; }

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

.bar-row { display: flex; flex-direction: column; gap: 5px; }

.bar-top {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 13px;
}

.bar-top .amount { font-variant-numeric: tabular-nums; color: var(--text-soft); }

.bar-track { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-track > i { display: block; height: 100%; border-radius: 999px; background: var(--brand-2); }

.trend {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 128px;
  padding-top: 8px;
}

.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  height: 100%;
  min-width: 0;
}

.trend-bar {
  width: 100%;
  max-width: 34px;
  border-radius: 7px 7px 3px 3px;
  background: color-mix(in srgb, var(--brand-2) 42%, var(--surface-2));
  min-height: 3px;
  transition: height .3s ease;
}

.trend-col.is-current .trend-bar { background: var(--brand-2); }

.trend-amount { font-size: 10px; color: var(--text-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend-label { font-size: 11px; color: var(--text-soft); }

.expense {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}

.expense:last-child { border-bottom: 0; }
.expense-main { flex: 1; min-width: 0; }
.expense-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.expense-amount { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- 菜单 ---------- */

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 10px;
}

.segmented button {
  flex: 1;
  padding: 9px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 550;
}

.segmented button.is-on {
  background: var(--surface);
  color: var(--brand);
  font-weight: 650;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.stepper-row { display: flex; gap: 10px; margin: 12px 0; }

.stepper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}

.stepper-label { flex: 1; font-size: 13px; color: var(--text-soft); }

.stepper button {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
}

.stepper button:disabled { opacity: .35; cursor: not-allowed; }

.stepper-value {
  min-width: 18px;
  text-align: center;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.inline-add { display: flex; gap: 8px; margin-top: 8px; }

.inline-add input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 14px;
}

.chip.is-on {
  border-style: solid;
  border-color: var(--brand-2);
  color: var(--brand);
  background: color-mix(in srgb, var(--brand-2) 10%, transparent);
  font-weight: 600;
}

.chip.blocked {
  border-style: solid;
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
  color: var(--danger);
}

.kcal-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.kcal-main {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.kcal-main small { font-size: 13px; font-weight: 500; color: var(--text-soft); }
.kcal-target { font-size: 12px; color: var(--text-soft); white-space: nowrap; }

.meal {
  border-top: 1px solid var(--line);
  padding: 12px 0 2px;
  margin-top: 10px;
}

.meal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.meal-name { font-size: 15px; font-weight: 650; }
.meal-time { margin-left: 6px; font-size: 12px; color: var(--text-soft); }
.meal-kcal { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.meal-note { margin: 4px 0 0; font-size: 11px; color: var(--text-soft); }

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

.dish-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}

.dish-row:last-child { border-bottom: 0; }
.dish-name { flex: 1; font-size: 14px; }
.dish-tags { font-size: 11px; color: var(--text-soft); }
.dish-cost { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.dish-kcal { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; min-width: 26px; text-align: right; }

.ing-list {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 14px;
}

.ing-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
}

.ing-qty { color: var(--text-soft); font-variant-numeric: tabular-nums; }

.week-list { margin-top: 12px; border-top: 1px solid var(--line); }

.week-day { border-bottom: 1px solid var(--line); }
.week-day:last-child { border-bottom: 0; }

.week-day-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 2px;
  border: 0;
  background: transparent;
  font-size: 14px;
  text-align: left;
}

.week-day-label { flex: 1; font-weight: 600; }
.week-day-kcal { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.week-day-head .caret { color: var(--text-soft); transition: transform .15s ease; }
.week-day.is-open .week-day-head .caret { transform: rotate(90deg); }

.week-day-body { padding: 0 2px 10px; }
.week-day-body .meal:first-child { border-top: 0; padding-top: 4px; }
.week-day-body .btn { margin-top: 8px; }

.week-day.is-open .week-day-head { color: var(--brand); }

/* ---------- 价格说明 ---------- */

.dlg-price {
  width: min(560px, calc(100vw - 24px));
  max-height: 86vh;
  padding: 16px 18px;
}

.price-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.price-head h2 { margin: 0; font-size: 18px; }

.price-body {
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 12px;
  padding-right: 4px;
}

.price-groups { margin-top: 10px; }

.price-group h3 {
  margin: 12px 0 4px;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-soft);
}

.price-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--line);
}

.price-row .p {
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.topbar-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.sync-pill { font-size: 11px; color: var(--text-soft); }
.sync-pill.is-error { color: var(--danger); }

/* ---------- 登录 ---------- */

.auth {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.auth-card h1 { margin: 0 0 16px; font-size: 26px; }

.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }

.local-btn { margin-top: 10px; }

.auth-foot { margin-top: 16px; text-align: center; }

.hint.is-error { color: var(--danger); }

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
}

.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.invite-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-2);
}

.invite-label { font-size: 13px; color: var(--text-soft); }

.invite-code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  letter-spacing: .12em;
}

.member-list { display: flex; flex-direction: column; }

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 2px;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

.member-row:last-child { border-bottom: 0; }
.member-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.request-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* ---------- 管理后台 ---------- */

.admin-user {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}

.admin-user:last-child { border-bottom: 0; }
.admin-user-main { flex: 1 1 100%; min-width: 0; }
.admin-user-email { font-size: 14px; font-weight: 600; word-break: break-all; }
.admin-user-meta { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.admin-user .btn { flex: 0 0 auto; }
.admin-user.is-disabled { opacity: .62; }

/* ---------- 设置 ---------- */

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field > span { color: var(--text-soft); }
.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 15px;
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.hint { font-size: 12px; line-height: 1.6; color: var(--text-soft); margin: 0; }

.settings-block { display: flex; flex-direction: column; gap: 12px; }
.settings-block + .settings-block { margin-top: 4px; }

.divider { height: 1px; background: var(--line); margin: 2px 0; }

.about { font-size: 12px; line-height: 1.8; color: var(--text-soft); }

/* ---------- 对话框 ---------- */

.dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}

.dialog::backdrop { background: rgba(6, 18, 12, .45); backdrop-filter: blur(2px); }
.dialog-sm { width: min(340px, calc(100vw - 32px)); }

.dialog h2 { margin: 0 0 14px; font-size: 18px; }

.dialog form { display: flex; flex-direction: column; gap: 12px; }

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

/* ---------- 底部导航 ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  max-width: 168px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-size: 11px;
}

.tab-icon { font-size: 17px; line-height: 1; }

.tab.is-active { color: var(--brand); background: color-mix(in srgb, var(--brand-2) 12%, transparent); font-weight: 650; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 14px;
  border-radius: 12px;
  background: #10251a;
  color: #f2fbf5;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button {
  border: 0;
  background: transparent;
  color: #7ee0a8;
  font-weight: 700;
  font-size: 13px;
  padding: 2px 0;
  white-space: nowrap;
}

@media (min-width: 600px) {
  .view { padding: 8px 22px 28px; }
  .topbar { padding: 24px 22px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
