/* OTW WC Swatches – Frontend */

/* ── Variables (defaults, overridden by inline :root block) ── */
:root {
  --otw-loop-swatch-width: 28px;
  --otw-loop-swatch-height: 28px;
  --otw-loop-swatch-radius: 50%;
  --otw-loop-swatch-gap: 6px;
  --otw-single-swatch-width: 36px;
  --otw-single-swatch-height: 36px;
  --otw-single-swatch-radius: 50%;
  --otw-single-swatch-gap: 8px;
  --otw-single-btn-height: 36px;
  --otw-single-btn-radius: 4px;
  --otw-single-btn-font-size: 13px;
  --otw-single-btn-padding-x: 10px;
}

/* ═══════════════════════════════════════
   LOOP SWATCHES
═══════════════════════════════════════ */

.otw-loop-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0;
}

/* Image overlay position */
.woocommerce ul.products li.product,
.jet-listing-grid .jet-listing-grid__item {
  position: relative;
}

.otw-loop-swatches--overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: 8px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.45));
  z-index: 2;
  pointer-events: none;
}

.otw-loop-swatches--overlay .otw-swatch {
  pointer-events: auto;
}

.otw-loop-swatch-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--otw-loop-swatch-gap);
}

/* Base swatch */
.otw-loop-swatches .otw-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--otw-loop-swatch-width);
  height: var(--otw-loop-swatch-height);
  border-radius: var(--otw-loop-swatch-radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-sizing: border-box;
  flex-shrink: 0;
  text-decoration: none;
  transition:
    transform 0.1s ease,
    border-color 0.1s ease;
}

.otw-loop-swatches .otw-swatch:hover {
  border-color: rgba(0, 0, 0, 0.4);
  transform: scale(1.1);
}

/* Color swatch */
.otw-loop-swatches .otw-swatch--color .otw-swatch__color {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

/* Image swatch */
.otw-loop-swatches .otw-swatch--image {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.otw-loop-swatches .otw-swatch--image .otw-swatch__img {
  display: block;
  width: 100%;
  height: 100%;
}

.otw-loop-swatches .otw-swatch--image .otw-swatch__img img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Text/pill swatch */
.otw-loop-swatches .otw-swatch--text {
  width: auto;
  min-width: var(--otw-loop-swatch-width);
  padding: 0 6px;
  background: #f5f5f5;
  font-size: 11px;
  font-weight: 500;
  color: #333;
  border-radius: 3px;
}

.otw-loop-swatches .otw-swatch--text .otw-swatch__text {
  display: block;
  line-height: 1;
}

/* "+N more" indicator */
.otw-loop-swatches .otw-swatch--more {
  width: auto;
  min-width: var(--otw-loop-swatch-width);
  padding: 0 5px;
  background: transparent;
  font-size: 11px;
  color: #888;
  border: 1px dashed #ccc;
  border-radius: 3px;
}

/* ═══════════════════════════════════════
   SINGLE PRODUCT SWATCHES
═══════════════════════════════════════ */

/* ── Override WC variations table: stack label above swatches ── */
.variations_form .variations,
.variations_form .variations tbody {
  display: block;
  width: 100%;
}

.variations_form .variations tr {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 8px;
  margin-bottom: 16px;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.variations_form .variations th.label {
  grid-column: 1;
  grid-row: 1;
  display: block;
  width: auto;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  background-color: transparent !important;
  border: none !important;
}

/* Flatten td and swatches-wrap so selected-label and swatches-list
   become independent grid items of the tr */
.variations_form .variations td.value {
  display: contents;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.variations_form .variations .otw-swatches-wrap {
  display: contents;
}

/* Hide the native WooCommerce select */
.otw-swatches-wrap select {
  display: none !important;
}

.otw-swatches-wrap {
  margin-bottom: 0;
}

.otw-swatches-selected-label {
  display: block;
  font-size: 12px;
  color: #777;
  margin-bottom: 6px;
}

/* In the variations grid: selected value sits on row 1 col 2 (next to attribute label) */
.variations_form .variations .otw-swatches-selected-label {
  grid-column: 2;
  grid-row: 1;
  margin-bottom: 0;
  align-self: center;
}

.otw-swatches-selected-label:empty {
  display: none;
}

/* In the variations grid: swatches span full width on row 2 */
.variations_form .variations .otw-swatches-list {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-top: 6px;
}

.otw-swatches-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--otw-single-swatch-gap);
  align-items: center;
}

/* Base swatch button */
.otw-swatches-list .otw-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--otw-single-swatch-width);
  height: var(--otw-single-swatch-height);
  border-radius: var(--otw-single-swatch-radius);
  overflow: hidden;
  cursor: pointer;
  /* border: 2px solid transparent; */
  outline: none;
  box-sizing: border-box;
  background: none;
  padding: 0;
  flex-shrink: 0;
  position: relative;
  transition:
    border-color 0.15s ease,
    transform 0.1s ease,
    opacity 0.15s ease;
}

.otw-swatches-list .otw-swatch:hover {
  border-color: #333;
  transform: scale(1.08);
}

.otw-swatches-list .otw-swatch:focus,
.otw-swatches-list .otw-swatch:active {
  outline: none;
}

.otw-swatches-list .otw-swatch.is-selected,
.otw-swatches-list .otw-swatch.is-selected:focus,
.otw-swatches-list .otw-swatch.is-selected:active {
  border: 2px solid #111;
  box-shadow: 0 0 0 2px #fff inset;
}

/* Color swatch */
.otw-swatches-list .otw-swatch--color .otw-swatch__color {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

/* Image swatch */
.otw-swatches-list .otw-swatch--image .otw-swatch__img {
  display: block;
  width: 100%;
  height: 100%;
}

.otw-swatches-list .otw-swatch--image .otw-swatch__img img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Text/pill swatch — uses its own independent sizing vars */
.otw-swatches-list .otw-swatch--text {
  width: auto;
  height: var(--otw-single-btn-height);
  padding: 0 var(--otw-single-btn-padding-x);
  background: #f5f5f5;
  font-size: var(--otw-single-btn-font-size);
  font-weight: 500;
  color: #333;
  border-radius: var(--otw-single-btn-radius);
  border: 1px solid #ddd;
}

.otw-swatches-list .otw-swatch--text:hover {
  background: #eee;
  border-color: #999;
}

.otw-swatches-list .otw-swatch--text.is-selected,
.otw-swatches-list .otw-swatch--text.is-selected:hover,
.otw-swatches-list .otw-swatch--text.is-selected:focus,
.otw-swatches-list .otw-swatch--text.is-selected:active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.otw-swatches-list .otw-swatch--text .otw-swatch__text {
  display: block;
  line-height: 1;
  pointer-events: none;
}

/* Out-of-stock state */
.otw-swatches-list .otw-swatch.is-out-of-stock {
  opacity: 0.4;
  cursor: not-allowed;
}

.otw-swatches-list .otw-swatch.is-out-of-stock::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(0, 0, 0, 0.15) 4px,
    rgba(0, 0, 0, 0.15) 5px
  );
  border-radius: inherit;
  pointer-events: none;
}

.otw-swatches-list .otw-swatch.is-not-purchasable {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Tooltip via title attribute — enhanced with CSS */
.otw-swatches-list .otw-swatch[title] {
  position: relative;
}
