/* -------------------------------------------------------------------------
 * TRM Gold Chart
 * Estilo sobrio y neutro: hereda la tipografía del tema para integrarse en
 * Divi sin imponer una identidad propia. Todos los colores son variables CSS,
 * de modo que se pueden ajustar a la marca sin tocar este archivo.
 * ---------------------------------------------------------------------- */

.trm-gold {
	--trm-gold-accent: #b08d4f;
	--trm-gold-up: #1f7a5a;
	--trm-gold-down: #a33a3a;
	--trm-gold-ink: #1a1a1a;
	--trm-gold-muted: #6f6f6f;
	--trm-gold-grid: rgba( 0, 0, 0, 0.08 );
	--trm-gold-rule: rgba( 0, 0, 0, 0.12 );
	--trm-gold-surface: transparent;
	--trm-gold-radius: 4px;

	color: var( --trm-gold-ink );
	background: var( --trm-gold-surface );
	font-family: inherit;
	line-height: 1.45;
	container-type: inline-size;
}

.trm-gold *,
.trm-gold *::before,
.trm-gold *::after {
	box-sizing: border-box;
}

/* Cifras: alineadas en columna y estables al cambiar de valor. */
.trm-gold .notranslate,
.trm-gold__stats,
.trm-gold__value,
.trm-gold__delta {
	font-variant-numeric: tabular-nums;
	font-feature-settings: "tnum" 1;
}

/* --- Cabecera ---------------------------------------------------------- */

.trm-gold__head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 1rem 1.5rem;
	padding-bottom: 0.9rem;
	border-bottom: 1px solid var( --trm-gold-rule );
}

.trm-gold__title {
	margin: 0;
	font-size: 1.25rem;
	line-height: 1.25;
	letter-spacing: -0.01em;
}

.trm-gold__subtitle {
	margin: 0.3rem 0 0;
	font-size: 0.8125rem;
	color: var( --trm-gold-muted );
}

.trm-gold__readout {
	display: flex;
	align-items: baseline;
	gap: 0.6rem;
	margin-left: auto;
}

.trm-gold__value {
	font-size: clamp( 1.5rem, 1.1rem + 1.4vw, 2.125rem );
	font-weight: 600;
	letter-spacing: -0.02em;
	white-space: nowrap;
}

.trm-gold__delta {
	font-size: 0.9375rem;
	font-weight: 600;
	white-space: nowrap;
}

.trm-gold__delta.is-up {
	color: var( --trm-gold-up );
}

.trm-gold__delta.is-down {
	color: var( --trm-gold-down );
}

/* --- Controles --------------------------------------------------------- */

.trm-gold__controls {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 0.75rem 1.25rem;
	margin: 0.9rem 0 0.5rem;
}

.trm-gold__ranges {
	display: flex;
	gap: 0.25rem;
	overflow-x: auto;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.trm-gold__ranges::-webkit-scrollbar {
	display: none;
}

.trm-gold__range {
	flex: 0 0 auto;
	padding: 0.4rem 0.85rem;
	border: 1px solid var( --trm-gold-rule );
	border-radius: var( --trm-gold-radius );
	background: transparent;
	color: var( --trm-gold-muted );
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 500;
	line-height: 1.2;
	cursor: pointer;
	transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.trm-gold__range:hover {
	color: var( --trm-gold-ink );
	border-color: var( --trm-gold-accent );
}

.trm-gold__range[ aria-pressed="true" ] {
	color: #fff;
	background: var( --trm-gold-accent );
	border-color: var( --trm-gold-accent );
}

.trm-gold__toggles {
	display: flex;
	gap: 0.75rem;
}

.trm-gold__field {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	min-width: 0;
}

.trm-gold__field--grow {
	flex: 1 1 12rem;
}

.trm-gold__field-label {
	font-size: 0.6875rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var( --trm-gold-muted );
}

.trm-gold select,
.trm-gold input[ type="date" ] {
	padding: 0.45rem 0.6rem;
	border: 1px solid var( --trm-gold-rule );
	border-radius: var( --trm-gold-radius );
	background: #fff;
	color: var( --trm-gold-ink );
	font: inherit;
	font-size: 0.875rem;
	line-height: 1.3;
	max-width: 100%;
}

.trm-gold :is( button, select, input ):focus-visible {
	outline: 2px solid var( --trm-gold-accent );
	outline-offset: 2px;
}

/* --- Gráfico ----------------------------------------------------------- */

.trm-gold__canvas-wrap {
	position: relative;
	width: 100%;
	min-height: 220px;
}

/* Marca de agua: caja centrada cuyo lado es un porcentaje del área del
 * gráfico. Con background-size:contain el logotipo se ajusta dentro de esa
 * caja sea cual sea su proporción (isotipo cuadrado o logotipo apaisado),
 * sin deformarse ni desbordar. Si no hay variables definidas la opacidad es
 * 0: el pseudoelemento existe pero no se ve. */
.trm-gold__canvas-wrap::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	z-index: 0;
	width: var( --trm-gold-watermark-size, 62% );
	height: var( --trm-gold-watermark-size, 62% );
	transform: translate( -50%, -50% );
	background-image: var( --trm-gold-watermark, none );
	background-repeat: no-repeat;
	background-position: center;
	background-size: contain;
	opacity: var( --trm-gold-watermark-opacity, 0 );
	pointer-events: none;
}

/* El lienzo es transparente, así que basta con apilarlo por encima. */
.trm-gold__canvas-wrap canvas {
	position: relative;
	z-index: 1;
	width: 100% !important;
	height: 100% !important;
}

.trm-gold__state {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	text-align: center;
	font-size: 0.875rem;
	color: var( --trm-gold-muted );
	background: rgba( 255, 255, 255, 0.75 );
}

.trm-gold__state[ hidden ] {
	display: none;
}

/* --- Estadísticas ------------------------------------------------------ */

.trm-gold__stats {
	display: grid;
	grid-template-columns: repeat( 3, minmax( 0, 1fr ) );
	gap: 0.75rem 1.5rem;
	margin: 0.75rem 0 0;
	padding-top: 0.9rem;
	border-top: 1px solid var( --trm-gold-rule );
}

.trm-gold__stats dt {
	margin: 0 0 0.15rem;
	font-size: 0.6875rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var( --trm-gold-muted );
}

.trm-gold__stats dd {
	margin: 0;
	font-size: 0.9375rem;
	font-weight: 500;
}

/* --- Consulta por fecha ------------------------------------------------ */

.trm-gold__lookup {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0.75rem;
	margin-top: 1.25rem;
	padding-top: 1rem;
	border-top: 1px solid var( --trm-gold-rule );
}

.trm-gold__lookup-btn {
	padding: 0.5rem 1.1rem;
	border: 1px solid var( --trm-gold-accent );
	border-radius: var( --trm-gold-radius );
	background: var( --trm-gold-accent );
	color: #fff;
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.3;
	cursor: pointer;
	transition: opacity 0.15s ease;
}

.trm-gold__lookup-btn:hover {
	opacity: 0.88;
}

.trm-gold__lookup-result {
	flex: 1 0 100%;
	margin: 0.25rem 0 0;
	font-size: 0.9375rem;
	font-weight: 500;
	min-height: 1.4em;
}

.trm-gold__lookup-result.is-error {
	color: var( --trm-gold-down );
	font-weight: 400;
}

/* --- Nota legal -------------------------------------------------------- */

.trm-gold__note {
	margin: 1.25rem 0 0;
	font-size: 0.75rem;
	line-height: 1.55;
	color: var( --trm-gold-muted );
}

/* --- Adaptación a anchos reducidos ------------------------------------- */

@container ( max-width: 560px ) {
	.trm-gold__readout {
		margin-left: 0;
		width: 100%;
	}

	.trm-gold__stats {
		grid-template-columns: 1fr;
		gap: 0.6rem;
	}

	.trm-gold__controls {
		flex-direction: column;
		align-items: stretch;
	}

	.trm-gold__lookup-btn {
		flex: 1 0 auto;
	}
}

/* Reserva para navegadores sin soporte de container queries. */
@media ( max-width: 560px ) {
	.trm-gold__stats {
		grid-template-columns: 1fr;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.trm-gold * {
		transition: none !important;
	}
}
