/* Reusable pieces: cards, buttons, inputs, chips, states. */

/* ---------- product card ----------
   Dense: small radius, hairline border instead of a drop shadow, and the
   photo carries the weight. Shadow only appears on hover, so a grid of 48
   stays flat and quiet while scrolling. */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease),
              transform var(--duration) var(--ease);
}
.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-hover);
}
@media (hover: hover) {
  .card:hover { transform: translateY(-2px); }
}
.card:focus-within { box-shadow: var(--focus-ring); }

.card__link {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.card__link:hover { text-decoration: none; }

.card__media {
  position: relative;
  /* Reserving the square stops the grid reflowing as photos arrive. */
  aspect-ratio: 1 / 1;
  background: var(--thumb-bg);
}
.card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* A photo that fails to load leaves the tile grey rather than showing a
   broken-image glyph 48 times over. */
.card__img[alt]::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--thumb-bg);
}

.card__count,
.card__badge {
  position: absolute;
  bottom: var(--space-2);
  left: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.66);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}
.card__badge--hidden {
  bottom: auto;
  top: var(--space-2);
  background: var(--warning);
}

.card__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3);
}

.card__brand {
  color: var(--ink-faint);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.card__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  /* Two lines then ellipsis, so cards in a row stay the same height. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__price {
  margin-top: var(--space-1);
  color: var(--price);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}
.card__price--ask {
  color: var(--ink-faint);
  font-weight: var(--weight-normal);
}

.card--hidden { opacity: 0.62; }

.card__save {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 15px;
  line-height: 1;
  transition: transform var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.card__save:hover { transform: scale(1.1); background: #fff; }
.card__save.is-saved { color: var(--danger); }
:root[data-theme="dark"] .card__save { background: rgba(20, 30, 50, 0.86); }
:root[data-theme="dark"] .card__save:hover { background: rgba(20, 30, 50, 1); }

/* ---------- tiles (sections and brands) ---------- */

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow-hover); text-decoration: none; }
.tile__media { aspect-ratio: 4 / 3; background: var(--thumb-bg); }
.tile__img { width: 100%; height: 100%; object-fit: cover; }
.tile__body { padding: var(--space-3); }
.tile__name { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.tile__meta { margin-top: 2px; color: var(--ink-faint); font-size: var(--text-xs); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: center;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); }

.btn--ghost { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn--quiet { background: transparent; color: var(--ink-soft); }
.btn--quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn--icon { min-height: 36px; width: 36px; padding: 0; border-radius: var(--radius-full); }

.btn--block { width: 100%; }

/* ---------- inputs ---------- */

.field {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.field:focus-visible { border-color: var(--accent-strong); }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search__input { padding-left: var(--space-6); }
.search__icon {
  position: absolute;
  left: var(--space-3);
  color: var(--ink-faint);
  pointer-events: none;
}

/* ---------- chips (filters) ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}
.chips--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: var(--space-1);
  scrollbar-width: none;
}
.chips--scroll::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.chip__count { opacity: 0.65; font-variant-numeric: tabular-nums; }

/* Filter bar stays reachable with a thumb on a long grid. */
.filterbar {
  position: sticky;
  top: 56px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-block: var(--space-2);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.filterbar__sort { margin-left: auto; flex: 0 0 auto; }

/* ---------- states ---------- */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  text-align: center;
}
.state__code {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--ink-faint);
  letter-spacing: var(--tracking-tight);
}
.state__title { font-size: var(--text-lg); }
.state__body { max-width: 46ch; color: var(--ink-soft); }
.state__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: center; }
.state--error .state__title { color: var(--danger); }

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* ---------- price block on the product page ---------- */

.price {
  color: var(--price);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}
.price--ask { color: var(--ink-soft); font-size: var(--text-lg); }

/* A set the supplier priced per piece: both prices, clearly separate, so
   nobody reads one number and assumes it covers the pair. */
.pieces {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--price-soft);
}
.pieces__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
}
.pieces__label { color: var(--ink-soft); font-size: var(--text-sm); }
.pieces__price {
  color: var(--price);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}
.pieces__note {
  margin-top: var(--space-1);
  color: var(--ink-faint);
  font-size: var(--text-xs);
}

/* ---------- misc ---------- */

.tag {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: var(--text-xs);
}

.notice {
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: var(--text-sm);
}

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: rgba(8, 12, 20, 0.94);
}

.lightbox__figure {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  min-width: 0;
}

.lightbox__img {
  max-width: 100%;
  /* Leaves room for the caption without the image ever overflowing. */
  max-height: calc(100vh - var(--space-8) - var(--space-6));
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox__caption {
  color: rgba(255, 255, 255, 0.75);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.lightbox__nav,
.lightbox__close {
  display: grid;
  place-items: center;
  width: 44px;              /* 44px is the minimum comfortable touch target */
  height: 44px;
  border: 0;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}
.lightbox__nav:hover,
.lightbox__close:hover { background: rgba(255, 255, 255, 0.24); }
.lightbox__nav[hidden] { visibility: hidden; display: grid; }

.lightbox__nav--prev { grid-column: 1; }
.lightbox__nav--next { grid-column: 3; }

.lightbox__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 1;
}

@media (max-width: 600px) {
  .lightbox { padding: var(--space-2); gap: var(--space-1); }
  .lightbox__nav, .lightbox__close { width: 40px; height: 40px; }
}
