:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --bg: #f4f6f4;
  --card: #ffffff;
  --ink: #1c2421;
  --muted: #6b7770;
  --line: #e3e8e3;
  --gold: #f3a712;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 40px;
}

/* ---------- login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(160deg, #2e7d32, #1b5e20);
}
.login-card {
  background: #fff; padding: 32px 26px; border-radius: 18px;
  width: min(360px, 90vw); text-align: center; box-shadow: var(--shadow);
}
.login-logo { font-size: 46px; }
.login-card h1 { margin: 6px 0 2px; }
.login-card input {
  width: 100%; padding: 14px; margin-top: 16px; border: 1px solid var(--line);
  border-radius: 12px; font-size: 16px;
}
.login-card button {
  width: 100%; padding: 14px; margin-top: 12px; border: 0; border-radius: 12px;
  background: var(--green); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.error { color: #c62828; font-size: 14px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--green); color: #fff; padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 18px; }
.zip { font-weight: 400; opacity: .8; font-size: 13px; margin-left: 4px; }
.moneylink { color: #fff; text-decoration: none; font-size: 14px; opacity: .95; }

/* ---------- search ---------- */
.searchwrap { display: flex; gap: 8px; padding: 12px 16px; }
.searchwrap input {
  flex: 1; padding: 14px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; background: #fff;
}
.searchwrap button {
  padding: 0 18px; border: 0; border-radius: 12px; background: var(--green);
  color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
}

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; padding: 0 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; }
.tab {
  flex: 0 0 auto; padding: 9px 16px; border: 0; border-radius: 999px;
  background: #e7ece7; color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
}
.tab.active { background: var(--green); color: #fff; }

main { padding: 14px 16px 0; }
.section-hint { color: var(--muted); font-size: 13px; margin: 4px 0 14px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

/* ---------- staple grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--card); border-radius: 14px; padding: 12px; box-shadow: var(--shadow);
  cursor: pointer; position: relative; display: flex; flex-direction: column; min-height: 120px;
}
.card .label { font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.card .price { font-size: 22px; font-weight: 800; color: var(--green-dark); line-height: 1; }
.card .store { font-size: 13px; color: var(--muted); margin-top: 4px; }
.card .deal-name { font-size: 12px; color: var(--muted); margin-top: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .loading { color: var(--muted); font-size: 13px; }
.card .none { color: var(--muted); font-size: 13px; margin-top: 6px; }
.badge {
  position: absolute; top: 10px; right: 10px; background: var(--gold); color: #fff;
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
}
.fav-btn {
  position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.9);
  border: 0; font-size: 18px; border-radius: 999px; width: 32px; height: 32px; cursor: pointer;
}

/* ---------- search results ---------- */
.results-head { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.results-head .pill { display:inline-block; background:#e7ece7; padding:4px 10px; border-radius:999px; margin-right:6px; color:var(--ink); }
.resultlist { display: flex; flex-direction: column; gap: 10px; }
.rowcard {
  display: flex; gap: 12px; background: var(--card); border-radius: 12px; padding: 10px;
  box-shadow: var(--shadow); align-items: center; text-decoration: none; color: inherit;
}
.rowcard img { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background:#fafafa; flex:0 0 auto; }
.rowcard .info { flex: 1; min-width: 0; }
.rowcard .rname { font-weight: 600; font-size: 14px; }
.rowcard .rmeta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rowcard .rprice { font-size: 18px; font-weight: 800; color: var(--green-dark); white-space: nowrap; }
.cheapest-tag { color: var(--gold); font-weight: 700; font-size: 11px; }

/* ---------- browse ---------- */
.storechips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; }
.store-pill {
  flex: 0 0 auto; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.store-pill.active { background: var(--green); color: #fff; border-color: var(--green); }
.browse-filter { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; margin-bottom: 12px; }
.more-btn { display: block; margin: 16px auto 4px; padding: 12px 22px; border: 0; border-radius: 12px;
  background: #e7ece7; color: var(--green-dark); font-weight: 700; font-size: 15px; cursor: pointer; }
.browse-card { text-decoration: none; color: inherit; }
.browse-card .bimg { width: 100%; height: 84px; object-fit: contain; background: #fafafa; border-radius: 8px; margin-bottom: 6px; }
.price.see-ad, .rprice.see-ad { color: var(--green); font-size: 14px; font-weight: 700; }

/* ---------- blog matchups ---------- */
.bloglist { display: flex; flex-direction: column; gap: 10px; }
.blog-section-title { font-weight: 700; font-size: 15px; margin: 4px 0 8px; display: flex; align-items: center; gap: 6px; }
.blogcard {
  background: var(--card); border-radius: 12px; padding: 10px;
  box-shadow: var(--shadow); cursor: pointer;
}
.blogcard .bhead { display: flex; gap: 12px; align-items: center; }
.blogcard img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; background: #fafafa; flex: 0 0 auto; }
.blogcard .binfo { flex: 1; min-width: 0; }
.blogcard .btitle { font-weight: 600; font-size: 14px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.blogcard .bmeta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.blogcard .bexcerpt { font-size: 12px; color: var(--muted); margin-top: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.price-chip { background: #eaf6ea; color: var(--green-dark); padding: 2px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.blog-body { display: none; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
  white-space: pre-wrap; font-size: 13px; line-height: 1.5; color: var(--ink); }
.blogcard.open .blog-body { display: block; }
.blogcard.open .bexcerpt { display: none; }
.blog-readmore { display: inline-block; margin-top: 10px; color: var(--green); font-weight: 600; font-size: 13px; text-decoration: none; }
.expand-hint { font-size: 11px; color: var(--green); font-weight: 600; margin-top: 6px; }
.blogcard.open .expand-hint { display: none; }
.src-chip { background: #eef3ee; color: var(--green-dark); padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.store-chip { background: #fff3df; color: #9a6b00; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; margin-left: 4px; }
.blog-hits-wrap { background: #f0f6f0; border: 1px solid #d9e7d9; border-radius: 12px; padding: 12px; margin-bottom: 14px; }

/* ---------- receipts / purchases ---------- */
.upload-box { background: var(--card); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.upload-title { font-weight: 700; font-size: 16px; margin: 0 0 4px; }
.upload-btn { display: inline-block; margin-top: 6px; padding: 12px 20px; background: var(--green); color: #fff;
  font-weight: 600; border-radius: 12px; cursor: pointer; font-size: 15px; }
.upload-btn:active { background: var(--green-dark); }
.upload-status { display: block; margin-top: 10px; font-size: 14px; font-weight: 600; }
.upload-status.ok { color: var(--green-dark); }
.upload-status.err { color: #c62828; }
.upload-status.busy { color: var(--muted); }

.subtabs { display: flex; gap: 8px; margin-bottom: 12px; }
.subtab { padding: 8px 14px; border: 0; border-radius: 999px; background: #e7ece7; color: var(--muted);
  font-weight: 600; font-size: 13px; cursor: pointer; }
.subtab.active { background: var(--green); color: #fff; }

.buy-row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px;
  padding: 11px 12px; box-shadow: var(--shadow); }
.buy-row .bn { flex: 1; min-width: 0; }
.buy-row .bn-name { font-size: 14px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.buy-row .bn-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.buy-row .bp { text-align: right; white-space: nowrap; }
.buy-row .bp-price { font-size: 17px; font-weight: 800; color: var(--green-dark); }
.buy-row .bp-each { font-size: 11px; color: var(--muted); }
.times-chip { background: #eef3ee; color: var(--green-dark); padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; }

.order-card { background: var(--card); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.order-head { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.order-head .o-date { font-weight: 700; font-size: 15px; }
.order-head .o-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.order-head .o-total { font-size: 18px; font-weight: 800; color: var(--green-dark); }
.order-items { display: none; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.order-card.open .order-items { display: block; }
.order-line { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; gap: 10px; }
.order-line .ol-name { color: var(--ink); min-width: 0; }
.order-line .ol-price { color: var(--muted); white-space: nowrap; }
.order-del { margin-top: 10px; background: none; border: 0; color: #c62828; font-size: 13px; font-weight: 600; cursor: pointer; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; z-index: 20; }
.modal[hidden] { display: none; }  /* the [hidden] attr alone loses to .modal's display:flex */
.modal-card {
  position: relative;  /* so the close button anchors to the card, not the viewport */
  background: #fff; width: 100%; max-height: 80vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal-close { position: absolute; right: 14px; top: 12px; border: 0; background: #eee; border-radius: 999px; width: 34px; height: 34px; font-size: 16px; cursor: pointer; }
.modal h2 { margin: 0 0 14px; padding-right: 40px; }
.store-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.store-row .s-name { font-weight: 600; }
.store-row .s-sub { font-size: 12px; color: var(--muted); }
.store-row .s-price { font-size: 18px; font-weight: 800; color: var(--green-dark); }
.store-row.win .s-price { color: var(--gold); }

@media (min-width: 720px) {
  main, .searchwrap, .tabs { max-width: 900px; margin-left: auto; margin-right: auto; }
  .modal { align-items: center; justify-content: center; }
  .modal-card { max-width: 460px; border-radius: 18px; }
}
