/* The shared product page — /products/<slug> and the admin's preview of it.
 *
 * One column on a phone, in the page's source order (photos, title, price,
 * form, description, reviews). From 900px the photos and the buying column sit
 * side by side, and everything from the description down returns to one
 * column at reading width. Every value is a token from tokens.css
 * (css-tokens.test.ts holds that line).
 *
 * Phone first. At 375px nothing here may be wider than the viewport: images
 * are `max-width: 100%`, long words break (`overflow-wrap: anywhere`), and
 * the gallery's thumbnails are a grid, never a row that scrolls the page.
 */

/* The site's `main` keeps a 24px gutter; on a phone this page uses 16px, so a
   photo gets the width it needs and the form its full touch targets. */
@media (max-width: 599px) {
  main:has(> .product-page),
  main:has(> .product-preview-bar) {
    padding-inline: var(--space-md);
  }
}

.product-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  min-width: 0;
}

.product-page img {
  max-width: 100%;
  height: auto;
}

/* ---- Hero: photos beside the buying column ------------------------------- */

.product-page__hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-xl);
  align-items: start;
}

@media (min-width: 900px) {
  .product-page__hero {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: var(--space-2xl);
  }

  /* No photos, no gallery (ProductGallery renders nothing): the buying
     column takes the row at reading width instead of half of it. */
  .product-page__buy:first-child {
    grid-column: 1 / -1;
    max-width: var(--measure);
  }
}

.product-gallery {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

.product-gallery__main {
  margin: 0;
  background: var(--paper-2);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.product-gallery__main img,
.product-gallery__more img {
  display: block;
  width: 100%;
  height: auto;
}

.product-gallery__more {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
}

@media (min-width: 900px) {
  .product-gallery__more {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.product-gallery__more li {
  background: var(--paper-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.product-gallery__thumb {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  outline: 2px solid transparent;
  outline-offset: -2px;
}

.product-gallery__thumb[aria-current='true'] {
  outline-color: var(--accent);
}

.product-gallery__thumb:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.product-page__buy {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
}

.product-page__buy > * {
  margin: 0;
}

.product-page__title {
  font-size: clamp(1.9rem, 1.35rem + 2.2vw, 2.9rem);
}

.product-page__summary {
  color: var(--ink-2);
  font-size: var(--text-md);
  line-height: 1.55;
}

.product-page__price {
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
}

.product-page__bulk {
  font-size: var(--text-base);
  color: var(--ink-2);
}

/* ---- Notices --------------------------------------------------------------
   Where the form would be when there is nothing to buy: archived, not on sale
   yet, or a photo-upload product. Text on a sunken surface, never colour
   alone. */

.product-notice {
  margin: 0;
  padding: var(--space-md);
  background: var(--paper-2);
  border-radius: var(--radius-md);
  color: var(--ink-2);
}

.product-notice--archived {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-sm);
}

.product-notice--archived p {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
}

/* ---- The options form (islands/OptionsBuyForm.tsx) ------------------------
   Plain stacked fields. Each label sits above its control so a long label
   wraps rather than squeezing the input, and every control is at least 44px
   tall: the touch floor the site's buttons use. 16px text in the inputs,
   because anything smaller makes iOS Safari zoom on focus. */

.options-buy {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
}

.options-buy__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

/* `:not(.options-buy__choice)`: a choice row is also a label directly inside
   its fieldset, and without the exclusion this rule (0,2,1 against the
   choice's 0,1,0) would strip its padding and set every answer in bold. */
.options-buy__field > label:not(.options-buy__choice),
.options-buy__field > legend {
  padding: 0;
  font-weight: 600;
  color: var(--ink);
}

.options-buy__field input[type='text'],
.options-buy__field input[type='number'],
.options-buy__field textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  font-size: var(--text-base);
  background: var(--paper-3);
  color: var(--ink);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.options-buy__field input[type='number'] {
  width: 7rem;
  font-variant-numeric: tabular-nums;
}

.options-buy__field textarea {
  resize: vertical;
}

.options-buy__field input:hover:not(:disabled),
.options-buy__field textarea:hover:not(:disabled) {
  border-color: var(--ink-3);
}

.options-buy__field input:focus-visible,
.options-buy__field textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.options-buy__field [aria-invalid='true'] {
  border-color: var(--danger);
}

/* A choice group carries `aria-invalid` on the fieldset itself, which has no
   border to colour, so it is marked with a rule down its left edge instead.
   The alert below the button names the field as well: colour is never the
   only signal. */
.options-buy__field[aria-invalid='true'] {
  border-left: 3px solid var(--danger);
  padding-left: var(--space-sm);
}

.options-buy__field input:disabled,
.options-buy__field textarea:disabled {
  background: var(--paper-2);
  color: var(--ink-3);
  cursor: not-allowed;
}

.options-buy__field small {
  color: var(--ink-3);
  font-size: var(--text-sm);
}

.options-buy__choice {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: 0 var(--space-sm);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-3);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.options-buy__choice + .options-buy__choice {
  margin-top: var(--space-2xs);
}

.options-buy__choice:has(input:checked) {
  border-color: var(--ink);
}

fieldset:disabled .options-buy__choice {
  color: var(--ink-3);
  cursor: not-allowed;
}

.options-buy__choice input {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  accent-color: var(--ink);
}

/* A filament colour field: the keychain designer's swatch row (`.swatches`,
   from configurator.css, which this page loads for such a product), under a
   legend that names the pick. The swatches bring their own spacing and 44px
   hit areas; this only gives the row room below the legend, since a swatch's
   hit area reaches 6px past its disc. */
.options-buy__colour .swatches {
  padding: var(--space-2xs) 0;
}

/* The picked colour's name, beside the label: read as the answer, not as more
   of the question. */
.options-buy__colour-name {
  font-weight: 400;
  color: var(--ink-2);
}

/* Clearing an optional colour: a quiet text button, at the touch floor. */
.options-buy__clear {
  align-self: flex-start;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--text-sm);
  text-decoration: underline;
  cursor: pointer;
}

.options-buy__clear:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.options-buy__price {
  margin: 0;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.options-buy__amount {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--ink);
}

/* The page's one primary action, in the site's button voice (global.css
   `.btn--primary`), written out because the island's markup carries its own
   class rather than the shared one. Full width on a phone. */
.options-buy__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition:
    background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}

.options-buy__cta:hover:not(:disabled) {
  background: var(--accent-deep);
  box-shadow: var(--shadow-md);
}

.options-buy__cta:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.options-buy__cta:disabled {
  background: var(--paper-2);
  color: var(--ink-3);
  border-color: var(--line-strong);
  box-shadow: none;
  cursor: not-allowed;
}

@media (max-width: 599px) {
  .options-buy__cta {
    width: 100%;
  }
}

@media (min-width: 600px) {
  .options-buy__cta {
    align-self: flex-start;
  }
}

.options-buy__note {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.options-buy__error {
  padding: var(--space-sm) var(--space-md);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  color: var(--danger);
}

/* ---- Description and details --------------------------------------------- */

.product-page__about {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  max-width: var(--measure);
  min-width: 0;
}

.rich-text {
  overflow-wrap: anywhere;
}

.rich-text > :first-child {
  margin-top: 0;
}

.rich-text h2 {
  margin-top: var(--space-xl);
}

.rich-text h3 {
  margin-top: var(--space-lg);
}

.rich-text ul {
  padding-left: var(--space-lg);
}

.rich-text li + li {
  margin-top: var(--space-2xs);
}

.product-details dl {
  margin: 0;
  border-top: 1px solid var(--line);
}

.product-details__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3xs);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--line);
}

@media (min-width: 600px) {
  .product-details__row {
    grid-template-columns: minmax(0, 12rem) minmax(0, 1fr);
    gap: var(--space-md);
  }
}

.product-details dt {
  color: var(--ink-3);
  font-size: var(--text-sm);
}

.product-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---- The admin preview's bar --------------------------------------------- */

.product-preview-bar {
  margin: 0 0 var(--space-lg);
  padding: var(--space-sm) var(--space-md);
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.product-preview-bar p {
  margin: 0;
  max-width: none;
}

.product-preview-bar p + p {
  margin-top: var(--space-2xs);
}

@media (prefers-reduced-motion: reduce) {
  .options-buy__field input,
  .options-buy__field textarea,
  .options-buy__cta {
    transition: none;
  }
}
