:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #1c231f;
  --muted: #6b766f;
  --faint: #a3ada6;
  --line: #e3e8e2;
  --brand: #1f7a55;
  --brand-2: #2e9a6c;
  --brand-soft: #e1f2e8;
  --danger: #c8443a;
  --danger-soft: #fbe9e7;
  --warn: #d38b1d;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 14px rgba(20, 40, 30, .05);
  --shadow-lg: 0 -8px 40px rgba(10, 30, 20, .18);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1b211e; --surface-2: #232b27; --text: #e8eeea; --muted: #97a39c;
    --faint: #5f6b65; --line: #2b3430; --brand: #4cc08a; --brand-2: #5fd39c; --brand-soft: #1e3a2d;
    --danger: #ef7a70; --danger-soft: #3a2220;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 -8px 40px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.4; min-height: 100dvh; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, textarea { outline: none; }
.hidden { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

.boot { flex: 1; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- כותרת ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(10px + var(--safe-t)) 16px 10px; }
.topbar-row { display: flex; align-items: center; gap: 10px; }
.title { flex: 1; min-width: 0; }
.title h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title .sub { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.live { background: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.dot.connecting { background: var(--warn); }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface);
  box-shadow: var(--shadow); font-size: 20px; flex: none; }
.icon-btn:active { transform: scale(.95); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- שורת הוספה ---------- */
.addbar { margin-top: 10px; position: relative; }
.add-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
.add-row { display: flex; gap: 6px; align-items: center; }
.add-row input { border: 0; background: transparent; min-width: 0; height: 46px; padding: 0 10px; font-size: 17px; }
#add-name { flex: 1; }
#add-qty { width: 64px; text-align: center; background: var(--surface-2); border-radius: 12px; font-size: 15px; height: 40px; }
.note-toggle { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.note-toggle.on { background: var(--brand-soft); color: var(--brand); }
.add-btn { width: 46px; height: 46px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.add-btn:active { transform: scale(.94); background: var(--brand-2); }
.add-btn svg { width: 24px; height: 24px; }
#add-note { width: 100%; border: 0; border-top: 1px solid var(--line); background: transparent; padding: 10px 10px 6px; font-size: 15px; }

.suggest { position: absolute; inset-inline: 0; top: calc(100% + 6px); background: var(--surface); border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0,0,0,.14); overflow: hidden; z-index: 30; }
.suggest button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px; text-align: start; font-size: 16px;
  border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: 0; }
.suggest button.active, .suggest button:hover { background: var(--surface-2); }
.suggest .s-icon { font-size: 18px; }
.suggest .s-hint { margin-inline-start: auto; font-size: 12.5px; color: var(--faint); }

/* ---------- רשימה ---------- */
main { flex: 1; padding: 6px 16px calc(40px + var(--safe-b)); }
.group { margin-top: 14px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 0 4px 6px; color: var(--muted); font-size: 14px; font-weight: 500; }
.group-head .g-icon { font-size: 17px; }
.group-head .g-count { margin-inline-start: auto; font-size: 12.5px; background: var(--surface-2); padding: 2px 8px; border-radius: 99px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

.item { display: flex; align-items: center; gap: 4px; min-height: 58px; border-bottom: 1px solid var(--line); position: relative; }
.item:last-child { border-bottom: 0; }
.check { width: 58px; height: 58px; display: grid; place-items: center; flex: none; }
.check span { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--faint); display: grid; place-items: center;
  transition: all .15s ease; }
.check span svg { width: 16px; height: 16px; color: #fff; opacity: 0; transition: opacity .15s; }
.item.done .check span { background: var(--brand); border-color: var(--brand); }
.item.done .check span svg { opacity: 1; }
.item-body { flex: 1; min-width: 0; padding: 10px 0 10px 4px; text-align: start; display: block; }
.item-name { font-size: 17px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qty { font-size: 13px; font-weight: 600; color: var(--brand); background: var(--brand-soft); padding: 1px 8px; border-radius: 99px; }
.item-note { font-size: 13.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.del-btn { width: 48px; height: 58px; display: grid; place-items: center; flex: none; color: var(--faint); border-radius: 12px; }
.del-btn svg { width: 20px; height: 20px; }
.del-btn:active { color: var(--danger); background: var(--danger-soft); }
@media (hover: hover) { .del-btn:hover { color: var(--danger); } }
.item.done .item-name { color: var(--faint); text-decoration: line-through; }
.item.done .qty { background: var(--surface-2); color: var(--faint); }
.item.pending { opacity: .6; }
.item.flash { animation: flash 1s ease; }
@keyframes flash { 0% { background: var(--brand-soft); } 100% { background: transparent; } }

.bought { margin-top: 26px; }
.bought-head { display: flex; align-items: center; gap: 8px; padding: 0 4px 8px; }
.bought-head h2 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 500; flex: 1; }
.chip-btn { font-size: 13.5px; padding: 7px 12px; border-radius: 99px; background: var(--surface); box-shadow: var(--shadow); color: var(--muted); }
.chip-btn.danger { color: var(--danger); }

.empty { text-align: center; padding: 60px 20px 20px; color: var(--muted); }
.empty .big { font-size: 54px; }
.empty h3 { margin: 10px 0 4px; color: var(--text); font-size: 19px; }
.empty p { margin: 0; font-size: 15px; }

.banner { margin: 8px 0 0; padding: 9px 12px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: 14px; text-align: center; }

/* ---------- גיליון תחתון ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 20, 15, .38); z-index: 50; animation: fade .18s ease; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 51; background: var(--surface); border-radius: 24px 24px 0 0;
  max-width: 640px; margin: 0 auto; max-height: 92dvh; overflow: auto; box-shadow: var(--shadow-lg);
  padding: 8px 18px calc(18px + var(--safe-b)); animation: up .22s cubic-bezier(.2,.8,.2,1); }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13.5px; color: var(--muted); margin: 0 4px 5px; }
.input { width: 100%; height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 14px; font-size: 16.5px; }
.input:focus { border-color: var(--brand); }
textarea.input { height: auto; min-height: 70px; padding: 12px 14px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }
.cat-opt { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
  font-size: 14.5px; text-align: start; border: 1.5px solid transparent; }
.cat-opt.sel { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.btn { height: 52px; border-radius: 15px; padding: 0 18px; font-size: 16.5px; font-weight: 600; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-2); }
.btn.ghost { background: var(--surface-2); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn-row .btn { flex: 1; }

.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-item { display: flex; align-items: center; gap: 14px; padding: 14px 10px; border-radius: 14px; font-size: 17px; text-align: start; width: 100%; }
.menu-item:active { background: var(--surface-2); }
.menu-item .mi-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .mi-icon { background: var(--danger-soft); }
.menu-item small { display: block; color: var(--muted); font-size: 13px; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 0; }
.hint-box { background: var(--surface-2); padding: 12px 14px; border-radius: 14px; font-size: 14px; color: var(--muted); margin-top: 8px; }

/* ---------- מסכים מלאים ---------- */
.view { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow: auto; animation: slide .2s ease; }
.view-inner { max-width: 640px; margin: 0 auto; padding-bottom: calc(30px + var(--safe-b)); }
@keyframes slide { from { transform: translateX(-24px); opacity: 0; } }
.view .topbar h1 { font-size: 20px; }
.view main { padding-top: 4px; }
.back-btn svg { transform: scaleX(-1); }

.hist-card { display: flex; align-items: center; gap: 12px; padding: 14px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: start; }
.hist-card:last-child { border-bottom: 0; }
.hist-card .h-icon { width: 44px; height: 44px; border-radius: 14px; background: var(--brand-soft); display: grid; place-items: center; font-size: 20px; flex: none; }
.hist-card .h-main { flex: 1; min-width: 0; }
.hist-card .h-date { font-weight: 600; font-size: 16px; }
.hist-card .h-sub { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--faint); font-size: 22px; }

.h-item { display: flex; align-items: center; gap: 4px; min-height: 54px; border-bottom: 1px solid var(--line); width: 100%; text-align: start; }
.h-item:last-child { border-bottom: 0; }
.h-item .item-body { padding-inline-start: 0; }
.h-item.in-list .item-name { color: var(--faint); }
.h-item.sel { background: var(--brand-soft); }
.h-item.sel .check span { background: var(--brand); border-color: var(--brand); }
.h-item.sel .check span svg { opacity: 1; }
.in-list-tag { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 1px 8px; border-radius: 99px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(transparent, var(--bg) 30%); display: flex; flex-direction: column; gap: 8px; }

.cat-row { display: flex; align-items: center; gap: 6px; padding: 8px 8px; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .emoji-btn { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); font-size: 21px; flex: none; }
.cat-row input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 16px; height: 44px; padding: 0 6px; border-radius: 10px; }
.cat-row input:focus { background: var(--surface-2); }
.mini { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); font-size: 17px; flex: none; }
.mini:active { background: var(--surface-2); }
.mini:disabled { opacity: .25; }
.mini.del { color: var(--danger); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.emoji-grid button { height: 48px; font-size: 24px; border-radius: 12px; background: var(--surface-2); }

/* ---------- טוסט ---------- */
#toast-root { position: fixed; inset-inline: 0; bottom: calc(18px + var(--safe-b)); z-index: 70; display: flex; flex-direction: column;
  align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: #1f2a24; color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 15px;
  display: flex; align-items: center; gap: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: up .2s ease; max-width: 100%; }
.toast button { color: #8ee0b5; font-weight: 600; }

/* ---------- כניסה ---------- */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 30px 22px calc(30px + var(--safe-b)); }
.logo { width: 84px; height: 84px; border-radius: 26px; background: linear-gradient(145deg, var(--brand-2), var(--brand)); display: grid;
  place-items: center; font-size: 44px; margin: 0 auto 18px; box-shadow: 0 10px 30px rgba(31, 122, 85, .35); }
.login h1 { text-align: center; margin: 0; font-size: 27px; }
.login .lead { text-align: center; color: var(--muted); margin: 6px 0 26px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; height: 42px; border-radius: 11px; font-weight: 500; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.err { color: var(--danger); font-size: 14.5px; min-height: 20px; margin: 2px 4px 10px; }
.setup-box { background: var(--surface); padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow); line-height: 1.6; }
.setup-box code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; direction: ltr; display: inline-block; }

@media (min-width: 700px) {
  main { padding-top: 12px; }
  .item:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
}
