:root {
  font-family: system-ui, sans-serif;
  color: #202124;
  background: #fff;
  --border: #ddd;
  --muted: #595959;
}

* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 1220px; margin: auto; padding: 24px; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none; }

:focus-visible {
  outline: 2px solid #245ea5;
  outline-offset: 3px;
}

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

select, #load-more, .copy-sku, .dialog-close {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  min-height: 44px;
}

select { max-width: 100%; }
#result-count { margin: 0; color: var(--muted); font-size: .875rem; }

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

.product {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  background: #fff;
}

.product:hover { border-color: #999; }

.product-photo, .dialog-photo {
  display: grid;
  place-items: center;
  width: 100%;
  position: relative;
  background: #f7f7f7;
}

.product-photo { aspect-ratio: 4 / 3; border-radius: 5px 5px 0 0; overflow: hidden; }
.product-photo img, .dialog-photo img { width: 100%; height: 100%; object-fit: contain; }
.product-photo img { position: absolute; inset: 0; }
.placeholder, .photo-label { color: var(--muted); font-size: .75rem; }
.photo-label { position: absolute; bottom: 6px; left: 6px; background: #fff; padding: 2px 5px; border-radius: 3px; }

.product-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 12px;
  gap: 6px;
}

.product-name { font-size: .875rem; line-height: 1.4; overflow-wrap: anywhere; }
.sku, .quantity { color: var(--muted); font-size: .8125rem; }
.price { font-weight: 700; line-height: 1.35; }
.price small { font-size: .75rem; font-weight: 400; white-space: nowrap; }

.product-bottom {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: auto;
  padding-top: 6px;
}

#load-more { display: block; margin: 20px auto 0; }
#load-more[hidden] { display: none; }
footer { margin-top: 24px; color: var(--muted); font-size: .8125rem; line-height: 1.5; }

dialog {
  width: min(680px, calc(100% - 24px));
  max-height: 90dvh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
}

dialog::backdrop { background: #0006; }
.dialog-close { position: absolute; top: 8px; right: 8px; z-index: 1; font-size: 1.25rem; }
.dialog-layout { display: grid; grid-template-columns: 1fr 1fr; }
.dialog-photo { min-height: 240px; }
.dialog-photo img { max-height: 300px; }
.dialog-info { padding: 56px 18px 18px; }
.dialog-info h2 { margin: 6px 0 12px; font-size: 1.125rem; line-height: 1.4; }
.dialog-info p { margin: 8px 0; }
.dialog-info .price { margin-top: 16px; font-size: 1.25rem; }
.dialog-note { color: var(--muted); font-size: .875rem; line-height: 1.5; }
.copy-sku { font-size: .8125rem; }

@media (max-width: 540px) {
  main { padding: 12px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .product-body { padding: 8px; }
  .dialog-layout { grid-template-columns: 1fr; }
  .dialog-photo { min-height: 180px; }
  .dialog-photo img { max-height: 230px; }
  .dialog-info { padding: 16px; }
}
