:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --muted: #5d6470;
  --border: #dde1e7;
  --accent: #e3350d;
  --ok: #117a3d;
  --ok-bg: #dcf3e5;
  --out: #6b7280;
  --out-bg: #eceef1;
  --warn: #9a5b00;
  --warn-bg: #fdf0d5;
  --danger: #b42318;
  --danger-bg: #fde7e5;
  --info: #3548c7;
  --info-bg: #e4e8fd;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaee;
    --muted: #9aa2ae;
    --border: #2a2f3a;
    --accent: #ff5a36;
    --ok: #5fd68f;
    --ok-bg: #173826;
    --out: #9aa2ae;
    --out-bg: #262a33;
    --warn: #f3b44b;
    --warn-bg: #3a2c10;
    --danger: #ff8a80;
    --danger-bg: #3d1a18;
    --info: #9fb0ff;
    --info-bg: #1f2548;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

a {
  color: inherit;
  text-underline-offset: 2px;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button,
a,
input,
select,
summary {
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    opacity 0.15s ease,
    transform 0.1s ease;
}

/* One consistent keyboard-focus ring everywhere, mouse/touch users never see it. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

.subtle {
  color: var(--muted);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, calc((100vw - 1280px) / 2));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 0;
  font-size: 0.85rem;
}

.logo {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--text);
  background: linear-gradient(var(--accent) 0 44%, var(--text) 44% 56%, var(--surface) 56%);
  position: relative;
  flex: none;
}

.logo::after {
  content: '';
  position: absolute;
  inset: 50% auto auto 50%;
  width: 9px;
  height: 9px;
  translate: -50% -50%;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--text);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 999px;
}

.tabs button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.tabs button:hover {
  color: var(--text);
}

.tabs button[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tabs button[aria-selected='true']:hover {
  color: var(--text);
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

.stores {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.store {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.store-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.store-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  text-decoration: none;
}

.store-name:hover {
  text-decoration: underline;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}

.dot.error {
  background: var(--danger);
}

.dot.pending {
  background: var(--warn);
}

.store-stats {
  font-size: 0.85rem;
}

.store-error {
  margin: 0;
  font-size: 0.8rem;
  color: var(--danger);
  overflow-wrap: anywhere;
}

.small-button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.small-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.small-button:active:not(:disabled) {
  transform: scale(0.96);
}

.small-button:disabled {
  cursor: progress;
  opacity: 0.7;
}

.small-button.active {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}

.small-button.active:hover:not(:disabled) {
  border-color: var(--ok);
  color: var(--ok);
  filter: brightness(0.92);
}

.small-button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.small-button.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border);
}

.watch-banner {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--ok-bg);
  border: 1px solid var(--ok);
  border-radius: var(--radius);
  color: var(--ok);
  font-size: 0.85rem;
  line-height: 1.5;
}

.watch-banner a {
  color: inherit;
  font-weight: 650;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field {
  flex: 1 1 240px;
  min-width: 160px;
}

.field-icon {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.search-field input[type='search'] {
  width: 100%;
  padding-left: 32px;
}

.filters input[type='search'],
.filters select {
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.filters input[type='search']:hover,
.filters select:hover {
  border-color: var(--muted);
}

/* Custom chevron so a themed select doesn't fall back to the browser's mismatched native arrow. */
.select-field select {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 1 auto;
  max-width: 100%;
  padding-right: 26px;
  cursor: pointer;
}

.select-field::after {
  content: '';
  position: absolute;
  right: 11px;
  top: 46%;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-50%) rotate(45deg);
  pointer-events: none;
}

/* A dropdown that is actually narrowing the list looks different from one left on its default. */
.select-field.is-active select {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 650;
}

.select-field.is-active::after {
  border-color: var(--accent);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.toggle:hover {
  background: var(--surface-2);
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.count {
  margin: 12px 2px;
  font-size: 0.9rem;
}

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition:
    box-shadow 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

/* The whole card is one click target (see .card-link) — this is the visible "you can click this" cue. */
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow:
    0 6px 18px rgb(16 24 40 / 12%),
    var(--shadow);
  transform: translateY(-2px);
}

.card:hover h3 {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.card.is-out .thumb img {
  opacity: 0.55;
  filter: grayscale(0.4);
}

.card.is-fresh {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px var(--ok), var(--shadow);
}

/* Stretched-link pattern: one invisible link fills the card so the whole thing is clickable and
   tappable, not just the title text. It sits at the bottom of the stacking order — the star
   button, the availability panel and its map links are given z-index so they stay independently
   clickable on top of it. */
.card-link {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.card-link:focus-visible {
  /* Negative offset keeps the ring inside .card's overflow:hidden instead of being clipped. */
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  border-radius: var(--radius);
}

.star-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.star-btn:hover {
  border-color: #f2b705;
  color: #f2b705;
  transform: scale(1.1);
}

.star-btn.active {
  color: #f2b705;
  border-color: #f2b705;
}

.badge.fresh {
  color: var(--ok);
  background: var(--ok-bg);
  animation: pulse 1.8s ease-in-out infinite;
}

.badge.units {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  font-weight: 750;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  .badge.fresh {
    animation: none;
  }
}

.maps-link {
  text-decoration: none;
  opacity: 0.75;
}

.maps-link:hover {
  opacity: 1;
}

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  max-width: 100%;
  overflow: hidden;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
}

.thumb .placeholder {
  color: #9aa2ae;
  font-size: 0.8rem;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px 12px;
  flex: 1;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.badge,
.chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  background: var(--ok-bg);
}

.badge.out {
  color: var(--out);
  background: var(--out-bg);
}

.badge.kind-RESTOCK {
  color: var(--ok);
  background: var(--ok-bg);
}

.badge.kind-NEW_PRODUCT {
  color: var(--info);
  background: var(--info-bg);
}

.badge.kind-PRICE_DROP {
  color: var(--warn);
  background: var(--warn-bg);
}

.badge.kind-SOLD_OUT {
  color: var(--out);
  background: var(--out-bg);
}

.chip {
  color: var(--muted);
  background: var(--surface-2);
}

.card h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.store-label {
  margin: 0;
  font-size: 0.85rem;
}

.card-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  font-size: 0.8rem;
}

.price {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.stock-detail {
  position: relative;
  z-index: 1; /* above .card-link, so the toggle and its map links stay independently clickable */
  margin-top: 2px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

.stock-detail summary {
  display: inline-flex;
  align-items: center;
  margin: -4px -6px;
  padding: 4px 6px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 650;
  list-style: none;
}

.stock-detail summary:hover {
  background: var(--surface-2);
}

.stock-detail summary::-webkit-details-marker {
  display: none;
}

.stock-detail summary::before {
  content: '▸';
  display: inline-block;
  width: 1em;
  color: var(--muted);
}

.stock-detail[open] summary::before {
  content: '▾';
}

.stock-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.stock-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  padding: 2px 0;
}

.stock-row.in {
  color: var(--ok);
  font-weight: 600;
}

.stock-row.in span.subtle {
  color: inherit;
}

.empty {
  grid-column: 1 / -1;
  padding: 40px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Placeholder cards shown for the instant before the first API response lands. */
.card.skeleton {
  pointer-events: none;
}

.card.skeleton:hover {
  transform: none;
  box-shadow: var(--shadow);
  border-color: var(--border);
}

.skel-block {
  display: block;
  background: var(--surface-2);
  border-radius: 6px;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip-button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.chip-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chip-button[aria-pressed='true'] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.chip-button[aria-pressed='true']:hover {
  color: var(--bg);
  border-color: var(--text);
  filter: brightness(1.15);
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.event {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.event:first-child {
  border-top: 0;
}

.event img,
.event .event-thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.event-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.event-main a {
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-main a:hover {
  text-decoration: underline;
}

.event-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.event time {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.event .empty {
  border: 0;
}

s {
  color: var(--muted);
}

@media (max-width: 520px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .event {
    grid-template-columns: 40px 1fr;
  }

  .event img,
  .event .event-thumb {
    width: 40px;
    height: 40px;
  }

  .event time {
    grid-column: 2;
  }
}
