/* Shopping — smart grocery list with auto-categorization
 * Palette: mustard + warm-cream
 * © אופיר ברנס (Ofir Baranes) 2026
 */

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

:root {
  --bg-1: #1c1810;
  --bg-2: #251f15;
  --bg-3: #2e271a;
  --mustard-300: #fde047;
  --mustard-400: #facc15;
  --mustard-500: #eab308;
  --mustard-600: #ca8a04;
  --mustard-700: #a16207;
  --mustard-800: #854d0e;
  --cream: #fef9c3;
  --cream-soft: #fef3c7;
  --cream-light: #fffbeb;
  --text-primary: #fef9c3;
  --text-secondary: rgba(254,249,195,0.72);
  --text-muted: rgba(254,249,195,0.42);
  --surface: rgba(254,243,199,0.05);
  --surface-strong: rgba(254,243,199,0.10);
  --border: rgba(253,224,71,0.16);
  --border-strong: rgba(253,224,71,0.28);
  --shadow-glass: 0 30px 60px -25px rgba(28,24,16,0.7);
  --bezier: cubic-bezier(.34,1.56,.64,1);
  --bezier-soft: cubic-bezier(.4,0,.2,1);
}

html, body {
  background: var(--bg-1);
  color: var(--text-primary);
  font-family: 'Heebo', system-ui, sans-serif;
  font-weight: 400;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 700px 800px at 80% -10%, rgba(234,179,8,0.18), transparent 60%),
    radial-gradient(ellipse 500px 600px at -10% 60%, rgba(202,138,4,0.16), transparent 65%),
    radial-gradient(ellipse 800px 1000px at 50% 110%, rgba(133,77,14,0.20), transparent 70%),
    linear-gradient(180deg, #1c1810 0%, #251f15 60%, #2e271a 110%);
  background-attachment: fixed;
  position: relative;
  padding-bottom: 60px;
}

.ambient-bg {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.orb-blur {
  position: absolute;
  border-radius: 50%;
  filter: blur(85px);
  opacity: 0.45;
}
.orb-blur.o1 { width: 420px; height: 420px; top: -120px; right: -120px; background: radial-gradient(circle, #facc15 0%, transparent 70%); animation: drift1 26s ease-in-out infinite; }
.orb-blur.o2 { width: 340px; height: 340px; bottom: 5%; left: -100px; background: radial-gradient(circle, #ca8a04 0%, transparent 70%); opacity: 0.35; animation: drift2 32s ease-in-out infinite; }
.orb-blur.o3 { width: 260px; height: 260px; top: 40%; right: 30%; background: radial-gradient(circle, #fde047 0%, transparent 70%); opacity: 0.22; animation: drift3 38s ease-in-out infinite; }
@keyframes drift1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-30px,40px) scale(1.1); } }
@keyframes drift2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(40px,-30px) scale(1.08); } }
@keyframes drift3 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-25px,-35px) scale(1.12); } }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(28,24,16,0.85) 0%, rgba(28,24,16,0.55) 100%);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--cream-light);
  letter-spacing: -0.01em;
}
.mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--mustard-400), var(--mustard-700));
  color: var(--bg-1);
  box-shadow: 0 0 18px rgba(234,179,8,0.4);
}
.mark svg { width: 18px; height: 18px; }

.header-actions { display: flex; gap: 8px; }
.icon-btn, .install-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  border-radius: 12px;
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.2s var(--bezier-soft);
  backdrop-filter: blur(10px);
}
.icon-btn { padding: 7px 9px; font-size: 16px; }
.icon-btn:hover, .install-btn:hover {
  background: var(--surface-strong);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.install-btn {
  background: linear-gradient(135deg, var(--mustard-400), var(--mustard-600));
  border: none;
  color: var(--bg-1);
  font-weight: 700;
}

main {
  position: relative;
  z-index: 1;
  padding: 20px 18px;
  max-width: 720px;
  margin: 0 auto;
}
.hidden { display: none !important; }

/* ===== Hero ===== */
.hero {
  margin-bottom: 22px;
}
.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
  gap: 16px;
  flex-wrap: wrap;
}
.hero-left { flex: 1; min-width: 0; }
.kicker {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--mustard-300);
  margin-bottom: 6px;
}
.hero-title {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: clamp(32px, 7vw, 48px);
  font-weight: 700;
  line-height: 1;
  color: var(--cream-light);
  letter-spacing: -0.025em;
  margin-bottom: 8px;
}
.list-switch-btn {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--mustard-300);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}
.list-switch-btn:hover {
  background: var(--surface);
  color: var(--cream-light);
}

.hero-stats {
  display: flex;
  gap: 14px;
}
.hs {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}
.hs-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 26px;
  font-weight: 600;
  color: var(--cream-light);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.hs-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.05em;
}

.progress-bar {
  height: 4px;
  background: rgba(254,243,199,0.05);
  border-radius: 100px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--mustard-400), var(--mustard-600));
  border-radius: 100px;
  width: 0;
  transition: width 0.6s var(--bezier);
}

/* ===== Add section ===== */
.add-section {
  position: relative;
  margin-bottom: 22px;
}
.add-row {
  display: flex;
  gap: 8px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 6px 6px 6px 14px;
  transition: all 0.2s var(--bezier-soft);
}
.add-row:focus-within {
  border-color: var(--mustard-400);
  background: var(--surface-strong);
  box-shadow: 0 0 0 4px rgba(234,179,8,0.10);
}
.add-input {
  flex: 1;
  padding: 12px 4px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cream-light);
  font-family: inherit;
  font-size: 16px;
  text-align: right;
  direction: rtl;
}
.add-input::placeholder { color: var(--text-muted); }
.add-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--mustard-400), var(--mustard-700));
  border: none;
  border-radius: 12px;
  color: var(--bg-1);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.25s var(--bezier);
  box-shadow: 0 6px 16px rgba(234,179,8,0.35);
  flex-shrink: 0;
}
.add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(234,179,8,0.5);
}
.add-btn:active { transform: scale(0.96); }
.add-btn svg { width: 22px; height: 22px; }

/* Auto-suggest */
.suggest-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  z-index: 30;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.suggest-item {
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--cream-light);
  transition: background 0.15s;
}
.suggest-item:hover, .suggest-item.active {
  background: rgba(234,179,8,0.15);
}
.suggest-cat {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ===== Categories ===== */
.cats {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cat-block {
  background: var(--surface);
  backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 16px;
  transition: all 0.2s;
}
.cat-block.collapsed .cat-items { display: none; }
.cat-block.collapsed .cat-toggle { transform: rotate(-90deg); }

.cat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  cursor: pointer;
}
.cat-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--cat-color) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--cat-color) 30%, transparent);
  flex-shrink: 0;
}
.cat-icon-wrap svg { width: 22px; height: 22px; color: var(--cat-color); }
.cat-name {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--cream-light);
  flex: 1;
  letter-spacing: -0.01em;
}
.cat-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.cat-toggle {
  color: var(--text-muted);
  transition: transform 0.2s var(--bezier);
}
.cat-toggle svg { width: 16px; height: 16px; }

.cat-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px 11px 8px;
  background: rgba(254,243,199,0.03);
  border: 1px solid rgba(253,224,71,0.08);
  border-radius: 12px;
  transition: all 0.2s var(--bezier-soft);
  cursor: pointer;
}
.item:hover {
  background: rgba(254,243,199,0.07);
  border-color: rgba(253,224,71,0.18);
  transform: translateX(-2px);
}
.item.checked {
  opacity: 0.45;
  background: rgba(254,243,199,0.02);
}
.item.checked .item-name { text-decoration: line-through; }

.item-check {
  width: 24px;
  height: 24px;
  border: 2px solid var(--cat-color, var(--mustard-500));
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s var(--bezier);
  background: transparent;
  padding: 0;
}
.item-check:hover { transform: scale(1.1); }
.item.checked .item-check {
  background: var(--cat-color, var(--mustard-500));
  border-color: var(--cat-color, var(--mustard-500));
}
.item-check svg {
  width: 14px;
  height: 14px;
  color: var(--bg-1);
  opacity: 0;
  transition: opacity 0.2s;
}
.item.checked .item-check svg { opacity: 1; }

.item-body { flex: 1; min-width: 0; }
.item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--cream-light);
  line-height: 1.3;
}
.item-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}
.item-meta .qty { color: var(--mustard-300); font-weight: 600; }
.item-meta .price { color: var(--cream-soft); }

.item-arrow {
  font-size: 16px;
  color: var(--text-muted);
  opacity: 0.5;
  transition: opacity 0.2s;
}
.item:hover .item-arrow { opacity: 1; }

/* ===== Empty state ===== */
.empty {
  text-align: center;
  padding: 50px 20px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: 24px;
}
.empty-illust {
  width: 110px;
  height: 110px;
  margin: 0 auto 16px;
  filter: drop-shadow(0 12px 20px rgba(234,179,8,0.25));
}
.empty-illust svg { width: 100%; height: 100%; }
.empty h3 {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--cream-light);
  margin-bottom: 8px;
}
.empty p {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 360px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ===== Done state ===== */
.done {
  text-align: center;
  padding: 36px 22px;
  background: linear-gradient(140deg, rgba(134,239,172,0.10), rgba(234,179,8,0.08));
  border: 1px solid rgba(134,239,172,0.25);
  border-radius: 24px;
  margin-top: 14px;
}
.done-icon {
  font-size: 42px;
  margin-bottom: 8px;
}
.done h3 {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: 22px;
  color: #86efac;
  margin-bottom: 4px;
}
.done p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.done-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn-primary, .btn-secondary, .btn-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--bezier);
  border: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--mustard-400), var(--mustard-700));
  color: var(--bg-1);
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(234,179,8,0.3);
  flex: 1;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(234,179,8,0.45); }
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--cream-light);
  flex: 1;
}
.btn-secondary:hover { background: var(--surface-strong); }
.btn-mini {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 11px 16px;
  font-size: 13px;
}
.btn-mini:hover { background: var(--surface-strong); color: var(--cream-light); }
.btn-mini.danger { color: #fda4af; border-color: rgba(253,164,175,0.3); }
.btn-mini.danger:hover { background: rgba(253,164,175,0.1); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,12,8,0.7);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: modal-fade 0.25s var(--bezier-soft);
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%;
  max-width: 540px;
  background: linear-gradient(180deg, #2e271a 0%, #1c1810 100%);
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: 28px 28px 0 0;
  padding: 20px 22px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  animation: modal-slide 0.4s var(--bezier);
  max-height: 92vh;
  overflow-y: auto;
}
@keyframes modal-slide {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.handle {
  width: 38px; height: 4px;
  background: var(--border-strong);
  border-radius: 4px;
  margin: 0 auto 16px;
}
.modal-card h3 {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  color: var(--cream-light);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 14px;
}
.modal-card p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 14px;
}
.mark-big {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--mustard-400), var(--mustard-700));
  border-radius: 18px;
  color: var(--bg-1);
  margin: 4px auto 14px;
  box-shadow: 0 0 30px rgba(234,179,8,0.4);
}
.mark-big svg { width: 32px; height: 32px; }

.modal-input {
  width: 100%;
  padding: 13px 14px;
  background: rgba(254,243,199,0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--cream-light);
  font-family: 'Heebo', sans-serif;
  font-size: 15px;
  margin-bottom: 12px;
  transition: all 0.2s;
  text-align: right;
  direction: rtl;
}
.modal-input.mono { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; direction: ltr; text-align: left; }
.modal-input:focus {
  outline: none;
  border-color: var(--mustard-400);
  background: rgba(254,243,199,0.10);
}
.modal-input::placeholder { color: var(--text-muted); }

.form-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--mustard-300);
  margin-bottom: 8px;
}
.form-row { margin-bottom: 12px; }
.form-row.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-col { display: flex; flex-direction: column; }
.form-col .modal-input { margin-bottom: 0; }

.cat-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
@media (max-width: 480px) { .cat-picker { grid-template-columns: repeat(3, 1fr); } }
.cat-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--bezier-soft);
}
.cat-pick:hover { background: var(--surface-strong); }
.cat-pick.active {
  background: color-mix(in srgb, var(--cp-color) 22%, transparent);
  border-color: var(--cp-color);
  color: var(--cream-light);
  font-weight: 600;
}
.cat-pick svg { width: 18px; height: 18px; color: var(--cp-color); }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

/* Lists modal */
.lm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.lm-header h3 { margin-bottom: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(254,243,199,0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.list-row:hover { background: rgba(234,179,8,0.10); border-color: rgba(234,179,8,0.3); }
.list-row.active { background: rgba(234,179,8,0.14); border-color: var(--mustard-400); }
.lr-name { flex: 1; color: var(--cream-light); font-size: 14px; font-weight: 500; }
.lr-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.lr-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
}
.lr-del:hover { color: #fda4af; background: rgba(253,164,175,0.08); }

/* History modal */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: rgba(254,243,199,0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
}
.search-svg { width: 16px; height: 16px; color: var(--mustard-400); flex-shrink: 0; }
.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cream-light);
  font-family: inherit;
  font-size: 14px;
  direction: rtl;
}
.search-bar input::placeholder { color: var(--text-muted); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50vh;
  overflow-y: auto;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(254,243,199,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}
.history-row:hover { background: rgba(234,179,8,0.10); }
.h-name { flex: 1; font-size: 13px; color: var(--cream-light); }
.h-cat {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}
.h-add {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--mustard-500);
  color: var(--bg-1);
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.h-add svg { width: 14px; height: 14px; }
