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

:root {
  --aldi-color:    #00539B;
  --aldi-light:    #ddeeff;
  --coles-color:   #CC0000;
  --coles-light:   #ffe0e0;
  --woolies-color: #00A651;
  --woolies-light: #d9f5e8;
  --best-color:    #f59e0b;
  --best-light:    #fef3c7;
  --text:          #1a1a2e;
  --muted:         #6b7280;
  --border:        #e5e7eb;
  --bg:            #f9fafb;
  --card-bg:       #ffffff;
  --radius:        12px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
  color: #fff;
  padding: 2.5rem 1rem 2rem;
  text-align: center;
}
.header-inner { max-width: 900px; margin: 0 auto; }
header h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 800; letter-spacing: -.5px; }
.subtitle { margin-top: .4rem; color: #94a3b8; font-size: .95rem; }

/* ── Main container ────────────────────────────────────────────── */
main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

/* ── Controls ──────────────────────────────────────────────────── */
.controls {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .875rem;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap input {
  width: 100%;
  padding: .75rem 2.5rem .75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color .2s;
  outline: none;
}
.search-wrap input:focus { border-color: var(--aldi-color); }
.clear-btn {
  position: absolute;
  right: .5rem;
  display: none;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: .75rem;
  color: var(--muted);
  transition: background .15s;
}
.clear-btn:hover { background: #d1d5db; }

.filter-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  align-items: center;
}
.filter-wrap label { font-size: .875rem; color: var(--muted); white-space: nowrap; }
.filter-wrap select {
  padding: .45rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  background: var(--bg);
  cursor: pointer;
  outline: none;
  transition: border-color .2s;
}
.filter-wrap select:focus { border-color: var(--aldi-color); }

/* ── Store legend ──────────────────────────────────────────────── */
.store-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1rem;
}

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .25rem .75rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.badge.aldi    { background: var(--aldi-light);    color: var(--aldi-color); }
.badge.coles   { background: var(--coles-light);   color: var(--coles-color); }
.badge.woolies { background: var(--woolies-light);  color: var(--woolies-color); }
.badge.best    { background: var(--best-light);    color: #92400e; }

/* ── Summary stats ─────────────────────────────────────────────── */
.summary {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  flex: 1 1 120px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .875rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  border-top: 3px solid var(--border);
}
.stat-card.aldi-bg    { border-top-color: var(--aldi-color); }
.stat-card.coles-bg   { border-top-color: var(--coles-color); }
.stat-card.woolies-bg { border-top-color: var(--woolies-color); }
.stat-card.savings-bg { border-top-color: var(--best-color); }
.stat-number { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.stat-label  { font-size: .75rem; color: var(--muted); text-align: center; }

/* ── Results grid ──────────────────────────────────────────────── */
.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ── Product card ──────────────────────────────────────────────── */
.product-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
  border: 1.5px solid var(--border);
}
.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
}

.product-header {
  padding: 1rem 1rem .75rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
}
.category-tag {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: .25rem;
}
.product-name {
  font-size: .95rem;
  font-weight: 700;
  line-height: 1.3;
}
.product-unit {
  display: inline-block;
  font-size: .75rem;
  color: var(--muted);
  margin-top: .15rem;
}

.savings-badge {
  flex-shrink: 0;
  background: var(--best-light);
  color: #92400e;
  font-size: .75rem;
  font-weight: 700;
  padding: .25rem .6rem;
  border-radius: 6px;
  white-space: nowrap;
}

/* ── Store prices row ──────────────────────────────────────────── */
.store-prices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border);
}
.store-col {
  padding: .75rem .5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  border-right: 1px solid var(--border);
  transition: background .15s;
}
.store-col:last-child { border-right: none; }

.store-col.best-price { background: var(--best-light); }
.store-col.na         { opacity: .45; }

.store-name-sm { font-size: .65rem; padding: .15rem .5rem; }

.price-val {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}
.store-col.na .price-val { font-size: .9rem; color: var(--muted); }

.best-tag {
  font-size: .65rem;
  font-weight: 700;
  color: #92400e;
  background: var(--best-color);
  padding: .1rem .4rem;
  border-radius: 4px;
}

/* ── No results ────────────────────────────────────────────────── */
.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.no-results p { margin-bottom: .5rem; }
.hidden { display: none !important; }

/* ── Footer ────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: .8rem;
  border-top: 1px solid var(--border);
}

/* ── Card actions (Add / qty control) ──────────────────────────── */
.card-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .4rem;
  flex-shrink: 0;
}
.add-btn {
  background: var(--aldi-color);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .35rem .75rem;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .1s;
}
.add-btn:hover  { background: #003f7a; }
.add-btn:active { transform: scale(.96); }

.qty-control {
  display: flex;
  align-items: center;
  gap: .25rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: .15rem .3rem;
}
.qty-btn {
  border: none;
  background: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--aldi-color);
  width: 1.6rem;
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background .12s;
}
.qty-btn:hover { background: var(--aldi-light); }
.qty-num { font-size: .9rem; font-weight: 700; min-width: 1.2rem; text-align: center; }

.product-card.in-list { border-color: var(--aldi-color); }

/* ── List sticky bar ────────────────────────────────────────────── */
.list-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  padding: .5rem 1rem;
  background: rgba(26,26,46,.85);
  backdrop-filter: blur(8px);
}
.list-bar-btn {
  background: var(--best-color);
  color: #1a1a2e;
  border: none;
  border-radius: 999px;
  padding: .65rem 1.5rem;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .6rem;
  transition: transform .15s, background .15s;
}
.list-bar-btn:hover { background: #fbbf24; transform: translateY(-1px); }
.list-bar-icon { font-size: 1.1rem; }
.list-bar-arrow { font-size: .7rem; }

/* ── Drawer overlay ─────────────────────────────────────────────── */
.list-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 110;
}

/* ── Drawer panel ───────────────────────────────────────────────── */
.list-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-height: 80vh;
  background: var(--card-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,.18);
  z-index: 120;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 640px) {
  .list-drawer {
    left: auto; right: 1rem; bottom: 0;
    width: 420px;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 85vh;
  }
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header h2 { font-size: 1.1rem; font-weight: 800; }
.drawer-header-actions { display: flex; align-items: center; gap: .75rem; }
.btn-text {
  border: none; background: none;
  color: var(--coles-color);
  font-size: .85rem; font-weight: 600;
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 4px;
  transition: background .12s;
}
.btn-text:hover { background: var(--coles-light); }
.drawer-close {
  border: none; background: none;
  font-size: 1rem; cursor: pointer;
  color: var(--muted);
  width: 2rem; height: 2rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background .12s;
}
.drawer-close:hover { background: var(--border); }

.drawer-body {
  overflow-y: auto;
  flex: 1;
  padding: .75rem 1rem;
}
.drawer-empty { color: var(--muted); text-align: center; padding: 2rem 0; }

/* ── Drawer item ────────────────────────────────────────────────── */
.drawer-item {
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}
.drawer-item:last-child { border-bottom: none; }
.drawer-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
}
.drawer-item-name { font-weight: 700; font-size: .9rem; display: block; }
.drawer-item-unit { font-size: .75rem; color: var(--muted); }

.drawer-store-row {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.drawer-store {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  padding: .2rem .4rem;
  border-radius: 5px;
}
.drawer-store.best-price { background: var(--best-light); font-weight: 600; }
.drawer-store.na { opacity: .5; }

/* ── Drawer footer: totals ──────────────────────────────────────── */
.drawer-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
  flex-shrink: 0;
  background: var(--bg);
}
.totals-block h4 { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.total-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .3rem .5rem;
  border-radius: 6px;
  margin-bottom: .25rem;
}
.total-row.best-total { background: var(--best-light); }
.total-amount { font-weight: 800; font-size: 1rem; margin-left: auto; }
.cheapest-tag {
  font-size: .7rem; font-weight: 700;
  background: var(--best-color); color: #1a1a2e;
  padding: .1rem .4rem; border-radius: 4px;
}
.saving-callout {
  margin-top: .75rem;
  background: #dcfce7;
  color: #14532d;
  border-radius: 8px;
  padding: .6rem .9rem;
  font-size: .85rem;
  line-height: 1.4;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .controls { flex-direction: row; align-items: center; }
  .search-wrap { flex: 1; }
}

@media (max-width: 400px) {
  .results { grid-template-columns: 1fr; }
  .stat-card { flex-basis: 100px; }
}

/* bottom padding so last card isn't hidden behind list bar */
main { padding-bottom: 5rem; }
