/**
 * Widget de soporte.
 *
 * En su propio archivo y no en style.css, que ya es muy largo: además solo se
 * carga donde el widget se pinta.
 */

.rb-soporte-boton {
	position: fixed;
	right: 22px;
	bottom: 22px;
	z-index: 99990;
	width: 56px;
	height: 56px;
	min-width: 0;
	padding: 0;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	background: var(--rb-orange);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(254, 85, 4, 0.34);
	transition: transform 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

/*
 * Mientras se hace scroll (ver soporte.js): más discreto en vez de tapar de
 * lleno lo que haya debajo en ese instante, y vuelve solo a su sitio en
 * cuanto la página deja de moverse.
 */
.rb-soporte-boton--atenuado {
	opacity: 0.35;
	pointer-events: none;
}

.rb-soporte-boton:hover {
	background: var(--rb-orange-dark);
	transform: translateY(-2px);
}

.rb-soporte-boton svg {
	width: 26px;
	height: 26px;
	grid-area: 1 / 1;
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.rb-soporte-boton__cerrar,
.rb-soporte-boton.is-abierto .rb-soporte-boton__abrir {
	opacity: 0;
	transform: scale(0.6);
}

.rb-soporte-boton.is-abierto .rb-soporte-boton__cerrar {
	opacity: 1;
	transform: none;
}

/* Punto de aviso cuando hay una conversación viva */
.rb-soporte-boton__aviso {
	position: absolute;
	top: 3px;
	right: 3px;
	width: 13px;
	height: 13px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: #d92d20;
}

.rb-soporte-boton:focus { outline: none; }

.rb-soporte-boton:focus-visible {
	outline: 2px solid var(--rb-ink);
	outline-offset: 3px;
}

/* --- La ventana --------------------------------------------------------- */

.rb-soporte {
	position: fixed;
	right: 22px;
	bottom: 90px;
	z-index: 99991;
	width: min(380px, calc(100vw - 32px));
	height: min(560px, calc(100vh - 130px));
	display: flex;
	flex-direction: column;
	border-radius: 14px;
	overflow: hidden;
	background: #fff;
	box-shadow: 0 18px 50px rgba(7, 23, 41, 0.22);
	opacity: 0;
	transform: translateY(14px) scale(0.98);
	transform-origin: bottom right;
	transition: opacity 0.22s ease, transform 0.22s ease;
}

.rb-soporte.is-abierto {
	opacity: 1;
	transform: none;
}

/* El atributo hidden pone display:none con muy poca fuerza, y el display:flex
   de arriba le gana: la ventana quedaba invisible pero seguía ahí, comiéndose
   los clics de toda la esquina inferior derecha de la página. */
.rb-soporte[hidden] {
	display: none;
}

.rb-soporte:focus { outline: none; }

.rb-soporte__cabecera {
	flex: none;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: var(--rb-ink);
	color: #fff;
}

.rb-soporte__cabecera > div {
	flex: 1;
	min-width: 0;
}

.rb-soporte__titulo {
	display: block;
	font-size: 14.5px;
	font-weight: 700;
}

.rb-soporte__subtitulo {
	font-size: 11.5px;
	color: #9aa6b4;
}

.rb-soporte .rb-soporte__cerrar,
.rb-soporte .rb-soporte__atras {
	flex: none;
	width: 30px;
	height: 30px;
	min-width: 0;
	padding: 0;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	font-size: 19px;
	line-height: 1;
	cursor: pointer;
}

.rb-soporte .rb-soporte__cerrar:hover,
.rb-soporte .rb-soporte__atras:hover {
	background: rgba(255, 255, 255, 0.22);
}

.rb-soporte__cuerpo {
	position: relative;
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	background: #f7f9fb;
}

/* Solo una vista a la vez */
.rb-soporte-vista {
	display: none;
	flex: 1;
	min-height: 0;
	flex-direction: column;
}

.rb-soporte-vista.is-activa {
	display: flex;
}

/* --- Listado ------------------------------------------------------------ */

.rb-soporte__conversaciones {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 12px;
}

.rb-soporte button.rb-soporte__conversacion {
	display: block;
	width: 100%;
	min-width: 0;
	margin-bottom: 8px;
	padding: 12px 14px;
	border: 1px solid var(--rb-line);
	border-radius: 9px;
	background: #fff;
	text-align: left;
	cursor: pointer;
}

.rb-soporte button.rb-soporte__conversacion:hover {
	border-color: var(--rb-orange);
}

.rb-soporte__conv-asunto {
	display: block;
	font-size: 13.5px;
	font-weight: 650;
	line-height: 1.35;
	color: var(--rb-ink);
}

.rb-soporte__conv-pie {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-top: 5px;
	font-size: 11px;
	color: var(--rb-muted);
}

.rb-soporte__conv-estado {
	padding: 2px 8px;
	border-radius: 999px;
	background: #eef1f5;
	font-weight: 650;
}

.rb-soporte__conv-estado.is-abierta {
	background: #fff7f2;
	color: var(--rb-orange-text);
}

.rb-soporte__vacio {
	margin: 24px 8px;
	text-align: center;
	font-size: 13px;
	color: var(--rb-muted);
}

.rb-soporte button.rb-soporte__nuevo {
	flex: none;
	margin: 0;
	width: 100%;
	height: 48px;
	min-width: 0;
	border: 0;
	border-top: 1px solid var(--rb-line);
	border-radius: 0;
	background: var(--rb-orange);
	color: #fff;
	font-size: 14px;
	font-weight: 650;
	cursor: pointer;
}

.rb-soporte button.rb-soporte__nuevo:hover {
	background: var(--rb-orange-dark);
}

/* --- Conversación ------------------------------------------------------- */

.rb-soporte__mensajes {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 14px 12px;
}

.rb-soporte__mensaje {
	max-width: 84%;
	margin-bottom: 10px;
	padding: 9px 12px;
	border-radius: 12px;
	font-size: 13px;
	line-height: 1.45;
}

/* Lo que escribe el cliente, a la derecha; lo del agente, a la izquierda */
.rb-soporte__mensaje.is-mio {
	margin-left: auto;
	background: var(--rb-orange);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.rb-soporte__mensaje.is-agente {
	background: #fff;
	border: 1px solid var(--rb-line);
	color: var(--rb-ink);
	border-bottom-left-radius: 4px;
}

.rb-soporte__texto p:first-child { margin-top: 0; }
.rb-soporte__texto p:last-child { margin-bottom: 0; }
.rb-soporte__texto img {
	/* !important a propósito: el cuerpo del mensaje viene de correo y suele
	   traer su propio "style=max-width:100%" en línea, que gana a cualquier
	   regla normal. Sin esto, una foto llena la conversación entera. */
	max-width: min(200px, 100%) !important;
	height: auto !important;
	width: auto !important;
	margin-top: 6px;
	border-radius: 6px;
	cursor: zoom-in;
	display: block;
}

.rb-soporte__hora {
	display: block;
	margin-top: 3px;
	font-size: 10.5px;
	opacity: 0.7;
}

.rb-soporte__responder {
	flex: none;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin: 0;
	padding: 10px 12px;
	border-top: 1px solid var(--rb-line);
	background: #fff;
}

/* El clip: el campo de archivo de serie es feo y no cabe, así que se esconde
   y se pulsa sobre el icono. */
.rb-soporte__clip {
	flex: none;
	width: 36px;
	height: 36px;
	display: grid;
	place-items: center;
	border-radius: 50%;
	color: var(--rb-muted);
	cursor: pointer;
}

.rb-soporte__clip:hover {
	background: #f1f4f7;
	color: var(--rb-ink);
}

.rb-soporte__clip input {
	display: none;
}

.rb-soporte__clip svg {
	width: 18px;
	height: 18px;
}

/* Y el del formulario de consulta nueva, que ahí sí se ve entero */
.rb-soporte .rb-soporte__form input[type="file"] {
	width: 100%;
	padding: 8px;
	border: 1px dashed var(--rb-line);
	border-radius: 7px;
	background: #fff;
	font-size: 12px;
}

.rb-soporte .rb-soporte__responder textarea {
	flex: 1;
	min-width: 0;
	max-height: 120px;
	padding: 10px 12px;
	border: 1px solid var(--rb-line);
	border-radius: 20px;
	background: #f7f9fb;
	font-size: 13px;
	line-height: 1.4;
	resize: none;
	overflow-y: auto;
}

.rb-soporte .rb-soporte__responder textarea:focus {
	border-color: var(--rb-orange);
	outline: 0;
}

.rb-soporte .rb-soporte__responder button {
	flex: none;
	width: 40px;
	height: 40px;
	min-width: 0;
	padding: 0;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	background: var(--rb-orange);
	color: #fff;
	cursor: pointer;
}

.rb-soporte .rb-soporte__responder button svg {
	width: 19px;
	height: 19px;
}

.rb-soporte__responder.is-enviando { opacity: 0.6; pointer-events: none; }

/* --- Formularios -------------------------------------------------------- */

.rb-soporte__form {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	margin: 0;
	padding: 14px;
}

.rb-soporte .rb-soporte__form p { margin: 0 0 12px; }

.rb-soporte .rb-soporte__form label {
	display: block;
	margin-bottom: 4px;
	font-size: 12px;
	font-weight: 650;
	color: var(--rb-ink);
}

.rb-soporte .rb-soporte__form input,
.rb-soporte .rb-soporte__form select,
.rb-soporte .rb-soporte__form textarea {
	width: 100%;
	padding: 9px 11px;
	border: 1px solid var(--rb-line);
	border-radius: 7px;
	background: #fff;
	font-size: 13px;
	line-height: 1.4;
}

.rb-soporte .rb-soporte__form input:focus,
.rb-soporte .rb-soporte__form select:focus,
.rb-soporte .rb-soporte__form textarea:focus {
	border-color: var(--rb-orange);
	outline: 0;
}

.rb-soporte .rb-soporte__form p > span {
	display: block;
	margin-top: 4px;
	font-size: 11px;
	color: var(--rb-muted);
}

.rb-soporte button.rb-soporte__enviar {
	width: 100%;
	height: 44px;
	min-width: 0;
	border: 0;
	border-radius: 7px;
	background: var(--rb-orange);
	color: #fff;
	font-size: 14px;
	font-weight: 650;
	cursor: pointer;
}

.rb-soporte button.rb-soporte__enviar:hover { background: var(--rb-orange-dark); }
.rb-soporte__form.is-enviando { opacity: 0.6; pointer-events: none; }

/* --- Enviada ------------------------------------------------------------ */

.rb-soporte__enviada {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 26px 24px;
	text-align: center;
}

.rb-soporte__enviada svg {
	width: 44px;
	height: 44px;
	padding: 10px;
	border-radius: 50%;
	background: #eaf6e2;
	color: #3f7a06;
}

.rb-soporte__enviada b { font-size: 15px; color: var(--rb-ink); }

.rb-soporte__enviada p {
	margin: 0;
	font-size: 12.5px;
	color: var(--rb-muted);
}

.rb-soporte button.rb-soporte__volver {
	margin-top: 8px;
	min-width: 0;
	padding: 9px 18px;
	border: 1px solid var(--rb-line);
	border-radius: 7px;
	background: #fff;
	font-size: 13px;
	font-weight: 650;
	color: var(--rb-ink);
	cursor: pointer;
}

/* --- Estados ------------------------------------------------------------ */

.rb-soporte__cargando {
	height: 3px;
	margin: 10px;
	border-radius: 3px;
	background: linear-gradient(90deg, #eef1f5 25%, #dde3ea 50%, #eef1f5 75%);
	background-size: 200% 100%;
	animation: rb-soporte-cargando 1.1s linear infinite;
}

@keyframes rb-soporte-cargando {
	from { background-position: 200% 0; }
	to   { background-position: -200% 0; }
}

.rb-soporte__error {
	position: absolute;
	left: 12px;
	right: 12px;
	bottom: 12px;
	margin: 0;
	padding: 10px 12px;
	border-radius: 8px;
	background: #d92d20;
	color: #fff;
	font-size: 12.5px;
}

/* --- Móvil -------------------------------------------------------------- */

@media (max-width: 480px) {
	/*
	 * Antes aquí ponía "bottom: 76px" para esquivar la barra fija que Storefront
	 * deja abajo en el móvil. Esa barra se quitó (todo está en la cabecera, que
	 * además se queda pegada), así que el botón estaba subido esquivando algo
	 * que ya no existe. Vuelve abajo, como en escritorio.
	 */
	.rb-soporte-boton {
		right: 14px;
		bottom: 16px;
		width: 50px;
		height: 50px;
	}

	.rb-soporte {
		right: 8px;
		left: 8px;
		/* 16 del botón + 50 de alto + 10 de hueco. */
		bottom: 76px;
		width: auto;
		height: min(520px, calc(100vh - 180px));
	}
}


/* --- Aviso de cookies --- */

/*
 * Mientras el aviso de cookies está en pantalla, el botón de soporte se sube
 * por encima. Si no, queda tapado y parece que ha desaparecido justo cuando
 * alguien puede tener dudas sobre lo que le están preguntando.
 *
 * La altura del aviso la mide su propio JavaScript y la deja en
 * --rb-cookies-alto, porque cambia con el ancho de la pantalla: en un móvil el
 * texto ocupa varias líneas más que en un ordenador.
 */
body.rb-cookies-visible .rb-soporte-boton {
	bottom: calc(22px + var(--rb-cookies-alto, 0px));
}

/*
 * Mientras la hoja de categorías está abierta (".cat-sheet", móvil), el botón
 * de soporte se aparta del todo en vez de solo subir: va fijo en la esquina
 * inferior derecha con z-index 99990, por encima de la hoja (9999), y ahí
 * tapaba la última fila de la lista de la derecha ("Cadenas" y las que caigan
 * en esa esquina). En cualquier vista a pantalla completa el botón solo
 * estorba.
 */
body.rb-cat-abierta .rb-soporte-boton {
	display: none;
}

body.rb-cookies-visible .rb-soporte {
	bottom: calc(94px + var(--rb-cookies-alto, 0px));
}

@media (max-width: 480px) {

	body.rb-cookies-visible .rb-soporte-boton {
		bottom: calc(16px + var(--rb-cookies-alto, 0px));
	}

	body.rb-cookies-visible .rb-soporte {
		bottom: calc(76px + var(--rb-cookies-alto, 0px));
	}
}
