:root {
  --green: #16805a; --green-dark: #0f6444; --green-soft: #e3f3ec;
  --bg: #f4f7f5; --card: #fff; --text: #17211c; --muted: #66756d; --line: #dbe4df;
  --warn: #c46a00; --warn-soft: #fff1dc; --danger: #b3261e;
  --tap: 52px; --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 17px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
h1, h2 { margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; }
.muted, .hint { color: var(--muted); }
.hint { margin: .5rem 0; font-size: .95rem; }
.error { color: var(--danger); min-height: 1.4em; font-weight: 600; text-align: center; }

input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; min-height: var(--tap); padding: 0 14px; border: 2px solid var(--line);
  border-radius: var(--radius); background: #fff; outline: none;
}
input:focus, select:focus { border-color: var(--green); }
input.qty { width: 38%; flex: none; }
label { display: block; margin: .8rem 0 .3rem; font-weight: 600; }

.btn {
  min-height: var(--tap); padding: 0 18px; border: 2px solid var(--line); border-radius: var(--radius);
  background: #fff; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn.small { min-height: 44px; padding: 0 14px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.warn { background: var(--warn-soft); border-color: #f0c98d; color: var(--warn); }
.btn.danger { background: #fff; border-color: #e7b9b5; color: var(--danger); width: 100%; margin-top: .8rem; }
.btn.link { border: none; background: none; color: var(--green); width: 100%; }
.btn.grow { flex: 1; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); border: none; background: none; font-size: 1.5rem; cursor: pointer; }

/* login */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 22px; padding: 28px 22px; box-shadow: 0 6px 24px rgba(0,0,0,.08); text-align: center; }
.login-card h1 { margin: 10px 0 14px; }
.login-card form, .login-card label { text-align: left; }
.login-card form .btn { width: 100%; margin-top: 14px; }
#profileButtons .btn { width: 100%; margin-bottom: 10px; min-height: 64px; font-size: 1.2rem; }

/* app */
#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 16px; padding-top: calc(6px + env(safe-area-inset-top)); background: var(--green); color: #fff; }
.topbar .who { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.topbar .muted { color: #cfeadf; font-size: .85rem; }
.topbar .icon-btn { color: #fff; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: #7ee2b0; flex: none; }
.dot.off { background: #ffb4a8; }
.tab { padding: 14px 14px 20px; }

.offline-bar { background: #fff3cd; color: #6b4e00; padding: 10px 16px; font-weight: 600; font-size: .95rem; }
.shopping-banner { background: var(--green-soft); color: var(--green-dark); padding: 12px 16px; font-weight: 700; border-bottom: 1px solid #c6e4d6; }

.shop-toggle { width: 100%; min-height: 64px; display: flex; align-items: center; justify-content: center; gap: 12px;
  border: 2px solid var(--green); border-radius: var(--radius); background: #fff; color: var(--green-dark);
  font-size: 1.15rem; font-weight: 700; cursor: pointer; margin-bottom: 14px; }
.shop-toggle.on { background: var(--green); color: #fff; }
.shop-icon { font-size: 1.6rem; }

.add-form { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 16px; }
.add-form .row { display: flex; gap: 8px; margin-bottom: 8px; }
.add-form .row:last-child { margin-bottom: 0; }
.add-form > .btn { width: 100%; }
.add-form h2 { margin-bottom: .6rem; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

.cat-head { margin: 18px 4px 6px; font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.item { display: flex; align-items: center; gap: 4px; background: var(--card); border-radius: var(--radius);
  margin-bottom: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.05); min-height: 60px; }
.item .check { flex: none; width: 60px; height: 60px; border: none; background: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.item .check i { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #9fb3a9; display: flex; align-items: center; justify-content: center; font-style: normal; color: #fff; font-weight: 800; }
.item.done .check i { background: var(--green); border-color: var(--green); }
.item .body { flex: 1; min-width: 0; padding: 8px 0; text-align: left; border: none; background: none; cursor: pointer; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .qtyline { color: var(--muted); font-size: .9rem; }
.item.done .name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.item .star { flex: none; width: 48px; height: 56px; border: none; background: none; font-size: 1.5rem; cursor: pointer; color: #b9a24a; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); margin-left: 6px; vertical-align: middle; }
.item.almost { border-left: 5px solid var(--warn); }

.done-head { display: flex; align-items: center; justify-content: space-between; margin-top: 22px; }
.done-head h2 { margin: 0; color: var(--muted); }

.fav { display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: var(--radius); margin-bottom: 8px; padding: 6px 6px 6px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.fav .info { flex: 1; min-width: 0; }
.fav .name { font-weight: 600; overflow-wrap: anywhere; }
.fav .sub { color: var(--muted); font-size: .88rem; }
.fav .btn { min-width: 52px; padding: 0; font-size: 1.4rem; }
.fav .btn.on-list { background: var(--green-soft); color: var(--green-dark); font-size: .8rem; }
.fav .del { border: none; background: none; width: 40px; height: 52px; color: #9aa; font-size: 1.1rem; cursor: pointer; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabbtn { flex: 1; min-height: 66px; border: none; background: none; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; position: relative; }
.tabbtn span { font-size: 1.4rem; }
.tabbtn.active { color: var(--green-dark); box-shadow: inset 0 3px 0 var(--green); }
.badge { background: var(--green); color: #fff; border-radius: 99px; font-size: .75rem; padding: 0 7px; margin-left: 4px; }
.tabbtn .badge { position: absolute; top: 6px; left: calc(50% + 14px); margin: 0; }

dialog { border: none; border-radius: 20px; padding: 20px; width: min(92vw, 420px); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .row { display: flex; gap: 8px; margin-top: 16px; }
dialog .row .btn { flex: 1; }
#nameFields input { margin-bottom: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); max-width: 90vw;
  background: #17211c; color: #fff; padding: 12px 18px; border-radius: 99px; font-weight: 600; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,.3); }

/* setup.php */
body.setup { display: flex; justify-content: center; padding: 24px 12px; }
.setup-card { max-width: 480px; width: 100%; text-align: left; }
.setup-card form { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.setup-card code { background: var(--green-soft); padding: 1px 5px; border-radius: 6px; }
.setup-card a.btn { display: block; text-align: center; text-decoration: none; margin-top: 8px; }
.bigcode { font-size: 1.6rem; font-weight: 700; text-align: center; letter-spacing: .5px; background: var(--green-soft); padding: 12px; border-radius: var(--radius); }
