:root {
  --green: #2f7d32;
  --green-dark: #245d27;
  --bg: #faf8f5;
  --card: #ffffff;
  --ink: #2b2b2b;
  --muted: #777;
  --line: #ececec;
  --done: #9aa39a;
  --shadow: 0 2px 12px #0000000d;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

/* --- nav --- */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 1rem;
  padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--green);
  color: #fff;
  box-shadow: var(--shadow);
}
.nav .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.nav-links { display: flex; align-items: center; gap: .25rem; }
.nav-links a {
  color: #fff; text-decoration: none; padding: .35rem .6rem;
  border-radius: 8px; font-size: .95rem; opacity: .85;
}
.nav-links a.on { background: #ffffff22; opacity: 1; }
.logout { margin: 0; }
.logout button {
  background: #ffffff22; color: #fff; border: 0; border-radius: 8px;
  padding: .35rem .55rem; font-size: 1rem; cursor: pointer;
}

/* --- headings --- */
.page-head { margin: 1rem 0 1.25rem; }
.page-head h1 { font-size: 1.5rem; margin: 0 0 .15rem; }
.muted { color: var(--muted); font-size: .9rem; margin: 0; }

/* --- cards (home) --- */
.card {
  background: var(--card); border-radius: 14px; padding: 1rem 1.1rem;
  margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.card-head h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.more { color: var(--green); text-decoration: none; font-size: .9rem; font-weight: 600; }
.mini-list { list-style: none; margin: .25rem 0 0; padding: 0; }
.mini-list li { display: flex; gap: .75rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .day { color: var(--muted); min-width: 5.5rem; }
.mini-list .dish { font-weight: 500; }

.progress { font-size: .9rem; color: var(--muted); margin: 0 0 .4rem; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--green); transition: width .3s; }

/* --- plan --- */
.plan-list { list-style: none; padding: 0; margin: 0; }
.plan-row {
  display: flex; gap: .9rem; background: var(--card); border-radius: 12px;
  padding: .85rem 1rem; margin-bottom: .6rem; box-shadow: var(--shadow);
}
.plan-day { min-width: 4.5rem; color: var(--green-dark); font-weight: 700; font-size: .9rem; padding-top: .1rem; }
.plan-dish { font-weight: 600; }
.plan-notes { color: var(--muted); font-size: .88rem; margin-top: .15rem; }
.stars { color: #e0a32e; font-size: .85rem; margin-left: .3rem; }
.tags { margin-top: .4rem; display: flex; flex-wrap: wrap; gap: .3rem; }
.tag { background: #eef4ee; color: var(--green-dark); font-size: .72rem; padding: .1rem .5rem; border-radius: 99px; }

/* --- shopping --- */
.shop-progress { margin-bottom: 1rem; }
.progress-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.clear-checked {
  border: 0; background: none; color: var(--muted); font-size: .8rem;
  cursor: pointer; text-decoration: underline; padding: 0;
}
.clear-checked:hover, .clear-checked:focus { color: #c0392b; }
.store-group { margin-bottom: 1.2rem; }
.store-name {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 0 0 .4rem; padding-left: .2rem;
}
.shop-list { list-style: none; margin: 0; padding: 0; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.shop-item {
  display: flex; align-items: stretch; background: var(--card);
  border-bottom: 1px solid var(--line); -webkit-tap-highlight-color: transparent;
}
.shop-item:last-child { border-bottom: 0; }
.row-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: .75rem;
  padding: .8rem .9rem; border: 0; background: none; font: inherit; color: inherit;
  text-align: left; cursor: pointer; user-select: none;
}
.shop-item .box {
  flex: 0 0 auto; width: 26px; height: 26px; border: 2px solid var(--green);
  border-radius: 7px; display: grid; place-items: center; color: #fff;
  font-size: .9rem; line-height: 1;
}
.shop-item.done .box { background: var(--green); }
.shop-item .label {
  flex: 1; min-width: 0; display: flex; flex-wrap: wrap;
  align-items: baseline; gap: .25rem .5rem;
}
.shop-item .iqty { color: var(--muted); font-size: .88rem; margin-left: auto; }
.shop-item.done .iname { text-decoration: line-through; color: var(--done); }
.shop-item.done .iqty { text-decoration: line-through; }
.row-del {
  flex: 0 0 auto; width: 44px; border: 0; border-left: 1px solid var(--line);
  background: none; color: var(--muted); font-size: 1rem; line-height: 1;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.row-del:hover, .row-del:focus { color: #c0392b; }

/* offer / staple badges */
.badge { font-size: .72rem; padding: .08rem .45rem; border-radius: 99px; white-space: nowrap; }
.badge.offer { background: #fff3e0; color: #b9610e; }
.badge.staple { background: transparent; padding: 0; font-size: .85rem; }
.shop-item.done .badge { opacity: .5; }

/* --- add forms --- */
.add-form { display: flex; gap: .5rem; margin: 1rem 0 0; }
.add-form input[type=text] {
  flex: 1; min-width: 0; padding: .65rem .75rem; border: 1px solid var(--line);
  border-radius: 10px; font-size: 1rem; background: #fff;
}
.add-form .qty-in, .add-form .note-in { flex: 0 0 6.5rem; }
.add-form button {
  flex: 0 0 auto; width: 46px; border: 0; border-radius: 10px;
  background: var(--green); color: #fff; font-size: 1.4rem; line-height: 1; cursor: pointer;
}

/* --- fixed add bar (shopping) --- */
.add-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
.add-bar-inner { display: flex; gap: .5rem; align-items: center; max-width: 640px; margin: 0 auto; }
/* reserve space so the last list item scrolls clear of the fixed bar */
.has-add-bar { padding-bottom: 6rem; }
.suggest-wrap { position: relative; flex: 1; min-width: 0; }
.add-bar input[type=text] {
  width: 100%; padding: .65rem .75rem; border: 1px solid var(--line);
  border-radius: 10px; font-size: 1rem; background: #fff;
}
.add-bar .qty-in { flex: 0 0 6rem; }
.add-bar .add-btn {
  flex: 0 0 auto; align-self: stretch; width: 52px; border: 0; border-radius: 10px;
  background: var(--green); color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer;
}
/* suggestions drop UP, above the input */
.suggest-box {
  position: absolute; bottom: calc(100% + .35rem); left: 0; right: 0; z-index: 20;
}
.suggest-list {
  list-style: none; margin: 0; padding: .25rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 14rem; overflow-y: auto;
}
.suggest-row { display: flex; align-items: center; }
.suggest-pick {
  flex: 1; min-width: 0; text-align: left; border: 0; background: none; font: inherit;
  color: inherit; padding: .55rem .6rem; border-radius: 8px; cursor: pointer;
}
.suggest-pick:hover, .suggest-pick:focus { background: #eef4ee; }
.suggest-del {
  flex: 0 0 auto; width: 34px; border: 0; background: none; color: var(--muted);
  font-size: .85rem; cursor: pointer; border-radius: 8px;
}
.suggest-del:hover, .suggest-del:focus { color: #c0392b; }

/* --- this week's deals --- */
.deals { margin: 0 0 1rem; }
.deals > summary {
  cursor: pointer; font-weight: 600; color: var(--green-dark);
  padding: .5rem .2rem; list-style: none;
}
.deals > summary::-webkit-details-marker { display: none; }
.deal-list { list-style: none; margin: .3rem 0 0; padding: 0; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.deal-row {
  display: flex; align-items: center; gap: .6rem; background: var(--card);
  padding: .65rem .9rem; border-bottom: 1px solid var(--line);
}
.deal-row:last-child { border-bottom: 0; }
.deal-name { font-weight: 600; flex: 1; min-width: 0; }
.deal-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; }
.deal-price { color: #b9610e; font-weight: 600; font-size: .9rem; }
.deal-add {
  flex: 0 0 auto; border: 1px solid var(--green); background: #fff; color: var(--green-dark);
  font-size: .82rem; padding: .35rem .6rem; border-radius: 99px; cursor: pointer; white-space: nowrap;
}
.deal-add:hover, .deal-add:focus { background: var(--green); color: #fff; }
.small { font-size: .82rem; }

/* --- staples --- */
.staple-list { list-style: none; margin: 1.2rem 0 0; padding: 0; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.staple-row { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; background: var(--card); padding: .75rem .9rem; border-bottom: 1px solid var(--line); }
.staple-row:last-child { border-bottom: 0; }
.iname { font-weight: 500; }

/* --- empty / misc --- */
.empty { background: var(--card); border-radius: 12px; padding: 1.5rem; text-align: center; box-shadow: var(--shadow); }
.empty p { margin: .25rem 0; }
.err { color: #b00020; font-size: .9rem; margin: .6rem 0 0; }

/* --- login --- */
.login-card {
  max-width: 340px; margin: 12vh auto 0; background: var(--card);
  padding: 2rem 1.75rem; border-radius: 16px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card > .muted { margin-bottom: 1.5rem; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .9rem; }
.login-card input {
  width: 100%; margin-top: .25rem; padding: .65rem .75rem; border: 1px solid var(--line);
  border-radius: 10px; font-size: 1rem; box-sizing: border-box;
}
.login-card button {
  width: 100%; margin-top: .5rem; padding: .7rem; border: 0; border-radius: 10px;
  background: var(--green); color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-card .err { text-align: center; }
