:root {
  --green: #0a7d3c;
  --green-dark: #065c2b;
  --bg: #f6f7f5;
  --card: #ffffff;
  --border: #e2e5e0;
  --text: #1c1f1c;
  --muted: #6b7268;
  --warn: #c0392b;
  --gold: #d4a017;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-card input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.login-error {
  color: var(--warn);
  font-size: 13px;
  min-height: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--green);
  color: white;
  gap: 16px;
}

.account-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  white-space: nowrap;
}

.account-info button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: white;
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
}
.account-info button:hover { background: rgba(255,255,255,0.15); }

.brand { font-weight: 700; font-size: 20px; }

.tabs { display: flex; gap: 8px; }

.tab-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: white;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
}

.tab-btn.active { background: white; color: var(--green-dark); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2 { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; }

.toolbar input, .card > input, .card > label + input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

#search-input, #off-search-input { flex: 1; }
#category-select { padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; background: white; }

.toolbar button, .manual-form button, .primary-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.toolbar button:hover, .manual-form button:hover, .primary-btn:hover { background: var(--green-dark); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.product-card {
  background: #fbfcfb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.product-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-1px); }
.product-card h3 { margin: 0 0 4px; font-size: 15px; }
.product-card .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.product-card .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.product-card-top { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 6px; }
.product-card-info { min-width: 0; }
.product-card-info h3 { overflow-wrap: break-word; }

.product-thumb {
  width: 48px; height: 48px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}
.product-thumb.large { width: 96px; height: 96px; }
.product-thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--muted); background: #f0f2ee;
}
.product-thumb.large.placeholder { font-size: 36px; }

.barcode-line {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  margin-bottom: 6px;
}
.barcode-line a { color: var(--green-dark); }

.modal-header { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 10px; }

.list-item-identity { display: flex; gap: 10px; align-items: flex-start; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eef1ec;
  color: var(--muted);
}
.badge.nutriscore-a, .badge.nutriscore-b { background: #eaf7ee; color: var(--green-dark); }
.badge.nutriscore-d, .badge.nutriscore-e { background: #fbeaea; color: var(--warn); }
.badge.allergen { background: #fff4e0; color: #8a5a00; }

.product-card button {
  margin-top: 8px;
  width: 100%;
  padding: 7px;
  border: none;
  border-radius: 6px;
  background: var(--green);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.product-card button:hover { background: var(--green-dark); }

.manual-add { margin-top: 14px; }
.manual-add summary { cursor: pointer; color: var(--green-dark); font-weight: 600; }
.manual-form { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.manual-form input { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; flex: 1; min-width: 140px; }

.price-table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.price-table th, .price-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.price-table tr.cheapest-row { background: #eaf7ee; }

.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.users-table select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
.users-table button { border: none; border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 12px; margin-right: 4px; }
.users-table .deactivate-btn { background: #fbeaea; color: var(--warn); }
.users-table .activate-btn { background: #eaf7ee; color: var(--green-dark); }
.users-table .reset-btn { background: #eef1ec; color: var(--muted); }
.role-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #eef1ec; }
.role-badge.admin { background: #fff4e0; color: #8a5a00; }
.status-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.status-badge.active { background: #eaf7ee; color: var(--green-dark); }
.status-badge.inactive { background: #fbeaea; color: var(--warn); }

.price-log-form { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.price-log-form input, .price-log-form select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }

.list-items { display: flex; flex-direction: column; gap: 12px; }

.list-item {
  background: #fbfcfb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.list-item-top { display: flex; align-items: flex-start; justify-content: space-between; }
.list-item .name { font-weight: 600; }
.list-item .sub { color: var(--muted); font-size: 13px; }
.list-item .pin-badge { background: var(--gold); color: white; font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 6px; }

.list-item button.remove-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--warn);
}

.score-bars { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.score-bar-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.score-bar-label { width: 90px; color: var(--muted); }
.score-bar-track { flex: 1; background: #e9ece8; border-radius: 4px; height: 10px; overflow: hidden; }
.score-bar-fill { height: 100%; }
.score-bar-fill.price { background: var(--green); }
.score-bar-fill.intolerance { background: var(--warn); }
.score-bar-fill.health { background: #2e6fbb; }
.score-bar-value { width: 34px; text-align: right; color: var(--muted); }

.treat-note { font-size: 12px; color: var(--gold); margin-top: 6px; }
.flagged-note { font-size: 12px; color: var(--warn); margin-top: 6px; }

.checkbox-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 14px; }

.swap-suggestions { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.swap-card {
  background: #fff8e6;
  border: 1px solid #f0dca0;
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.swap-card .reason { color: var(--muted); font-size: 12px; }
.swap-card .swap-actions { display: flex; gap: 6px; }
.swap-card button {
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
}
.swap-card .dismiss-btn { background: #eee; color: var(--muted); }

.baseline-suggestions { display: flex; flex-direction: column; gap: 8px; }
.baseline-card {
  display: flex; align-items: center; gap: 10px;
  background: #fbfcfb; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
.baseline-info { flex: 1; min-width: 0; }
.baseline-info .name { font-weight: 600; font-size: 13px; }
.baseline-info .sub { color: var(--muted); font-size: 12px; font-weight: 400; }
.baseline-add-btn {
  border: none; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  background: var(--green); color: white; font-weight: 600; font-size: 12px;
}
.baseline-add-btn:hover { background: var(--green-dark); }

.basket-comparison { display: flex; flex-direction: column; gap: 8px; }
.basket-row { display: flex; align-items: center; gap: 12px; }
.basket-row .retailer-name { width: 110px; font-weight: 600; }
.basket-row .bar-track { flex: 1; background: #e9ece8; border-radius: 6px; height: 22px; overflow: hidden; }
.basket-row .bar-fill { height: 100%; background: var(--green); }
.basket-row.cheapest .bar-fill { background: var(--gold); }
.basket-row .total { width: 140px; text-align: right; font-weight: 700; }
.basket-row.cheapest .retailer-name::after { content: " 🏆"; }

/* Profile tab */
#tab-profile label { display: block; margin: 10px 0 4px; font-size: 13px; font-weight: 600; }
#tab-profile input[type="text"], #tab-profile input[type="number"] {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px;
}
.checkbox-label { display: flex !important; align-items: center; gap: 8px; font-weight: 400 !important; }
.checkbox-label input { width: auto !important; }

#sensitivity-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.sensitivity-row {
  display: flex; justify-content: space-between; align-items: center;
  background: #fbfcfb; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font-size: 13px;
}
.sensitivity-row button { background: none; border: none; color: var(--warn); cursor: pointer; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-overlay.hidden { display: none; }
.modal { background: white; border-radius: 12px; padding: 24px; max-width: 640px; width: 90%; max-height: 85vh; overflow-y: auto; position: relative; }
.modal-close { position: absolute; top: 12px; right: 16px; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); }

.empty-state { color: var(--muted); padding: 20px; text-align: center; }

canvas#history-chart { max-height: 220px; }
