/* components.css — Buttons, forms, cards, badges, flash messages */

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: var(--leading-normal);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--color-primary-hover);
}

.btn--dark {
  background: var(--gray-900);
  color: #fff;
}

.btn--dark:hover {
  background: var(--gray-700);
}

.btn--outline {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}

.btn--outline:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.btn--danger-outline {
  background: var(--color-bg);
  color: var(--red-500);
  border-color: var(--red-100);
}

.btn--danger-outline:hover {
  color: var(--red-700);
  border-color: var(--red-500);
}

.btn--ghost {
  background: none;
  color: var(--color-text-secondary);
  padding: var(--space-1) var(--space-3);
}

.btn--ghost:hover {
  color: var(--color-text);
  background: var(--color-bg-alt);
}

.btn--small {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
}

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

.btn--lg {
  padding: var(--space-3) var(--space-5);
}

.btn--success {
  background: var(--green-600);
  color: #fff;
}

.btn--success:hover {
  background: var(--green-700);
}

.btn--danger {
  color: var(--red-600);
}

.btn--danger:hover {
  color: var(--red-800);
}

.btn--accent {
  background: var(--color-accent, var(--color-primary));
  color: #fff;
}

.btn--accent:hover {
  background: var(--color-accent-hover, var(--color-primary-hover));
}

.btn--disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
  text-align: center;
}

/* A button that is working: Turbo disables real submit buttons while a form
   submits; the file-picker labels (which can't be :disabled) get aria-busy
   from auto_submit_controller. Both wear the same muted, unclickable look. */
.btn:disabled,
.btn[aria-busy="true"] {
  opacity: 0.65;
  cursor: not-allowed;
  pointer-events: none;
}


/* ---- Cards ---- */

.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.card--padded {
  padding: var(--space-5);
}

.card--form {
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border-light);
}

.card-header h2 {
  font-size: var(--text-sm);
  font-weight: 600;
}

.card-body {
  padding: var(--space-5);
}

.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border-light);
}


/* ---- Data List (divided rows) ---- */

.data-list > * + * {
  border-top: 1px solid var(--color-border-light);
}

.data-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
}

.data-row--top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
}


/* ---- Badges ---- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
}

.badge--pending {
  background: var(--yellow-100);
  color: var(--yellow-800);
}

.badge--success {
  background: var(--green-100);
  color: var(--green-800);
}

.badge--danger {
  background: var(--red-100);
  color: var(--red-800);
}

.badge--info {
  background: var(--blue-100);
  color: var(--blue-800);
}

.badge--warning {
  background-color: var(--amber-100, #fef3c7);
  color: var(--amber-800, #92400e);
}

.badge--neutral {
  background: var(--gray-100);
  color: var(--gray-500);
}

.badge--default {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge--featured {
  background: var(--yellow-50);
  color: var(--yellow-700);
}

.badge--sale {
  background: var(--red-50);
  color: var(--red-600);
}


/* ---- Flash Messages ---- */

.flash {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-sm);
  border-bottom: 1px solid transparent;
}

.flash--notice {
  background: var(--green-50);
  color: var(--green-800);
  border-color: var(--green-100);
}

.flash--alert {
  background: var(--red-50);
  color: var(--red-800);
  border-color: var(--red-100);
}

.flash--floating {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 50;
  border-radius: var(--radius-lg);
  border: 1px solid;
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) var(--space-4);
}

.flash-dismiss {
  margin-left: var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.7;
}

.flash-dismiss:hover {
  opacity: 1;
}


/* ---- Forms ---- */

.field {
  margin-bottom: var(--space-4);
}

.field:last-child {
  margin-bottom: 0;
}

.field label,
label.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--space-1);
}

.field-hint {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

input[type="number"].input-narrow {
  width: 5rem;
}

input[type="number"].input-center {
  text-align: center;
  width: 4rem;
}

input[type="file"] {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--color-primary);
}

.field-row {
  display: grid;
  gap: var(--space-4);
}

.field-row-2 { grid-template-columns: repeat(2, 1fr); }
.field-row-3 { grid-template-columns: repeat(3, 1fr); }
.field-row-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 639px) {
  .field-row-2,
  .field-row-3,
  .field-row-4 {
    grid-template-columns: 1fr;
  }

  /* iOS Safari auto-zooms focused fields below 16px computed font-size */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    font-size: var(--text-base);
  }
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--gray-700);
}

.radio-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--gray-700);
}

.radio-option + .radio-option {
  margin-top: var(--space-2);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.error-box {
  background: var(--red-50);
  border: 1px solid var(--red-100);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--red-700);
  margin-bottom: var(--space-4);
}

.error-box:last-child {
  margin-bottom: 0;
}

.error-box ul {
  list-style: disc;
  padding-left: var(--space-5);
}

.error-box li + li {
  margin-top: var(--space-1);
}


/* ---- Form Section (grouped fields) ---- */

.form-section {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.form-section h2 {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-4);
}

.form-section .field:last-child {
  margin-bottom: 0;
}

details.form-section {
  cursor: default;
}

details.form-section > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

details.form-section > summary::-webkit-details-marker { display: none; }

details.form-section > summary::before {
  content: "▶";
  font-size: 1rem;
  transition: transform 0.15s;
}

details.form-section[open] > summary::before {
  transform: rotate(90deg);
}

details.form-section > summary h2 {
  margin-bottom: 0;
}

details.form-section > .stack--tight {
  margin-top: var(--space-4);
}


/* ---- Pills (filter chips) ---- */

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* One-line, side-scrolling chip row — long category/brand lists must not
   stack into a wall that pushes the content below the fold. */
.pills--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: var(--space-1);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.pills--scroll::-webkit-scrollbar {
  display: none;
}

.pills--scroll .pill {
  flex-shrink: 0;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.pill:hover {
  background: var(--color-bg-alt);
}

.pill.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}


/* ---- Definition List ---- */

.dl-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
}

.dl-row + .dl-row {
  margin-top: var(--space-1);
}

.dl-row dt {
  color: var(--color-text-secondary);
}

.dl-row dd {
  font-weight: 500;
  text-align: right;
}

.dl-row--bold {
  font-weight: 700;
  padding-top: var(--space-1);
  border-top: 1px solid var(--color-border-light);
}


/* ---- Summary Row ---- */

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.summary-row + .summary-row {
  margin-top: var(--space-1);
}

.summary-total {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
  padding-top: var(--space-1);
  border-top: 1px solid var(--color-border-light);
}


/* ---- Thumbnail gallery ---- */

.thumb-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.thumb-gallery__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.thumb-gallery__preview {
  position: relative;
  display: block;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
  border-radius: var(--radius-lg);
}

.thumb-gallery__preview:hover img {
  border-color: var(--color-primary);
}

.thumb-gallery__preview:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.thumb-gallery__expand {
  position: absolute;
  right: 0.25rem;
  bottom: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-sm);
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  pointer-events: none;
}

.thumb-gallery__preview img {
  width: 5rem;
  height: 5rem;
  object-fit: cover;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.thumb-gallery__remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.thumb-gallery__remove:hover {
  color: var(--red-600);
  border-color: var(--red-300);
  background: var(--red-50);
}

.thumb-gallery__hint {
  flex-basis: 100%;
  margin: 0;
}

.thumb-gallery__item .cp-photo-source {
  flex-basis: 100%;
  margin: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--color-text-muted);
}


/* ---- Product photo lightbox (store PDP + admin) ---- */

.product-gallery-lightbox {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  padding: 0;
  border: none;
  background: transparent;
}

.product-gallery-lightbox:modal {
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0;
}

.product-gallery-lightbox::backdrop {
  background: rgb(0 0 0 / 0.92);
}

.product-gallery-lightbox-inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-gallery-lightbox-btn {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: rgb(255 255 255 / 0.15);
  color: #fff;
  cursor: pointer;
}

.product-gallery-lightbox-btn:hover {
  background: rgb(255 255 255 / 0.25);
}

.product-gallery-lightbox-close {
  top: var(--space-4);
  right: var(--space-4);
  width: 2.5rem;
  height: 2.5rem;
}

.product-gallery-lightbox-counter {
  position: absolute;
  top: var(--space-4);
  left: 50%;
  translate: -50% 0;
  z-index: 2;
  font-size: var(--text-sm);
  font-weight: 500;
  color: #fff;
}

.product-gallery-lightbox-arrow {
  top: 50%;
  translate: 0 -50%;
  width: 2.75rem;
  height: 2.75rem;
}

.product-gallery-lightbox-arrow--prev {
  left: var(--space-4);
}

.product-gallery-lightbox-arrow--next {
  right: var(--space-4);
}

.product-gallery-lightbox-scroll {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  width: 100%;
  height: 100%;
}

.product-gallery-lightbox-scroll::-webkit-scrollbar {
  display: none;
}

.product-gallery-lightbox-slide {
  flex: 0 0 100%;
  min-width: 0;
  scroll-snap-align: start;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
}

.product-gallery-lightbox-image {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  /* Inline background-image uses the 600px gallery variant while full-size loads. */
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
}

/* Admin edit only — room for the per-slide delete link below the image. */
.product-gallery-lightbox--editable .product-gallery-lightbox-slide {
  flex-direction: column;
  height: 100%;
}

.product-gallery-lightbox--editable .product-gallery-lightbox-image {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
}

.product-gallery-lightbox-delete {
  margin-top: var(--space-4);
  flex-shrink: 0;
}

.photos-inputs {
  display: grid;
  gap: var(--space-4);
}

/* Tiles: the edit page's photo sources (upload / catalog / brand site) and the
   new page's import options are the same card — an equal-width auto-fit grid
   that wraps to a column on narrow screens. The grid and card chrome are shared
   here; each context sets only its own gap and inner layout. */
.photo-sources,
.import-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.photo-sources { gap: var(--space-3); }
.import-options { gap: var(--space-4); }

.photo-sources > .field,
.import-option {
  padding: var(--space-3);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  background: var(--gray-50);
}

.photo-sources > .field {
  margin: 0;
}

/* Import tiles stack their title / hint / form vertically. */
.import-option {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.import-option__title {
  margin: 0;
  font-size: var(--text-base);
}

.import-option .field-hint {
  flex: 1;
}

.import-option__form {
  display: grid;
  gap: var(--space-2);
}

/* The upload label acts as a button; surface focus from the hidden input. */
.photo-source__upload {
  position: relative;
}

.photo-source__upload:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.photo-sources .btn {
  width: 100%;
}

.photos-inputs__brand--disabled .btn {
  background: var(--gray-100);
  color: var(--gray-400);
  border-color: var(--color-border);
  cursor: not-allowed;
  opacity: 1;
}

.photos-inputs__brand:not(.photos-inputs__brand--disabled) .btn:disabled {
  cursor: wait;
  opacity: 0.75;
}

.photos-inputs__best-effort {
  margin-top: var(--space-1);
}

.photos-inputs__result {
  color: var(--green-700);
}

/* Photos card (product edit): the live zone — changes apply immediately */
.photos-card__header {
  display: grid;
  gap: var(--space-1);
}

.photos-card__header h2 {
  margin: 0;
}

/* Catalog-review panel (product edit): current vs catalog values, per field */
.catalog-review {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
}

.catalog-review__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
}

.catalog-review__title {
  margin: 0;
  font-size: 1rem;
}

.catalog-review__actions {
  display: flex;
  gap: var(--space-2);
}

.catalog-review__row {
  display: grid;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.catalog-review__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.catalog-review__diff {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

@media (max-width: 640px) {
  .catalog-review__diff {
    grid-template-columns: 1fr;
  }
}

.catalog-review__value {
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--gray-50);
}

.catalog-review__value--proposed {
  background: var(--green-50);
  border-color: var(--green-100);
}

.catalog-review__value p {
  margin: var(--space-1) 0 0;
  font-size: 0.875rem;
  white-space: pre-line;
  max-height: 9rem;
  overflow-y: auto;
}

.catalog-review__value-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--gray-500);
}

.catalog-review__empty {
  color: var(--gray-400);
  font-style: italic;
}

.catalog-review__row--applied .catalog-review__value--proposed {
  outline: 2px solid var(--green-600);
}

.photos-inputs__failure-detail {
  margin: var(--space-2) 0 0;
  color: var(--red-600);
}

.photos-inputs__fetching {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  color: var(--color-text-secondary);
}

.photos-inputs__fetching::before {
  content: "";
  flex-shrink: 0;
  width: 0.875rem;
  height: 0.875rem;
  margin-top: 0.125rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: photos-fetch-spin 0.75s linear infinite;
}

@keyframes photos-fetch-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- Empty State ---- */

.empty-state {
  padding: var(--space-16) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}


/* ---- Price display ---- */

.price {
  font-weight: 700;
  color: var(--color-text);
}

.price--large {
  font-size: var(--text-2xl);
}

.price--original {
  color: var(--color-text-muted);
  text-decoration: line-through;
  font-weight: 400;
}

.price--highlight {
  color: var(--orange-600);
}

.price--free {
  color: var(--green-600);
}


/* ---- Pagination ---- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  margin-top: var(--space-4);
  border-top: 1px solid var(--color-border-light);
}

.pagination__pages {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.pagination__page,
.pagination__step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.pagination__page:hover,
.pagination__step:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.pagination__page--current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

.pagination__step--disabled {
  color: var(--gray-400);
  background: var(--gray-100);
  cursor: not-allowed;
}

.pagination__gap {
  min-width: 1.25rem;
  text-align: center;
  color: var(--color-text-muted);
}

.pagination__summary {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.pagination-loading {
  text-align: center;
  padding: var(--space-4) 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
