:root {
  --cream: #FFF6EB;
  --cream-2: #FBE8D4;
  --ink: #3D2914;
  --ink-soft: #6B4F35;
  --muted: #8A6A4E;
  --card: #FFFFFF;
  --line: #F0D9C2;
  --orange: #E85D04;
  --orange-dark: #C44D03;
  --orange-soft: #FFE0C7;
  --ok: #2F9E6B;
  --ok-soft: #E3F6EC;
  --danger: #C0392B;
  --danger-soft: #FDECEC;
  --shadow: 0 8px 24px rgba(91, 48, 12, 0.08);
  --radius: 20px;
  --tap: 52px;
  --costco: #E25C4A;
  --bjs: #D9940F;
  --fresh: #2F9E6B;
  --tashkent: #3C8D8A;
  --anywhere: #7B5EA7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--cream); color: var(--ink); }
body {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-weight: 600;
  min-height: 100dvh;
  line-height: 1.35;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; font-weight: 800; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.topbar {
  background: linear-gradient(180deg, #F16B14 0%, var(--orange) 100%);
  color: #fff;
  padding: calc(14px + var(--safe-top)) 16px 18px;
  box-shadow: 0 6px 18px rgba(232, 93, 4, 0.28);
}
.topbar h1 {
  font-size: 1.22rem;
  letter-spacing: -0.02em;
  text-align: center;
  line-height: 1.25;
}
.topbar .sub {
  margin-top: 4px;
  text-align: center;
  font-size: 0.88rem;
  opacity: 0.92;
  font-weight: 700;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar-row h1 { flex: 1; text-align: center; }
.topbar-titles { flex: 1; min-width: 0; text-align: center; }
.topbar-titles h1 { flex: none; }
.login-screen { display: flex; flex-direction: column; justify-content: center; padding-top: 28px; }
.login-screen .pin-wrap { margin-top: 8px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255,255,255,0.16);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn svg { width: 22px; height: 22px; display: block; }
.ghost-space { width: 44px; flex-shrink: 0; }

/* Avatars */
.avatar {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  flex-shrink: 0;
  letter-spacing: 0;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
}
.avatar.sm { width: 28px; height: 28px; font-size: 0.85rem; }
.avatar.md { width: 36px; height: 36px; font-size: 1rem; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.35rem; }
.avatar.xl { width: 64px; height: 64px; font-size: 1.6rem; }

/* Screens */
.screen { flex: 1; padding: 16px 16px calc(24px + var(--safe-bottom)); }
.hint { color: var(--ink-soft); text-align: center; margin: 4px 0 16px; }

/* Login */
.who-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.person-card {
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 22px;
  padding: 16px 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  min-height: 118px;
  color: var(--ink);
}
.person-card .name { font-weight: 800; font-size: 1.02rem; }
.person-card.selected {
  border-color: var(--orange);
  background: #FFF8F1;
  box-shadow: 0 0 0 3px var(--orange-soft), var(--shadow);
}
.pin-wrap { margin-top: 22px; }
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 16px;
}
.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--orange);
  background: transparent;
}
.pin-dot.filled { background: var(--orange); }
.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
}
.pad button {
  height: var(--tap);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.4rem;
  font-weight: 800;
}
.pad button:active { transform: scale(0.97); background: var(--orange-soft); }
.pad .pad-action { font-size: 0.95rem; color: var(--ink-soft); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 16px;
  font-weight: 800;
  width: 100%;
}
.btn-primary { background: var(--orange); color: #fff; box-shadow: 0 6px 14px rgba(232, 93, 4, 0.28); }
.btn-primary:active { background: var(--orange-dark); }
.btn-secondary { background: var(--orange-soft); color: var(--orange-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: 0.5; }

.add-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(16px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(255,246,235,0) 0%, var(--cream) 28%);
}
.add-bar .btn { font-size: 1.08rem; }

/* Store sections */
.section { margin: 0 0 18px; }
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 2px 10px;
}
.section-mark {
  width: 10px;
  height: 28px;
  border-radius: 8px;
}
.section-head h2 { font-size: 1.12rem; }
.section-head .count {
  margin-left: auto;
  background: var(--cream-2);
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 3px 9px;
}
.store-costco .section-mark { background: var(--costco); }
.store-costco h2 { color: #B83A2C; }
.store-bjs .section-mark { background: var(--bjs); }
.store-bjs h2 { color: #8A5E08; }
.store-superfresh .section-mark { background: var(--fresh); }
.store-superfresh h2 { color: #1D704B; }
.store-tashkent .section-mark { background: var(--tashkent); }
.store-tashkent h2 { color: #266663; }
.store-anywhere .section-mark { background: var(--anywhere); }
.store-anywhere h2 { color: #5A3D86; }

/* Items */
.item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 12px 12px 10px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px 8px;
  align-items: start;
  margin-bottom: 10px;
}
.check {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  align-self: start;
}
.check-box {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 2.5px solid #D7B99A;
  background: #fff;
  display: grid;
  place-items: center;
}
.item.done .check-box {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.item-body { min-width: 0; padding-top: 2px; }
.item-title {
  font-weight: 800;
  font-size: 1.05rem;
  word-wrap: break-word;
}
.qty {
  display: inline-block;
  background: var(--orange-soft);
  color: var(--orange-dark);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.85rem;
  font-weight: 800;
  margin-right: 6px;
}
.item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}
.item-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tiny {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: var(--cream);
}
.tiny.danger { color: var(--danger); background: var(--danger-soft); }
.item.done { opacity: 0.96; }
.item.done .item-title { color: var(--ink-soft); }
.got-by { color: var(--ok); font-weight: 800; }
.store-chip {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 2px 8px;
  color: #fff;
}
.store-chip.costco { background: var(--costco); }
.store-chip.bjs { background: var(--bjs); }
.store-chip.superfresh { background: var(--fresh); }
.store-chip.tashkent { background: var(--tashkent); }
.store-chip.anywhere { background: var(--anywhere); }

/* Completed */
.completed-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #F4EEE6;
  border-radius: 16px;
  padding: 12px 14px;
  min-height: 52px;
  font-weight: 800;
  color: var(--ink-soft);
}
.completed-toggle .chevron { margin-left: auto; transition: transform 0.15s ease; }
.completed-toggle.open .chevron { transform: rotate(180deg); }
.completed-body { margin-top: 10px; }

/* Empty */
.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--ink-soft);
}
.empty p { margin: 8px 0 0; }

/* Sheets / forms */
.sheet {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 30px rgba(91, 48, 12, 0.12);
  padding: 18px 16px calc(20px + var(--safe-bottom));
  margin: 0 -16px -16px;
}
.sheet h2 { font-size: 1.35rem; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input[type="text"],
.field textarea {
  width: 100%;
  border: 2px solid var(--line);
  background: #FFFCF8;
  border-radius: 16px;
  padding: 14px 14px;
  min-height: var(--tap);
  outline: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--orange); }
.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stepper button {
  width: var(--tap);
  height: var(--tap);
  border-radius: 16px;
  background: var(--orange-soft);
  color: var(--orange-dark);
  font-size: 1.6rem;
  font-weight: 800;
}
.stepper .qty-val {
  min-width: 48px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
}
.store-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.store-pill {
  min-height: 56px;
  border-radius: 16px;
  border: 2px solid transparent;
  background: var(--cream);
  font-weight: 800;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.store-pill .dot { width: 12px; height: 12px; border-radius: 50%; }
.store-pill.selected { background: #fff; box-shadow: var(--shadow); }
.store-pill.costco.selected { border-color: var(--costco); }
.store-pill.bjs.selected { border-color: var(--bjs); }
.store-pill.superfresh.selected { border-color: var(--fresh); }
.store-pill.tashkent.selected { border-color: var(--tashkent); }
.store-pill.anywhere.selected { border-color: var(--anywhere); }

/* Admin */
.member-row {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.member-row .who { flex: 1; font-weight: 800; }
.badge {
  font-size: 0.72rem;
  background: var(--orange-soft);
  color: var(--orange-dark);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 800;
}
.row-actions { display: flex; flex-direction: column; gap: 6px; }

/* Misc */
.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 0 0 14px;
  font-weight: 700;
}
.banner {
  background: var(--ok-soft);
  color: #1D704B;
  border-radius: 14px;
  padding: 12px 14px;
  margin: 0 0 14px;
  font-weight: 700;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: calc(100% - 32px);
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(61, 41, 20, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  border-radius: 24px;
  padding: 20px 16px calc(16px + var(--safe-bottom));
  box-shadow: 0 16px 40px rgba(0,0,0,0.18);
}
.modal h2 { margin-bottom: 8px; }
.modal p { color: var(--ink-soft); margin: 0 0 16px; }
.pin-reveal {
  font-size: 2rem;
  letter-spacing: 0.35em;
  text-align: center;
  font-weight: 800;
  background: var(--cream);
  border-radius: 16px;
  padding: 14px;
  margin: 0 0 16px;
}
.stack { display: flex; flex-direction: column; gap: 8px; }
.back-row { margin-bottom: 8px; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
}
@media (min-width: 500px) {
  .modal-backdrop { align-items: center; }
}
