:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --ink: #20211d;
  --ink-soft: #6b6a62;
  --line: #e7e1d7;
  --brand: #2f8f5b;
  --brand-ink: #1f6b41;
  --brand-soft: #e3f1e8;
  --warn: #c4541f;
  --warn-soft: #fbe7da;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(32,33,29,.06), 0 8px 24px rgba(32,33,29,.07);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--ink-soft); }

button { font-family: inherit; cursor: pointer; }

/* ---------------- Identity gate ---------------- */
.identity {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #e3f1e8, #faf7f2 60%);
}
.identity-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.identity-logo { font-size: 56px; }
.identity-card h1 { margin: 8px 0 2px; font-size: 24px; }
.identity-list { display: grid; gap: 10px; margin-top: 20px; }
.identity-list button, .pick {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 17px; font-weight: 600; color: var(--ink);
  text-align: left;
}
.identity-list button:active { background: var(--surface-2); }
.identity-list .emoji, .pick .emoji { font-size: 24px; }

/* ---------------- App shell ---------------- */
.app { min-height: 100vh; padding-bottom: calc(var(--tab-h) + var(--safe-b)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 20px; font-weight: 700; }
.who {
  border: none; background: var(--brand-soft); color: var(--brand-ink);
  font-weight: 700; font-size: 14px;
  padding: 7px 12px; border-radius: 999px;
  display: flex; align-items: center; gap: 6px;
}

.screen { padding: 16px 16px 24px; max-width: 640px; margin: 0 auto; }

/* ---------------- Cards / list ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list { display: grid; gap: 12px; }

.item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.item:active { background: var(--surface-2); }
.item.depleted { opacity: .55; }
.item-thumb {
  width: 52px; height: 52px; flex: none;
  border-radius: var(--radius-sm); object-fit: cover;
  background: var(--surface-2);
  display: grid; place-items: center; font-size: 26px;
}
img.item-thumb { cursor: zoom-in; }

/* Full-screen photo viewer (tap to dismiss). */
.lightbox {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.85);
  display: grid; place-items: center;
  cursor: zoom-out; padding: 16px;
}
.lightbox img { max-width: 95%; max-height: 95%; object-fit: contain;
  border-radius: var(--radius-sm); }

.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 700; font-size: 16px; }
.item-sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-right { text-align: right; flex: none; }
.gram-badge {
  font-weight: 700; font-size: 15px;
}
.gram-bar { height: 5px; border-radius: 999px; background: var(--surface-2);
  margin-top: 6px; width: 64px; overflow: hidden; }
.gram-bar > i { display: block; height: 100%; background: var(--brand); }
.pill {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.pill.low { background: var(--warn-soft); color: var(--warn); }
.pill.out { background: #eee; color: var(--ink-soft); }
.pill.reserved { background: #e7eefb; color: #2f5bbf; }

.brand { font-weight: 500; color: var(--ink-soft); font-size: 13px; }

/* Reserved warning banner (consume sheet) */
.reserved-warn {
  background: #e7eefb; color: #2f5bbf; font-weight: 600; font-size: 13px;
  padding: 10px 12px; border-radius: var(--radius-sm); margin: 8px 0;
}

/* Shopping-list request cards */
.req {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.req-main { flex: 1; min-width: 0; }
.req-right { flex: none; display: flex; gap: 8px; align-items: center; }
.req-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 16px; display: grid; place-items: center;
}
.req-icon:active { background: var(--line); }
.btn.small { padding: 8px 14px; font-size: 14px; width: auto; }

.check { display: flex; align-items: center; gap: 10px; margin: 12px 2px;
  font-weight: 600; font-size: 15px; }
.check input { width: 20px; height: 20px; }

.section-label { font-size: 13px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .04em; margin: 18px 2px 8px; }

.empty { text-align: center; color: var(--ink-soft); padding: 48px 16px; }
.empty .big { font-size: 40px; }

/* ---------------- Kitchen toolbar / zones ---------------- */
.kitchen-toolbar {
  display: flex; gap: 8px; align-items: center; margin-bottom: 14px;
}
.k-search {
  flex: 1; min-width: 0;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); padding: 11px 14px;
  font-size: 15px; color: var(--ink);
}
.k-controls { display: flex; gap: 8px; flex: none; }
.k-select {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 10px 10px; font-size: 14px; font-weight: 600;
}
.k-toggle {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; font-weight: 700;
}
.k-toggle.active { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); }

.section { margin-bottom: 6px; }
.section.lowstock .list { gap: 10px; }
.section.lowstock .item { border-color: var(--warn); }

.cat-group { margin-bottom: 14px; }
.cat-head { font-weight: 700; font-size: 14px; margin: 4px 2px 8px; }

.finished { margin-top: 18px; }
.finished-toggle {
  width: 100%; text-align: left;
  border: 1px dashed var(--line); background: transparent; color: var(--ink-soft);
  border-radius: var(--radius-sm); padding: 12px 14px; font-weight: 700; font-size: 14px;
}
.finished-list { margin-top: 12px; }

.export-links { display: grid; gap: 10px; margin-top: 12px; }
.export-links .btn { text-align: center; text-decoration: none; }

/* ---------------- Balances ---------------- */
.balance-hero {
  text-align: center; padding: 22px; margin-bottom: 8px;
}
.balance-hero .amount { font-size: 34px; font-weight: 800; }
.balance-hero .amount.owe { color: var(--warn); }
.balance-hero .amount.owed { color: var(--brand-ink); }
.balance-hero .amount.flat { color: var(--ink-soft); }

.transfer {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
}
.transfer + .transfer { border-top: 1px solid var(--line); }
.transfer-txt { flex: 1; font-weight: 600; }
.transfer-amt { font-weight: 800; }
.btn-mini {
  border: 1px solid var(--brand); color: var(--brand-ink); background: var(--brand-soft);
  border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 13px;
}
.row-balance { display:flex; justify-content:space-between; padding:10px 14px; }
.row-balance + .row-balance { border-top: 1px solid var(--line); }

/* ---------------- Buttons / forms ---------------- */
.btn {
  display: block; width: 100%;
  border: none; border-radius: var(--radius-sm);
  padding: 15px; font-size: 16px; font-weight: 700;
  background: var(--brand); color: #fff;
}
.btn:active { filter: brightness(.95); }
.btn[disabled] { opacity: .5; }
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; }

label.field { display: block; margin: 14px 0 0; }
label.field > span { display: block; font-size: 13px; font-weight: 700;
  color: var(--ink-soft); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=search] {
  width: 100%; padding: 13px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
}
input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 13px; border-radius: 999px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.seg { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; }
.seg button { flex: 1; border: none; background: transparent; padding: 9px;
  border-radius: 999px; font-weight: 700; color: var(--ink-soft); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.suggests { display: grid; gap: 8px; max-height: 240px; overflow-y: auto; margin-top: 8px; }
.suggest {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-weight: 600; text-align: left; width: 100%;
}
.suggest:active, .suggest.active { background: var(--brand-soft); border-color: var(--brand); }
.suggest small { color: var(--ink-soft); font-weight: 600; }

/* Category filter bar in the add sheets: one horizontally scrollable row. */
.cat-filter { flex-wrap: nowrap; overflow-x: auto; margin-top: 10px; padding-bottom: 4px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.cat-filter::-webkit-scrollbar { display: none; }
.cat-filter .chip { flex: 0 0 auto; }

/* Loading skeletons. */
.skel-row { padding: 14px 12px; }
.skel-row + .skel-row { border-top: 1px solid var(--line); }
.skel-line { height: 14px; border-radius: 999px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skel-row:nth-child(even) .skel-line { width: 70%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skel-line { animation: none; } }

.cost-preview { text-align: center; font-size: 28px; font-weight: 800;
  color: var(--brand-ink); margin: 6px 0; }
.cost-preview small { display:block; font-size: 12px; color: var(--ink-soft); font-weight:600; }

/* ---------------- FAB + tabbar ---------------- */
.fab {
  position: fixed; right: 18px;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  width: 60px; height: 60px; border-radius: 50%;
  border: none; background: var(--brand); color: #fff;
  font-size: 32px; line-height: 1;
  box-shadow: 0 6px 18px rgba(47,143,91,.45);
  z-index: 30;
}
.fab:active { transform: scale(.95); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; font-weight: 700; color: var(--ink-soft);
}
.tab .tab-ico { font-size: 22px; filter: grayscale(.4); opacity: .7; }
.tab.active { color: var(--brand-ink); }
.tab.active .tab-ico { filter: none; opacity: 1; }

/* ---------------- Bottom sheet ---------------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20,20,18,.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 640px;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-b));
  max-height: 92vh; overflow-y: auto;
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line);
  margin: 8px auto 4px; }
.sheet h2 { margin: 6px 2px 2px; font-size: 20px; }
.sheet .sub { margin: 0 2px 10px; }
.sheet-actions { margin-top: 18px; display: grid; gap: 10px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-b) + 24px);
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  z-index: 60; box-shadow: var(--shadow); max-width: 90%;
}

.photo-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.photo-preview { width: 56px; height: 56px; border-radius: var(--radius-sm);
  object-fit: cover; background: var(--surface-2); }

/* ---------------- v2: steppers, portions, multi-select ---------------- */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 48px; height: 48px; flex: none; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 24px; font-weight: 700;
  color: var(--brand-ink);
}
.stepper button:active { background: var(--brand-soft); }
.stepper input { text-align: center; font-weight: 700; }

.chips.portions { margin-top: 10px; }
.chips.portions button {
  padding: 9px 13px; border-radius: 999px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.chips.portions button:active { background: var(--surface-2); }
.chips.portions button.finish { border-color: var(--brand); color: var(--brand-ink); background: var(--brand-soft); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two-col .field { margin-top: 0; }

/* ---------------- v2: activity feed ---------------- */
.feed { padding: 4px 0; }
.feed-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; }
.feed-row + .feed-row { border-top: 1px solid var(--line); }
.feed-ico { font-size: 22px; width: 28px; text-align: center; flex: none; }
.feed-main { flex: 1; min-width: 0; }
.feed-title { font-weight: 600; }
.feed-side { text-align: right; flex: none; }
.feed-time { font-size: 12px; color: var(--ink-soft); }
.feed-acts { margin-top: 4px; white-space: nowrap; }
.lnk {
  border: none; background: none; padding: 0 0 0 8px;
  color: var(--brand-ink); font-weight: 700; font-size: 13px;
}
.lnk.del { color: var(--danger); }

/* tappable balance rows */
.row-balance.tappable {
  width: 100%; border: none; background: none; font: inherit; color: inherit;
  align-items: center; text-align: left;
}
.row-balance.tappable:active { background: var(--surface-2); }

/* toast with undo */
.toast { display: flex; align-items: center; gap: 12px; }
.toast-undo {
  border: none; background: transparent; color: #7fd6a3;
  font-weight: 800; font-size: 14px; padding: 0;
}

/* receipt import */
textarea, select {
  width: 100%; padding: 13px 14px; font-size: 16px; font: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); resize: vertical;
}
textarea:focus, select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.imp-details { margin-top: 12px; }
.imp-details summary { cursor: pointer; font-size: 13px; }
.imp-prompt {
  margin-top: 8px; max-height: 240px; overflow: auto; white-space: pre-wrap;
  font-size: 12px; padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-soft);
}
.imp-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.imp-row {
  padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
.imp-alert { border-color: #e0a800; background: rgba(224, 168, 0, 0.08); }
.imp-row-top { display: flex; gap: 8px; align-items: center; }
.imp-row-top .imp-name { flex: 1; }
.imp-del {
  flex: none; width: 38px; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink-soft); font-size: 16px; font-weight: 700;
}
.imp-row-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-top: 8px; }
.imp-row-grid input, .imp-row-grid select { padding: 10px; font-size: 14px; }
.imp-note { margin-top: 8px; font-size: 12px; color: var(--ink-soft); }
