/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f5f6f8;
  color: #1a1a2e;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
header {
  background: #fff;
  border-bottom: 1px solid #e2e4e9;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-bar {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  cursor: pointer;
}
.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #16a34a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}
.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a1a2e;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.freshness-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  margin-left: 0.75rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: #4b5563;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  white-space: nowrap;
  cursor: default;
}
.freshness-badge[hidden] { display: none; }
.freshness-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #16a34a;
}
.freshness-badge.is-stale { color: #92400e; background: #fef3c7; border-color: #fde68a; }
.freshness-badge.is-stale .freshness-dot { background: #d97706; }
.freshness-badge.is-old { color: #991b1b; background: #fee2e2; border-color: #fecaca; }
.freshness-badge.is-old .freshness-dot { background: #dc2626; }
.nav-divider {
  width: 1px;
  height: 20px;
  background: #e2e4e9;
  margin: 0 0.5rem;
}
.nav-pill {
  background: none;
  border: 1px solid transparent;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  border-radius: 999px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.nav-pill:hover { color: #16a34a; background: #f0fdf4; }
.nav-pill.active { color: #16a34a; background: #f0fdf4; border-color: #bbf7d0; }
.cart-count {
  background: #16a34a;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

/* ===== MAIN ===== */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
  width: 100%;
}
.view { display: none; }
.view.active { display: block; }

/* ===== STATS ROW ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem;
  border: 1px solid #e2e4e9;
}
.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: #16a34a;
}
.stat-card .stat-label {
  font-size: 0.85rem;
  color: #6b7280;
  margin-top: 0.25rem;
}

/* ===== SECTION CARDS ===== */
.section-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  border: 1px solid #e2e4e9;
  margin-bottom: 1.5rem;
}
.section-card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: #1a1a2e;
}

/* ===== CATEGORY GRID ===== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.category-card {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}
.category-card:hover { border-color: #16a34a; background: #dcfce7; }
.category-card .cat-name { font-weight: 600; font-size: 1rem; }
.category-card .cat-count { font-size: 0.8rem; color: #6b7280; margin-top: 0.25rem; }

/* ===== STORE LIST ===== */
.store-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}
.store-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid #e2e4e9;
  border-radius: 8px;
}
.store-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #16a34a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.store-info .store-name { font-weight: 600; }
.store-info .store-location { font-size: 0.8rem; color: #6b7280; }

/* ===== BROWSE VIEW ===== */
.browse-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.browse-header h2 { font-size: 1.25rem; }
.browse-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.browse-controls select,
.browse-controls input {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
}
.browse-controls input { min-width: 200px; }

.product-table-wrap { overflow-x: auto; }
.product-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e2e4e9;
}
.product-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 1px solid #e2e4e9;
}
.product-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.9rem;
}
.product-table tr:last-child td { border-bottom: none; }
.product-table tr:hover { background: #f9fafb; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-red { background: #fee2e2; color: #b91c1c; }

.btn-sm {
  padding: 0.35rem 0.75rem;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #374151;
  transition: all 0.15s;
}
.btn-sm:hover { background: #f3f4f6; border-color: #16a34a; color: #16a34a; }

.sale-tag {
  display: inline-block;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.35rem;
  text-transform: uppercase;
}

/* ===== COMPARE VIEW ===== */
.compare-header { margin-bottom: 0.5rem; }
.compare-header h2 { font-size: 1.25rem; }
.compare-subtitle { font-size: 0.9rem; color: #6b7280; margin-top: 0.25rem; }
.compare-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.compare-controls input[type="search"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  min-width: 0;
}
.compare-controls select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  min-width: 180px;
  flex-shrink: 0;
}

.compare-card {
  background: #fff;
  border: 1px solid #e2e4e9;
  border-radius: 10px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.compare-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: #f9fafb;
  border-bottom: 1px solid #e2e4e9;
}
.compare-card-header h3 { font-size: 1rem; font-weight: 600; }
.compare-card-header .unit-label { font-size: 0.8rem; color: #6b7280; }
.compare-prices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0;
}
.compare-price-cell {
  padding: 1rem 1.25rem;
  border-right: 1px solid #f3f4f6;
  border-bottom: 1px solid #f3f4f6;
  position: relative;
  transition: background 0.15s;
}
.compare-price-cell:last-child { border-right: none; }
.compare-price-cell.cheapest { background: #f0fdf4; }

/* Hover effect for addable cells */
.compare-price-cell.addable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.compare-price-cell.addable .cell-hover-overlay {
  position: absolute;
  inset: 0;
  background: rgba(240, 253, 244, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  border-radius: 0;
  z-index: 2;
}
.compare-price-cell.addable:not(.has-counter):hover .cell-hover-overlay {
  opacity: 1;
}
.compare-price-cell.addable:not(.has-counter):hover {
  box-shadow: inset 0 0 0 2px #bbf7d0;
}
/* After adding: green tint with legible text, no blur */
.compare-price-cell.addable.has-counter {
  background: #f0fdf4;
}
.compare-price-cell.addable.has-counter .cell-hover-overlay {
  opacity: 0;
}
/* Show frosted overlay + counter only on hover when item is in cart */
.compare-price-cell.addable.has-counter:hover .cell-hover-overlay {
  opacity: 1;
}
.compare-price-cell.addable.has-counter .qty-control-wrap {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.compare-price-cell.addable.has-counter:hover .qty-control-wrap {
  opacity: 1;
  pointer-events: auto;
}
.cell-add-label {
  background: #16a34a;
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
}
/* Hide "Add to Cart" label when counter is showing */
.compare-price-cell.addable.has-counter .cell-add-label {
  display: none;
}
.compare-store-name {
  font-size: 0.8rem;
  color: #6b7280;
  margin-bottom: 0.25rem;
  font-weight: 500;
}
.compare-alias-name {
  font-size: 0.7rem;
  color: #9ca3af;
  font-style: italic;
  margin-bottom: 0.35rem;
  line-height: 1.3;
}
.compare-price-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a2e;
}
.compare-price-cell.cheapest .compare-price-value { color: #16a34a; }
.compare-unit-price {
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 0.15rem;
}
.compare-recorded {
  font-size: 0.7rem;
  color: #9ca3af;
  margin-top: 0.35rem;
}
.no-data {
  text-align: center;
  padding: 3rem;
  color: #9ca3af;
  font-size: 0.95rem;
}
.no-data-cell {
  color: #d1d5db;
  font-size: 0.85rem;
  font-style: italic;
}

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open {
  display: flex;
}
.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #6b7280;
  line-height: 1;
}
.modal-close:hover { color: #1a1a2e; }
.modal h3 { font-size: 1.15rem; margin-bottom: 1rem; }

.price-history-list {
  list-style: none;
}
.price-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid #f3f4f6;
}
.price-history-item:last-child { border-bottom: none; }
.price-history-date { font-size: 0.85rem; color: #6b7280; }
.price-history-value { font-weight: 600; }
.price-history-change {
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: 0.5rem;
}
.price-up { color: #dc2626; }
.price-down { color: #16a34a; }

/* ===== HOME / SEARCH VIEW (mobile-first) ===== */

/* Hero with brand gradient — extends edge-to-edge so the green frames the page */
.home-hero {
  /* Pull out of the centered <main> padding so it spans full width */
  margin: -1.5rem -1.5rem 2rem;
  padding: 2.5rem 1.5rem 2.5rem;
  text-align: center;
  background:
    radial-gradient(1000px 380px at 20% 0%, #d1fae5 0%, transparent 60%),
    radial-gradient(800px 320px at 90% 10%, #ccfbf1 0%, transparent 60%),
    linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);
  border-bottom: 1px solid #eceef2;
}
.home-hero-inner {
  max-width: 720px;
  margin: 0 auto;
}
.home-eyebrow {
  display: inline-block;
  background: #ecfdf5;
  color: #047857;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  margin-bottom: 0.85rem;
}
.home-title {
  font-size: clamp(1.65rem, 5vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 800;
  color: #0f172a;
}
.home-title-accent {
  background: linear-gradient(135deg, #16a34a, #0d9488);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.home-subtitle {
  font-size: 1rem;
  color: #475569;
  margin: 0.6rem auto 0;
  max-width: 460px;
}

/* Search box — lives inside the hero, large and elevated */
.home-search-wrap {
  max-width: 600px;
  margin: 1.75rem auto 0;
}
.home-search-box {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 0.4rem 0.5rem 0.4rem 1rem;
  gap: 0.65rem;
  box-shadow: 0 12px 30px -12px rgba(15, 23, 42, 0.18);
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: text;
}
.home-search-box:focus-within {
  border-color: #16a34a;
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.14), 0 12px 30px -12px rgba(15, 23, 42, 0.18);
}
.search-icon {
  width: 22px;
  height: 22px;
  color: #94a3b8;
  flex-shrink: 0;
}
.home-search-box input {
  border: none;
  outline: none;
  font-size: 1rem; /* 16px prevents iOS zoom on focus */
  width: 100%;
  background: transparent;
  color: #0f172a;
  padding: 0.85rem 0;
  min-height: 44px; /* tap target */
}
.home-search-box input::placeholder { color: #94a3b8; }
.search-clear {
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.search-clear:hover { background: #e2e8f0; color: #0f172a; }

/* Empty state container */
.home-empty-state { padding: 0.5rem 0 1rem; }

/* Stats strip */
.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  max-width: 640px;
  margin: 0 auto 2rem;
}
.home-stat {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.85rem 0.5rem;
  text-align: center;
}
.home-stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: #16a34a;
  line-height: 1.1;
}
.home-stat-label {
  font-size: 0.72rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}

/* Best deals section */
.deals-section { margin-bottom: 2.25rem; }
.deals-header {
  margin-bottom: 0.85rem;
}
.deals-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}
.deals-sub {
  display: block;
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 0.2rem;
}
.deals-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}
.deal-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.75rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  width: 100%;
  font: inherit;
}
.deal-card:hover,
.deal-card:focus-visible {
  border-color: #bbf7d0;
  box-shadow: 0 8px 20px -10px rgba(15, 23, 42, 0.18);
  transform: translateY(-1px);
  outline: none;
}
.deal-card-main {
  min-width: 0;
}
.deal-card-name {
  font-weight: 600;
  color: #0f172a;
  font-size: 0.95rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.deal-card-meta {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 0.25rem;
}
.deal-card-meta strong { color: #0f172a; font-weight: 600; }
.deal-card-savings {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}
.deal-savings-amt {
  background: #16a34a;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}
.deal-savings-pct {
  font-size: 0.72rem;
  color: #16a34a;
  font-weight: 600;
}

/* Suggestion chips section */
.suggestions-section {}
.suggestions-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 0.85rem;
}
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.suggestion-chip {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 40px;
}
.suggestion-chip:hover,
.suggestion-chip:focus-visible {
  border-color: #16a34a;
  color: #16a34a;
  background: #f0fdf4;
  outline: none;
}

/* Search results */
.search-results-info {
  max-width: 640px;
  margin: 0 auto 0.75rem;
  font-size: 0.85rem;
  color: #6b7280;
}
.search-result-list {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.search-result-card {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e2e4e9;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  gap: 0.85rem;
  transition: border-color 0.15s;
}
.search-result-card:hover { border-color: #d1d5db; }
.search-result-card.best-price { border-color: #bbf7d0; background: #fafffe; }
.result-rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f3f4f6;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.search-result-card.best-price .result-rank { background: #16a34a; color: #fff; }
.result-body { flex: 1; min-width: 0; }
.result-store-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.store-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}
.best-price-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  background: #16a34a;
  color: #fff;
}
.price-diff {
  font-size: 0.8rem;
  color: #6b7280;
}
.result-unit-info {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-top: 0.15rem;
}
.result-price-col {
  text-align: right;
  flex-shrink: 0;
}
.result-total-price {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a2e;
}
.result-unit-price {
  font-size: 0.8rem;
  color: #6b7280;
}
.qty-control-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.inline-qty {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
  width: 88px;
  height: 32px;
}
.inline-qty-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  transition: all 0.15s;
  flex-shrink: 0;
}
.inline-qty-btn:hover { background: #f0fdf4; color: #16a34a; }
.inline-qty-val {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #1a1a2e;
  user-select: none;
}
.result-product-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.2rem;
}

/* ===== LIST / CART VIEW ===== */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.list-header h2 { font-size: 1.25rem; font-weight: 700; }
.btn-clear-cart {
  background: none;
  border: 1px solid #d1d5db;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-clear-cart:hover { border-color: #dc2626; color: #dc2626; }
.list-empty {
  text-align: center;
  padding: 4rem 1rem;
}
.list-empty-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.list-empty h3 { font-size: 1.15rem; color: #374151; margin-bottom: 0.5rem; }
.list-empty-sub { color: #6b7280; font-size: 0.9rem; margin-bottom: 1.25rem; }
.btn-start-search {
  background: #16a34a;
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-start-search:hover { background: #15803d; }

.cart-item {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e2e4e9;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  gap: 0.85rem;
}
.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; font-size: 0.95rem; }
.cart-item-store { font-size: 0.8rem; color: #6b7280; }
.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.cart-item-qty button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #d1d5db;
  background: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  transition: all 0.15s;
}
.cart-item-qty button:hover { border-color: #16a34a; color: #16a34a; }
.cart-item-qty span { font-weight: 600; min-width: 20px; text-align: center; }
.cart-item-price { font-weight: 700; font-size: 1rem; min-width: 60px; text-align: right; }
.cart-item-remove {
  border: none;
  background: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: #9ca3af;
  padding: 0.25rem;
  transition: color 0.15s;
}
.cart-item-remove:hover { color: #dc2626; }

.cart-store-group {
  margin-bottom: 1.25rem;
}
.cart-store-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e2e4e9;
}
.cart-store-header .store-badge {
  font-size: 0.8rem;
  padding: 0.15rem 0.6rem;
}
.cart-store-meta {
  font-size: 0.8rem;
  color: #6b7280;
}

.cart-summary {
  background: #fff;
  border: 1px solid #e2e4e9;
  border-radius: 10px;
  padding: 1.25rem;
  margin-top: 1rem;
}
.cart-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  font-size: 0.9rem;
  color: #6b7280;
}
.cart-summary-row.total {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a2e;
  border-top: 1px solid #e2e4e9;
  padding-top: 0.75rem;
  margin-top: 0.35rem;
}
.cart-store-breakdown {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e2e4e9;
}
.cart-store-breakdown h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 0.5rem;
}

/* ===== FOOTER ===== */
.site-footer {
  background: #0f172a;
  color: #cbd5e1;
  padding: 1.5rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  margin-top: auto;
}
.site-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.site-footer-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}
.site-footer-copy { font-size: 0.82rem; }

/* ===== LOADING ===== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #e2e4e9;
  border-top-color: #16a34a;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td {
  text-align: center;
  padding: 2rem;
  color: #9ca3af;
}

/* ===== RESPONSIVE ===== */

/* Tablet & small desktop */
@media (max-width: 768px) {
  main { padding: 1rem; }
  .home-hero { margin: -1rem -1rem 1.5rem; padding: 2rem 1rem; }
  .compare-controls { flex-direction: column; }
  .compare-controls select { min-width: 0; width: 100%; }
  .compare-prices { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .browse-header { flex-direction: column; align-items: stretch; }
  .browse-controls { width: 100%; }
  .browse-controls select,
  .browse-controls input { width: 100%; min-width: 0; }
  .freshness-badge { display: none; }
}

/* Mobile phones */
@media (max-width: 640px) {
  /* Header: horizontal scrollable nav instead of wrapping */
  .header-bar {
    flex-direction: column;
    height: auto;
    padding: 0.5rem 1rem;
    gap: 0.35rem;
  }
  .header-nav {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 0.35rem;
    padding-bottom: 0.25rem;
    /* Hide scrollbar visually */
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .header-nav::-webkit-scrollbar { display: none; }
  .nav-pill {
    flex-shrink: 0;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    /* Apple-recommended min tap target */
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .nav-divider { display: none; }

  /* Search */
  .home-hero { margin: -1rem -1rem 1.5rem; padding: 2rem 1rem 2rem; }
  .home-search-wrap { margin-top: 1.5rem; }
  .home-search-box { padding: 0.35rem 0.4rem 0.35rem 0.9rem; border-radius: 12px; }
  .home-stats { gap: 0.4rem; margin-bottom: 1.5rem; }
  .home-stat { padding: 0.7rem 0.4rem; }
  .home-stat-value { font-size: 1.1rem; }
  .deal-card { padding: 0.85rem; }

  /* Search result cards */
  .search-result-card {
    flex-wrap: wrap;
    padding: 0.75rem;
    gap: 0.5rem;
  }

  /* Compare */
  .compare-prices { grid-template-columns: 1fr; }
  .compare-price-cell { padding: 0.85rem 1rem; border-right: none; }
  .compare-card-header { padding: 0.85rem 1rem; }

  /* Browse table → card layout on mobile */
  .product-table thead { display: none; }
  .product-table,
  .product-table tbody,
  .product-table tr,
  .product-table td {
    display: block;
    width: 100%;
  }
  .product-table tr {
    background: #fff;
    border: 1px solid #e2e4e9;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    padding: 0.75rem;
  }
  .product-table td {
    padding: 0.25rem 0;
    border-bottom: none;
    text-align: left;
  }
  .product-table tr:hover { background: #fff; }

  /* Stats */
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .stat-card { padding: 1rem; }
  .stat-card .stat-value { font-size: 1.5rem; }

  /* Categories & stores */
  .category-grid { grid-template-columns: repeat(2, 1fr); }
  .store-list { grid-template-columns: 1fr; }

  /* Cart */
  .cart-item { flex-wrap: wrap; gap: 0.5rem; }
  .list-header h2 { font-size: 1.1rem; }

  /* Modal */
  .modal {
    width: 95%;
    max-height: 90vh;
    padding: 1rem;
    border-radius: 10px;
  }

  /* Footer */
  .site-footer { padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom)); }
  .site-footer-inner { justify-content: center; text-align: center; }

  /* Safe area insets for iPhone notch/home indicator */
  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===== Tablet+ deals grid (2 columns) ===== */
@media (min-width: 600px) {
  .deals-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Active nav pill — filled green for clearer mobile affordance ===== */
.nav-pill.active {
  background: #16a34a;
  color: #fff;
  border-color: #16a34a;
}
.nav-pill.active:hover { background: #15803d; color: #fff; }
.nav-pill.active .cart-count { background: #fff; color: #16a34a; }
