/**
 * AES Design Kit v6 — Loop Carousel V3 (Pro Elements) bridge
 *
 * The Loop Carousel writes Swiper, arrow and pagination values as local CSS
 * custom properties. This file maps those properties to AES tokens and styles
 * the product card used by the Design Kit V3 loop item.
 *
 * Scope: body.aes-elementor, so it applies only when the theme marker is
 * present and never leaks into the editor UI or the WordPress admin.
 *
 * ## Variable contract
 *
 * The widget reads 46 custom properties (Pro Elements 4.3.0,
 * `widget-loop-carousel.min.css` + `base/base-carousel-trait.php`). They are
 * all declared or documented below, including the ones the AES bridge does not
 * brand.
 *
 * Cascade:
 * - `body.aes-elementor .elementor-widget-loop-carousel` (0,2,1) declares the
 *   native inventory. It wins over Pro's static defaults (0,1,0) but loses to
 *   Elementor's per-instance CSS (0,3,0), so panel settings keep working.
 * - `body.aes-elementor .elementor-widget-loop-carousel.elementor-element`
 *   (0,3,1) maps the brand-facing values to AES tokens and intentionally wins
 *   over the per-instance rules.
 * - Pagination-size rules add one class (0,4,1) and win over both.
 *
 * Do not raise the inventory block's specificity: it is the fallback contract,
 * not a style override.
 */

/* --------------------------------------------------------------------------
   1. Native inventory — all widget variables
   --------------------------------------------------------------------------
   Values mirror the Pro Elements 4.3.0 defaults/fallbacks. The AES token
   overrides in section 2 win where the design kit has an opinion; everything
   else stays available to the Elementor panel.
   -------------------------------------------------------------------------- */
body.aes-elementor .elementor-widget-loop-carousel {
  /* Swiper */
  --swiper-slides-to-display: 1;
  --swiper-slides-gap: 10px;
  --swiper-offset-size: 0px;
  --swiper-pagination-size: 0px;
  --swiper-pagination-spacing: 10px;
  --swiper-padding-bottom: calc(
    var(--swiper-pagination-size) + var(--swiper-pagination-spacing)
  );

  /* Arrows — size and geometry */
  --arrow-size: 25px;
  --arrow-prev-left-align: 0px;
  --arrow-prev-left-position: 0px;
  --arrow-prev-translate-x: 0px;
  --arrow-prev-top-align: 50%;
  --arrow-prev-top-position: 0px;
  --arrow-prev-translate-y: 0px;
  --arrow-prev-caption-spacing: 15px;
  --arrow-next-right-align: 0px;
  --arrow-next-right-position: 0px;
  --arrow-next-translate-x: 0px;
  --arrow-next-top-align: 50%;
  --arrow-next-top-position: 0px;
  --arrow-next-translate-y: 0px;
  --arrow-next-caption-spacing: 15px;

  /* Arrows — colors (Pro fallbacks) */
  --arrow-normal-color: hsla(0, 0%, 93.3%, 0.9);
  --arrow-hover-color: hsla(0, 0%, 93.3%, 0.9);

  /* Dots */
  --dots-normal-color: #000;
  --dots-hover-color: #000;
  --dots-horizontal-position: 50%;
  --dots-horizontal-offset: 0px;
  --dots-horizontal-transform: -50%;
  --dots-vertical-position: 100%;
  --dots-vertical-offset: 0px;
  --dots-vertical-transform: -100%;

  /* Fraction */
  --fraction-color: #000;
  --fraction-horizontal-position: 50%;
  --fraction-horizontal-offset: 0px;
  --fraction-horizontal-transform: -50%;
  --fraction-vertical-position: 100%;
  --fraction-vertical-offset: 0px;
  --fraction-vertical-transform: -100%;

  /* Progress bar */
  --progressbar-normal-color: #000;
  --progressbar-hover-color: #000;
}

/*
 * Variables read by the widget CSS but intentionally not declared above:
 *
 * --number-of-gaps, --gaps-width-total
 *   Computed by Pro on each `.swiper--slide` from `--swiper-slides-to-display`
 *   and `--swiper-slides-gap`. Declaring them on the widget would be inert and
 *   misleading.
 *
 * --direction-multiplier
 *   Global on `:root` (`1`, `-1` for RTL, elementor/assets/css/templates/
 *   frontend.css). Declaring it here would break RTL pagination.
 *
 * --display
 *   Used only by `.swiper-slide a.e-con` (linked container slides) and never
 *   written by the widget. Declaring it would override the link's own display.
 *
 * --arrow-normal-border-type, --arrow-hover-border-type
 *   Read by the widget CSS (`border-style: var(...)`) but never written by the
 *   controls: Group_Control_Border writes `border-style` directly on the arrow.
 *   The AES bridge styles the arrow border itself, so these stay unset.
 */

/* --------------------------------------------------------------------------
   2. AES token overrides
   -------------------------------------------------------------------------- */
/*
 * `--swiper-slides-gap` only feeds the pre-init fallback (`gap` on
 * `.swiper-wrapper:not(.swiper-initialized)`). After init Swiper writes an
 * inline `margin-right` from the widget setting `image_spacing_custom`, whose
 * AES default is set in `Widgets\AES_Loop_Carousel::gap_default()`
 * (32px desktop, 24px tablet/mobile).
 */
body.aes-elementor .elementor-widget-loop-carousel.elementor-element {
  --swiper-slides-gap: var(--aes-sys-space-component);
  --swiper-offset-size: 0px;
  --swiper-pagination-spacing: var(--aes-ref-space-4);

  --arrow-size: var(--aes-ref-icon-md);
  --arrow-normal-color: var(--aes-sys-color-action-primary);
  --arrow-hover-color: var(--aes-sys-color-text-inverse);

  --dots-normal-color: var(--aes-sys-color-border);
  --dots-hover-color: var(--aes-sys-color-action-primary);

  --fraction-color: var(--aes-sys-color-text-muted);

  --progressbar-normal-color: var(--aes-sys-color-action-primary);
  --progressbar-hover-color: var(--aes-sys-color-action-primary-hover);
}

/* --swiper-pagination-size is shared by dots, fraction and progressbar. */
body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets {
  --swiper-pagination-size: var(--aes-ref-icon-2xs);
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-fraction {
  --swiper-pagination-size: var(--aes-sys-font-size-body-md);
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-progressbar {
  --swiper-pagination-size: var(--aes-sys-border-width);
}

/* --------------------------------------------------------------------------
   Arrows
   -------------------------------------------------------------------------- */
body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-prev,
body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-next {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--aes-ref-control-sm);
  height: var(--aes-ref-control-sm);
  padding: 0;
  color: var(--aes-sys-color-action-primary);
  background: var(--aes-sys-color-surface);
  border: var(--aes-sys-border-width) solid var(--aes-sys-color-border);
  border-radius: var(--aes-sys-radius);
  transition:
    color var(--aes-sys-motion-fast) var(--aes-sys-ease),
    background-color var(--aes-sys-motion-fast) var(--aes-sys-ease),
    border-color var(--aes-sys-motion-fast) var(--aes-sys-ease);
  z-index: 0;
}

body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-prev:hover,
body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-next:hover {
  color: var(--aes-sys-color-text-inverse);
  background: var(--aes-sys-color-action-primary);
  border-color: var(--aes-sys-color-action-primary);
}

body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-prev:focus-visible,
body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-next:focus-visible {
  outline: var(--aes-sys-border-width) solid var(--aes-sys-color-border-focus);
  outline-offset: var(--aes-ref-space-1);
}

body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-prev
  svg,
body.aes-elementor
  .elementor-widget-loop-carousel
  .elementor-swiper-button-next
  svg {
  fill: currentColor;
  width: 1em;
  height: 1em;
}

/* --------------------------------------------------------------------------
   Dots, fraction and progress bar
   -------------------------------------------------------------------------- */
body.aes-elementor .elementor-widget-loop-carousel .swiper-pagination-bullet {
  opacity: 1;
}

body.aes-elementor
  .elementor-widget-loop-carousel
  .swiper-pagination-bullet-active {
  background: var(--aes-sys-color-action-primary);
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-progressbar
  .swiper {
  padding-bottom: var(--swiper-padding-bottom);
}

body.aes-elementor
  .elementor-widget-loop-carousel
  .swiper-pagination-progressbar {
  top: auto;
  bottom: 0;
  background: var(--aes-sys-color-border);
  border-radius: var(--aes-sys-radius);
}

body.aes-elementor .elementor-widget-loop-carousel .swiper-pagination-fraction {
  font-family: var(--aes-ref-font-body);
  font-weight: var(--aes-ref-weight-medium);
  letter-spacing: var(--aes-ref-tracking-wide);
}

/* --------------------------------------------------------------------------
   Control bar — bullets pagination
   --------------------------------------------------------------------------
   Bullets mode moves pagination and arrows below the slider:

     [1–4 di 16  • • • •]                              [prev] [next]

   The range label is written by aes-elementor-loop-carousel.js into
   `data-aes-range` and rendered by the pagination ::before. The grid keeps
   the bar aligned with the slider even when the widget has no arrows.
   -------------------------------------------------------------------------- */
body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-rows: auto auto;
  column-gap: var(--aes-ref-space-2);
  row-gap: var(--aes-ref-space-4);
  align-items: center;
  padding-bottom: var(--aes-ref-space-2);
}

/* Non-optimized markup wraps the slider in .elementor-widget-container. */
body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  > .elementor-widget-container {
  display: contents;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .swiper {
  grid-column: 1 / -1;
  grid-row: 1;
  width: 100%;
  max-width: 100%;
  margin-inline: 0;
  padding-bottom: 0;
  z-index: 0;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .swiper-pagination {
  position: static;
  inset: auto;
  transform: none;
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: var(--aes-ref-space-3);
  width: auto;
  height: auto;
  font-size: var(--aes-sys-font-size-body-sm);
  line-height: 1;
  color: var(--aes-sys-color-text-muted);
  z-index: 0;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .swiper-pagination::before {
  content: attr(data-aes-range);
  font-family: var(--aes-ref-font-body);
  font-size: var(--aes-sys-font-size-body-sm);
  font-weight: var(--aes-ref-weight-regular);
  line-height: var(--aes-ref-leading-ui);
  color: var(--aes-sys-color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .swiper-pagination-bullet {
  flex: 0 0 auto;
  margin: 0;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .elementor-swiper-button-prev,
body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .elementor-swiper-button-next {
  position: static;
  inset: auto;
  transform: none;
  grid-row: 2;
  align-self: center;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .elementor-swiper-button-prev {
  grid-column: 2;
  justify-self: end;
}

body.aes-elementor
  .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
  .elementor-swiper-button-next {
  grid-column: 3;
  justify-self: end;
}

@media (prefers-reduced-motion: reduce) {
  body.aes-elementor
    .elementor-widget-loop-carousel
    .elementor-swiper-button-prev,
  body.aes-elementor
    .elementor-widget-loop-carousel
    .elementor-swiper-button-next {
    transition: none;
  }
}

/* On phones the side arrows would steal 60px from a single-slide carousel.
   With bullets they live in the control bar below, so they stay visible;
   for the other pagination types they are still hidden. */
@media (max-width: 767px) {
  body.aes-elementor
    .elementor-widget-loop-carousel.elementor-arrows-position-outside
    .swiper {
    width: 100%;
  }

  body.aes-elementor
    .elementor-widget-loop-carousel:not(.elementor-pagination-type-bullets)
    .elementor-swiper-button-prev,
  body.aes-elementor
    .elementor-widget-loop-carousel:not(.elementor-pagination-type-bullets)
    .elementor-swiper-button-next {
    display: none;
  }

  body.aes-elementor
    .elementor-widget-loop-carousel.elementor-element.elementor-pagination-type-bullets
    .swiper-pagination {
    flex-wrap: wrap;
    row-gap: var(--aes-ref-space-1);
  }
}
