/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:    #22c55e;
  --green-d:  #16a34a;
  --green-l:  #dcfce7;
  --yellow:   #eab308;
  --yellow-l: #fef9c3;
  --purple:   #a855f7;
  --purple-l: #f3e8ff;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --white:    #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.14);
  --radius:   12px;
  --radius-lg:18px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ===== AUTH OVERLAY ===== */
.auth-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #064e3b 0%, #065f46 50%, #166534 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 16px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px; justify-content: center;
}
.auth-logo .logo-icon { font-size: 2rem; }
.auth-logo .logo-text { font-size: 1.6rem; font-weight: 700; color: var(--green-d); }

.auth-tabs {
  display: flex; border-radius: 8px;
  background: var(--gray-100);
  padding: 4px; gap: 4px;
  margin-bottom: 28px;
}
.tab-btn {
  flex: 1; padding: 10px;
  border: none; border-radius: 6px;
  cursor: pointer; font-size: .9rem; font-weight: 500;
  background: transparent; color: var(--gray-600);
  transition: all .2s;
}
.tab-btn.active {
  background: var(--white);
  color: var(--gray-800);
  box-shadow: var(--shadow-sm);
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--gray-600); }
.field input {
  padding: 12px 14px; border: 1.5px solid var(--gray-200);
  border-radius: 8px; font-size: .95rem;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.field input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}

.form-error {
  background: #fef2f2; border: 1px solid #fecaca;
  color: #dc2626; padding: 10px 14px;
  border-radius: 8px; font-size: .85rem;
}

.btn-primary {
  background: var(--green); color: var(--white);
  border: none; border-radius: 8px;
  padding: 13px 24px; font-size: .95rem; font-weight: 600;
  cursor: pointer; transition: background .2s, transform .1s;
}
.btn-primary:hover { background: var(--green-d); }
.btn-primary:active { transform: scale(.98); }
.btn-primary.full { width: 100%; }

.btn-ghost {
  background: transparent; color: var(--gray-600);
  border: 1.5px solid var(--gray-200); border-radius: 8px;
  padding: 11px 24px; font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: all .2s;
}
.btn-ghost:hover { border-color: var(--gray-400); color: var(--gray-800); }

.demo-hint {
  text-align: center; font-size: .8rem; color: var(--gray-400);
}

/* ===== HEADER ===== */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 0 20px; height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}
.header-logo { display: flex; align-items: center; gap: 8px; }
.header-logo .logo-icon { font-size: 1.5rem; }
.header-logo .logo-text { font-size: 1.2rem; font-weight: 700; color: var(--green-d); }

.header-actions { display: flex; align-items: center; gap: 12px; }
.user-greeting { font-size: .85rem; color: var(--gray-600); }

.cart-btn {
  position: relative; background: var(--green-l);
  border: none; border-radius: 10px;
  padding: 8px 14px; font-size: 1.1rem;
  cursor: pointer; transition: background .2s;
}
.cart-btn:hover { background: #bbf7d0; }
.cart-badge {
  position: absolute; top: -6px; right: -6px;
  background: var(--green); color: var(--white);
  border-radius: 999px; font-size: .7rem; font-weight: 700;
  min-width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

.btn-logout {
  background: transparent; border: 1.5px solid var(--gray-200);
  border-radius: 8px; padding: 8px 14px;
  font-size: .82rem; color: var(--gray-600); cursor: pointer;
  transition: all .2s;
}
.btn-logout:hover { border-color: #fca5a5; color: #dc2626; background: #fef2f2; }

/* ===== HERO ===== */
.hero {
  background: linear-gradient(135deg, #064e3b, #15803d);
  color: var(--white); padding: 56px 20px;
}
.hero-inner { max-width: 1200px; margin: 0 auto; }
.hero h1 { font-size: 2.2rem; font-weight: 800; line-height: 1.2; margin-bottom: 12px; }
.hero h1 em { font-style: normal; color: #86efac; }
.hero p { font-size: 1.05rem; color: #bbf7d0; max-width: 480px; }

/* ===== TOOLBAR ===== */
.main-content { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }

.toolbar { margin-bottom: 24px; display: flex; flex-direction: column; gap: 14px; }

#search-input {
  width: 100%; padding: 14px 18px;
  border: 1.5px solid var(--gray-200); border-radius: var(--radius);
  font-size: 1rem; background: var(--white);
  box-shadow: var(--shadow-sm); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#search-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}

.category-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  padding: 6px 16px; border-radius: 999px;
  background: var(--white); border: 1.5px solid var(--gray-200);
  font-size: .83rem; font-weight: 500; cursor: pointer;
  color: var(--gray-600); transition: all .2s;
}
.pill:hover { border-color: var(--green); color: var(--green-d); }
.pill.active {
  background: var(--green-l); border-color: var(--green);
  color: var(--green-d);
}

/* ===== PRODUCT GRID ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-200);
  padding: 20px 16px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 8px;
  transition: box-shadow .2s, border-color .2s, transform .15s;
  cursor: pointer;
}
.product-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--green);
  transform: translateY(-2px);
}

.product-emoji { font-size: 2.4rem; }
.product-name { font-size: .9rem; font-weight: 600; color: var(--gray-800); line-height: 1.3; }
.product-category { font-size: .75rem; color: var(--gray-400); }
.product-price { font-size: 1rem; font-weight: 700; color: var(--green-d); }

.product-add-btn {
  margin-top: 6px; width: 100%;
  background: var(--green-l); color: var(--green-d);
  border: none; border-radius: 8px;
  padding: 9px; font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.product-add-btn:hover { background: #bbf7d0; }
.product-add-btn.in-cart {
  background: var(--green); color: var(--white);
}

/* ===== CART SIDEBAR ===== */
.cart-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 500;
  backdrop-filter: blur(2px);
}
.cart-panel {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 100%; max-width: 420px;
  background: var(--white);
  display: flex; flex-direction: column;
  box-shadow: -4px 0 32px rgba(0,0,0,.12);
  animation: slideIn .25s ease;
}
@keyframes slideIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.cart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--gray-200);
}
.cart-header h2 { font-size: 1.2rem; font-weight: 700; }
.close-btn {
  background: var(--gray-100); border: none; border-radius: 8px;
  width: 34px; height: 34px; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.close-btn:hover { background: var(--gray-200); }

.cart-items { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 12px; }

.cart-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: var(--gray-50);
  border-radius: var(--radius); border: 1px solid var(--gray-200);
}
.cart-item-emoji { font-size: 1.6rem; flex-shrink: 0; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: .88rem; font-weight: 600; }
.cart-item-price { font-size: .8rem; color: var(--gray-400); }

.qty-control {
  display: flex; align-items: center; gap: 6px;
}
.qty-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1.5px solid var(--gray-200); background: var(--white);
  font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.qty-btn:hover { background: var(--green-l); border-color: var(--green); color: var(--green-d); }
.qty-btn.remove:hover { background: #fef2f2; border-color: #fca5a5; color: #dc2626; }
.qty-value { font-size: .9rem; font-weight: 700; min-width: 20px; text-align: center; }

.cart-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--gray-400);
}
.cart-empty span { font-size: 3rem; }
.cart-empty p { font-size: .95rem; }

.cart-footer {
  padding: 20px 24px; border-top: 1px solid var(--gray-200);
  display: flex; flex-direction: column; gap: 12px;
}
.cart-total {
  display: flex; justify-content: space-between; align-items: center;
}
.cart-total span { font-size: .95rem; color: var(--gray-600); }
.cart-total strong { font-size: 1.4rem; color: var(--green-d); }
.cart-disclaimer { font-size: .75rem; color: var(--gray-400); }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  z-index: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--white); border-radius: var(--radius-lg);
  padding: 40px; width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: popIn .25s ease;
}
.modal-wide { max-width: 680px; }

@keyframes popIn {
  from { transform: scale(.9); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.modal h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.modal > p { color: var(--gray-600); margin-bottom: 28px; }

/* Price choices */
.price-choices { display: flex; gap: 14px; margin-bottom: 20px; }
.price-card {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 24px 12px;
  border: 2px solid var(--gray-200); border-radius: var(--radius);
  background: var(--white); cursor: pointer; transition: all .2s;
}
.price-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.price-card:nth-child(1):hover { border-color: var(--green);  background: var(--green-l); }
.price-card:nth-child(2):hover { border-color: var(--yellow); background: var(--yellow-l); }
.price-card:nth-child(3):hover { border-color: var(--purple); background: var(--purple-l); }
.price-emoji { font-size: 2rem; }
.price-label { font-size: .95rem; font-weight: 700; }
.price-desc  { font-size: .75rem; color: var(--gray-400); text-align: center; }

/* Result modal */
.result-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 6px;
}
.result-icon { font-size: 2rem; }

.recommended-store {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border: 2px solid var(--green);
  border-radius: var(--radius);
  padding: 24px; margin-bottom: 24px;
}
.store-name { font-size: 1.3rem; font-weight: 800; color: var(--green-d); margin-bottom: 4px; }
.store-meta { font-size: .85rem; color: var(--gray-600); margin-bottom: 16px; display: flex; gap: 16px; flex-wrap: wrap; }
.store-meta span { display: flex; align-items: center; gap: 4px; }
.store-prices-row { display: flex; gap: 16px; margin-top: 12px; flex-wrap: wrap; }
.store-price-box {
  flex: 1; min-width: 100px; padding: 12px;
  background: var(--white); border-radius: 8px;
  text-align: center; border: 1px solid var(--gray-200);
}
.store-price-box .label { font-size: .75rem; color: var(--gray-400); margin-bottom: 4px; }
.store-price-box .value { font-size: 1.1rem; font-weight: 700; color: var(--green-d); }
.best-badge {
  display: inline-block; background: var(--green); color: var(--white);
  font-size: .72rem; font-weight: 700; padding: 3px 10px;
  border-radius: 999px; margin-bottom: 12px;
}

.other-stores-title { font-size: .9rem; font-weight: 600; color: var(--gray-600); margin-bottom: 12px; }
.other-stores { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.other-store-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); background: var(--gray-50);
}
.other-store-left { display: flex; flex-direction: column; gap: 2px; }
.other-store-name { font-size: .9rem; font-weight: 600; }
.other-store-type { font-size: .77rem; color: var(--gray-400); }
.other-store-right { text-align: right; }
.other-store-price { font-size: 1rem; font-weight: 700; }
.other-store-dist  { font-size: .77rem; color: var(--gray-400); }

.result-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .hero h1 { font-size: 1.6rem; }
  .price-choices { flex-direction: column; }
  .modal { padding: 28px 20px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .header-logo .logo-text, .user-greeting { display: none; }
}
