* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --green: #16a34a;
  --green-light: #dcfce7;
  --text: #1f2937;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --radius: 14px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Heebo", "Arial Hebrew", sans-serif;
  background: #fff;
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- PIN screen ---------- */
#pin-screen {
  position: fixed; inset: 0; background: #fff; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.pin-box { text-align: center; width: min(320px, 85vw); }
.pin-cart { font-size: 3.5rem; margin-bottom: .5rem; }
.pin-box h1 { font-size: 1.4rem; margin-bottom: 1.5rem; }
.pin-box input {
  width: 100%; padding: 14px; font-size: 1.4rem; text-align: center;
  border: 2px solid var(--border); border-radius: var(--radius); letter-spacing: .4em;
}
.pin-box input:focus { outline: none; border-color: var(--green); }
.pin-box button {
  width: 100%; margin-top: 1rem; padding: 14px; font-size: 1.1rem;
  background: var(--green); color: #fff; border: none; border-radius: var(--radius);
  font-weight: 600; cursor: pointer;
}
#pin-error { color: #dc2626; margin-top: .8rem; }

/* ---------- Header / search ---------- */
header {
  position: sticky; top: 0; z-index: 10; background: #fff;
  padding: max(env(safe-area-inset-top), 10px) 16px 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
h1 { font-size: 1.25rem; }
.count { color: var(--gray); font-size: 1rem; font-weight: 400; }
.gear { text-decoration: none; font-size: 1.3rem; padding: 6px; }

.search-wrap { position: relative; }
#search {
  width: 100%; padding: 13px 16px; font-size: 1.05rem;
  border: 2px solid var(--border); border-radius: var(--radius); background: var(--gray-light);
}
#search:focus { outline: none; border-color: var(--green); background: #fff; }
#clear-search {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  border: none; background: var(--border); color: var(--gray);
  width: 28px; height: 28px; border-radius: 50%; font-size: .9rem; cursor: pointer;
}

/* ---------- Suggestions ---------- */
#suggestions {
  position: absolute; right: 16px; left: 16px; margin-top: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; z-index: 20;
}
.sug-row {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; border-bottom: 1px solid var(--gray-light); cursor: pointer;
}
.sug-row:last-child { border-bottom: none; }
.sug-row:active { background: var(--green-light); }
.sug-main { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.sug-name { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-cat { color: var(--gray); font-size: .8rem; flex-shrink: 0; }
.sug-new { color: var(--green); font-weight: 600; }
.sug-amt-btn {
  border: 1.5px solid var(--border); background: #fff; color: var(--gray);
  border-radius: 10px; padding: 7px 12px; font-size: .85rem; cursor: pointer; flex-shrink: 0;
}

/* ---------- Quick chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-top: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { padding-top: 0; }
.chip {
  flex-shrink: 0; background: var(--gray-light); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px; font-size: .95rem; cursor: pointer; color: var(--text);
}
.chip:active { background: var(--green-light); border-color: var(--green); }

/* ---------- List ---------- */
main { padding: 12px 16px calc(90px + env(safe-area-inset-bottom)); }
.cat-section { margin-bottom: 14px; }
.cat-header {
  display: flex; align-items: center; gap: 6px;
  color: var(--green); font-weight: 700; font-size: .95rem;
  padding: 6px 4px; border-bottom: 2px solid var(--green-light); margin-bottom: 2px;
}
.entry {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 2px; min-height: 52px;
  border-bottom: 1px solid var(--gray-light);
  transition: opacity .25s, transform .25s;
}
.entry.checking { opacity: 0; transform: translateX(-30px); }
.checkbox {
  width: 26px; height: 26px; flex-shrink: 0;
  border: 2.5px solid #cbd5e1; border-radius: 50%; background: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.entry-tap { flex: 1; display: flex; align-items: center; min-width: 0; align-self: stretch; cursor: pointer; }
.entry-name { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-amount {
  color: var(--gray); font-size: .95rem; flex-shrink: 0;
  padding: 8px 10px; border-radius: 10px; cursor: pointer; min-width: 44px; text-align: center;
}
.entry-amount:active { background: var(--gray-light); }
.entry-amount.empty-amt { color: #d1d5db; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--gray); }
.empty-icon { font-size: 3rem; margin-bottom: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); right: 16px; left: 16px;
  background: var(--text); color: #fff; border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; justify-content: space-between;
  z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: toast-in .25s;
}
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }
.toast button {
  border: none; background: none; color: #4ade80; font-weight: 700; font-size: 1rem;
  cursor: pointer; padding: 4px 8px;
}

/* ---------- Bottom sheet ---------- */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; }
.sheet {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 61;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  animation: sheet-in .22s;
}
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet h2 { font-size: 1.2rem; margin-bottom: 14px; }
.sheet-section { margin-bottom: 16px; }
.sheet-section label { display: block; color: var(--gray); font-size: .85rem; margin-bottom: 8px; }
.amount-row { display: flex; gap: 10px; align-items: center; }
.amount-row input {
  flex: 1; text-align: center; font-size: 1.3rem; padding: 10px;
  border: 2px solid var(--border); border-radius: var(--radius); min-width: 0;
}
.amount-row input:focus { outline: none; border-color: var(--green); }
.step {
  width: 48px; height: 48px; font-size: 1.5rem; flex-shrink: 0;
  border: 2px solid var(--border); background: var(--gray-light); border-radius: var(--radius); cursor: pointer;
}
.unit-chips, .cat-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.cat-chips { max-height: 130px; overflow-y: auto; }
.unit-chip, .cat-chip {
  border: 1.5px solid var(--border); background: #fff; border-radius: 999px;
  padding: 8px 14px; font-size: .95rem; cursor: pointer;
}
.unit-chip.active, .cat-chip.active {
  background: var(--green-light); border-color: var(--green); color: var(--green); font-weight: 600;
}
button.primary {
  width: 100%; padding: 15px; font-size: 1.1rem; font-weight: 600;
  background: var(--green); color: #fff; border: none; border-radius: var(--radius); cursor: pointer;
}

/* ---------- Categories page ---------- */
.cat-list { padding: 12px 16px; }
.cat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 8px; border-bottom: 1px solid var(--gray-light);
}
.cat-item .name { flex: 1; font-size: 1.05rem; }
.cat-item button {
  border: 1px solid var(--border); background: var(--gray-light); border-radius: 10px;
  width: 40px; height: 40px; font-size: 1rem; cursor: pointer;
}
.cat-item button:disabled { opacity: .3; }
.add-cat-row { display: flex; gap: 8px; padding: 16px; }
.add-cat-row input {
  flex: 1; padding: 12px; font-size: 1rem; border: 2px solid var(--border); border-radius: var(--radius);
}
.add-cat-row button {
  padding: 12px 20px; background: var(--green); color: #fff; border: none;
  border-radius: var(--radius); font-weight: 600; cursor: pointer;
}
.back-link { text-decoration: none; font-size: 1.3rem; padding: 6px; }
