:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #767672;
  --border: #e6e6e2;
  --accent: #2563eb;
}

* {
  box-sizing: border-box;
}

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

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  margin: 0;
}

.page-header span {
  color: var(--muted);
  font-size: 14px;
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.card:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.card-image {
  aspect-ratio: 1 / 1;
  background: #ffffff;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-image img {
  width: 100%;
  height: 100%;
  /* Show the whole product photo — shops crop to different aspect ratios. */
  object-fit: contain;
}

.card-image .placeholder {
  color: var(--muted);
  font-size: 13px;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
}

.card-price {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}

.card-site {
  font-size: 12px;
  color: var(--muted);
}

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

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.chips--sub {
  margin-top: -12px;
}

.chip {
  flex: none;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.chip--active {
  background: var(--text);
  border-color: var(--text);
  color: var(--card);
}

.chip-count {
  color: var(--muted);
  font-size: 12px;
}

.chip--active .chip-count {
  color: inherit;
  opacity: 0.7;
}

.section + .section {
  margin-top: 40px;
}

.section h2 {
  font-size: 18px;
  margin: 0 0 16px;
}

.section h2 a {
  color: inherit;
  text-decoration: none;
}

.subsection + .subsection {
  margin-top: 28px;
}

.subsection h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
}

.section-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.section-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 16px 0;
}

@media (max-width: 560px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

/* Cards are buttons now (they open the details dialog). */
button.card {
  width: 100%;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  overflow-y: auto;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.dialog-close {
  position: sticky;
  top: 8px;
  float: right;
  margin: 8px 8px -48px 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.dialog-image {
  aspect-ratio: 1 / 1;
  max-height: 60dvh;
  width: 100%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.dialog-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.dialog-body {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--border);
}

.dialog-title {
  font-size: 18px;
  line-height: 1.3;
  margin: 0;
}

.dialog-price {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
}

.dialog-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 14px;
}

.dialog-meta dt {
  color: var(--muted);
}

.dialog-meta dd {
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
}

.btn--primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--card);
}

/* Photo carousel in the item dialog: swipe via scroll-snap, arrows + dots. */
.gallery {
  position: relative;
  background: #ffffff;
}

.gallery-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

.gallery-track::-webkit-scrollbar {
  display: none;
}

.gallery-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  aspect-ratio: 1 / 1;
  max-height: 60dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.gallery-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.gallery-nav--prev {
  left: 8px;
}

.gallery-nav--next {
  right: 8px;
}

.gallery-dots {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.gallery-dot {
  width: 7px;
  height: 7px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.gallery-dot.is-active {
  background: rgba(0, 0, 0, 0.65);
}
