/* ==========================================================================
   bl-toc — Índice flotante tipo "dynamic island"
   blomon-base · vanilla, sin dependencias
   ========================================================================== */

.bl-toc {
  --bl-toc-bg: #ffffff;
  --bl-toc-fg: #111111;
  --bl-toc-muted: rgba(17, 17, 17, 0.45);
  --bl-toc-track: rgba(17, 17, 17, 0.12);
  --bl-toc-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --bl-toc-z: 9990;

  /* MEDIDAS — cámbialas aquí (y en el @media de móvil, más abajo).
     OJO con min(): se queda con el MENOR de los dos valores. En una pantalla
     normal manda el de px; el de vh solo entra en pantallas bajas. */
  --bl-toc-w:      min(280px, calc(100vw - 32px)); /* cápsula cerrada: ancho */
  --bl-toc-h:      52px;                            /* cápsula cerrada: alto  */
  --bl-toc-open-w: min(340px, calc(100vw - 32px)); /* panel abierto: ancho   */
  --bl-toc-open-h: min(400px, 65vh);                /* panel abierto: alto    */
  --bl-toc-bottom: 30px;                            /* POSICIÓN: distancia al borde inferior */

  position: fixed;
  bottom: var(--bl-toc-bottom);
  left: 50%;
  transform: translateX(-50%) translateY(24px);
  z-index: var(--bl-toc-z);
  opacity: 0;
  transition: opacity 0.4s var(--bl-toc-ease), transform 0.5s var(--bl-toc-ease);
}

.bl-toc.is-ready {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Oculta la isla mientras hay un overlay de Elementor abierto */
.bl-toc.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(24px);
}

/* --- Reset: neutraliza los estilos de botón de Astra/Elementor.
       Va antes que las reglas de componente para que estas ganen. --- */

.bl-toc button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: none;
  text-decoration: none;
}

.bl-toc button:hover,
.bl-toc button:focus,
.bl-toc button:active {
  border: 0;
  background: none;
  box-shadow: none;
  color: inherit;
}

/* --- Velo de fondo --- */

.bl-toc__scrim {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--bl-toc-ease);
}

.bl-toc.is-open .bl-toc__scrim {
  opacity: 1;
  pointer-events: auto;
}

/* --- Cápsula --- */

.bl-toc__island {
  position: relative;
  width: var(--bl-toc-w);
  height: var(--bl-toc-h);
  border-radius: 26px;
  overflow: hidden;
  background: var(--bl-toc-bg);
  color: var(--bl-toc-fg);
  /* El contorno es un anillo INTERIOR (inset), no un `border`: un border de 1px
     deja el panel (inset:0) 1px más pequeño con el MISMO radio, y las curvas no
     encajan en las esquinas -> se veía un doble borde. El anillo inset sigue
     exactamente el recorte del contenido. */
  border: 0;
  box-shadow:
    inset 0 0 0 1px var(--bl-toc-ring, rgba(17, 17, 17, 0.1)),
    0 18px 45px -12px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  isolation: isolate;
  /* Sin el hack de mask-image (radial-gradient): era un apaño para Safari
     antiguo que además recorta el box-shadow al border-box y pinta un canto
     oscuro en el borde redondeado. overflow:hidden + border-radius bastan. */
  transition: width 0.5s var(--bl-toc-ease), height 0.5s var(--bl-toc-ease),
    border-radius 0.5s var(--bl-toc-ease);
}

.bl-toc.is-open .bl-toc__island {
  width: var(--bl-toc-open-w);
  height: var(--bl-toc-open-h);
  border-radius: 4px;   /* personalización del proyecto */
  cursor: default;
}

/* --- Estado cerrado --- */

.bl-toc__pill {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  opacity: 1;
  transform: scale(1);
  filter: blur(0);
  transition: opacity 0.4s var(--bl-toc-ease) 0.1s,
    transform 0.5s var(--bl-toc-ease), filter 0.4s var(--bl-toc-ease);
}

.bl-toc.is-open .bl-toc__pill {
  opacity: 0;
  transform: scale(0.95);
  filter: blur(4px);
  pointer-events: none;
  transition-delay: 0s;
}

.bl-toc__dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.bl-toc__current {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.bl-toc__current.is-swapping {
  opacity: 0;
  transform: translateY(-10px);
}

.bl-toc__progress {
  flex: 0 0 auto;
  transform: rotate(-90deg);
}

.bl-toc__progress circle {
  fill: none;
  stroke-width: 2.5;
}

.bl-toc__progress-track {
  stroke: var(--bl-toc-track);
}

.bl-toc__progress-bar {
  stroke: currentColor;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.15s linear;
}

/* --- Estado abierto --- */

.bl-toc__panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border-radius: inherit;
  overflow: hidden;
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
  transition: opacity 0.35s var(--bl-toc-ease), transform 0.5s var(--bl-toc-ease);
}

.bl-toc.is-open .bl-toc__panel {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  transition-delay: 0.1s;
}

.bl-toc__head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 12px;
}

.bl-toc__heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--bl-toc-muted);
}

.bl-toc__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 25px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--bl-toc-muted);
  cursor: pointer;
  transition: color 0.25s ease, background 0.25s ease;
}

.bl-toc__close:hover,
.bl-toc__close:focus-visible {
  color: var(--bl-toc-fg);
  background: rgba(17, 17, 17, 0.06);
}

.bl-toc__close svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

.bl-toc__list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px 16px 12px;
  margin-right: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--bl-toc-track) transparent;
}

.bl-toc__list::-webkit-scrollbar {
  width: 4px;
}

.bl-toc__list::-webkit-scrollbar-track {
  background: transparent;
}

.bl-toc__list::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: var(--bl-toc-track);
}

.bl-toc__link {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(17, 17, 17, 0.45);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: background 0.3s ease, color 0.3s ease;
}

.bl-toc__link:hover,
.bl-toc__link:focus-visible {
  background: rgba(17, 17, 17, 0.05);
  color: rgba(17, 17, 17, 0.85);
}

.bl-toc__link.is-active {
  background: rgba(17, 17, 17, 0.1);
  color: var(--bl-toc-fg);
  font-weight: 500;
}

.bl-toc__link-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: transform 0.3s ease;
}

.bl-toc__link:hover .bl-toc__link-text {
  transform: translateX(4px);
}

.bl-toc__marker {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  margin-left: 12px;
  border-radius: 50%;
  background: currentColor;
  transform: scale(0);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.bl-toc__link.is-active .bl-toc__marker {
  transform: scale(1);
  opacity: 1;
}

/* --- Variante oscura --- */

.bl-toc.bl-toc--dark {
  --bl-toc-bg: #101010;
  --bl-toc-fg: #f5f5f5;
  --bl-toc-muted: rgba(245, 245, 245, 0.5);
  --bl-toc-track: rgba(245, 245, 245, 0.16);
}

.bl-toc.bl-toc--dark {
  --bl-toc-ring: rgba(245, 245, 245, 0.12);
}

.bl-toc--dark .bl-toc__link {
  color: rgba(245, 245, 245, 0.45);
}

.bl-toc--dark .bl-toc__link:hover,
.bl-toc--dark .bl-toc__link:focus-visible {
  background: rgba(245, 245, 245, 0.07);
  color: rgba(245, 245, 245, 0.85);
}

.bl-toc--dark .bl-toc__link.is-active {
  background: rgba(245, 245, 245, 0.12);
  color: var(--bl-toc-fg);
}

.bl-toc--dark .bl-toc__close:hover,
.bl-toc--dark .bl-toc__close:focus-visible {
  background: rgba(245, 245, 245, 0.08);
}

/* --- Accesibilidad y responsive --- */

.bl-toc :focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* --- Móvil: cápsula más compacta, sigue centrada --- */

@media (max-width: 767px) {
  .bl-toc {
    /* MEDIDAS EN MÓVIL (< 768px). Recuerda: min() coge el MENOR. Para que el
       panel abierto sea más alto, sube el valor en px (el vh casi nunca manda). */
    --bl-toc-bottom: 27px;                          /* POSICIÓN en móvil */
    --bl-toc-w:      min(240px, calc(100vw - 28px));
    --bl-toc-h:      38px;
    --bl-toc-open-w: calc(100vw - 28px);
    --bl-toc-open-h: min(360px, 62vh);
  }

  .bl-toc__island {
    border-radius: 22px;
  }

  .bl-toc.is-open .bl-toc__island {
    border-radius: 20px;
  }

  .bl-toc__pill {
    gap: 12px;
    padding: 0 14px;
  }

  .bl-toc__dot {
    width: 6px;
    height: 6px;
  }

  .bl-toc__current {
    font-size: 13px;
  }

  .bl-toc__progress {
    transform: rotate(-90deg) scale(0.8);
  }

  .bl-toc__head {
    padding: 16px 18px 10px;
  }

  .bl-toc__link {
    font-size: 13px;
    padding: 7px 10px;
  }
}

/* --- Escritorio: anclada abajo a la derecha --- */

@media (min-width: 1025px) {
  .bl-toc {
    --bl-toc-bottom: 26px;                          /* POSICIÓN en escritorio */
    left: auto;
    right: 72px;
    transform: translateY(24px);
    align-items: flex-end;
  }

  .bl-toc.is-ready {
    transform: translateY(0);
  }

  .bl-toc.is-hidden {
    transform: translateY(24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bl-toc,
  .bl-toc *,
  .bl-toc *::before {
    transition-duration: 0.01ms !important;
  }
}
