/* Widget de chat flotante (asistente IA). z-index por debajo de modales
   de Bootstrap (~1050) y del panel de carrito lateral. */

.chat-widget {
	position: relative;
}

.chat-widget-bubble {
	position: fixed;
	bottom: 24px;
	right: 24px;
	/* 1035: por encima de .barraCarrito (1030, barra "Añadir al carrito" de
	   la ficha en móvil — si no, tapa la burbuja e impide abrir el chat) y
	   por debajo del backdrop de Bootstrap (~1040) y sus modales (~1050). */
	z-index: 1035;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	border: none;
	background-color: var(--rp-brand, #C51A4A);
	color: #fff;
	font-size: 22px;
	cursor: pointer;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-widget-bubble:hover {
	transform: scale(1.06);
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.chat-widget-badge {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background-color: #ffb020;
	border: 2px solid #fff;
}

.chat-widget-panel {
	position: fixed;
	bottom: 92px;
	right: 24px;
	z-index: 1035;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 120px);
	display: none;
	flex-direction: column;
	background-color: #fff;
	border-radius: 12px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
	overflow: hidden;
}

.chat-widget-panel.chat-widget-open {
	display: flex;
}

.chat-widget-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background-color: var(--rp-brand, #C51A4A);
	color: #fff;
	font-weight: 600;
}

.chat-widget-title i {
	margin-right: 6px;
}

.chat-widget-close,
.chat-widget-minimize {
	background: none;
	border: none;
	color: #fff;
	font-size: 16px;
	cursor: pointer;
	padding: 4px;
}

/* El botón de minimizar solo se muestra en móvil (el X de escritorio ya cumple esa función). */
.chat-widget-minimize {
	display: none;
}

.chat-widget-messages {
	flex: 1;
	overflow-y: auto;
	padding: 14px 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background-color: #f7f7f9;
}

.chat-widget-msg {
	max-width: 82%;
	padding: 8px 12px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.4;
	word-wrap: break-word;
}

.chat-widget-msg--user {
	align-self: flex-end;
	background-color: var(--rp-brand, #C51A4A);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.chat-widget-msg--assistant {
	align-self: flex-start;
	background-color: #fff;
	color: #222;
	border: 1px solid #e3e3e8;
	border-bottom-left-radius: 4px;
}

.chat-widget-msg--system {
	align-self: center;
	background-color: #fff8e1;
	color: #6b5300;
	border: 1px solid #f0e0a8;
	font-size: 13px;
	text-align: center;
	max-width: 92%;
}

.chat-widget-msg-time {
	font-size: 10px;
	opacity: 0.6;
	margin-top: 3px;
	text-align: right;
}

.chat-widget-msg-text a {
	color: var(--rp-brand, #C51A4A);
	text-decoration: underline;
	word-break: break-all;
}

.chat-widget-msg-text a:hover {
	color: var(--rp-brand-dark, #a8153f);
}

.chat-widget-cards {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-self: flex-start;
	max-width: 100%;
}

.chat-widget-card {
	display: flex;
	flex-direction: column;
	width: 130px;
	padding: 8px;
	border: 1px solid #e3e3e8;
	border-radius: 12px;
	background: #fff;
	text-decoration: none;
	color: #222;
	transition: border-color .15s ease, box-shadow .15s ease;
}

.chat-widget-card:hover {
	border-color: var(--rp-brand, #C51A4A);
	box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.chat-widget-card-img {
	width: 100%;
	height: 90px;
	object-fit: contain;
	margin-bottom: 6px;
}

.chat-widget-card-name {
	font-size: 12px;
	line-height: 1.3;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.chat-widget-card-price {
	font-size: 13px;
	font-weight: 700;
	color: var(--rp-brand, #C51A4A);
	margin-top: 4px;
}

.chat-widget-card-badge {
	font-size: 11px;
	color: #8a6d00;
	background: #fff3cd;
	border-radius: 6px;
	padding: 1px 6px;
	margin-top: 4px;
	align-self: flex-start;
}

.chat-widget-typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 8px 16px;
	background-color: #f7f7f9;
	font-size: 12px;
	color: #777;
}

.chat-widget-typing.d-none {
	display: none;
}

.chat-widget-typing-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background-color: #999;
	animation: chatWidgetBlink 1.2s infinite;
}

.chat-widget-typing-dot:nth-child(2) {
	animation-delay: 0.2s;
}

.chat-widget-typing-dot:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes chatWidgetBlink {
	0%, 80%, 100% { opacity: 0.3; }
	40% { opacity: 1; }
}

.chat-widget-form {
	display: flex;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #e3e3e8;
	background-color: #fff;
}

.chat-widget-input {
	flex: 1;
	border: 1px solid #d0d0d8;
	border-radius: 20px;
	padding: 8px 14px;
	font-size: 14px;
	outline: none;
}

.chat-widget-input:focus {
	border-color: var(--rp-brand, #C51A4A);
}

.chat-widget-send {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background-color: #d0d0da;
	color: #fff;
	cursor: pointer;
	flex-shrink: 0;
	transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-widget-send.chat-widget-send--active {
	background-color: var(--rp-brand, #C51A4A);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.chat-widget-send.chat-widget-send--active:hover {
	background-color: var(--rp-brand-dark, #a8153f);
}

.chat-widget-send:disabled {
	opacity: 0.5;
	cursor: default;
}

/* Móvil: el panel ocupa toda la pantalla. */
@media (max-width: 768px) {
	.chat-widget-bubble {
		/* 76px: la barra "Añadir al carrito" (.barraCarrito, ~47px + margen)
		   ocupa todo el ancho abajo en la ficha; la burbuja debe quedar
		   por encima de ella para no tapar el botón de compra. */
		bottom: 76px;
		right: 16px;
	}

	.chat-widget-panel {
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		max-width: 100%;
		/* height:560px del estilo base seguía ganando a bottom:0 y el panel
		   quedaba cortado a media pantalla; hay que fijar la altura al viewport. */
		height: 100vh;
		height: 100dvh;
		max-height: 100vh;
		max-height: 100dvh;
		border-radius: 0;
	}

	.chat-widget-minimize {
		display: block;
	}

	/* Con el panel abierto en móvil la burbuja se oculta (el panel es fullscreen). */
	.chat-widget.chat-widget-active .chat-widget-bubble {
		display: none;
	}
}
