/* ─── CSS Variables ─────────────────────────────── */
:root {
  --orange: #FF6B35;
  --yellow: #FFD166;
  --green:  #06D6A0;
  --blue:   #118AB2;
  --purple: #9B5DE5;
  --pink:   #F72585;
  --tesco:  #EE1C25;
  --lidl:   #0050AA;
  --aldi:   #FF6600;
  --bg:     #FFF9F0;
  --card:   #FFFFFF;
  --text:   #2D2D2D;
  --muted:  #888;
  --radius: 20px;
  --shadow: 0 4px 20px rgba(0,0,0,0.10);
}

/* ─── Reset ─────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 90px;
}

h1, .brand { font-family: 'Fredoka One', cursive; }

/* ─── Header ─────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--orange), var(--pink));
  padding: 20px 20px 30px;
  border-radius: 0 0 30px 30px;
  color: white;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 4px 20px rgba(255,107,53,0.3);
}
.header-top { display: flex; justify-content: space-between; align-items: center; }
.brand { font-size: 26px; letter-spacing: 0.5px; }
.brand span { color: var(--yellow); }
.location-pill {
  background: rgba(255,255,255,0.25);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; gap: 4px;
}
.search-bar {
  margin-top: 14px;
  background: white;
  border-radius: 50px;
  display: flex; align-items: center;
  padding: 10px 16px; gap: 10px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
.search-bar input {
  border: none; outline: none; flex: 1;
  font-family: 'Nunito', sans-serif;
  font-size: 15px; font-weight: 600;
  color: var(--text); background: transparent;
}
.search-bar input::placeholder { color: #ccc; }
.search-icon { color: var(--orange); font-size: 18px; }

/* ─── Bottom Nav ─────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: white;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.10);
  display: flex; justify-content: space-around;
  padding: 10px 0 20px;
  z-index: 200;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; background: none; border: none; cursor: pointer;
  font-family: 'Nunito', sans-serif; font-size: 11px;
  color: var(--muted); font-weight: 700;
  padding: 6px 12px; border-radius: 16px; transition: all 0.2s;
}
.nav-btn.active { color: var(--orange); }
.nav-btn .icon { font-size: 22px; }
.nav-btn.active .icon { transform: scale(1.15); }

/* ─── Pages ──────────────────────────────────────── */
.page { display: none; padding: 20px; }
.page.active { display: block; }

/* ─── Section Title ──────────────────────────────── */
.section-title {
  font-family: 'Fredoka One', cursive;
  font-size: 20px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}

/* ─── Store Badges ───────────────────────────────── */
.store-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 800; color: white;
}
.store-tesco  { background: var(--tesco); }
.store-lidl   { background: var(--lidl); }
.store-aldi   { background: var(--aldi); }
.store-custom { background: var(--purple); }

/* ─── Price Cards ────────────────────────────────── */
.price-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: 2px solid transparent;
  transition: all 0.2s;
  position: relative; overflow: hidden;
}
.price-card.cheapest { border-color: var(--green); }
.cheapest-ribbon {
  position: absolute; top: 10px; right: -20px;
  background: var(--green); color: white;
  font-size: 10px; font-weight: 800;
  padding: 3px 28px; transform: rotate(12deg);
}
.price-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.item-name  { font-size: 16px; font-weight: 800; }
.item-unit  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.price-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.price-row  {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 12px; background: #F8F8F8;
}
.price-row.best { background: #E8FDF6; }
.price-amount { font-size: 18px; font-weight: 800; }
.price-amount.best  { color: var(--green); }
.price-amount.worst { color: #FF4444; }
.price-diff { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ─── Basket ─────────────────────────────────────── */
.basket-item {
  background: white;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.basket-item-info  { flex: 1; }
.basket-item-name  { font-weight: 700; font-size: 14px; }
.basket-item-store { font-size: 12px; color: var(--muted); }
.basket-item-price { font-weight: 800; font-size: 16px; color: var(--orange); }
.basket-remove { background: none; border: none; cursor: pointer; color: #ddd; font-size: 18px; }
.basket-remove:hover { color: var(--pink); }

/* ─── Optimizer ──────────────────────────────────── */
.optimizer-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius);
  padding: 20px; color: white; margin-bottom: 16px;
}
.optimizer-card h3 { font-family: 'Fredoka One', cursive; font-size: 20px; margin-bottom: 12px; }
.store-route {
  background: rgba(255,255,255,0.15);
  border-radius: 12px; padding: 12px; margin-bottom: 8px;
}
.store-route-name  { font-weight: 800; font-size: 15px; }
.store-route-items { font-size: 12px; opacity: 0.85; margin-top: 4px; }
.store-route-price { font-size: 18px; font-weight: 800; margin-top: 4px; }
.savings-pill {
  background: var(--yellow); color: #333;
  border-radius: 20px; padding: 6px 16px;
  font-weight: 800; font-size: 14px;
  display: inline-block; margin-top: 10px;
}

/* ─── Add Item Form ──────────────────────────────── */
.add-form {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.form-row { margin-bottom: 12px; }
.form-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; display: block; }
.form-input {
  width: 100%; border: 2px solid #EEE; border-radius: 12px;
  padding: 10px 14px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px; font-weight: 600;
  outline: none; transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--orange); }
.store-price-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.store-price-input { text-align: center; }
.store-price-label { font-size: 10px; font-weight: 800; text-align: center; margin-bottom: 4px; }

/* ─── Buttons ────────────────────────────────────── */
.btn {
  border: none; cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 800; border-radius: 50px;
  padding: 12px 24px; font-size: 15px;
  transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--orange); color: white; width: 100%; justify-content: center; }
.btn-green   { background: var(--green);  color: white; width: 100%; justify-content: center; }
.btn-purple  { background: var(--purple); color: white; width: 100%; justify-content: center; }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-outline { background: transparent; border: 2px solid var(--orange); color: var(--orange); }

/* ─── Receipt / Split ────────────────────────────── */
.receipt-upload {
  border: 2px dashed #DDD; border-radius: var(--radius);
  padding: 30px 20px; text-align: center;
  background: white; cursor: pointer; margin-bottom: 16px;
  transition: all 0.2s;
}
.receipt-upload:hover { border-color: var(--orange); background: #FFF5EF; }
.receipt-upload .upload-icon { font-size: 40px; margin-bottom: 8px; }
.receipt-upload p { font-weight: 700; color: var(--muted); }

.split-item {
  background: white; border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.split-item-name  { flex: 1; font-weight: 700; font-size: 14px; }
.split-item-price { font-weight: 800; font-size: 15px; color: var(--text); width: 55px; text-align: right; }
.split-toggle { display: flex; background: #F0F0F0; border-radius: 20px; overflow: hidden; }
.split-btn {
  border: none; cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-size: 11px; font-weight: 800;
  padding: 5px 9px; background: transparent; color: var(--muted);
  transition: all 0.15s;
}
.split-btn.active-me     { background: var(--orange); color: white; border-radius: 20px; }
.split-btn.active-them   { background: var(--blue);   color: white; border-radius: 20px; }
.split-btn.active-shared { background: var(--green);  color: white; border-radius: 20px; }

.split-summary {
  background: linear-gradient(135deg, var(--orange), var(--yellow));
  border-radius: var(--radius); padding: 20px; margin-top: 16px; color: white;
}
.split-summary h3 { font-family: 'Fredoka One', cursive; font-size: 20px; margin-bottom: 12px; }
.split-row   { display: flex; justify-content: space-between; margin-bottom: 8px; font-weight: 700; }
.split-amount { font-size: 24px; font-weight: 800; }

/* ─── Trends ─────────────────────────────────────── */
.trend-card {
  background: white; border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.trend-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.trend-title  { font-weight: 800; font-size: 15px; }
.trend-chart  { display: flex; align-items: flex-end; gap: 4px; height: 60px; margin-top: 8px; }
.trend-bar {
  flex: 1; border-radius: 4px 4px 0 0; min-height: 4px;
  position: relative; transition: all 0.3s;
}
.trend-bar-label { font-size: 9px; text-align: center; margin-top: 4px; color: var(--muted); }
.trend-insight {
  background: #F0F9FF; border-radius: 10px; padding: 8px 12px;
  margin-top: 10px; font-size: 12px; color: var(--blue); font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}

/* ─── AI Badge ───────────────────────────────────── */
.ai-badge {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white; font-size: 10px; font-weight: 800;
  padding: 2px 8px; border-radius: 20px;
  display: inline-flex; align-items: center; gap: 3px;
}

/* ─── Chips ──────────────────────────────────────── */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  background: white; border: 2px solid #EEE;
  border-radius: 20px; padding: 6px 14px;
  font-size: 13px; font-weight: 700; cursor: pointer; transition: all 0.15s;
}
.chip.active { border-color: var(--orange); color: var(--orange); background: #FFF5EF; }

/* ─── Toast ──────────────────────────────────────── */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: white;
  padding: 10px 20px; border-radius: 30px;
  font-weight: 700; font-size: 14px;
  opacity: 0; transition: all 0.3s; z-index: 999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 500;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; border-radius: 28px 28px 0 0;
  padding: 24px; width: 100%; max-width: 480px;
  max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 40px; height: 4px; background: #EEE; border-radius: 4px; margin: 0 auto 20px; }

/* ─── Misc ───────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .e-icon { font-size: 50px; margin-bottom: 10px; }
.empty-state p { font-weight: 700; }

.spinner {
  border: 3px solid #f3f3f3; border-top: 3px solid var(--orange);
  border-radius: 50%; width: 24px; height: 24px;
  animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-box { text-align: center; padding: 24px; font-weight: 700; color: var(--muted); }
.loading-box p { margin-top: 10px; font-size: 13px; }

/* ─── New additions v4 ───────────────────────────── */
.header-right { display: flex; align-items: center; gap: 8px; }
.ai-status-pill {
  background: rgba(255,255,255,0.2);
  border-radius: 20px; padding: 4px 10px;
  font-size: 11px; font-weight: 800; cursor: pointer; transition: all 0.2s;
}
.ai-status-pill:active { transform: scale(0.95); }
.scraper-card {
  background: white; border-radius: 16px; padding: 14px 16px;
  margin-bottom: 16px; box-shadow: var(--shadow);
  border-left: 4px solid var(--orange);
}
.scraper-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 800; font-size: 14px; margin-bottom: 4px;
}
.scraper-status { font-size: 12px; font-weight: 700; color: var(--muted); }
.scraper-meta   { font-size: 12px; color: var(--muted); font-weight: 600; }
code {
  font-family: 'Courier New', monospace;
  line-height: 1.8;
}
