/* ─── LowGrocery.com — ClaroPixel LLC ─────────────────────────────────────
   Design system: Market-board editorial meets organic produce aesthetic.
   Typography: Playfair Display (display) + DM Sans (body)
   Palette: Deep forest green headers, warm cream backgrounds, vivid accents
   ─────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,700;0,900;1,500&family=DM+Sans:wght@400;500;600;700&display=swap');

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'DM Sans', sans-serif;
  background: #f4f0e6;
  color: #1c1c1c;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── CSS Variables ────────────────────────────────────────────────────────── */
:root {
  --forest:   #0f2318;
  --forest2:  #1a3a2a;
  --leaf:     #2d6a3f;
  --mint:     #7fba8a;
  --cream:    #f4f0e6;
  --parchment:#ede8da;
  --sand:     #d9d3c3;
  --ink:      #1c1c1c;
  --muted:    #6b6355;
  --white:    #ffffff;
  --best-bg:  #ecfdf5;
  --best-txt: #065f46;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
  --transition: 0.18s ease;
  --header-h: 64px;
}

/* ── Typography ────────────────────────────────────────────────────────────── */
.font-display { font-family: 'Playfair Display', Georgia, serif; }
h1, h2, h3 { font-family: 'Playfair Display', Georgia, serif; line-height: 1.15; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ── Header ────────────────────────────────────────────────────────────────── */
#app-header {
  background: var(--forest);
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--header-h);
  box-shadow: 0 2px 20px rgba(0,0,0,0.35);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand-icon {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.brand-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 900;
  color: #f0e9d8;
  letter-spacing: -0.02em;
  line-height: 1;
}
.brand-sub {
  font-size: 0.6rem;
  color: var(--mint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}
.header-actions { display: flex; gap: 8px; align-items: center; }
.btn-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--leaf);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.btn-refresh:hover { background: #3a7d4f; }
.btn-refresh:active { transform: scale(0.97); }
.btn-refresh.loading .refresh-icon { animation: spin 0.8s linear infinite; }
.refresh-icon { font-size: 1rem; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hero Band ──────────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(160deg, var(--forest2) 0%, #0d3520 100%);
  padding: 32px 16px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.025'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.hero-title {
  font-size: clamp(1.4rem, 5vw, 2rem);
  color: #f0e9d8;
  font-weight: 700;
  margin-bottom: 8px;
  position: relative;
}
.hero-title em { font-style: italic; color: #a8e6b8; }
.hero-sub {
  font-size: 0.88rem;
  color: rgba(255,255,255,0.6);
  position: relative;
}
.hero-company {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  position: relative;
}

/* ── Ad Banner ──────────────────────────────────────────────────────────────── */
.ad-banner {
  background: var(--parchment);
  border: 1px dashed var(--sand);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  margin: 14px 0;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-label {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ── Controls Bar ───────────────────────────────────────────────────────────── */
.controls {
  background: var(--white);
  border-bottom: 1px solid var(--sand);
  padding: 12px 16px;
  position: sticky;
  top: var(--header-h);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.controls-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.search-row { display: flex; gap: 10px; align-items: center; }
.search-wrap {
  position: relative;
  flex: 1;
}
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 10px 36px 10px 34px;
  border: 1.5px solid var(--sand);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--leaf); }
.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2px;
  display: none;
}
.search-clear.visible { display: block; }
.last-updated {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Store Filter Chips */
.store-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px 5px 7px;
  border-radius: 20px;
  border: 1.5px solid var(--sand);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  background: var(--parchment);
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.filter-chip:active { transform: scale(0.96); }
.filter-chip.active {
  color: #fff;
  border-color: transparent;
}
.chip-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  border-radius: 9px;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0 4px;
  color: #fff;
}
.filter-chip.active .chip-badge { background: rgba(255,255,255,0.25); }

/* Category Filter */
.cat-filters {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.cat-chip {
  padding: 3px 10px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--parchment);
  color: var(--muted);
  border-color: var(--sand);
}
.cat-chip.active {
  border-color: var(--leaf);
  background: #e8f5ee;
  color: var(--leaf);
}

/* ── Main Content ───────────────────────────────────────────────────────────── */
.main { padding: 0 16px 100px; max-width: 1100px; margin: 0 auto; }

/* ── Error Bar ──────────────────────────────────────────────────────────────── */
.error-bar {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  color: #92400e;
  margin: 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.error-bar button {
  background: none;
  border: none;
  color: #92400e;
  text-decoration: underline;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.error-bar.hidden { display: none; }

/* ── Skeleton Loading ───────────────────────────────────────────────────────── */
.skeleton-wrap { margin: 12px 0; }
.skeleton-row {
  height: 64px;
  background: linear-gradient(90deg, #e5e0d5 25%, #f0ece3 50%, #e5e0d5 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Price Table ────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.price-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  min-width: 520px;
}

/* Table head */
.price-table thead tr {
  background: var(--parchment);
  border-bottom: 2px solid var(--sand);
}
.price-table th {
  padding: 10px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  text-align: center;
}
.price-table th.th-product {
  text-align: left;
  padding-left: 14px;
  min-width: 160px;
}
.th-store {
  min-width: 110px;
  border-top: 3px solid transparent;
}
.th-store-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.th-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 20px;
  border-radius: 6px;
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  padding: 0 5px;
}
.th-store-name { font-size: 0.68rem; color: #3a3530; font-weight: 700; }

/* Table rows */
.price-table tbody tr {
  border-bottom: 1px solid #eee8dc;
  transition: background var(--transition);
}
.price-table tbody tr:last-child { border-bottom: none; }
.price-table tbody tr:hover { background: #faf6ed; }
.price-table tbody tr:nth-child(even) { background: #faf8f4; }
.price-table tbody tr:nth-child(even):hover { background: #f5f0e5; }

/* Product cell */
.td-product {
  padding: 12px 8px 12px 14px;
  vertical-align: middle;
}
.product-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.product-emoji { font-size: 1.5rem; flex-shrink: 0; }
.product-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2a2520;
  line-height: 1.3;
}
.product-cat {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 8px;
  text-transform: capitalize;
  margin-top: 2px;
}

/* Price cell */
.td-price {
  text-align: center;
  padding: 10px 6px;
  vertical-align: middle;
  position: relative;
  border-left: 2px solid transparent;
  transition: all var(--transition);
}
.td-price.is-best {
  background: var(--best-bg) !important;
}
.price-amount {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.td-price.is-best .price-amount { color: var(--best-txt); }
.price-unit {
  display: block;
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: 1px;
}
.best-badge {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 800;
  color: #fff;
  padding: 1px 5px;
  border-radius: 5px;
  margin-top: 3px;
  letter-spacing: 0.05em;
}
.price-unavail {
  color: #ccc;
  font-size: 1rem;
  font-weight: 600;
}
.price-oos {
  font-size: 0.6rem;
  color: #bbb;
  display: block;
}

/* ── Savings Summary ────────────────────────────────────────────────────────── */
.savings-bar {
  background: var(--forest2);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.savings-label { font-size: 0.8rem; color: var(--mint); font-weight: 500; }
.savings-stores {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.savings-store {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.savings-store-name { font-size: 0.68rem; color: rgba(255,255,255,0.6); }
.savings-store-total { font-size: 1.1rem; font-weight: 700; }

/* ── Info Cards ────────────────────────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.info-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--parchment);
}
.info-card-icon { font-size: 1.4rem; }
.info-card-title { font-size: 0.88rem; font-weight: 700; color: var(--forest2); }
.info-card-desc { font-size: 0.78rem; color: var(--muted); line-height: 1.5; }

/* ── Footer ────────────────────────────────────────────────────────────────── */
footer {
  background: var(--forest);
  color: rgba(255,255,255,0.5);
  padding: 28px 16px;
  margin-top: 40px;
}
.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.footer-brand { color: #d4e8d8; font-size: 0.9rem; }
.footer-brand strong { color: #fff; }
.footer-links { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.footer-links button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  text-decoration: underline;
  padding: 0;
  transition: color var(--transition);
}
.footer-links button:hover { color: var(--mint); }
.footer-copy { font-size: 0.68rem; color: rgba(255,255,255,0.3); }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal-box {
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal-overlay.open .modal-box { transform: translateY(0); }
.modal-handle {
  width: 36px; height: 4px;
  background: var(--sand);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--parchment);
  flex-shrink: 0;
}
.modal-title {
  font-size: 1.1rem;
  color: var(--forest2);
}
.modal-close {
  width: 30px; height: 30px;
  background: var(--parchment);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--sand); }
.modal-body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 0.85rem;
  line-height: 1.75;
  color: #3a3530;
}
.modal-body p { margin-bottom: 0.6em; }

/* ── Toast notification ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--forest);
  color: var(--mint);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 600;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── PWA Install Banner ──────────────────────────────────────────────────────── */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  background: var(--forest2);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 400;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.install-banner.show { transform: translateY(0); }
.install-banner-text { font-size: 0.82rem; line-height: 1.4; flex: 1; }
.install-banner-text strong { display: block; font-size: 0.9rem; }
.install-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-install {
  background: var(--leaf);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
}
.btn-install-dismiss {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.8rem;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  :root { --header-h: 68px; }
  .hero { padding: 48px 24px 36px; }
  .hero-title { font-size: 2rem; }
  .search-row { flex-direction: row; }
  .brand-name { font-size: 1.7rem; }
}
@media (min-width: 900px) {
  .price-table th { padding: 12px 10px; font-size: 0.72rem; }
  .price-amount { font-size: 1.1rem; }
  .product-name { font-size: 0.9rem; }
}

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
