:root {
  --paper: #FBFAF6;
  --card: #FFFFFF;
  --ink: #23211C;
  --muted: #6E6A5F;
  --faint: #9A937F;
  --line: #E8E4D9;
  --line-strong: #DAD5C7;
  --herb: #2F6B4F;
  --herb-dark: #245540;
  --amber: #E08A2B;
  --danger: #B6443B;
  --shadow: 0 1px 2px rgba(35,33,28,.05), 0 8px 24px rgba(35,33,28,.06);
  --card-shadow: 0 1px 2px rgba(35,33,28,.05);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

/* ---------- App shell ---------- */
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
#main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; }
.wrap { max-width: 640px; margin: 0 auto; padding: 18px 16px 40px; }
.wrap--footer { padding-bottom: 120px; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  flex: none;
  background: var(--herb);
  color: var(--paper);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 14px;
  box-shadow: 0 1px 0 rgba(0,0,0,.06);
  position: relative; z-index: 4;
}
.brand { display: flex; align-items: center; gap: 12px; max-width: 640px; margin: 0 auto; }
.brand__mark { width: 34px; height: 34px; flex: none; border-radius: 9px; display: block; }
.brand__text { flex: 1; min-width: 0; }
.brand__name { font-size: 19px; font-weight: 700; letter-spacing: .04em; line-height: 1; }
.brand__sub { font-size: 12px; opacity: .82; margin-top: 3px; letter-spacing: .01em; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.16);
  display: grid; place-items: center; font-size: 14px; font-weight: 600; flex: none;
  cursor: pointer; border: none; color: inherit; font-family: inherit;
}
.avatar:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(255,255,255,.4); }

/* ---------- Offline banner ---------- */
.offline-banner {
  flex: none; background: #F3EAD8; color: #8A5A44; font-size: 12.5px; font-weight: 600;
  padding: 7px 18px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border-bottom: 1px solid var(--line);
}

/* ---------- Tab bar ---------- */
.tabbar {
  flex: none; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 6px calc(env(safe-area-inset-bottom) + 10px); position: relative; z-index: 4;
}
.tab {
  flex: 1; background: transparent; border: none; cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--faint); padding: 4px 0;
}
.tab__label { font-size: 11px; font-weight: 600; }
.tab.is-active { color: var(--herb); }
.tab:focus-visible { outline: none; }
.tab:focus-visible .tab__label { box-shadow: 0 0 0 3px rgba(47,107,79,.25); border-radius: 4px; }

/* ---------- Section labels ---------- */
.section__title,
.eyebrow {
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 12px 2px;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 15px; font-weight: 600; border-radius: var(--radius-sm);
  padding: 12px 18px; border: 1px solid transparent; cursor: pointer;
  transition: filter .12s ease, background .12s ease; color: #fff;
}
.btn--primary { background: var(--herb); }
.btn--primary:hover { filter: brightness(1.06); }
.btn--primary:active { filter: brightness(.96); }
.btn--ghost { background: transparent; color: var(--muted); border-color: var(--line-strong); }
.btn--ghost:hover { color: var(--ink); }
.btn--danger { background: var(--danger); }
.btn--block { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(47,107,79,.25); }

.btn-google {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 11px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 12px; padding: 14px;
  font: inherit; font-size: 16px; font-weight: 600; color: var(--ink); cursor: pointer;
  box-shadow: 0 1px 2px rgba(35,33,28,.05);
}
.linkbtn {
  background: transparent; border: none; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--faint); cursor: pointer; padding: 4px;
}
.linkbtn:hover { color: var(--muted); }

/* small pill button used for "New" / "Add" */
.pillbtn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--herb); color: #fff;
  border: none; border-radius: var(--radius-sm); padding: 9px 14px; font: inherit;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.pillbtn--ghost { background: transparent; color: var(--herb); border: 1px solid var(--line-strong); padding: 7px 11px; font-size: 13px; }

/* dashed full-width add button */
.dashbtn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 7px;
  background: transparent; border: 1.5px dashed #C9C2B0; border-radius: 12px; padding: 13px;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--herb); cursor: pointer;
}
.dashbtn--muted { color: var(--muted); }

/* ---------- Generic card / inputs ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--card-shadow); padding: 16px;
}
.card__label {
  font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 12px;
}
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field__label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; font-size: 16px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 11px 12px; appearance: none; font-family: inherit;
}
textarea { min-height: 64px; resize: none; }
input::placeholder, textarea::placeholder { color: #A9A395; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--herb); box-shadow: 0 0 0 3px rgba(47,107,79,.15);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236E6A5F' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}

/* staple toggle */
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
  width: 44px; height: 26px; border-radius: 999px; background: var(--line-strong);
  position: relative; transition: background .15s ease; flex: none;
}
.toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s ease;
}
.toggle input:checked + .toggle__track { background: var(--amber); }
.toggle input:checked + .toggle__track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle__track { box-shadow: 0 0 0 3px rgba(224,138,43,.3); }
.toggle__text { font-size: 14px; }
.toggle__hint { display: block; font-size: 12px; color: var(--muted); }

/* ---------- Auth ---------- */
.auth {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px 32px calc(env(safe-area-inset-bottom) + 48px);
  animation: fadeIn .4s ease;
}
.auth__logo { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 8px 24px rgba(35,33,28,.12); }
.auth__name { font-size: 30px; font-weight: 700; letter-spacing: .06em; margin-top: 26px; }
.auth__tag { font-size: 16px; color: var(--muted); margin-top: 10px; max-width: 240px; }
.auth__cta { width: 100%; max-width: 300px; margin-top: 40px; }
.auth__fine { font-size: 12px; color: var(--faint); margin-top: 16px; }

/* ---------- Household ---------- */
.hh__title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.hh__sub { font-size: 14px; color: var(--muted); margin-bottom: 22px; }
.card + .card { margin-top: 14px; }
.or {
  display: flex; align-items: center; gap: 12px; margin: 14px 0; color: var(--faint);
  font-size: 12px; font-weight: 600;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.invite {
  margin-top: 14px; background: #F3EAD8; border: 1px dashed #C9A86A; border-radius: var(--radius-sm);
  padding: 14px; text-align: center; animation: fadeIn .3s ease;
}
.invite__label { font-size: 12px; color: #8A5A44; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.invite__code { font-size: 30px; font-weight: 700; letter-spacing: .18em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.invite__hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.code-input { text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Catalog (products) ---------- */
.catalog__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.count b { color: var(--ink); font-weight: 700; }
.search { position: relative; flex: 1; max-width: 220px; }
.search input { padding-left: 34px; font-size: 15px; padding-top: 9px; padding-bottom: 9px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; }

.group { margin-bottom: 18px; }
.group__head {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px 2px;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 12px 12px 13px; margin-bottom: 8px;
}
.item__main { flex: 1; min-width: 0; }
.item__name { font-size: 16px; font-weight: 600; }
.item__meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.unit { background: var(--paper); border: 1px solid var(--line-strong); border-radius: 6px; padding: 1px 7px; font-weight: 600; color: #57523f; }
.staple { display: inline-flex; align-items: center; gap: 4px; color: var(--amber); font-weight: 600; }
.staple svg { display: block; }
.item__actions { display: flex; gap: 2px; flex: none; }
.icon-btn {
  width: 36px; height: 36px; border: none; background: transparent; border-radius: 9px;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--paper); color: var(--ink); }
.icon-btn--danger:hover { background: #FBEEEC; color: var(--danger); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(47,107,79,.25); }
.item--editing { border-color: var(--herb); box-shadow: 0 0 0 2px rgba(47,107,79,.12); }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 36px 18px; color: var(--muted); }
.empty img { width: 52px; height: 52px; border-radius: 14px; opacity: .85; margin-bottom: 14px; }
.empty__title { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.empty__text { font-size: 14px; }
.empty .btn, .empty .pillbtn { margin-top: 16px; }

/* ---------- List heads ---------- */
.listhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.subhead { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 10px; }

/* ---------- Recipe cards ---------- */
.reccard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--card-shadow); padding: 15px 16px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.reccard__main { flex: 1; min-width: 0; }
.reccard__name { font-size: 17px; font-weight: 600; }
.reccard__meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.chev { flex: none; }

/* ---------- Recipe builder ---------- */
.stepper-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px;
}
.stepper-row__title { font-size: 15px; font-weight: 600; }
.stepper-row__hint { font-size: 12px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper__btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--paper); font-size: 20px; color: var(--ink); cursor: pointer;
  display: grid; place-items: center; font-family: inherit;
}
.stepper__val { font-size: 18px; font-weight: 700; min-width: 20px; text-align: center; }

.ing-empty { text-align: center; padding: 24px 18px; color: var(--faint); font-size: 14px; border: 1px dashed var(--line-strong); border-radius: 12px; margin-bottom: 8px; }
.ing-row {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px;
}
.ing-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.ing-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; }
.ing-qty { width: 64px; font-size: 15px; text-align: right; padding: 7px 8px; border-radius: 8px; }
.ing-unit {
  font-size: 13px; color: #57523f; background: var(--paper); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 3px 7px; font-weight: 600; min-width: 38px; text-align: center;
}
.ing-remove {
  width: 32px; height: 32px; border: none; background: transparent; border-radius: 8px;
  display: grid; place-items: center; cursor: pointer; color: var(--faint); flex: none;
}
.ing-remove:hover { color: var(--danger); }

/* ---------- Action bar (sticky footer) ---------- */
.actionbar {
  flex: none; padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: linear-gradient(to top, var(--paper) 72%, rgba(251,250,246,0));
}
.actionbar__inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.btn--build { box-shadow: 0 6px 18px rgba(47,107,79,.28); padding: 15px; font-size: 16px; font-weight: 700; }

/* ---------- Week pool ---------- */
.week-sub { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.meal-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--card-shadow); padding: 15px 16px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px;
}
.meal__main { flex: 1; min-width: 0; }
.meal__name { font-size: 17px; font-weight: 600; }
.meal__meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.stepper--sm .stepper__btn { width: 34px; height: 34px; font-size: 18px; border-radius: 9px; }
.stepper--sm { gap: 10px; }
.stepper--sm .stepper__val { font-size: 16px; min-width: 18px; }
.meal__remove {
  width: 32px; height: 32px; border: none; background: transparent; border-radius: 8px;
  display: grid; place-items: center; cursor: pointer; color: var(--faint); flex: none;
}

/* ---------- Grocery ---------- */
.gro-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.gro-count { font-size: 13px; color: var(--muted); }
.gro-count b { color: var(--ink); font-weight: 700; }
.gro-group { margin-bottom: 18px; }
.gro-group__head {
  display: flex; align-items: center; gap: 8px; margin: 0 0 6px 2px;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.gro-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.checkrow {
  display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 9px 14px;
  cursor: pointer; border-bottom: 1px solid #F0ECE1;
}
.checkrow:last-child { border-bottom: none; }
.checkbox {
  width: 26px; height: 26px; border-radius: 7px; background: #fff; border: 2px solid var(--line-strong);
  flex: none; display: grid; place-items: center; transition: background .12s ease, border-color .12s ease;
}
.checkrow.is-checked .checkbox { background: var(--herb); border-color: var(--herb); }
.checkrow__main { flex: 1; min-width: 0; }
.checkrow__name { font-size: 16px; font-weight: 600; }
.checkrow.is-checked .checkrow__name { color: var(--faint); text-decoration: line-through; }
.checkrow__qty { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.checkrow.is-checked .checkrow__qty { color: #B3AC9C; }

.probably { margin-top: 24px; opacity: .82; }
.probably__head { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin: 0 0 6px 2px; }
.probably__list { background: #F7F4EC; border: 1px solid #ECE7DA; border-radius: var(--radius-sm); overflow: hidden; }
.probably .checkrow { min-height: 50px; padding: 7px 14px; border-bottom-color: #ECE7DA; }

/* ---------- Bottom sheet / overlays ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(35,33,28,.38); z-index: 70;
  display: flex; align-items: flex-end; animation: fadeIn .2s ease;
}
.sheet {
  width: 100%; max-height: 72dvh; background: var(--paper); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column; animation: slideUp .26s cubic-bezier(.22,1,.36,1);
  margin: 0 auto; max-width: 640px;
}
.sheet__handle { width: 38px; height: 5px; border-radius: 99px; background: var(--line-strong); margin: 14px auto 14px; flex: none; }
.sheet__head { padding: 0 18px 6px; flex: none; }
.sheet__title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.sheet__scroll { flex: 1; overflow-y: auto; padding: 6px 14px calc(env(safe-area-inset-bottom) + 24px); }
.opt-row {
  display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.opt__main { flex: 1; min-width: 0; }
.opt__name { font-size: 16px; font-weight: 600; }
.opt__meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.opt__aisle { font-size: 12px; color: var(--muted); }

/* ---------- Confirm modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(35,33,28,.42); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 28px; animation: fadeIn .15s ease;
}
.modal { width: 100%; max-width: 360px; background: #fff; border-radius: 16px; padding: 22px 20px 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal__title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal__msg { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }
.btn--cancel { background: var(--paper); color: var(--muted); border-color: var(--line-strong); }

/* ---------- Account menu ---------- */
.acct-backdrop { position: fixed; inset: 0; z-index: 74; animation: fadeIn .12s ease; }
.menu {
  position: fixed; z-index: 75; top: calc(env(safe-area-inset-top) + 58px); right: 14px; width: 220px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 14px 36px rgba(35,33,28,.2); overflow: hidden; animation: fadeIn .14s ease;
}
.menu__head { padding: 14px 16px; border-bottom: 1px solid #F0ECE1; }
.menu__name { font-size: 14px; font-weight: 600; }
.menu__email { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.menu__hh { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; align-items: center; gap: 6px; }
.menu__signout {
  width: 100%; text-align: left; background: transparent; border: none; padding: 13px 16px;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--danger); cursor: pointer;
  display: flex; align-items: center; gap: 10px;
}
.menu__signout:hover { background: #FBEEEC; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(env(safe-area-inset-bottom) + 92px); left: 50%; transform: translateX(-50%);
  z-index: 90; background: var(--ink); color: var(--paper); font-size: 14px; font-weight: 600;
  padding: 11px 18px; border-radius: 99px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  white-space: nowrap; animation: toastUp .25s ease;
}

/* ---------- Skeleton ---------- */
.skel { padding: 18px 16px; max-width: 640px; margin: 0 auto; }
.skel-line, .skel-row {
  border-radius: 8px;
  background: linear-gradient(90deg,#EDE9DE 25%,#F6F3EA 50%,#EDE9DE 75%);
  background-size: 600px 100%; animation: shimmer 1.3s infinite;
}
.skel-line { height: 13px; width: 120px; margin: 0 0 16px 2px; }
.skel-row { height: 66px; margin-bottom: 8px; }

/* ---------- Animations ---------- */
@keyframes flash { from { background: #EAF3EE; } to { background: var(--card); } }
.item--flash { animation: flash 1.1s ease; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }
@keyframes toastUp { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes spin { to { transform: rotate(360deg); } }

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