:root {
  --green: #1f5f3f;
  --green-soft: #e3efe7;
  --red: #b3262e;
  --red-soft: #f8e4e4;
  --gold: #b9851b;
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #22211f;
  --muted: #6d6a64;
  --line: #e7e2d9;
  --s-idea: #8a8780;
  --s-purchased: #2f6db3;
  --s-delivered: #b9851b;
  --s-wrapped: #1f8a4c;
  --radius: 14px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--green); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.loading { text-align: center; color: var(--muted); padding: 3rem 1rem; }

#view { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) 16px 0; }

/* ---------- top of page ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-weight: 600; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.summary { background: var(--green); color: #fff; border: 0; }
.summary .big-number { font-size: 2rem; font-weight: 700; }
.summary .row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 4px; opacity: .92; }
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; }
.counter {
  display: block; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 6px; text-align: center;
}
.counter b { display: block; font-size: 1.5rem; }
.counter span { font-size: .8rem; color: var(--muted); }

.group-title { margin: 18px 4px 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.person-card { display: block; text-decoration: none; color: inherit; }
.person-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.person-card .name { font-weight: 700; font-size: 1.1rem; }
.person-card .money { font-weight: 600; white-space: nowrap; }
.person-card .meta { color: var(--muted); font-size: .85rem; margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; display: flex; }
.bar i { display: block; height: 100%; }
.bar .spent { background: var(--green); }
.bar .planned { background: #9cc4ab; }
.bar.over .spent { background: var(--red); }
.bar.over .planned { background: #e8a0a4; }
.over-note { color: var(--red); font-weight: 600; }

/* ---------- items ---------- */
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 20px 2px 8px; }
.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; margin-bottom: 8px;
}
.item .thumb {
  width: 52px; height: 52px; border-radius: 10px; flex: 0 0 52px;
  background: var(--green-soft) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.item .body { flex: 1; min-width: 0; cursor: pointer; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.item .actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.item.dim { opacity: .75; }

.chip {
  border: 0; border-radius: 99px; padding: 6px 10px; font: inherit; font-size: .8rem; font-weight: 700;
  color: #fff; white-space: nowrap; cursor: pointer;
}
.chip.idea { background: var(--s-idea); }
.chip.purchased { background: var(--s-purchased); }
.chip.delivered { background: var(--s-delivered); }
.chip.wrapped { background: var(--s-wrapped); }
.star { background: none; border: 0; font-size: 1.3rem; padding: 0 2px; cursor: pointer; line-height: 1; }

.empty { text-align: center; color: var(--muted); padding: 18px 10px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: #fff; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; font-size: 1.2rem; padding: 6px 8px; cursor: pointer; color: var(--muted); }

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; /* 16px stops iPhone zooming in */
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { display: inline-block; width: 22px; height: 22px; margin: 0 8px 0 0; vertical-align: middle; }
.check { display: flex; align-items: center; font-weight: 500; margin-top: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.with-btn { display: flex; gap: 8px; align-items: flex-end; }
.with-btn input { flex: 1; }
.with-btn .btn { margin-bottom: 1px; height: 46px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; }
.lookup-msg { font-size: .85rem; margin-top: 6px; min-height: 1.2em; color: var(--muted); }
.lookup-msg.warn { color: var(--gold); }
.preview-img { max-width: 120px; max-height: 120px; border-radius: 10px; margin-top: 10px; display: block; }

.segmented { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-top: 6px; }
.segmented button {
  flex: 1; border: 0; background: none; padding: 9px 4px; border-radius: 9px;
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.tabbar a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; }
.tabbar a span { display: block; font-size: 1.3rem; line-height: 1.3; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--green); }
.tabbar a.on span { filter: none; opacity: 1; }
.add-btn {
  width: 56px; height: 56px; border-radius: 50%; border: 0; margin-top: -22px;
  background: var(--red); color: #fff; font-size: 2rem; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 12px rgba(179,38,46,.35);
}

/* ---------- bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 0 16px calc(20px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; justify-content: space-between; align-items: center; padding: 14px 0 6px; z-index: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: #22211f; color: #fff; border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast[hidden] { display: none; }
.toast button { background: none; border: 0; color: #9fd8b4; font: inherit; font-weight: 700; cursor: pointer; }

/* ---------- sign-in pages ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: 100%; max-width: 380px; }
.auth-card.wide { max-width: 480px; }
.auth-card h1 { text-align: center; margin-bottom: 8px; }
.auth-card .btn { margin-top: 20px; }
.auth-logo { font-size: 3rem; text-align: center; }
.auth-error { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 16px 0 0; padding: 4px 12px 12px; }
legend { font-weight: 700; padding: 0 6px; }

@media (min-width: 700px) {
  .sheet { border-radius: 18px; margin-bottom: 4vh; }
  .sheet-backdrop { align-items: center; }
}
