:root {
  --bg: #1B211D;
  --panel: #232B24;
  --panel-raised: #2A332B;
  --line: #3A443C;
  --text: #F2EEE4;
  --text-muted: #9AA69C;
  --fruit: #C4443A;
  --veg: #D9A441;
  --salad: #4F7942;
  --radius: 10px;
  --font-display: 'Oswald', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

select {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
select option {
  background: var(--panel-raised);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--veg);
  outline-offset: 2px;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 12px 14px 0;
}
/* bar itself stays full-bleed (border/background look right edge to edge on
   wide screens); the controls inside line up with the 640px content column
   below instead of stretching across the whole desktop window */
#finderHeader, #scanListHeader {
  max-width: 640px;
  margin: 0 auto;
}

.data-badge {
  font-size: 10px;
  color: var(--text-muted);
  cursor: default;
}
.data-badge.published { color: var(--veg); }
.data-badge.local { color: #6BA3D6; }
.data-badge.default { color: var(--fruit); }

.icon-btn {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn.active { border-color: var(--veg); color: var(--veg); }

.fav-toggle {
  width: auto;
  min-width: 38px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 15px;
}
.fav-count { font-size: 11px; }

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

#searchInput {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 16px;
}
#searchInput::placeholder { color: var(--text-muted); }

.filter-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.filter-btn[aria-expanded="true"] { border-color: var(--veg); color: var(--veg); }

.aisle-tabs-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
}

.aisle-tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

.badge-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--veg);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border-radius: 999px;
  padding: 3px 5px;
  min-width: 16px;
  text-align: center;
}

.aisle-tab {
  flex: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.aisle-tab.active { background: var(--panel-raised); color: var(--text); border-color: var(--text-muted); }
.aisle-tab.active[data-color="Salad"] { border-color: var(--salad); color: var(--salad); }
.aisle-tab.active[data-color="Veg"] { border-color: var(--veg); color: var(--veg); }
.aisle-tab.active[data-color="Fruit"] { border-color: var(--fruit); color: var(--fruit); }

.store-label {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding-bottom: 8px;
}

.store-select {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 12px;
}

.filter-panel {
  background: var(--panel);
  border-top: 1px dashed var(--line);
  padding: 12px 2px 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.filter-group { display: flex; align-items: center; gap: 8px; }

/* ---------- Content ---------- */

main { padding: 14px; max-width: 640px; margin: 0 auto; }

.category-heading {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 10px 2px 2px;
}
.category-heading:first-child { padding-top: 0; }

.empty-state { color: var(--text-muted); text-align: center; padding: 40px 0; }

/* ---------- Product cards ---------- */

.product-list { display: flex; flex-direction: column; gap: 8px; }

.product-card {
  position: relative;
  display: grid;
  grid-template-columns: 58px 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: pointer;
  min-height: 108px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.product-card::before {
  content: '';
  position: absolute;
  left: 0; top: 10px; bottom: 10px;
  width: 4px;
  border-radius: 2px;
  background: var(--veg);
}
.product-card[data-color="Fruit"]::before { background: var(--fruit); }
.product-card[data-color="Salad"]::before { background: var(--salad); }

.card-img {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-raised);
}
.card-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-muted);
}

.card-body { min-width: 0; }
.card-name {
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.aisle-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--panel-raised);
  color: var(--veg);
}
.product-card[data-color="Fruit"] .aisle-badge { color: var(--fruit); }
.product-card[data-color="Salad"] .aisle-badge { color: var(--salad); }
.card-category { font-size: 12px; color: var(--text-muted); }
.card-sku {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: inline-block;
  cursor: pointer;
  border-bottom: 1px dotted var(--text-muted);
}
.card-sku:active { color: var(--veg); border-color: var(--veg); }

.card-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.add-btn {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-raised);
  color: var(--veg);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-btn.in-list { background: var(--veg); color: var(--bg); border-color: var(--veg); }

.card-qr {
  width: 92px;
  height: 92px;
  background: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  transition: opacity 0.15s ease, filter 0.15s ease;
}
.card-qr img, .card-qr canvas { width: 100%; height: 100%; }
.card-needs-sku {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  width: 92px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 4px;
  line-height: 1.2;
  transition: opacity 0.15s ease, filter 0.15s ease;
}

/* Scan lock: hold a card's QR to dim/blur every other card's QR so a
   handheld scanner can't pick up the wrong one by accident. Tap
   anywhere to release. */
#productList.qr-locked .product-card:not(.scan-lock-target) .card-qr,
#productList.qr-locked .product-card:not(.scan-lock-target) .card-needs-sku {
  opacity: 0.15;
  filter: blur(4px);
}
.product-card.scan-lock-target .card-qr {
  box-shadow: 0 0 0 2px var(--veg);
}

/* ---------- Scan list ---------- */

.scanlist-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 10px;
}
.scanlist-progress { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }
.scanlist-progress b { color: var(--veg); }
.sort-select { padding: 5px 7px; font-size: 12px; }

#scanItems .product-card { cursor: pointer; }
#scanItems .product-card.is-active { border-color: var(--veg); box-shadow: 0 0 0 1px var(--veg); }
#scanItems .product-card:not(.is-active) .card-qr,
#scanItems .product-card:not(.is-active) .card-needs-sku {
  opacity: 0.15;
  filter: blur(4px);
}
.active-tag {
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--veg);
  margin-bottom: 2px;
}
#scanItems .product-card:not(.is-active) .active-tag { visibility: hidden; }

.scan-item-qty { display: flex; align-items: center; gap: 5px; margin-top: 6px; }
.scan-item-qty input {
  width: 52px;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px;
  font-size: 12.5px;
  color: var(--text);
  text-align: center;
  font-family: var(--font-mono);
}
.scan-item-qty select { padding: 5px 4px; font-size: 11px; }

.scan-item-del {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 3px;
}

.confirm-inline {
  grid-column: 1 / -1;
  background: var(--bg);
  border: 1px dashed var(--fruit);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.confirm-inline button { font-size: 11px; padding: 6px 10px; border-radius: 6px; cursor: pointer; }

.fab-clear {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: 14px 14px 16px;
}
.fab-clear button { width: 100%; max-width: 640px; margin: 0 auto; display: block; }

.scanlist-empty-hint { color: var(--text-muted); text-align: center; padding: 40px 20px; font-size: 14px; }

.toggle-switch {
  position: relative;
  width: 38px;
  height: 22px;
  background: var(--panel-raised);
  border-radius: 999px;
  border: 1px solid var(--line);
  cursor: pointer;
  flex: none;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--text-muted);
  transition: transform 0.15s ease, background 0.15s ease;
}
.toggle-switch.on { background: rgba(217, 164, 65, 0.25); border-color: var(--veg); }
.toggle-switch.on::after { transform: translateX(16px); background: var(--veg); }

.admin-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  margin-top: 6px;
  font-size: 13px;
}

.star-btn {
  background: none;
  border: none;
  font-size: 15px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px 0 0;
}
.star-btn.active { color: var(--veg); }

.hide-btn {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}
.hide-btn.active { border-color: var(--fruit); color: var(--fruit); }

.product-card.card-hidden { opacity: 0.5; }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px 28px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  max-height: 90vh;
  overflow-y: auto;
}
@media (min-width: 520px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 16px; }
}

.modal-img {
  width: 96px;
  height: 96px;
  border-radius: 12px;
  object-fit: cover;
  margin: 0 auto 12px;
  display: block;
  background: var(--panel-raised);
}
.modal-eyebrow {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--veg);
  margin: 0 0 4px;
}
.modal-card h2 { margin: 0 0 4px; font-size: 20px; }
.modal-sub { color: var(--text-muted); margin: 0 0 18px; font-size: 14px; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.btn-primary {
  background: var(--veg);
  color: #1B211D;
  border: none;
  border-radius: 10px;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  cursor: pointer;
}
.btn-danger {
  background: transparent;
  border: 1px solid var(--fruit);
  color: var(--fruit);
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.qty-row { display: flex; gap: 8px; margin-bottom: 18px; }
.qty-row input {
  flex: 1;
  min-width: 0;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  color: var(--text);
  text-align: center;
  font-family: var(--font-mono);
}
.qty-row select {
  flex: 1;
  min-width: 0;
  padding: 12px 8px;
  font-size: 14px;
}
.prefill-note { font-size: 12px; color: var(--veg); margin: -12px 0 16px; }

.qr-large {
  width: 220px;
  height: 220px;
  background: #fff;
  border-radius: 12px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.qr-large img, .qr-large canvas { width: 100%; height: 100%; }

/* ---------- Admin ---------- */

.admin-card { text-align: left; }
.admin-card h2 { text-align: center; }
.admin-card .modal-sub { text-align: center; }
.field-label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.admin-card select, .admin-card input {
  width: 100%;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
}

.admin-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--veg);
  color: var(--bg);
  padding: 10px 14px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  z-index: 30;
}
.admin-bar-row { margin-top: 6px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.admin-store-row { flex-wrap: nowrap; max-width: 420px; margin-left: auto; margin-right: auto; }
.admin-store-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--bg);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
}
.admin-store-input::placeholder { color: var(--text-muted); }
.admin-store-input-narrow { flex: 0 0 70px; }
.admin-file-btn {
  display: inline-block;
  background: var(--bg);
  color: var(--veg);
  border-radius: 6px;
  padding: 7px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
  text-decoration: none;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--veg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
}
.toast button {
  background: var(--bg);
  color: var(--veg);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  flex: none;
}
.toast button.toast-dismiss {
  background: transparent;
  color: var(--bg);
  opacity: 0.7;
  padding: 4px 6px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
