@layer componentes {
	/* ---------------------------------------------------------- superficies */

	/* Plana: el borde ya separa. La sombra se reserva para lo que flota */
	.tarjeta {
		background: var(--superficie);
		border: 1px solid var(--borde);
		border-radius: var(--r-superficie);
		padding: var(--e5);
		margin-bottom: var(--e4);
	}
	.tarjeta.discreta { background: transparent; border-style: dashed; }
	.tarjeta > h2:first-child { margin-top: 0; }
	@media (max-width: 600px) { .tarjeta { padding: var(--e4); } }

	.bloque-cabecera { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--e2) var(--e5); margin-bottom: var(--e2); }
	.bloque-cabecera h2 { margin: 0; }

	.ayuda { color: var(--tenue); font-size: var(--t-sm); margin: var(--e1) 0 var(--e2); max-width: 78ch; }
	.suave { color: var(--suave); }
	.error { color: var(--error); }
	.contador { color: inherit; opacity: .7; font-weight: 500; font-variant-numeric: tabular-nums; }

	.aviso { background: var(--aviso-fondo); color: var(--aviso-texto); padding: var(--e3) var(--e4); border-radius: var(--r-control); }
	.aviso.ok-suave { background: var(--exito-fondo); color: var(--exito); }

	/* Vacío: dice qué falta y qué hacer, no solo que no hay nada */
	.vacio { color: var(--suave); background: var(--lienzo); border: 1px dashed var(--borde-fuerte); border-radius: var(--r-control); padding: var(--e4); margin: var(--e2) 0; }
	.vacio strong { color: var(--texto); }
	.vacio p { margin: var(--e1) 0 0; }

	/* ------------------------------------------------------------- botones */

	button.primario { background: var(--marca); color: var(--marca-texto); border-color: var(--marca); }
	button.primario:hover:not(:disabled) { background: var(--marca-hover); border-color: var(--marca-hover); color: var(--marca-texto); }
	button.primario:active:not(:disabled) { background: #0a4fc0; }
	button.exito { background: var(--exito); color: #fff; border-color: var(--exito); }
	button.exito:hover:not(:disabled) { background: #0f6534; border-color: #0f6534; color: #fff; }
	button.peligro { color: var(--error); border-color: var(--error-borde); }
	button.peligro:hover:not(:disabled) { background: var(--error-fondo); border-color: var(--error); color: var(--error); }
	button.peligro-lleno { background: var(--error); color: #fff; border-color: var(--error); }
	button.peligro-lleno:hover:not(:disabled) { background: #8f1e18; border-color: #8f1e18; color: #fff; }

	/* Acción de texto dentro de tablas y listas. Hit area de 32px aunque se vea pequeña */
	button.enlace {
		border: 0;
		background: none;
		color: var(--marca);
		padding: 6px var(--e2);
		min-height: 32px;
		text-decoration: underline;
		text-underline-offset: 2px;
		font-weight: 500;
	}
	button.enlace:hover:not(:disabled) { background: var(--tinte); border: 0; color: var(--marca); }
	button.enlace.peligro { color: var(--error); }
	button.enlace.peligro:hover:not(:disabled) { background: var(--error-fondo); color: var(--error); }

	/* -------------------------------------------------------- formularios */

	.fila-form { display: flex; flex-wrap: wrap; align-items: end; gap: var(--e3); margin: var(--e3) 0; }
	.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--e4); margin: var(--e3) 0 var(--e1); }
	.rejilla :is(input, select) { width: 100%; }

	/* ------------------------------------------------------------- insignias */

	.insignia {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		padding: 2px 10px;
		border-radius: var(--r-pastilla);
		font-size: 12px;
		font-weight: 700;
		line-height: 1.6;
		background: var(--lienzo);
		color: var(--suave);
		border: 1px solid var(--borde);
		white-space: nowrap;
	}
	/* Estado por forma y por color: punto lleno = activo, anillo = inactivo */
	.insignia.activa { background: var(--exito-fondo); color: var(--exito); border-color: var(--exito-borde); }
	.insignia.activa::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
	.insignia.inactiva::before { content: ""; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
	.insignia.plan { background: var(--tinte); color: var(--tinte-texto); border-color: #c6dcf3; }
	.insignia.aviso { background: var(--aviso-fondo); color: var(--aviso-texto); border-color: var(--aviso-borde); padding: 2px 10px; }

	/* --------------------------------------------------------------- avisos */

	.toast {
		position: fixed;
		left: 50%;
		bottom: var(--e5);
		transform: translateX(-50%);
		z-index: 60;
		display: flex;
		align-items: flex-start;
		gap: var(--e3);
		width: min(640px, calc(100vw - 2 * var(--e4)));
		padding: var(--e3) var(--e4);
		border-radius: var(--r-superficie);
		border: 1px solid var(--error-borde);
		background: var(--error-fondo);
		color: var(--error);
		font-weight: 500;
		white-space: pre-line;
		box-shadow: var(--sombra-flota);
		animation: sube var(--movimiento) ease-out;
	}
	.toast.ok { border-color: var(--exito-borde); background: var(--exito-fondo); color: var(--exito); }
	.toast span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
	.toast .cerrar { border: 0; background: none; color: inherit; font-size: 20px; line-height: 1; padding: 0 var(--e1); min-height: 28px; }
	.toast .cerrar:hover:not(:disabled) { background: rgba(0, 0, 0, .06); color: inherit; border: 0; }

	.dialogo {
		width: min(460px, calc(100vw - 32px));
		max-height: calc(100dvh - 32px);
		overflow-y: auto;
		overscroll-behavior: contain;
		padding: var(--e5);
		border: 1px solid var(--borde);
		border-radius: var(--r-superficie);
		background: var(--superficie);
		color: var(--texto);
		box-shadow: var(--sombra-flota);
	}
	.dialogo.ancho { width: min(760px, calc(100vw - 32px)); }
	.dialogo::backdrop { background: rgba(11, 31, 58, .45); }
	.dialogo[open] { animation: sube var(--movimiento) ease-out; }
	.dialogo p { margin: 0 0 var(--e5); color: var(--suave); white-space: pre-line; }
	.dialogo-botones { display: flex; justify-content: flex-end; gap: var(--e2); flex-wrap: wrap; }
	.dialogo label { margin-bottom: var(--e4); }
	.dialogo label.casilla { margin-top: 0; }

	@keyframes sube { from { opacity: 0; transform: translate(var(--desplaza, 0), 6px); } }
	.toast { --desplaza: -50%; }

	/* ---------------------------------------------------------- pestañas */

	/* Subrayadas: es navegación dentro de la página, no una acción */
	.pestanas {
		display: flex;
		gap: var(--e1);
		margin: var(--e5) 0 var(--e4);
		border-bottom: 1px solid var(--borde);
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scrollbar-width: thin;
	}
	.pestanas button {
		position: relative;
		border: 0;
		border-radius: var(--r-control) var(--r-control) 0 0;
		background: none;
		color: var(--suave);
		padding: var(--e3) var(--e4);
		white-space: nowrap;
	}
	.pestanas button::after { content: ""; position: absolute; left: var(--e2); right: var(--e2); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: transparent; transition: background-color var(--movimiento); }
	.pestanas button:hover:not(:disabled) { color: var(--marca); background: var(--tinte); border: 0; }
	.pestanas button[aria-selected="true"] { color: var(--marca); }
	.pestanas button[aria-selected="true"]::after { background: var(--marca); }

	/* ------------------------------------------------------------- datos */

	.datos { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--e4) var(--e5); margin: var(--e4) 0 0; }
	.dato dt { font-size: var(--t-xs); color: var(--tenue); font-weight: 600; }
	.dato dd { margin: 2px 0 0; overflow-wrap: anywhere; }

	/* ---------------------------------------------------------------- tablas */

	.tabla-caja { overflow: auto; margin: var(--e2) 0; border: 1px solid var(--borde); border-radius: var(--r-control); max-height: min(78vh, 900px); max-width: 100%; min-width: 0; overscroll-behavior: contain; }
	th, td { text-align: left; padding: 10px var(--e3); border-bottom: 1px solid var(--borde); white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
	th { background: var(--lienzo); color: var(--suave); font-weight: 700; font-size: var(--t-xs); position: sticky; top: 0; z-index: 1; }
	td { font-variant-numeric: tabular-nums; }
	/* Tablas para revisar datos de un cliente: el texto se parte en vez de cortarse con «…» */
	.muestra-datos th, .muestra-datos td, .vista th, .vista td, #tabla-bandeja th, #tabla-bandeja td { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; min-width: 90px; max-width: 460px; vertical-align: top; }
	th.num, td.num { text-align: right; }
	tbody tr:hover td, tbody tr:focus-within td { background: #f7faff; }
	tbody tr:last-child td { border-bottom: 0; }
	td.cambio { background: var(--aviso-fondo); color: var(--aviso-texto); font-weight: 700; }
	td .insignia { vertical-align: middle; }

	/* ---------------------------------------------------------------- cifras */

	.cifras { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--e3); margin: var(--e3) 0; }
	.cifra { border: 1px solid var(--borde); border-radius: var(--r-control); padding: var(--e3) var(--e4); display: grid; align-content: start; gap: 2px; background: var(--superficie); }
	.cifra strong { font-size: var(--t-lg); line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -.015em; overflow-wrap: anywhere; }
	.cifra span { color: var(--suave); font-size: var(--t-sm); }
	.cifra.mal strong { color: var(--error); }
	.cifra.bien strong { color: var(--exito); }
}
