:root {
  --green: #2f6b4f; --green-2: #e6f1ea; --ink: #1d2520; --muted: #6b756f;
  --line: #e3e7e4; --bg: #f5f6f3; --card: #fff; --red: #b3261e; --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 16px; line-height: 1.4; position: relative; min-height: 100vh; }

/* Produce-aisle photo background. A fixed layer (works on iPhone, unlike background-attachment: fixed)
   with a light wash on top so the list stays easy to read. Adjust --bg-wash to taste:
   lower = more artwork visible, higher = calmer. */
:root { --bg-wash: .6; }
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(rgba(245,246,243,var(--bg-wash)), rgba(245,246,243,var(--bg-wash))),
    url("bg-produce.jpg") center / cover no-repeat,
    var(--bg);
}
a { color: var(--green); }
h1, h2, h3 { margin: 0; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-bottom: .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 1rem; }
.hidden { display: none !important; }
.break { word-break: break-all; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.gap { gap: .6rem; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--green); color: #fff;
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; flex-wrap: wrap; }
.topbar h1 { font-size: 1.15rem; }
.tabs { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.tabs button { background: transparent; color: #fff; border: 0; padding: .45rem .8rem; border-radius: 999px;
  font: inherit; cursor: pointer; white-space: nowrap; opacity: .85; }
.tabs button.active { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.signout { color: #fff; font-size: .85rem; opacity: .85; }

main { max-width: 860px; margin: 0 auto; padding: .75rem; }
.card { background: var(--card); border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.card.empty { text-align: center; }

/* controls */
input, select { font: inherit; padding: .5rem .6rem; border: 1px solid #cfd6d1; border-radius: 8px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--green); outline-offset: 0; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; margin-bottom: .6rem; flex: 1; }
label.toggle { flex-direction: row; align-items: center; gap: .5rem; }
.btn { font: inherit; padding: .5rem .9rem; border-radius: 8px; border: 1px solid #cfd6d1; background: #fff; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f0; }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: #e7c3c0; margin-right: auto; }
.icon { background: none; border: 0; font-size: 1.05rem; cursor: pointer; color: var(--muted); padding: .35rem .45rem; border-radius: 6px; }
.icon:hover { background: #eef1ef; color: var(--ink); }
.star { color: #c9cfcb; }
.star.on { color: #e0a800; }

.quick-add { display: flex; gap: .5rem; margin: .9rem 0 .3rem; }
.quick-add input { flex: 1; }
.quick-add select { max-width: 9.5rem; }
.filters { margin-top: .75rem; }
.filters input[type=search] { flex: 1; min-width: 12rem; }
.filters label { flex: 0 1 auto; margin: 0; }
.selbar { margin-top: .75rem; padding: .6rem .8rem; background: var(--green-2); border-radius: 8px; }

.progress { height: 6px; background: var(--line); border-radius: 3px; margin-top: .6rem; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--green); transition: width .3s; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li.checked .li-name { text-decoration: line-through; color: var(--muted); }
.check, .sel { width: 1.35rem; height: 1.35rem; accent-color: var(--green); flex: none; cursor: pointer; }
.onlist { width: 1.35rem; text-align: center; color: var(--green); font-weight: 700; flex: none; }
.li-main { flex: 1; min-width: 0; }
.li-name { font-weight: 500; }
.li-name a { color: inherit; text-decoration: none; }
.li-name a:hover { text-decoration: underline; }
.li-sub { color: var(--muted); }
.li-qty { display: flex; align-items: center; gap: .15rem; color: var(--muted); }
.li-qty input { width: 3.6rem; padding: .3rem .4rem; text-align: center; }
.group h3 { color: var(--green); text-transform: uppercase; letter-spacing: .04em; font-size: .8rem; }

.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin: .25rem 0; }
.chip { font-size: .8rem; padding: .15rem .55rem; border-radius: 999px; background: #eef1ef; white-space: nowrap; }
.chip.best { background: var(--green-2); color: var(--green); font-weight: 600; }
.chip.link { text-decoration: none; background: #fff; border: 1px solid #cfd6d1; color: var(--ink); }
.chip.link:hover { border-color: var(--green); }

/* spending */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: .5rem; }
.stats > div { background: var(--bg); border-radius: 10px; padding: .7rem; display: flex; flex-direction: column; }
.big { font-size: 1.35rem; font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.bar { display: grid; grid-template-columns: 7.5rem 1fr 4.5rem; gap: .5rem; align-items: center; font-size: .85rem; margin: .3rem 0; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar-track span { display: block; height: 100%; background: var(--green); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }
.trip { border-top: 1px solid var(--line); padding: .5rem 0; }
.trip summary { cursor: pointer; display: flex; gap: .3rem; align-items: baseline; }
.trip-total { margin-left: auto; font-weight: 600; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; margin: .3rem 0; }
.tbl th, .tbl td { text-align: left; padding: .35rem .3rem; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 500; font-size: .8rem; }
.tbl .r { text-align: right; }

/* modal */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 1.5rem)); max-height: 90vh; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,30,25,.45); }
.modal-inner { padding: 1.1rem; }
.modal-inner h2 { margin-bottom: .8rem; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.section-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: .9rem 0 .3rem; }
.w-price { width: 6rem; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%);
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 8px; transition: transform .25s; z-index: 50; max-width: 90vw; opacity: 0; visibility: hidden; }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
#toast.err { background: var(--red); }

.notice { padding: .6rem .8rem; border-radius: 8px; }
.notice.ok { background: var(--green-2); color: var(--green); }
.notice.err { background: #fbe9e7; color: var(--red); }

/* auth pages */
.auth-page { display: flex; justify-content: center; padding: 2rem 1rem; }
.auth-page { --bg-wash: .1; min-height: 100vh; align-items: center; }
.auth-card { background: rgba(255,255,255,.96); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 440px; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.auth-card h1 { margin-bottom: 1rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 1rem; padding: .8rem; }
legend { font-weight: 600; padding: 0 .3rem; }

@media (max-width: 600px) {
  .topbar { gap: .5rem; }
  .topbar h1 { font-size: 1rem; }
  .tabs { order: 3; flex-basis: 100%; }
  .quick-add { flex-wrap: wrap; }
  .quick-add input { flex-basis: 100%; }
  .quick-add select { flex: 1; max-width: none; }
  .two-col { grid-template-columns: 1fr; }
  .stats .big { font-size: 1.1rem; }
  .bar { grid-template-columns: 6rem 1fr 4rem; }
}
