:root {
  --bg: #ffffff;
  --page: #e7eaf0;
  --ink: #14181f;
  --muted: #9097a1;
  --soft: #f4f6f8;
  --line: #e9ecf0;
  --brand: #15a34a;
  --brand-2: #0f7d39;
  --brand-ink: #ffffff;
  --danger: #e23b3b;
  --bought: #aab0b8;
  --shadow-sm: 0 1px 2px rgba(20,24,31,.06);
  --shadow-md: 0 4px 14px rgba(20,24,31,.08);
  --shadow-lg: 0 12px 40px rgba(20,24,31,.16);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --r: 14px;
}

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

html, body { margin: 0; height: 100%; }
html { background: var(--page); }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100dvh;
  max-width: 600px; margin: 0 auto;
  box-shadow: 0 0 0 1px var(--line), 0 8px 40px rgba(20,24,31,.10);
}

/* === Header === */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; color: var(--brand-ink);
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -.2px; display: flex; align-items: center; gap: 6px; }
.refresh-btn {
  background: none; border: none; color: var(--brand-ink);
  font-size: 18px; cursor: pointer; padding: 2px 4px; border-radius: 6px;
  opacity: .75; transition: opacity .15s, transform .3s;
}
.refresh-btn:hover { opacity: 1; }
.refresh-btn.spinning { animation: spin .5s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.whoami {
  background: rgba(255,255,255,.20); color: var(--brand-ink); border: none;
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.whoami:hover { background: rgba(255,255,255,.30); }
.push-btn {
  background: none; border: none; color: var(--brand-ink);
  font-size: 20px; cursor: pointer; padding: 4px 6px; border-radius: 8px;
  transition: background .15s; opacity: .75;
}
.push-btn:hover { background: rgba(255,255,255,.20); opacity: 1; }
.push-btn.active { opacity: 1; }

/* === Tabs === */
.tabs {
  display: flex; gap: 8px; padding: 12px; overflow-x: auto;
  background: var(--bg); border-bottom: 1px solid var(--line);
  position: sticky; top: 56px; z-index: 9; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 999px; padding: 9px 16px; font-size: 14px; font-weight: 600; white-space: nowrap;
  cursor: pointer; transition: all .15s;
}
.tab:hover { border-color: #d4d9df; }
.tab.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); box-shadow: var(--shadow-sm); }
.tab.add { color: var(--brand); border-style: dashed; }
.tab { display: inline-flex; align-items: center; gap: 6px; }
.store-logo { height: 20px; width: auto; max-width: 60px; object-fit: contain; border-radius: 4px; }
.tab-emoji { font-size: 16px; line-height: 1; }
.tab-name { font-size: 14px; font-weight: 600; }

/* === Store head === */
.storehead {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 18px 6px;
}
.storehead .name { font-size: 22px; font-weight: 800; letter-spacing: -.4px; }
.storehead .manage {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 7px 13px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.storehead .manage:hover { color: var(--ink); border-color: #d4d9df; }

/* === Board === */
.board { flex: 1; overflow-y: auto; padding: 6px 14px 96px; }
.empty { text-align: center; color: var(--muted); margin-top: 56px; font-size: 15px; line-height: 1.7; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 18px 4px; line-height: 1.7; }

.family { margin-top: 18px; }
.family > h3 {
  font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 4px 8px;
  letter-spacing: .4px; text-transform: uppercase;
}
.fam-empty {
  border: 1px dashed var(--line); border-radius: var(--r); color: var(--muted);
  font-size: 13px; text-align: center; padding: 12px; background: var(--soft);
}

.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 15px; margin-bottom: 9px; box-shadow: var(--shadow-sm);
  touch-action: pan-y; user-select: none; position: relative; transition: box-shadow .15s;
}
.item:hover { box-shadow: var(--shadow-md); }
.item .txt { flex: 1; font-size: 16px; font-weight: 500; }
.item .by {
  font-size: 11px; color: var(--muted); background: var(--soft);
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.item.bought { box-shadow: none; background: var(--soft); border-style: dashed; }
.item.item-highlighted { background: #fff3e0; border-color: #ff9800; box-shadow: 0 0 0 3px rgba(255,152,0,.25); flex-wrap: wrap; }
.inline-reply-inp {
  flex-basis: 100%; margin-top: 8px;
  border: 1px solid #ff9800; border-radius: 8px; padding: 10px 14px;
  font-size: 16px; background: #fff8f0; outline: none;
}
.inline-reply-send {
  flex-basis: 100%; margin-top: 6px;
  border: none; background: #ff9800; color: #fff;
  border-radius: 8px; padding: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.reply-btn {
  flex: 0 0 auto; border: 1px solid #ddd; background: #f5f5f5; color: #333;
  border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.reply-ok { border-color: #4caf50; background: #f1f8f1; color: #2e7d32; }
.reply-no { border-color: #ef5350; background: #fff5f5; color: #c62828; }
.inline-reply-inp {
  flex: 1; border: 1px solid #ff9800; border-radius: 8px; padding: 6px 10px;
  font-size: 15px; background: #fff8f0; outline: none; min-width: 0;
}
.inline-reply-send {
  border: none; background: #ff9800; color: #fff;
  border-radius: 8px; padding: 6px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.item.bought .txt { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.swipe-del-label {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 13px; font-weight: 600; color: #c62828; opacity: 0; pointer-events: none;
  transition: opacity .1s;
}

.bought-head {
  display: flex; align-items: center; justify-content: space-between; margin: 26px 4px 10px;
}
.bought-head h3 { font-size: 12px; font-weight: 700; color: var(--muted); margin: 0; letter-spacing: .4px; text-transform: uppercase; }
.bought-head button { border: none; background: none; color: var(--danger); font-size: 13px; font-weight: 600; cursor: pointer; }

/* === Add bar === */
.addbar {
  position: sticky; bottom: 0; display: flex; gap: 10px;
  padding: 12px 14px calc(12px + var(--safe-b));
  background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.additem {
  flex: 1; border: 1px solid var(--line); border-radius: var(--r); padding: 13px 15px;
  font-size: 16px; background: var(--soft); transition: all .15s;
}
.additem:focus { outline: none; border-color: var(--brand); background: var(--bg); box-shadow: 0 0 0 3px rgba(21,163,74,.14); }
.addbtn {
  flex: 0 0 auto; width: 50px; border: none; border-radius: var(--r);
  background: var(--brand); color: var(--brand-ink); font-size: 26px; font-weight: 700;
  cursor: pointer; transition: transform .1s, background .15s;
}
.addbtn:hover { background: var(--brand-2); }
.addbtn:active { transform: scale(.94); }

/* === Modal === */
.overlay {
  position: fixed; inset: 0; background: rgba(20,24,31,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 600px;
  border-radius: 20px 20px 0 0; padding: 22px 20px calc(20px + var(--safe-b));
  box-shadow: var(--shadow-lg); max-height: 86vh; overflow-y: auto;
  animation: rise .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.sheet h2 { font-size: 19px; margin: 0 0 16px; font-weight: 700; letter-spacing: -.2px; }
.sheet .field {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px;
  font-size: 16px; background: var(--soft); margin-bottom: 12px;
}
.sheet .field:focus { outline: none; border-color: var(--brand); background: var(--bg); box-shadow: 0 0 0 3px rgba(21,163,74,.14); }
.sheet .row { display: flex; gap: 10px; margin-top: 6px; }
.btn { flex: 1; border: none; border-radius: 12px; padding: 14px; font-size: 15px; font-weight: 600; cursor: pointer; transition: filter .15s; }
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: var(--soft); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }

.choice {
  display: block; width: 100%; text-align: start; border: 1px solid var(--line);
  background: var(--bg); border-radius: 12px; padding: 14px 15px; margin-bottom: 8px;
  font-size: 15px; font-weight: 500; cursor: pointer; transition: all .12s;
}
.choice:hover { border-color: var(--brand); background: #f3fbf5; }
.choice .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 400; }

.manage-list { margin: 4px 0 14px; }
.manage-row {
  display: flex; align-items: center; gap: 8px; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--soft);
}
.manage-row .n { flex: 1; font-size: 15px; font-weight: 500; }
.manage-row button { border: none; background: none; font-size: 16px; padding: 4px 6px; cursor: pointer; border-radius: 8px; }
.manage-row button:hover { background: rgba(0,0,0,.05); }
.manage-row .del { color: var(--danger); }

/* === Quantity === */
.item .qtybadge { font-size: 13px; font-weight: 700; color: var(--brand); }
.addqty {
  flex: 0 0 auto; width: 54px; border: 1px solid var(--line); border-radius: var(--r);
  padding: 13px 4px; font-size: 16px; text-align: center; background: var(--soft);
}
.addqty:focus { outline: none; border-color: var(--brand); background: var(--bg); box-shadow: 0 0 0 3px rgba(21,163,74,.14); }
