/* ==========================================================================
   Tabla responsive con cabeceras sticky — layout ACF responsive_table_block
   Mobile-first. Sticky resuelto por breakpoint (992px = Bootstrap lg):
     - movil  (<992px): columna fija (primera o ultima) al scroll horizontal.
     - desktop (>=992px): cabecera (thead) fija al hacer scroll vertical,
       anclada bajo el header del sitio (var --header-height).
   No se puede tener overflow-x:auto y thead sticky al viewport a la vez:
   el overflow crea un contexto de scroll que rompe el sticky vertical.
   ========================================================================== */

/* Bloque dentro del flujo de contenido de una noticia (ACF Gutenberg):
   sin section/container/padding del theme, solo separacion vertical. */
.responsive-table-block--inline {
	margin-block: 1.5rem;
}

.responsive-table {
	--rt-border: rgba(30, 41, 59, 0.12);
	--rt-head-bg: var(--primary, #1E293B);
	--rt-head-color: #ffffff;
	--rt-row-alt: #f4f5f7;            /* equivalente solido a primary ~4% */
	--rt-cell-bg: #ffffff;
	/* Offset del thead sticky en desktop: bajo el header fijo del sitio.
	   En paginas con development-sticky-nav, sumar su alto, p. ej.:
	   .responsive-table { --rt-sticky-top: calc(var(--header-height) + 50px); } */
	--rt-sticky-top: var(--header-height, 54px);
	position: relative;
}

/* Contenedor de scroll: en movil habilita scroll horizontal y muestra
   sombras (tecnica Lea Verou) que indican contenido oculto a los lados. */
.responsive-table__scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border-radius: 0.5rem;
	border: 1px solid var(--rt-border);
	background:
		linear-gradient(to right, var(--rt-cell-bg) 30%, rgba(255, 255, 255, 0)) left center,
		linear-gradient(to left, var(--rt-cell-bg) 30%, rgba(255, 255, 255, 0)) right center,
		radial-gradient(farthest-side at 0 50%, rgba(30, 41, 59, 0.18), rgba(0, 0, 0, 0)) left center,
		radial-gradient(farthest-side at 100% 50%, rgba(30, 41, 59, 0.18), rgba(0, 0, 0, 0)) right center;
	background-repeat: no-repeat;
	background-size: 2.5rem 100%, 2.5rem 100%, 1rem 100%, 1rem 100%;
	background-attachment: local, local, scroll, scroll;
}

.responsive-table__scroll:focus-visible {
	outline: 2px solid var(--secondary, #CA9500);
	outline-offset: 2px;
}

.responsive-table table {
	width: 100%;
	border-collapse: collapse;
	background: var(--rt-cell-bg);
	font-size: 0.875rem;
	line-height: 1.4;
}

.responsive-table caption {
	caption-side: top;
	text-align: left;
	font-weight: 600;
	padding: 0.75rem 1rem;
	color: var(--primary, #1E293B);
}

.responsive-table th,
.responsive-table td {
	padding: 0.75rem 1rem;
	text-align: left;
	vertical-align: top;
	border-bottom: 1px solid var(--rt-border);
}

/* Cabeceras de columna: fondo solido (necesario para el sticky). */
.responsive-table thead th {
	background: var(--rt-head-bg);
	color: var(--rt-head-color);
	font-weight: 600;
	white-space: nowrap;
	border-bottom: none;
}

/* Zebra striping (colores solidos para no transparentar bajo el sticky). */
.responsive-table tbody tr:nth-child(even) th,
.responsive-table tbody tr:nth-child(even) td {
	background: var(--rt-row-alt);
}

/* Encabezado de fila = primera columna: fondo solido + sin wrap. */
.responsive-table tbody th[scope="row"] {
	font-weight: 600;
	color: var(--primary, #1E293B);
	background: var(--rt-cell-bg);
	white-space: nowrap;
}
.responsive-table tbody tr:nth-child(even) th[scope="row"] {
	background: var(--rt-row-alt);
}

/* --------------------------------------------------------------------------
   MOVIL (<992px): columna fija al hacer scroll horizontal.
   Variante --sticky-col-first (primera, left) o --sticky-col-last (ultima, right).
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
	/* --- Primera columna fija (izquierda) --- */
	.responsive-table--sticky-col-first thead th:first-child,
	.responsive-table--sticky-col-first tbody th:first-child {
		position: -webkit-sticky;
		position: sticky;
		left: 0;
		z-index: 3;
	}
	.responsive-table--sticky-col-first thead th:first-child {
		z-index: 4; /* esquina por encima del resto de la cabecera */
	}
	/* Sombra al borde derecho de la columna fija. */
	.responsive-table--sticky-col-first thead th:first-child::after,
	.responsive-table--sticky-col-first tbody th:first-child::after {
		content: "";
		position: absolute;
		top: 0;
		bottom: -1px;
		right: 0;
		width: 0.5rem;
		transform: translateX(100%);
		background: linear-gradient(to right, rgba(30, 41, 59, 0.14), rgba(0, 0, 0, 0));
		pointer-events: none;
	}

	/* --- Ultima columna fija (derecha) --- */
	.responsive-table--sticky-col-last thead th:last-child,
	.responsive-table--sticky-col-last tbody th:last-child,
	.responsive-table--sticky-col-last tbody td:last-child {
		position: -webkit-sticky;
		position: sticky;
		right: 0;
		z-index: 3;
		background: var(--rt-cell-bg); /* fondo solido: la columna no es th de fila */
	}
	.responsive-table--sticky-col-last thead th:last-child {
		z-index: 4;
		background: var(--rt-head-bg); /* conserva el fondo de cabecera */
	}
	/* Respeta el zebra striping en la columna fija. */
	.responsive-table--sticky-col-last tbody tr:nth-child(even) th:last-child,
	.responsive-table--sticky-col-last tbody tr:nth-child(even) td:last-child {
		background: var(--rt-row-alt);
	}
	/* Sombra al borde izquierdo de la columna fija. */
	.responsive-table--sticky-col-last thead th:last-child::after,
	.responsive-table--sticky-col-last tbody th:last-child::after,
	.responsive-table--sticky-col-last tbody td:last-child::after {
		content: "";
		position: absolute;
		top: 0;
		bottom: -1px;
		left: 0;
		width: 0.5rem;
		transform: translateX(-100%);
		background: linear-gradient(to left, rgba(30, 41, 59, 0.14), rgba(0, 0, 0, 0));
		pointer-events: none;
	}
}

/* --------------------------------------------------------------------------
   DESKTOP (>=992px): cabecera fija al hacer scroll vertical.
   overflow-x:visible permite anclar el thead al viewport (no al wrapper).
   -------------------------------------------------------------------------- */
@media (min-width: 992px) {
	.responsive-table table {
		font-size: 0.95rem;
	}
	.responsive-table--sticky-header .responsive-table__scroll {
		overflow-x: visible;
		/* sin scroll horizontal: las sombras laterales sobran */
		background: none;
		border-radius: 0.5rem;
	}
	.responsive-table--sticky-header thead th {
		position: -webkit-sticky;
		position: sticky;
		top: var(--rt-sticky-top, var(--header-height, 54px));
		/* acompaña la animacion del header (#head transition: all .3s) */
		transition: top 0.3s ease;
		z-index: 2;
	}
	/* Header hide-on-scroll: al ocultarse (#head.oculta) deja libre su franja,
	   asi que la cabecera sube a top:0 en vez de dejar un hueco. */
	body:has(#head.oculta) .responsive-table--sticky-header thead th {
		top: 0;
	}
}
