/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f5f6f8;
  --surface:     #ffffff;
  --border:      #e2e6ea;
  --text:        #1a1d23;
  --text-muted:  #6b7280;
  --accent:      #2563eb;
  --accent-dark: #1d4ed8;
  --accent-bg:   #eff6ff;
  --selected-border: #2563eb;
  --selected-bg: #eff6ff;
  --footer-h:    72px;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: var(--footer-h);
}

/* ── Header ───────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.logo-img {
  height: 40px;
  width: auto;
  object-fit: contain;
  border-radius: 0;
}

.logo-img--small {
  height: 30px;
}

.logo-fallback {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.header-text { flex: 1; }

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.header p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Controls Row ─────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

#searchInput:focus { border-color: var(--accent); background: var(--surface); }

.btn-ghost {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ── Category Tabs ────────────────────────────────── */
.tabs-wrap {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-wrap::-webkit-scrollbar { display: none; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 0;
  white-space: nowrap;
}

.tab-btn {
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 20px;
  background: transparent;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Product Grid ─────────────────────────────────── */
.main {
  padding: 20px 24px;
}

.results-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

/* ── Product Card ─────────────────────────────────── */
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  position: relative;
  user-select: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card:hover { border-color: #c7d2dc; box-shadow: var(--shadow); }
.card.selected {
  border-color: var(--selected-border);
  background: var(--selected-bg);
}

.card-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: rgba(255,255,255,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  z-index: 2;
}
.card.selected .card-check {
  background: var(--accent);
  border-color: var(--accent);
}
.card-check svg { display: none; }
.card.selected .card-check svg { display: block; }

/* Product image */
.card-img-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.card:hover .card-img { transform: scale(1.04); }

.card-body {
  padding: 12px 14px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-name {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 8px;
  color: var(--text);
  flex: 1;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Category badge colours */
.badge-dairy     { background: #fef9c3; color: #854d0e; }
.badge-bakery    { background: #fde8d0; color: #9a3412; }
.badge-fruit     { background: #dcfce7; color: #166534; }
.badge-meat      { background: #fee2e2; color: #991b1b; }
.badge-drinks    { background: #dbeafe; color: #1e40af; }
.badge-snacks    { background: #f3e8ff; color: #6b21a8; }
.badge-household { background: #f0fdf4; color: #15803d; }
.badge-beverages { background: #fef3c7; color: #92400e; }

.card-price {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Empty State ──────────────────────────────────── */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty svg { margin-bottom: 12px; opacity: 0.4; }
.empty p { font-size: 0.9375rem; }

/* ── Sticky Footer ────────────────────────────────── */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  z-index: 10;
}

.footer-count {
  font-size: 0.9375rem;
  color: var(--text-muted);
}
.footer-count strong {
  color: var(--text);
  font-size: 1.125rem;
}

.btn-primary {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Summary Screen ───────────────────────────────── */
#summaryView {
  display: none;
  padding: 32px 24px;
  max-width: 860px;
  margin: 0 auto;
}

#summaryView.visible { display: block; }

.summary-logo {
  margin-bottom: 16px;
}

.summary-header {
  margin-bottom: 28px;
}
.summary-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.summary-header p { color: var(--text-muted); font-size: 0.9375rem; }

/* ── Confirmation Screen ──────────────────────────── */
#confirmView {
  display: none;
  min-height: calc(100vh - var(--footer-h));
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

#confirmView.visible {
  display: flex;
}

.confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.confirm-icon {
  width: 64px;
  height: 64px;
  background: #dcfce7;
  color: #16a34a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 auto 20px;
}

.confirm-box h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  color: var(--text);
}

.confirm-box p {
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.5;
  margin-bottom: 8px;
}

.confirm-sub {
  font-size: 0.875rem !important;
}

.confirm-stats {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 8px 18px;
  border-radius: 20px;
  margin: 16px 0 28px;
}

.confirm-stats span {
  font-size: 1.1rem;
  font-weight: 800;
}

.summary-stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  min-width: 140px;
}
.stat-card .stat-num {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.stat-card .stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.summary-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.btn-outline {
  padding: 10px 20px;
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-outline:hover { background: var(--accent-bg); }

.category-breakdown {
  margin-bottom: 28px;
}
.category-breakdown h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

.breakdown-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.breakdown-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8125rem;
}
.breakdown-pill .count {
  font-weight: 700;
  color: var(--accent);
}

/* ── Summary Table ────────────────────────────────── */
.summary-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.summary-table-wrap h3 {
  padding: 14px 16px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

tbody td { padding: 10px 16px; }
tbody td:last-child { text-align: right; font-weight: 600; }

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 600px) {
  .header { padding: 12px 16px; gap: 12px; }
  .logo-img { height: 36px; }
  .controls, .tabs-wrap, .main { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .footer { padding: 0 16px; }
  #summaryView { padding: 20px 16px; }
  .summary-stats { gap: 10px; }
  .stat-card { min-width: 110px; padding: 12px 14px; }
  .confirm-box { padding: 32px 20px; }
}
