:root {
  --green: #2b6a3e;
  --green-soft: #e2efe5;
  --red: #b3262e;
  --red-soft: #f8e4e4;
  --amber: #b9741b;
  --amber-soft: #fbefdc;
  --bg: #f7f8f4;
  --card: #ffffff;
  --text: #22211f;
  --muted: #6b6d66;
  --line: #e3e5dc;
  --radius: 14px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--green); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; margin-bottom: 4px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.warn { color: var(--amber); }
.loading { text-align: center; color: var(--muted); padding: 3rem 1rem; }
code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

#view { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) 16px 0; }

/* ---------- top of page ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-weight: 600; }
.note { border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; font-size: .9rem; }
.note.warn { background: var(--amber-soft); color: #7a4a0c; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card.banner { display: block; text-decoration: none; color: var(--green); font-weight: 600; background: var(--green-soft); border-color: #cfe3d4; }
.list-card.on { border-color: var(--green); box-shadow: 0 0 0 1px var(--green) inset; }
.list-card .flagline { color: var(--amber); margin-top: 8px; }
.list-card .skipline { color: var(--muted); margin-top: 4px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row-btns:empty { display: none; }

.group-title { margin: 20px 4px 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 16px 10px; border: 1px dashed var(--line); border-radius: var(--radius); margin-bottom: 8px; }

details.later { margin-top: 20px; }
details.later summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 8px 4px; }
details.later .card { opacity: .85; }

/* ---------- rows ---------- */
.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; gap: 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; min-height: 52px;
}
.item[data-act] { cursor: pointer; }
.item .grow, .grow { flex: 1; min-width: 0; }
.item b { font-weight: 600; }
.item .sub, .check-row .sub { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.item .actions { display: flex; gap: 6px; }
.item.dim { opacity: .6; }
.item.flagged { border-color: #ecd3ad; background: #fffaf2; }
.chev { color: var(--muted); font-size: 1.4rem; }
.ext { font-size: .85rem; font-weight: 600; white-space: nowrap; text-decoration: none; }

.check-row { display: flex; align-items: flex-start; gap: 10px; margin: 0; font-weight: 400; font-size: 1rem; cursor: pointer; }
.check-row input[type=checkbox] { flex: 0 0 24px; width: 24px; height: 24px; margin: 1px 0 0; accent-color: var(--green); }

.tag { display: inline-block; font-size: .72rem; font-weight: 700; border-radius: 99px; padding: 1px 7px; vertical-align: 1px; }
.tag.low { background: var(--amber-soft); color: var(--amber); }
.tag.out { background: var(--red-soft); color: var(--red); }

.flagbtns { display: flex; gap: 6px; }
.fbtn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px;
  font: inherit; font-size: .85rem; font-weight: 700; color: var(--muted); cursor: pointer; min-width: 52px;
}
.fbtn.low.on { background: var(--amber); border-color: var(--amber); color: #fff; }
.fbtn.out.on { background: var(--red); border-color: var(--red); color: #fff; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; -webkit-overflow-scrolling: touch; }
.chipbtn {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 8px 12px;
  font: inherit; font-size: .9rem; font-weight: 600; color: var(--text); cursor: pointer; white-space: nowrap;
}
.chipbtn span { color: var(--muted); font-weight: 500; margin-left: 2px; }
.chipbtn.on { background: var(--green); border-color: var(--green); color: #fff; }
.chipbtn.on span { color: #d6eadb; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: #fff; }
.btn.small { padding: 7px 11px; font-size: .88rem; }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 12px; }
.btn:disabled { opacity: .5; }
.sticky-cta { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); margin-top: 22px; box-shadow: 0 4px 14px rgba(43,106,62,.3); z-index: 5; }
.icon-btn { border: 0; background: none; font-size: 1.2rem; padding: 6px 8px; cursor: pointer; color: var(--muted); }

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; /* 16px stops iPhone zooming in */
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
input[type=search] { margin: 0 0 4px; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { display: inline-block; width: 22px; height: 22px; margin: 0 8px 0 0; vertical-align: middle; }
.check { display: flex; align-items: center; font-weight: 500; margin-top: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn { flex: 1; }
form .btn.small { margin-top: 10px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.tabbar a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; position: relative; }
.tabbar a span { display: block; font-size: 1.3rem; line-height: 1.3; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--green); }
.tabbar a.on span { filter: none; opacity: 1; }
.badge {
  position: absolute; top: -2px; left: calc(50% + 6px); background: var(--red); color: #fff;
  font-size: .65rem; border-radius: 99px; padding: 1px 6px; font-weight: 700;
}

/* ---------- bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 0 16px calc(20px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; justify-content: space-between; align-items: center; padding: 14px 0 6px; z-index: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: #22211f; color: #fff; border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 14px; align-items: center; width: max-content; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast[hidden] { display: none; }
.toast button { background: none; border: 0; color: #9fd8b4; font: inherit; font-weight: 700; cursor: pointer; }

/* ---------- sign-in pages ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: 100%; max-width: 380px; }
.auth-card.wide { max-width: 480px; }
.auth-card h1 { text-align: center; margin-bottom: 8px; }
.auth-card .btn { margin-top: 20px; }
.auth-logo { font-size: 3rem; text-align: center; }
.auth-error { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 16px 0 0; padding: 4px 12px 12px; }
legend { font-weight: 700; padding: 0 6px; }

@media (min-width: 700px) {
  .sheet { border-radius: 18px; margin-bottom: 4vh; }
  .sheet-backdrop { align-items: center; }
}
