/* Navegación entre páginas del tema (Atrás, números, Siguiente) */
.tema-paginacion-row {
  margin-top: 0.5rem;
}

.tema-paginacion {
  width: 100%;
  max-width: 100%;
  padding: 0.25rem 0;
}

.tema-paginacion-grupo {
  display: inline-flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: stretch;
  gap: 0;
  max-width: 100%;
  width: auto;
  vertical-align: middle;
}

.tema-paginacion-grupo > .btn,
.tema-paginacion-paginas > .btn {
  float: none;
  margin: 0 !important;
  border-radius: 4px !important;
  white-space: nowrap;
  line-height: 1.25;
}

.tema-paginacion-paginas {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
}

.tema-paginacion-paginas > .btn + .btn {
  margin-left: 0 !important;
}

/* Compatibilidad: páginas sin reestructurar aún */
.tema-paginacion .btn-group:not(.tema-paginacion-grupo) {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 0.5rem;
  max-width: 100%;
  width: 100%;
}

.tema-paginacion .btn-group:not(.tema-paginacion-grupo) .btn {
  float: none;
  margin: 0 !important;
  border-radius: 4px !important;
  white-space: nowrap;
}

@media (max-width: 991.98px) {
  .tema-paginacion {
    padding: 0.5rem 0 0.25rem;
  }

  /* Layout definitivo: Atrás | Siguiente arriba + números con scroll abajo */
  .tema-paginacion-grupo {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 0.5rem;
    width: 100%;
  }

  .tema-paginacion-grupo > .btn {
    min-height: 2.5rem;
    padding: 0.55rem 0.85rem !important;
    padding-left: 0.85rem !important;
    font-size: 0.875rem;
    width: 100%;
  }

  .tema-paginacion-grupo > .btn:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .tema-paginacion-grupo > .btn:last-child {
    grid-column: 2;
    grid-row: 1;
  }

  .tema-paginacion-paginas {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: stretch;
    gap: 0.4rem;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 0.5rem;
    scrollbar-width: thin;
    padding: 0.15rem 0.1rem 0.35rem;
    position: relative;
    mask-image: linear-gradient(
      to right,
      transparent 0,
      #000 0.5rem,
      #000 calc(100% - 0.5rem),
      transparent 100%
    );
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0,
      #000 0.5rem,
      #000 calc(100% - 0.5rem),
      transparent 100%
    );
  }

  /* Todos los números caben en pantalla: centrados, sin scroll */
  .tema-paginacion-paginas.tema-paginacion-paginas--fit {
    justify-content: center;
    overflow-x: hidden;
    mask-image: none;
    -webkit-mask-image: none;
  }

  /* Hay más páginas de las que caben: tira desplazable, activa centrada vía JS */
  .tema-paginacion-paginas.tema-paginacion-paginas--scroll {
    justify-content: flex-start;
  }

  .tema-paginacion-paginas > .btn {
    flex: 0 0 2.75rem;
    width: 2.75rem;
    min-width: 2.75rem;
    max-width: 2.75rem;
    min-height: 2.5rem;
    padding: 0.5rem 0.35rem !important;
    padding-left: 0.35rem !important;
    font-size: 0.875rem;
    scroll-snap-align: center;
  }

  .tema-paginacion-paginas.tema-paginacion-paginas--scroll::before,
  .tema-paginacion-paginas.tema-paginacion-paginas--scroll::after {
    content: "";
    flex: 0 0 0.15rem;
  }

  /* 7–9 páginas: botones un poco más compactos */
  .tema-paginacion-paginas:has(.btn:nth-child(7)) {
    gap: 0.35rem;
  }

  .tema-paginacion-paginas:has(.btn:nth-child(7)) > .btn {
    flex: 0 0 2.5rem;
    width: 2.5rem;
    min-width: 2.5rem;
    max-width: 2.5rem;
    font-size: 0.8125rem;
  }

  /* 10+ páginas: aún más compactos, sin límite de cantidad */
  .tema-paginacion-paginas:has(.btn:nth-child(10)) {
    gap: 0.3rem;
  }

  .tema-paginacion-paginas:has(.btn:nth-child(10)) > .btn {
    flex: 0 0 2.35rem;
    width: 2.35rem;
    min-width: 2.35rem;
    max-width: 2.35rem;
    font-size: 0.75rem;
    padding: 0.45rem 0.25rem !important;
    padding-left: 0.25rem !important;
  }

  /* Fallback legacy btn-group sin wrapper de páginas */
  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn {
    min-height: 2.5rem;
    padding: 0.55rem 0.85rem !important;
    padding-left: 0.85rem !important;
    font-size: 0.875rem;
    width: 100%;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn:last-child {
    grid-column: 2;
    grid-row: 1;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn:not(:first-child):not(:last-child) {
    grid-row: 2;
    width: 100%;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn:nth-child(2):nth-last-child(2) {
    grid-column: 1 / -1;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn:nth-child(2):nth-last-child(3) {
    grid-column: 1;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo):not(:has(.btn:nth-child(5))) .btn:nth-child(3):nth-last-child(2) {
    grid-column: 2;
  }
}

@media (max-width: 374px) {
  .tema-paginacion-grupo > .btn {
    font-size: 0.8125rem;
    min-height: 2.35rem;
    padding: 0.45rem 0.625rem !important;
    padding-left: 0.625rem !important;
  }

  .tema-paginacion-paginas > .btn {
    flex: 0 0 2.5rem;
    width: 2.5rem;
    min-width: 2.5rem;
    max-width: 2.5rem;
    font-size: 0.8125rem;
  }
}

@media (min-width: 992px) {
  .tema-paginacion-grupo {
    display: inline-flex;
    flex-wrap: nowrap;
    width: auto;
    gap: 0;
  }

  .tema-paginacion-paginas {
    display: contents;
  }

  .tema-paginacion-grupo > .btn,
  .tema-paginacion-paginas > .btn {
    padding: 10px 14px !important;
    padding-left: 14px !important;
  }

  .tema-paginacion-grupo > .btn:not(:last-child),
  .tema-paginacion-paginas > .btn:not(:last-child) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
  }

  .tema-paginacion-grupo > .btn:not(:first-child),
  .tema-paginacion-paginas > .btn:not(:first-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    margin-left: -1px !important;
  }

  .tema-paginacion-grupo > .btn:first-child {
    border-top-left-radius: 4px !important;
    border-bottom-left-radius: 4px !important;
  }

  .tema-paginacion-grupo > .btn:last-child {
    border-top-right-radius: 4px !important;
    border-bottom-right-radius: 4px !important;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo) {
    display: inline-flex;
    flex-wrap: nowrap;
    width: auto;
    gap: 0;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo) .btn {
    padding: 10px 14px !important;
    padding-left: 14px !important;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo) .btn:not(:last-child) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo) .btn:not(:first-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    margin-left: -1px !important;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo) .btn:first-child {
    border-top-left-radius: 4px !important;
    border-bottom-left-radius: 4px !important;
  }

  .tema-paginacion .btn-group:not(.tema-paginacion-grupo) .btn:last-child {
    border-top-right-radius: 4px !important;
    border-bottom-right-radius: 4px !important;
  }
}
