:root {
  --bg: #0f1410;
  --surface: #1a221c;
  --surface2: #243028;
  --text: #f2f5f0;
  --muted: #9aab9c;
  --accent: #1b8a4a;
  --accent-hover: #22a558;
  --danger: #c44536;
  --border: #2f3d33;
  --check: #2ecf6e;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(88px + var(--safe-bottom)); }

.hidden { display: none !important; }

#pin-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pin-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 22px;
  text-align: center;
}
.pin-card h1 { margin: 0 0 8px; font-size: 1.35rem; }
.pin-card p { margin: 0 0 20px; color: var(--muted); font-size: 0.95rem; }
.pin-card input {
  width: 100%;
  font-size: 16px;
  letter-spacing: 0.35em;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}
.pin-card .error { color: #ff8a7a; font-size: 0.9rem; min-height: 1.2em; margin-bottom: 8px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 20, 16, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px 10px;
}
.app-header h1 {
  margin: 0 0 10px;
  font-size: 1.15rem;
  font-weight: 700;
}
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}
.toolbar {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-ghost { background: transparent; }

.meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 8px 14px 0;
}

#list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0 10px 20px;
}
.section-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px 7px;
  margin: 0;
  background: linear-gradient(to bottom, var(--bg) 72%, rgba(15, 20, 16, 0.92));
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.section-title {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.item {
  display: grid;
  grid-template-columns: auto 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}
.item.checked { border-color: #2a6b44; background: #17241c; }
.item label.check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}
.item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--check);
}
.item .info { min-width: 0; }
.item .thumb {
  width: 52px;
  height: 52px;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
}
.item .thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.item .thumb-placeholder,
.item .thumb.placeholder::before {
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1.1;
  text-align: center;
}
.item .thumb.placeholder::before { content: "No image"; }
.item .thumb.placeholder .thumb-placeholder { display: none; }
.item .name {
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.25;
  word-break: break-word;
}
.item .sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 3px;
}
.qty {
  display: flex;
  align-items: center;
}
.qty select {
  min-width: 56px;
  height: 36px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  /* iOS Safari zooms focused controls under 16px */
  font-size: 16px;
  font-weight: 700;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

.footer-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  background: rgba(15, 20, 16, 0.96);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
}
.footer-bar .sel-count {
  flex: 1;
  color: var(--muted);
  font-size: 0.9rem;
}
.footer-bar .btn-primary {
  flex: 1.2;
  padding: 14px;
  font-size: 1rem;
  border-radius: 14px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  background: #123822;
  border: 1px solid #2ecf6e;
  color: #e8ffe8;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
#toast.error {
  background: #3a1814;
  border-color: var(--danger);
  color: #ffe8e4;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}
.overlay .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.overlay .card h2 { margin: 0 0 8px; }
.overlay .card p { color: var(--muted); margin: 0 0 16px; }

.image-card {
  max-width: 620px !important;
}
.image-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.image-card-header h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  text-align: left;
  overflow-wrap: anywhere;
}
.image-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-image {
  display: block;
  width: 100%;
  max-height: 65vh;
  object-fit: contain;
  border-radius: 10px;
  background: var(--bg);
  margin-bottom: 16px;
}
.lightbox-placeholder {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
}

.confirm-actions {
  display: flex;
  gap: 10px;
}
.confirm-actions .btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
}

/* Review is a full-page second step; its rows keep the item treatment without controls. */
.review-header h1 { margin-bottom: 0; }
.review-header .meta { margin-left: 0; margin-right: 0; }
#review-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0 10px 20px;
}
.review-item {
  grid-template-columns: 52px minmax(0, 1fr) auto;
}
.review-item .review-thumb {
  cursor: default;
}
.review-item .sub:empty {
  display: none;
}
.qty-badge {
  min-width: 42px;
  padding: 8px 9px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  text-align: center;
}
.review-footer #review-back,
.review-footer #submit {
  flex: 1;
  padding: 14px;
  font-size: 1rem;
  border-radius: 14px;
}

/* Store catalog toggle (Woolies Dash / Loads of Water) */
.store-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 10px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.store-tab {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
}
.store-tab.active {
  background: var(--accent);
  color: #fff;
}
.store-tab:not(.active):hover {
  color: var(--text);
  background: var(--surface2);
}

.qty .qty-input {
  width: 72px;
  height: 36px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  touch-action: manipulation;
  -moz-appearance: textfield;
}
.qty .qty-input::-webkit-outer-spin-button,
.qty .qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
