/**
 * Eco Preview Stock
 * Variant availability preview shown over the product miniature.
 */

.eps {
  --eps-gap: 0.75rem;
  --eps-radius: 0.75rem;
  --eps-surface: #ffffff;
  --eps-border: #e9ecf2;
  --eps-title: #16205a;
  --eps-label: #6b7280;
  --eps-value: #26324f;
  --eps-value-border: #dfe3ec;
  --eps-accent: #1a49f5;
  --eps-muted: #aab0bf;
  --eps-muted-bg: #f7f8fa;
  --eps-muted-border: #edeff4;
  --eps-shadow: 0 0.5rem 1.5rem rgba(20, 30, 70, 0.12);
}

/* The miniature becomes the positioning context for the overlay. */
.product-miniature {
  position: relative;
}

/* ---------------------------------------------------------------- Panel */

.eps__panel {
  position: absolute;
  z-index: 20;
  top: -15rem;
  right: var(--eps-gap);
  left: var(--eps-gap);
  padding: 0.875rem 1rem 1rem;
  text-align: left;
  background-color: var(--eps-surface);
  border: 1px solid var(--eps-border);
  border-radius: var(--eps-radius);
  box-shadow: var(--eps-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-0.375rem);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;

  /* Purely informative panels let clicks through to the product link below. */
  pointer-events: none;
}

/* Multi-group panels are interactive (cross-filtering), so they capture clicks. */
.eps__panel[data-eps-combinations],
.eps.eps--open .eps__panel {
  pointer-events: auto;
}

.eps__title {
  margin: 0 1.5rem 0.75rem 0;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--eps-title);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.eps__group + .eps__group {
  margin-top: 0.75rem;
}

.eps__group-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--eps-label);
}

.eps__values {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.eps__value-item {
  margin: 0;
}

/* ---------------------------------------------------------------- Pills */

.eps__value {
  display: inline-flex;
  gap: 0.375rem;
  align-items: center;
  padding: 0.3125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--eps-value);
  white-space: nowrap;
  background-color: var(--eps-surface);
  border: 1px solid var(--eps-value-border);
  border-radius: 0.5rem;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

button.eps__value {
  cursor: pointer;
  appearance: none;
}

button.eps__value:hover,
button.eps__value:focus-visible {
  color: var(--eps-accent);
  border-color: var(--eps-accent);
  outline: none;
}

button.eps__value[aria-pressed="true"] {
  color: var(--eps-surface);
  background-color: var(--eps-title);
  border-color: var(--eps-title);
}

/* Out of stock (or unreachable with the current selection). */
.eps__value--oos {
  color: var(--eps-muted);
  text-decoration: line-through;
  background-color: var(--eps-muted-bg);
  border-color: var(--eps-muted-border);
}

button.eps__value--oos:hover,
button.eps__value--oos:focus-visible {
  color: var(--eps-muted);
  border-color: var(--eps-muted-border);
}

.eps__value--oos .eps__swatch {
  opacity: 0.4;
}

.eps__value--more {
  color: var(--eps-label);
  border-style: dashed;
}

.eps__swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  background-position: center;
  background-size: cover;
  border: 1px solid rgba(20, 30, 70, 0.15);
  border-radius: 50%;
}

.eps__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- Toggle */

.eps__toggle {
  position: absolute;
  z-index: 22;
  top: var(--eps-gap);
  right: var(--eps-gap);
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: var(--eps-title);
  cursor: pointer;
  background-color: var(--eps-surface);
  border: 1px solid var(--eps-border);
  border-radius: 50%;
  box-shadow: 0 0.125rem 0.5rem rgba(20, 30, 70, 0.1);
  appearance: none;
}

.eps__toggle:focus-visible {
  outline: 2px solid var(--eps-accent);
  outline-offset: 2px;
}

.eps__toggle-icon {
  display: block;
  transition: transform 0.18s ease;
}

.eps.eps--open .eps__toggle-icon {
  transform: rotate(90deg);
}

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

/* Touch devices, and keyboard users on any device: explicit toggle. */
.eps.eps--open .eps__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s;
}

.eps.eps--open .eps__toggle,
.eps__toggle:focus-visible {
  display: inline-flex;
}

@media (hover: none), (pointer: coarse) {
  .eps__toggle {
    display: inline-flex;
  }
}

/* Desktop: pure CSS hover, no JS needed. */
@media (hover: hover) and (pointer: fine) {
  .product-miniature:hover .eps__panel,
  .product-miniature:focus-within .eps__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition-delay: 0s;
  }

  /* Keep the overlay clean: theme badges would peek out behind the panel. */
  .product-miniature:has(.eps) .product-flags {
    transition: opacity 0.18s ease;
  }

  .product-miniature:has(.eps):hover .product-flags,
  .product-miniature:has(.eps):focus-within .product-flags {
    opacity: 0;
  }
}

.product-miniature:has(.eps.eps--open) .product-flags {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .eps__panel,
  .eps__value,
  .eps__toggle-icon {
    transition: none;
  }
}

/* =================================================================
 * Product page - stock status added by ecopreviewstock.js to the
 * "radio" attribute groups. Each value becomes a pill with its
 * availability underneath; dropdowns and colour swatches are
 * left untouched.
 *
 * The markup differs from one theme to another (the <input> may sit
 * before the <label> or inside it, the row may be a <div> or a <ul>),
 * so everything hangs off the classes added by the JS:
 *   .eps-pp__options > .eps-pp__option > label
 *
 * Colours and radii are driven by the --eps-pp-* custom properties:
 * redefine them in the theme to follow another palette.
 * ================================================================= */

.eps-pp,
.ap5-attributes {
  --eps-pp-in-stock: #17974b;
  --eps-pp-supplier-stock: #17974b;
  --eps-pp-out-of-stock: #dc2743;
  --eps-pp-on: #ffffff;
  --eps-pp-ink: #1b2432;
  --eps-pp-muted: #b6bbc4;
  --eps-pp-line: #e4e7ec;
  --eps-pp-accent: var(--bs-primary, #0b69f6);
  --eps-pp-surface: #ffffff;
  --eps-pp-pill-radius: 50rem;
  --eps-pp-status-radius: 0.375rem;
}

/* Row of values: also resets the <ul> themes sometimes use. */
.eps-pp .eps-pp__options,
.ap5-attributes .ap5-attribute-fieldset ul:has(> li > .ap5-attribute-radio) {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  column-gap: 0.75rem;
  row-gap: 0.875rem;
  padding-left: 0;
  margin-bottom: 0;
  list-style: none;
}

.eps-pp .eps-pp__option,
.ap5-attributes .ap5-attribute-fieldset li.input-container:has(> .ap5-attribute-radio) {
  padding: 0;
  margin: 0;
  text-align: center;
}

/* The native radio stays the control, the pill becomes its skin. */
.eps-pp .eps-pp__option input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  pointer-events: none;
}

.eps-pp .eps-pp__option > label,
.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio + .radio-label {
  display: block;
  min-width: 5rem;
  padding: 0.2rem 0.5rem;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--eps-pp-ink);
  cursor: pointer;
  background-color: var(--eps-pp-surface);
  border: 2px solid var(--eps-pp-line);
  border-radius: 5px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.eps-pp .eps-pp__option > label:hover,
.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio:not(:disabled):hover + .radio-label {
  border-color: var(--eps-pp-accent);
}

/* Selected value. Two rules for two markups: the input can be a sibling of
   the label (Hummingbird) or nested inside it (input-in-label themes). */
.eps-pp .eps-pp__option > input[type="radio"]:checked + label,
.eps-pp .eps-pp__option > label:has(input[type="radio"]:checked),
.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio:checked + .radio-label {
  color: var(--eps-pp-accent);
  border-color: var(--eps-pp-accent);
}

.eps-pp .eps-pp__option > input[type="radio"]:focus-visible + label,
.eps-pp .eps-pp__option > label:has(input[type="radio"]:focus-visible),
.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio:focus-visible + .radio-label {
  outline: 2px solid var(--eps-pp-accent);
  outline-offset: 2px;
}

/* Out of stock values stay selectable, but read as inactive. */
.eps-pp .eps-pp__option--out-of-stock > label,
.ap5-attributes .ap5-attribute-fieldset li.eps-pp__option--out-of-stock > .radio-label,
.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio:disabled + .radio-label {
  color: var(--eps-pp-muted);
}

/* Advanced Pack (pm_advancedpack): same pills, only the way the native radio
   is hidden differs. Its markup has no <label> (input + span.radio-label) and
   its JS listens to `click` on .ap5-attribute-radio itself, so the input must
   keep receiving the click: it is stretched, transparent, over the whole pill
   instead of being clipped away. Behaviour and events stay untouched. */
.ap5-attributes .ap5-attribute-fieldset li.input-container:has(> .ap5-attribute-radio) {
  position: relative;
  float: none;
}

.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  opacity: 0;
}

.ap5-attributes .ap5-attribute-fieldset .ap5-attribute-radio:disabled {
  cursor: not-allowed;
}

/* ------------------------------------------------------ Status label */

.eps-pp__status {
  display: block;
  margin: -0.25rem 0.25rem 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--eps-pp-on);
  text-align: center;
  border-radius: var(--eps-pp-status-radius);
}

.eps-pp__status--in-stock {
  background-color: var(--eps-pp-in-stock);
}

/* Only available at the supplier's (ecosupplierstock). */
.eps-pp__status--supplier-stock {
  background-color: var(--eps-pp-supplier-stock);
}

.eps-pp__status--out-of-stock {
  background-color: var(--eps-pp-out-of-stock);
}

@media (prefers-reduced-motion: reduce) {
  .eps-pp .eps-pp__option > label {
    transition: none;
  }
}
