/* ============================================================
   AF18 — COMPARATEUR [af_offers_comparator]
   Chargé uniquement sur les pages contenant le shortcode.
   ============================================================ */

/* ---- LAYOUT ---- */
.af-comparator {
  margin: 32px 0;
}

.af-comparator .bb-repeater-spec.is-hidden {
  display: none;
}

.af-comparator__body {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.af-comparator .af-offer-card__roaming-link {
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.12em;
  cursor: pointer;
  padding: 0;
}

/* ---- SIDEBAR ---- */
.af-comparator__sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 80px; /* header fixe 64px + 16px marge */
}

body.admin-bar .af-comparator__sidebar {
  top: 112px; /* admin bar 32px + header 64px + 16px marge */
}

.af-comparator__filters {
  background: var(--glass-bg);
  border: 1px solid var(--white-pure);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 10px;
}

.af-comparator__filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.af-comparator__filter-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.af-comparator__filter-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.af-data-slider-val {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
}

/* ---- SLIDER DATA ---- */
.af-data-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  accent-color: var(--accent);
  --af-slider-progress: 0%;
  --af-slider-track-inactive: var(--border);
  --af-slider-track-active: var(--accent);
  cursor: pointer;
  height: 28px;
  margin: -2px -14px -6px;
  display: block;
  position: relative;
  z-index: 1;
  border: 10px solid transparent;
  background: transparent;
  box-sizing: content-box;
  touch-action: pan-x;
}
.af-data-slider::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--af-slider-track-inactive) 0 var(--af-slider-progress),
    var(--af-slider-track-active) var(--af-slider-progress) 100%
  );
}
.af-data-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
}
.af-data-slider::-moz-range-track {
  border: none;
  background: linear-gradient(
    to right,
    var(--af-slider-track-inactive) 0 var(--af-slider-progress),
    var(--af-slider-track-active) var(--af-slider-progress) 100%
  );
  height: 4px;
  border-radius: 2px;
}
.af-data-slider::-moz-range-progress {
  background: transparent;
  height: 4px;
  border-radius: 2px;
}
.af-data-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
}

.af-comparator__pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

/* ---- PILL ---- */
.af-comp-pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white-pure);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.18s;
}

.af-comp-pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

.af-comp-pill.is-active {
  background: var(--accent-light);
  border-color: var(--accent-border);
  color: var(--accent-text);
}

[data-theme="dark"] .af-comp-pill.is-active { color: var(--accent); }

.af-comp-pill--5gplus.is-active {
  background: #f0fdf4;
  border-color: #15803d;
  color: #15803d;
  font-weight: 800;
}

.af-comp-pill--5g.is-active {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green);
}

.af-comp-pill--4g.is-active {
  background: var(--blue-light);
  border-color: var(--blue);
  color: var(--blue);
}

/* Pills logo opérateur */
.af-comparator__pills--logos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.af-comparator__pills--logos .af-comp-pill {
  width: 100%;
  height: 36px;
  padding: 2px 8px;
  justify-content: center;
}

.af-comp-pill--logo img {
  max-width: 100%;
  max-height: 24px;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

/* ---- RESET ---- */
.af-comparator__reset {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}

.af-comparator__reset:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-light);
}

/* ---- CONTENU PRINCIPAL ---- */
.af-comparator__main {
  flex: 1;
  min-width: 0;
}

/* ---- BARRE RÉSULTATS / TRI ---- */
.af-comparator__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
}

.af-comparator__count {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0;
}

.af-comparator__count strong {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.af-comparator__sort {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  background: var(--white-pure);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 30px 5px 12px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.18s;
}

.af-comparator__sort:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---- TOOLBAR RIGHT (toggle + sort) ---- */
.af-comparator__toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}


/* ---- TOGGLE MENSUEL / ANNUEL ---- */
.af-price-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
}

.af-price-toggle__label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  transition: color 0.18s;
  white-space: nowrap;
}

.af-price-toggle__label small {
  font-size: 0.68rem;
  font-weight: 400;
  opacity: 0.75;
}

.af-price-toggle__track {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.af-price-toggle__input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.af-price-toggle__thumb {
  position: absolute;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: left 0.2s;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.af-price-toggle__input:checked ~ .af-price-toggle__thumb {
  left: 19px;
}

.af-price-toggle__track:has(.af-price-toggle__input:checked) {
  background: var(--accent);
}

/* Labels : label actif en gras */
.af-price-toggle .af-price-toggle__label:first-child {
  color: var(--text);
  font-weight: 600;
}
.af-price-toggle .af-price-toggle__label:last-child {
  color: var(--muted);
  font-weight: 500;
}
.af-price-toggle:has(.af-price-toggle__input:checked) .af-price-toggle__label:first-child {
  color: var(--muted);
  font-weight: 500;
}
.af-price-toggle:has(.af-price-toggle__input:checked) .af-price-toggle__label:last-child {
  color: var(--text);
  font-weight: 600;
}

/* ---- GRILLE ---- */
.af-comparator__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.af-comparator__load-more {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.af-comparator__load-more-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 30px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--white-pure);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.18s, font-weight 0.18s;
}

.af-comparator__load-more-btn::after {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.18s;
}

.af-comparator__load-more-btn:hover {
  font-weight: 600;
}

/* ---- ÉTAT VIDE ---- */
.af-comparator__empty {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  margin: 24px auto;
  padding: 40px 28px;
  background: var(--white-pure);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.af-comparator__empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-text);
}

.af-comparator__empty-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.af-comparator__empty-text {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--muted);
}

.af-comparator__reset-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 24px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-strong-text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s, transform 0.18s, box-shadow 0.18s;
}

.af-comparator__reset-inline:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-accent);
}

/* ---- ÉLÉMENTS MOBILE (masqués sur desktop) ---- */
.af-comparator__bottom-bar,
.af-comparator__more-filters,
.af-comparator__sidebar-header,
.af-comparator__drawer-footer,
.af-comparator__overlay { display: none; }

.af-comparator__toggle-badge {
  display: none;
  background: var(--accent);
  color: var(--accent-strong-text);
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  align-items: center;
  justify-content: center;
  line-height: 1;
}


/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
  .af-comparator__grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  .af-comparator__sidebar {
    width: 180px;
  }
}

@media (max-width: 640px) {
  .af-data-slider.is-touch-active::-webkit-slider-thumb {
    border-color: rgba(255, 211, 1, 0.48);
    box-shadow: 0 0 0 18px rgba(255, 211, 1, 0.22), 0 1px 2px rgba(15, 23, 42, 0.18);
  }

  .af-data-slider.is-touch-active::-moz-range-thumb {
    border-color: rgba(255, 211, 1, 0.48);
    box-shadow: 0 0 0 18px rgba(255, 211, 1, 0.22), 0 1px 2px rgba(15, 23, 42, 0.18);
  }

  .af-comparator__toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px 12px;
  }

  .af-comparator__toolbar-right {
    display: contents;
  }

  .af-comparator__count {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .af-comparator__sort {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    max-width: 100%;
  }

  .af-price-toggle {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    margin-top: 20px;
  }

  /* Masquer la sidebar classique */
  .af-comparator__sidebar {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 10svh;
    top: 10vh; /* fallback */
    bottom: 0; left: 0; right: 0;
    z-index: 1002;
    background: var(--white);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
    overflow: hidden;
    width: auto;
    transform: translateY(32px);
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.42s ease-out, visibility 0s linear 0.42s;
  }

  /* Drawer bas */
  .af-comparator__sidebar.is-open {
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
  }

  /* Zone scrollable (filtres + reset) */
  .af-comparator__drawer-scroll {
    flex: 1 1 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 20px;
    min-height: 0;
  }

  /* Footer sticky */
  .af-comparator__drawer-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-light);
    background: var(--white);
  }

  .af-comparator__drawer-apply {
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--accent-strong-text);
    background: var(--accent);
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background 0.18s;
  }
  .af-comparator__drawer-apply:hover { background: var(--accent-hover); }
  /* Header du drawer */
  .af-comparator__sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border-light);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 1;
    flex-shrink: 0;
  }

  .af-comparator__sidebar-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color 0.18s;
  }
  .af-comparator__sidebar-close:hover { color: var(--text); }

  /* Overlay */
  .af-comparator__overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1001;
    visibility: hidden;
    pointer-events: none;
  }
  .af-comparator__overlay.is-active {
    visibility: visible;
    pointer-events: auto;
  }

  /* Barre de filtres mobile fixe sous le header */
  .af-comparator__bottom-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    left: 12px;
    right: 12px;
    top: calc(64px + var(--admin-bar-offset, 0px) + 8px);
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: 12px;
    padding: 12px 14px;
    z-index: 90;
    color: var(--accent-text);
    box-shadow: 0 8px 20px rgba(15,23,42,0.12);
    opacity: 0;
    transform: translateY(calc(-100% - 16px));
    pointer-events: none;
    transition: opacity 0.34s ease-out, transform 0.34s ease-out;
    touch-action: pan-x;
    overscroll-behavior: contain;
  }
  .af-comparator.is-bottom-bar-visible .af-comparator__bottom-bar {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .af-comparator__bottom-bar.is-bottom-bar-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
  .af-comparator__bottom-bar--filters-only {
    justify-content: center;
    padding: 0;
  }

  .af-comparator__bottom-data {
    flex: 1;
    min-width: 0;
    position: relative;
    isolation: isolate;
    touch-action: pan-x;
  }
  .af-comparator__pills--bar {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .af-comparator__pills--bar::-webkit-scrollbar { display: none; }
  .af-comparator__pills--bar .af-comp-pill {
    white-space: nowrap;
    flex-shrink: 0;
    background: var(--white-pure);
    color: var(--text);
    border-color: var(--border);
  }
  .af-comparator__pills--bar .af-comp-pill.is-active {
    background: var(--accent);
    color: var(--text);
    border-color: var(--accent);
  }
  .af-comparator__bottom-bar .af-comparator__filter-label,
  .af-comparator__bottom-bar .af-data-slider-val {
    color: var(--accent-text);
  }
  .af-comparator__bottom-bar .af-data-slider {
    z-index: 2;
    --af-slider-track-inactive: color-mix(in srgb, var(--accent-light) 72%, var(--accent-border) 28%);
    --af-slider-track-active: var(--accent);
  }
  [data-theme="dark"] .af-comparator__bottom-bar {
    background: color-mix(in srgb, var(--accent) 12%, var(--surface) 88%);
    color: var(--accent);
  }
  [data-theme="dark"] .af-comparator__bottom-bar .af-comparator__filter-label,
  [data-theme="dark"] .af-comparator__bottom-bar .af-data-slider-val {
    color: var(--accent);
  }

  /* Bouton "Filtres" */
  .af-comparator__more-filters {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent-text);
    background: color-mix(in srgb, var(--accent-light) 60%, var(--accent-border) 40%);
    border: 1px solid var(--accent-border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.18s, background 0.18s;
    touch-action: manipulation;
  }
  .af-comparator__more-filters:hover {
    border-color: var(--accent-text);
    background: color-mix(in srgb, var(--accent-light) 35%, var(--accent) 65%);
  }
  .af-comparator__bottom-bar--filters-only .af-comparator__more-filters {
    justify-content: center;
    width: 100%;
    min-height: 52px;
    border: 0;
    border-radius: 12px;
    background: transparent;
  }
  .af-comparator__bottom-bar--filters-only .af-comparator__more-filters:hover {
    background: color-mix(in srgb, var(--accent-light) 45%, var(--accent) 55%);
  }
  [data-theme="dark"] .af-comparator__more-filters {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, var(--surface) 82%);
    border-color: color-mix(in srgb, var(--accent) 30%, var(--surface) 70%);
  }
  [data-theme="dark"] .af-comparator__more-filters:hover {
    background: color-mix(in srgb, var(--accent) 28%, var(--surface) 72%);
    border-color: color-mix(in srgb, var(--accent) 42%, var(--surface) 58%);
  }

  .af-comparator__grid {
    grid-template-columns: 1fr;
  }
}

/* ---- SWITCHES "Autres" ---- */
.af-comp-switches {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.af-comp-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.af-comp-switch-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.af-comp-switch-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.af-comp-switch {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.af-comp-switch-thumb {
  position: absolute;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: left 0.2s;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.af-comp-switch:checked ~ .af-comp-switch-thumb {
  left: 19px;
}

.af-comp-switch-track:has(.af-comp-switch:checked) {
  background: var(--accent);
}
