/* Components. Every reusable piece the pages compose: button, input, chip, badge, card, price, sheet,
   skeleton, toast, empty and error states. Names are stable because pages reference them. */

/* ---------- Button ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 48px; padding: var(--sp-2) var(--sp-5);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 2px solid var(--primary); border-radius: var(--radius);
  background: var(--surface); color: var(--link);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.button:active:not(:disabled), .chip:active { transform: scale(.95); }
.button-primary { background: var(--primary); color: var(--on-primary); width: 100%; }
.button-primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--on-primary); }
.button:hover:not(:disabled) { border-color: var(--primary-hover); color: var(--link-hover); }
.button-ghost { border-color: transparent; background: transparent; color: var(--link); }
.button-ghost:hover:not(:disabled) { background: var(--ghost-hover-bg); border-color: transparent; }
.button-small { min-height: var(--tap); padding: var(--sp-1) var(--sp-3); font-size: var(--text-sm); }
.button:disabled { opacity: .6; cursor: progress; }
.row .button-primary { width: auto; }
@media (min-width: 40rem) { .button-primary { width: auto; } }

.link-action {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0;
  background: none; border: 0; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer;
}

/* ---------- Fields ---------- */
label { display: block; font-weight: 600; margin-bottom: .35rem; }
input[type="text"], input[type="search"], input[type="tel"], select {
  width: 100%; min-height: 48px; padding: var(--sp-2) var(--sp-3);
  font: inherit; color: var(--ink); background: var(--surface);
  border: 2px solid var(--line-strong); border-radius: 10px;
}
input:disabled { background: var(--surface-alt); color: var(--muted); border-color: var(--line); }
input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-weight: 600; font-size: var(--text-sm); margin: var(--sp-1) 0 0; }
.field-error:empty { display: none; }
.row { display: flex; gap: var(--sp-2); align-items: flex-start; }
.row input { flex: 1; min-width: 0; }

/* Search field: the scanner button lives inside it, so the field stays the primary action of the home. */
.search-field { position: relative; display: flex; align-items: center; }
.search-field input { padding-right: 3.25rem; }
.search-field .scan-button {
  position: absolute; right: var(--sp-1);
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 10px; background: transparent; color: var(--link);
  font-size: 1.25rem; cursor: pointer;
}
.search-field .scan-button:hover { background: var(--ghost-hover-bg); }

/* Camera preview inside the scanner sheet */
.scanner-video {
  width: 100%; aspect-ratio: 4 / 3; margin-top: var(--sp-2);
  background: #000; border-radius: var(--radius); object-fit: cover;
}

/* Autocomplete list */
.suggestions {
  list-style: none; margin: var(--sp-1) 0 0; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow-md); overflow: hidden;
}
.suggestions li { border-bottom: 1px solid var(--line); }
.suggestions li:last-child { border-bottom: 0; }
.suggestions button {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%;
  min-height: var(--tap); padding: var(--sp-2) var(--sp-3);
  background: none; border: 0; font: inherit; text-align: left; color: var(--ink); cursor: pointer;
}
.suggestions button:hover, .suggestions button[aria-selected="true"] { background: var(--surface-alt); }
.suggestions .suggestion-kind { margin-left: auto; color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; }

/* ---------- Chip ---------- */
.chip {
  min-height: var(--tap); padding: var(--sp-1) var(--sp-4);
  font: inherit; cursor: pointer; white-space: nowrap;
  border: 2px solid var(--primary); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--link);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
a.chip { display: inline-flex; align-items: center; text-decoration: none; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); font-weight: 700; }
.chip:hover:not([aria-pressed="true"]) { background: var(--ghost-hover-bg); }

/* Horizontal scroller used by the chip row: no scrollbar, snaps, and never clips the focus ring. */
.chip-row {
  display: flex; gap: var(--sp-2); overflow-x: auto; padding: var(--sp-1) 0 var(--sp-2);
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chip-row::-webkit-scrollbar { display: none; }

/* ---------- Icon (Lucide, stroke, currentColor) ---------- */
.icon {
  display: inline-block; width: 1.15em; height: 1.15em;
  vertical-align: -0.18em; flex: none;
  transition: color var(--dur-fast) var(--ease);
}
.icon-sm { width: 1rem; height: 1rem; vertical-align: -0.15em; }
.icon-lg { width: 1.5rem; height: 1.5rem; vertical-align: -0.25rem; }
.icon-xl { width: 2.25rem; height: 2.25rem; vertical-align: middle; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: var(--text-xs); font-weight: 700; padding: .1rem .55rem; border-radius: var(--radius-pill);
  border: 1px solid transparent;
}
.badge-best { background: var(--primary); color: var(--on-primary); }
.badge-sample { background: var(--sample-bg); color: var(--sample-ink); border-color: var(--warning-line); }
.badge-stale { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.badge-origin { background: var(--info-bg); color: var(--info-ink); }
.badge-fresh { background: var(--success-bg); color: var(--success); }
.badge-condition { background: var(--warning-bg); color: var(--warning-ink); border-color: var(--warning-line); }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: var(--sp-4); margin-bottom: var(--sp-4); box-shadow: var(--shadow-sm);
  /* Cards hold .visually-hidden text, which is position: absolute: without a positioned ancestor it anchors to the page. */
  position: relative;
}
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.market-list { list-style: none; margin: 0; padding: 0; }

/* ---------- Price ---------- */
.price-main { font-size: var(--text-lg); margin: var(--sp-1) 0; }
/* Price is the loudest element on the screen: bold, large, with tabular figures so values do not shift while scrolling. */
.price-amount {
  font-family: var(--font-numeric); font-variant-numeric: tabular-nums;
  font-size: var(--text-xl); font-weight: 800; letter-spacing: -.01em; color: var(--ink);
}
.price-unit { color: var(--muted); font-size: var(--text-sm); }
/* The headline price of a block (best price, search result): bigger and in the price colour; list rows keep the plain ink colour. */
.price-main .price-amount { font-size: var(--text-2xl); font-weight: 900; color: var(--text-price); }
.price-main .price-unit { font-size: var(--text-xs); font-weight: 500; }
.price-row-best { border: 2px solid var(--primary); }
.is-expired { opacity: .6; }

/* ---------- Product card ---------- */
.product-card .product-head { display: flex; justify-content: space-between; gap: var(--sp-3); align-items: baseline; }
.product-card p { margin: var(--sp-1) 0; }
.product-meta { display: flex; flex-wrap: wrap; gap: var(--sp-1); align-items: center; margin-top: var(--sp-2); }

/* ---------- Skeleton ---------- */
.skeleton {
  display: block; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--line) 37%, var(--surface-alt) 63%);
  background-size: 400% 100%; animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-line { height: .9rem; margin: var(--sp-2) 0; }
.skeleton-line:first-child { width: 60%; }
.skeleton-block { height: 3.5rem; margin-bottom: var(--sp-2); }
@keyframes skeleton-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Empty and error states ---------- */
.empty, .error-state { text-align: center; padding: var(--sp-6) var(--sp-4); }
.empty-icon { font-size: 2rem; display: block; margin-bottom: var(--sp-2); }
.error { color: var(--danger); font-weight: 600; }
.error[hidden] { display: none; }
.hint { color: var(--muted); font-size: var(--text-sm); margin: var(--sp-1) 0 0; }
.muted { color: var(--muted); }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: var(--z-sheet);
  background: var(--backdrop); border: 0; padding: 0;
  animation: fade-in var(--dur) var(--ease);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: calc(var(--z-sheet) + 1);
  max-height: 85vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg); animation: sheet-up var(--dur) var(--ease);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line);
}
.sheet-header h2 { margin: 0; font-size: var(--text-lg); }
.sheet-body { overflow-y: auto; padding: var(--sp-4); }
.sheet-footer { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line); display: flex; gap: var(--sp-2); }
.sheet-footer .button { flex: 1; }
.sheet-close {
  min-height: var(--tap); min-width: var(--tap); border: 0; background: transparent;
  font-size: 1.2rem; color: var(--muted); cursor: pointer; border-radius: var(--radius-sm);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed; left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--tap) + var(--sp-5));
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--page); border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-md); font-size: var(--text-sm);
  animation: fade-in var(--dur) var(--ease);
}
@media (min-width: 48rem) { .toast-host { left: auto; right: var(--sp-5); max-width: 22rem; } }

/* ---------- Radius picker and toggles ---------- */
.radius-picker { border: 0; padding: 0; margin: 0 0 var(--sp-3); display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.radius-picker legend { font-weight: 600; width: 100%; padding: 0; margin-bottom: var(--sp-1); }
.view-toggle { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.separator { text-align: center; color: var(--muted); margin: var(--sp-3) 0; }

/* Notification bell in the header: the badge sits on the icon and never widens the header. */
.bell { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); color: inherit; }
.bell-badge {
  position: absolute; top: 4px; right: 2px; min-width: 1.1rem; height: 1.1rem; padding: 0 .25rem;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--danger, #c62828); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700; line-height: 1;
}
.card.is-unread { border-left: 4px solid var(--primary); }

/* Offline notice: quiet, not alarming, and placed above the content so it is read before anything else. */
.offline-banner {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4); font-size: var(--text-sm);
  background: var(--warning-bg); color: var(--warning-ink); border-bottom: 1px solid var(--warning-line);
}

/* Read-only share text, big enough to select on a phone. */
.share-text {
  width: 100%; padding: var(--sp-3); font: inherit; color: var(--ink);
  background: var(--surface-alt); border: 1px solid var(--line); border-radius: var(--radius); resize: vertical;
}

/* ---------- Sparkline (price history) ---------- */
.sparkline { display: block; width: 100%; height: 64px; overflow: visible; }
.sparkline-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round;
  vector-effect: non-scaling-stroke; }
.sparkline-area { fill: var(--ghost-hover-bg); stroke: none; opacity: .9; }
.sparkline-dot { fill: var(--primary); }
.sparkline-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: var(--text-xs); }

/* ---------- Action bar (favourite, list, alert, share) ---------- */
.action-bar { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: var(--sp-3) 0; }
.action-bar .button { flex: 1 1 8rem; }
.icon-filled { fill: currentColor; }

/* ---------- Markets and map ---------- */
.market-card p { margin: var(--sp-1) 0; }
.market-head { display: flex; justify-content: space-between; gap: var(--sp-3); align-items: baseline; }
.distance { font-weight: 700; white-space: nowrap; color: var(--link); }
.map { height: 60vh; min-height: 320px; border: 1px solid var(--line); border-radius: var(--radius); }
@media (min-width: 40rem) { .map { height: 28rem; } }

/* ---------- Fixed filter bar above the bottom navigation ---------- */
.filter-bar {
  position: sticky; bottom: calc(var(--tap) + env(safe-area-inset-bottom, 0px)); z-index: 50;
  display: flex; gap: var(--sp-2); margin: 0 calc(var(--sp-4) * -1) var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  background: var(--page); border-top: 1px solid var(--line);
}
.filter-bar .button { flex: 1; }
.filter-bar .filter-count { background: var(--primary); color: var(--on-primary); border-radius: var(--radius-pill); padding: 0 .4rem; font-size: var(--text-xs); }
/* Long-form text pages (Privacy). Line length is capped for reading: a full-width paragraph on a wide screen is hard to follow. */
.prose { max-width: 68ch; }
.prose h1 { margin-bottom: var(--sp-2); }
.prose h2 { margin: var(--sp-5) 0 var(--sp-2); font-size: 1.15rem; }
.prose p, .prose li { line-height: 1.7; }
.prose ul { padding-left: var(--sp-4); display: grid; gap: var(--sp-1); }
.prose li { list-style: disc; }

/* Two text actions on one market card: stacked on a phone so neither wraps mid-phrase. */
.market-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
