/* ============================================
   RESET & CUSTOM PROPERTIES
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --primary:       #2d6a4f;
  --primary-dark:  #1b4332;
  --primary-light: #d1fae5;
  --accent:        #f59e0b;
  --success:       #10b981;
  --danger:        #ef4444;
  --bg:            #f8fafc;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-2:        #64748b;
  --text-3:        #94a3b8;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:     0 20px 40px rgba(0,0,0,.14);
  --radius:        12px;
  --radius-sm:     8px;
  --transition:    .2s ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.logo-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.logo-tagline {
  font-size: .6rem;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: .03em;
  line-height: 1.2;
  white-space: nowrap;
}

/* Search */
.search-form { flex: 1; max-width: 600px; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 50px;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.search-icon {
  flex-shrink: 0;
  margin-left: 16px;
  color: var(--text-3);
  pointer-events: none;
}

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  font-family: inherit;
  font-size: .95rem;
  color: var(--text);
  outline: none;
  min-width: 0;
}

.search-input::placeholder { color: var(--text-3); }

.search-btn {
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 20px;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.search-btn:hover { background: var(--primary-dark); }

.photo-search-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  padding: 10px 14px;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
}
.photo-search-btn:hover { color: var(--primary); background: var(--primary-light); }
.photo-search-btn:disabled { opacity: .5; cursor: wait; }
.photo-search-btn.loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.api-key-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: inherit;
  font-size: .95rem;
  color: var(--text);
  outline: none;
  margin-bottom: 16px;
  transition: border-color var(--transition);
}
.api-key-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.api-key-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.api-key-cancel {
  background: var(--bg);
  color: var(--text-2);
  border: 1.5px solid var(--border);
}
.api-key-cancel:hover { background: var(--border); }

/* ── Scan results modal ───────────────────────────── */
.scan-modal {
  max-width: 660px;
  padding: 0;
  text-align: left;
  overflow: hidden;
}

.scan-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.scan-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
}
.scan-modal-title h3 { font-size: 1.1rem; font-weight: 700; color: var(--text); }

.scan-list {
  list-style: none;
  max-height: 420px;
  overflow-y: auto;
}

.scan-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.scan-item:last-child { border-bottom: none; }
.scan-item:hover { background: var(--bg); }

.scan-item-info { flex: 1; min-width: 0; }

.scan-item-brand {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 2px;
}

.scan-item-name {
  display: block;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scan-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scan-badge {
  flex-shrink: 0;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 50px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.scan-badge--open   { background: #d1fae5; color: #065f46; }
.scan-badge--closed { background: var(--primary-light); color: var(--primary-dark); }

.usage-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 50px;
  overflow: hidden;
  min-width: 60px;
}
.usage-bar {
  height: 100%;
  border-radius: 50px;
  transition: width .4s ease;
}
.usage-bar--high   { background: var(--success); }
.usage-bar--mid    { background: var(--accent); }
.usage-bar--low    { background: var(--danger); }

.usage-pct {
  flex-shrink: 0;
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-2);
  min-width: 34px;
  text-align: right;
}

.scan-search-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.scan-search-btn:hover { background: var(--primary); color: #fff; }

.scan-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scan-history-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-2);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.scan-history-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.scan-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.scan-shopping-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}
.scan-shopping-btn:hover { background: #059669; }
.scan-shopping-btn:disabled { opacity: .45; cursor: not-allowed; }

.scan-close-btn { width: 100%; margin: 0; }

/* Expiry badges */
.scan-expiry {
  flex-shrink: 0;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 50px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.scan-expiry--expired { background: #fee2e2; color: #991b1b; }
.scan-expiry--urgent  { background: #fee2e2; color: #991b1b; }
.scan-expiry--soon    { background: #fef3c7; color: #92400e; }
.scan-expiry--ok      { background: #d1fae5; color: #065f46; }

/* History modal items */
.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--bg); }

.history-item-info { flex: 1; min-width: 0; }

.history-date {
  display: block;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.history-summary {
  font-size: .8rem;
  color: var(--text-2);
}

.history-low { color: var(--danger); font-weight: 700; }

.history-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-3);
  font-size: .95rem;
}

/* Cart toggle */
.cart-toggle {
  position: relative;
  background: none;
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: border-color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.cart-toggle:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

.cart-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}
.cart-badge.bump { transform: scale(1.4); }

/* ============================================
   HERO
   ============================================ */
.hero {
  background: linear-gradient(135deg, #1b4332 0%, #40916c 100%);
  color: #fff;
  padding: 56px 24px;
  text-align: center;
}

.hero-inner { max-width: 700px; margin: 0 auto; }

.hero h1 {
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.25;
}

.hero p {
  font-size: 1.05rem;
  opacity: .88;
  margin-bottom: 28px;
}

.hero-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.cat-chip {
  background: rgba(255,255,255,.2);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,.4);
  border-radius: 50px;
  padding: 8px 18px;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.cat-chip:hover { background: rgba(255,255,255,.35); transform: translateY(-1px); }

/* ============================================
   MAIN / GRID
   ============================================ */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.results-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 24px;
}

.results-header h2 { font-size: 1.4rem; font-weight: 700; }

.results-count {
  font-size: .9rem;
  color: var(--text-2);
  font-weight: 500;
}

/* Product grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 24px;
}

/* Product card */
.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  role: listitem;
}
.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.product-img-wrap {
  position: relative;
  background: #f1f5f9;
  height: 200px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-img {
  max-height: 170px;
  max-width: 90%;
  object-fit: contain;
  transition: transform .3s ease;
}
.product-card:hover .product-img { transform: scale(1.06); }

.product-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: var(--accent);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 50px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.product-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.product-category {
  font-size: .72rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.product-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-rating {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--text-2);
}

.stars { color: var(--accent); letter-spacing: -.05em; }

.product-footer {
  padding: 12px 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.product-price {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.product-price .old-price {
  display: block;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-3);
  text-decoration: line-through;
}

.add-to-cart-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), transform var(--transition);
}
.add-to-cart-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.add-to-cart-btn:active { transform: translateY(0); }
.add-to-cart-btn.added { background: var(--success); }

/* ============================================
   SKELETON
   ============================================ */
.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  height: 340px;
  overflow: hidden;
  position: relative;
}
.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 20%, rgba(255,255,255,.7) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.skeleton-card::before {
  content: '';
  display: block;
  height: 100%;
  background:
    linear-gradient(var(--border) 200px, transparent 0),
    linear-gradient(var(--border) 20px, transparent 0),
    linear-gradient(var(--border) 14px, transparent 0),
    linear-gradient(var(--border) 36px, transparent 0);
  background-repeat: no-repeat;
  background-size: 100% 200px, 70% 20px, 50% 14px, 50% 36px;
  background-position: 0 0, 16px 216px, 16px 246px, 16px 288px;
}
@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position:  200% 0; }
}

/* ============================================
   EMPTY / ERROR STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-2);
}
.empty-state svg { color: var(--border); margin-bottom: 16px; }
.empty-state h3 { font-size: 1.2rem; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: .95rem; }

/* ============================================
   CART SIDEBAR
   ============================================ */
.cart-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}
.cart-backdrop.open { opacity: 1; pointer-events: all; }

.cart-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background: var(--surface);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  box-shadow: var(--shadow-lg);
}
.cart-sidebar.open { transform: translateX(0); }

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cart-header h2 { font-size: 1.15rem; font-weight: 700; }

.cart-close {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition);
}
.cart-close:hover { background: #fee2e2; border-color: var(--danger); color: var(--danger); }

.cart-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.cart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  gap: 12px;
  color: var(--text-3);
  padding: 40px;
  text-align: center;
}
.cart-empty svg { color: var(--border); }
.cart-empty p { font-size: .95rem; font-weight: 500; }

.cart-list { list-style: none; }

/* Cart item */
.cart-item {
  display: flex;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
  animation: slideInRight .2s ease;
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.cart-item-img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #f1f5f9;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  padding: 4px;
}

.cart-item-info { flex: 1; min-width: 0; }

.cart-item-title {
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}

.cart-item-price {
  font-size: .9rem;
  font-weight: 700;
  color: var(--primary);
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.qty-btn {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.qty-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.qty-value {
  font-size: .9rem;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

.cart-item-remove {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.cart-item-remove:hover { color: var(--danger); background: #fee2e2; }

/* Cart footer */
.cart-footer {
  border-top: 1px solid var(--border);
  padding: 20px 24px;
  flex-shrink: 0;
  background: var(--surface);
}

.cart-summary { margin-bottom: 16px; display: flex; flex-direction: column; gap: 10px; }

.cart-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: .92rem;
  color: var(--text-2);
}
.cart-summary-row.total {
  padding-top: 10px;
  border-top: 2px solid var(--border);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.free-shipping { color: var(--success); font-weight: 600; }

.checkout-btn {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--transition), transform var(--transition);
  margin-bottom: 10px;
}
.checkout-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }

.clear-cart-btn {
  width: 100%;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.clear-cart-btn:hover { border-color: var(--danger); color: var(--danger); background: #fff5f5; }

/* ============================================
   TOAST
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 50px;
  font-size: .88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  animation: toastIn .25s cubic-bezier(.34,1.56,.64,1);
  pointer-events: all;
}
.toast.success::before { content: '✓'; font-weight: 800; color: #6ee7b7; }
.toast.error::before   { content: '✕'; font-weight: 800; color: #fca5a5; }
.toast.hiding { animation: toastOut .2s ease forwards; }

@keyframes toastIn  { from { opacity:0; transform:translateY(12px) scale(.9); } to { opacity:1; transform:translateY(0) scale(1); } }
@keyframes toastOut { from { opacity:1; transform:translateY(0) scale(1); } to { opacity:0; transform:translateY(8px) scale(.95); } }

/* ============================================
   MODAL
   ============================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 40px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: scaleIn .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes scaleIn { from { transform:scale(.85); opacity:0; } to { transform:scale(1); opacity:1; } }

.modal-icon {
  width: 80px;
  height: 80px;
  background: #d1fae5;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: var(--success);
}
.modal h3 { font-size: 1.4rem; font-weight: 700; margin-bottom: 10px; }
.modal p { color: var(--text-2); margin-bottom: 28px; line-height: 1.6; }

.modal-close-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 28px;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.modal-close-btn:hover { background: var(--primary-dark); }

.modal-order-list {
  list-style: none;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 20px;
  text-align: left;
}

.modal-order-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.modal-order-item:last-child { border-bottom: none; }

.modal-order-title {
  font-size: .83rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  line-height: 1.3;
}

.modal-merchant-btn {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: .75rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition);
}
.modal-merchant-btn:hover { background: var(--primary-dark); }

.modal-no-link {
  font-size: .75rem;
  color: var(--text-3);
  flex-shrink: 0;
}

.cart-item-link {
  display: inline-block;
  margin-top: 5px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}
.cart-item-link:hover { text-decoration: underline; }

/* Cart merchant groups */
.cart-merchant-header {
  list-style: none;
  padding: 10px 24px 10px;
  background: var(--bg);
  border-top: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cart-merchant-header:first-child { border-top: none; }

.cart-merchant-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

.cart-merchant-name {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.cart-merchant-total {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text);
}

.cart-merchant-order-btn {
  width: 100%;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background var(--transition), color var(--transition);
}
.cart-merchant-order-btn:hover { background: var(--primary); color: #fff; }

/* ============================================
   NUTRI-SCORE
   ============================================ */
.nutriscore {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.product-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 0;
}

.product-grammage {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
}

.nutriscore-a { background: #038141; }
.nutriscore-b { background: #85bb2f; }
.nutriscore-c { background: #fecb02; color: #333; }
.nutriscore-d { background: #ee8100; }
.nutriscore-e { background: #e63312; }

/* ============================================
   HISTORY NAV LINK (header of index.html)
   ============================================ */
.history-nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.history-nav-link:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ============================================
   HISTORY PAGE
   ============================================ */
.history-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.history-page-inner { max-width: 1100px; margin: 0 auto; }

.history-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.history-page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.history-page-sub {
  font-size: .9rem;
  color: var(--text-2);
}

.history-clear-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.history-clear-btn:hover { border-color: var(--danger); color: var(--danger); background: #fff5f5; }

/* Scan entry card */
.scan-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.scan-entry-header {
  padding: 14px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
}

.scan-entry-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.scan-entry-date {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
}

.scan-entry-count {
  font-size: .82rem;
  color: var(--text-2);
  font-weight: 500;
}

.scan-entry-alert {
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 50px;
  background: #fee2e2;
  color: #991b1b;
}

/* Table */
.scan-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.products-table thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.products-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.products-table tbody tr:last-child { border-bottom: none; }
.products-table tbody tr:hover { background: var(--bg); }

.products-table td {
  padding: 12px 14px;
  vertical-align: middle;
}

/* Column: thumbnail */
.col-thumb { width: 72px; }
.pt-thumb { width: 72px; }

.scan-entry-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
  flex-shrink: 0;
}

.scan-entry-thumb--empty {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  flex-shrink: 0;
}

/* Column: name */
.col-name { min-width: 160px; }
.pt-name { font-size: .9rem; color: var(--text); }
.pt-name strong { font-weight: 600; }

/* Column: description */
.col-desc { min-width: 180px; }
.pt-desc { font-size: .83rem; color: var(--text-2); line-height: 1.45; }

/* Column: state */
.col-state { width: 90px; }
.pt-state { white-space: nowrap; }

/* Column: remaining % */
.col-pct { width: 90px; }
.pt-pct { font-size: .9rem; font-weight: 700; color: var(--text); text-align: center; }

/* Column: status dot */
.col-status { width: 64px; }
.pt-status { text-align: center; }

.status-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  vertical-align: middle;
}
.status-dot--green  { background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
.status-dot--orange { background: #f97316; box-shadow: 0 0 0 3px #ffedd5; }
.status-dot--red    { background: #ef4444; box-shadow: 0 0 0 3px #fee2e2; }
.status-dot--grey   { background: #94a3b8; box-shadow: 0 0 0 3px #f1f5f9; }

/* History nav: back link */
.history-nav { margin-left: auto; }

.history-back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.history-back-link:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

/* Empty state */
.history-empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.history-empty-state svg { color: var(--border); }
.history-empty-state p { font-size: 1rem; font-weight: 500; }

/* ============================================
   RESPONSIVE
   ============================================ */

/* Prevent any horizontal overflow at root level */
html, body { overflow-x: hidden; max-width: 100%; }

@media (max-width: 640px) {
  /* Header: two rows on mobile
     Row 1 → [Logo]  [Cart]
     Row 2 → [Search full-width]          */
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 16px;
    gap: 8px;
  }

  .logo { flex: 1; }
  .logo-tagline { display: none; }

  /* Cart stays right in row 1 */
  .cart-toggle { order: 2; }

  /* Search drops to row 2, full width */
  .search-form {
    order: 3;
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* Shorten the submit button text on small screens */
  .search-btn { padding: 10px 14px; font-size: .8rem; }

  /* History link: icon only on mobile */
  .history-nav-label { display: none; }
  .history-nav-link { padding: 8px 10px; }

  /* History page */
  .history-main { padding: 20px 12px 60px; }
  .history-page-title { font-size: 1.15rem; }
  .scan-entry-header { padding: 12px 14px; }
  .products-table thead th,
  .products-table td { padding: 10px 10px; }
  .col-desc, .pt-desc { display: none; } /* hide description column on mobile */

  /* Hero */
  .hero { padding: 36px 16px; }

  /* Main grid */
  .main { padding: 20px 12px 60px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .product-img-wrap { height: 140px; }

  /* Cart footer */
  .cart-footer { padding: 14px 16px; }

  /* Modals: full-width on mobile */
  .modal { padding: 32px 20px; width: 95%; }
  .scan-modal { max-width: 100%; width: 95%; }

  /* Scan item: stack price/controls on small screens */
  .scan-item { gap: 10px; padding: 12px 16px; }
  .scan-modal-header { padding: 16px; }
  .scan-footer { padding: 12px 16px 16px; }
  .scan-list { max-height: 50vh; }

  /* Cart sidebar full-width on mobile */
  .cart-sidebar { width: 100vw; }
}

@media (max-width: 400px) {
  .logo-name { font-size: 1rem; }
  .search-input { font-size: .85rem; }
  .product-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
