/* =========================================================
   Primaderm Chat — widget flotante
   Blindado frente al tema de WordPress: todo va bajo .pdc-root
   ========================================================= */

/* --- Variables de marca y reset de caja --- */
.pdc-root {
	--pdc-brand: #8c004b;
	--pdc-brand-dark: #6d003b;
	--pdc-ink: #111111;
	--pdc-surface: #ffffff;
	--pdc-bot-bg: #f4f4f5;
	--pdc-border: #e5e5e5;
	--pdc-muted: #6b6b6b;

	position: fixed;
	bottom: 20px;
	z-index: 999998;
	font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
	line-height: normal;
	box-sizing: border-box;
}

.pdc-root,
.pdc-root * ,
.pdc-root *::before,
.pdc-root *::after {
	box-sizing: border-box;
}

.pdc-root h2,
.pdc-root p {
	margin: 0;
}

.pdc-root button {
	border: 0;
	background: none;
	font: inherit;
	color: inherit;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

/* --- Posición del widget --- */
.pdc-pos-right {
	right: 20px;
}

.pdc-pos-left {
	left: 20px;
}

/* --- Utilidad accesible: oculta visualmente sin quitar del flujo AT --- */
.pdc-root .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* --- Blindaje para el atributo hidden dentro del plugin --- */
.pdc-root [hidden] {
	display: none !important;
}

/* --- Burbuja flotante ---
   Los selectores de botón van prefijados con .pdc-root para superar en
   especificidad al reset `.pdc-root button` de arriba; si no, el reset
   les quitaría el fondo y el color. --- */
.pdc-root .pdc-toggle {
	position: relative;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--pdc-brand);
	color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
	transition: background-color 0.2s ease, transform 0.15s ease;
}

.pdc-root .pdc-toggle:hover {
	background: var(--pdc-brand-dark);
	transform: scale(1.05);
}

.pdc-root .pdc-toggle:active {
	transform: scale(0.97);
}

/* --- Iconos superpuestos de la burbuja (chat / cerrar) --- */
.pdc-icon {
	position: absolute;
	top: 50%;
	left: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transform: translate(-50%, -50%);
	transition: opacity 0.15s ease, transform 0.15s ease;
}

.pdc-icon-chat {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

.pdc-icon-close {
	opacity: 0;
	transform: translate(-50%, -50%) scale(0.6);
}

.pdc-root[data-open="true"] .pdc-icon-chat {
	opacity: 0;
	transform: translate(-50%, -50%) scale(0.6);
}

.pdc-root[data-open="true"] .pdc-icon-close {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

/* --- Panel de conversación --- */
.pdc-panel {
	position: absolute;
	bottom: 76px;
	width: 380px;
	height: min(70vh, 600px);
	background: var(--pdc-surface);
	border-radius: 14px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(8px);
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.pdc-pos-right .pdc-panel {
	right: 0;
}

.pdc-pos-left .pdc-panel {
	left: 0;
}

.pdc-root[data-open="true"] .pdc-panel {
	opacity: 1;
	transform: translateY(0);
}

/* --- Cabecera --- */
.pdc-header {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	background: var(--pdc-brand);
	color: #ffffff;
	padding: 14px 16px;
}

.pdc-root .pdc-title {
	margin: 0;
	padding: 0;
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.3;
	color: #ffffff;
	text-transform: none;
	letter-spacing: normal;
}

.pdc-root .pdc-reset {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	color: #ffffff;
	opacity: 0.8;
	transition: opacity 0.15s ease, background-color 0.15s ease;
}

.pdc-root .pdc-reset:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.15);
}

/* --- Historial de mensajes --- */
.pdc-log {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scrollbar-width: thin;
	scrollbar-color: var(--pdc-border) transparent;
}

.pdc-log::-webkit-scrollbar {
	width: 6px;
}

.pdc-log::-webkit-scrollbar-track {
	background: transparent;
}

.pdc-log::-webkit-scrollbar-thumb {
	background-color: var(--pdc-border);
	border-radius: 999px;
}

/* --- Mensajes --- */
.pdc-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 0.95rem;
	line-height: 1.45;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.pdc-msg-user {
	align-self: flex-end;
	background: var(--pdc-brand);
	color: #ffffff;
	border-bottom-right-radius: 4px;
}

.pdc-msg-bot {
	align-self: flex-start;
	background: var(--pdc-bot-bg);
	color: var(--pdc-ink);
	border-bottom-left-radius: 4px;
}

.pdc-msg-error {
	border-left: 3px solid var(--pdc-brand);
	color: #3a3a3a;
}

/* La API devuelve nombres de producto en negrita. */
.pdc-root .pdc-msg strong {
	font-weight: 600;
}

/* --- Indicador "escribiendo…" --- */
.pdc-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 12px 14px;
}

.pdc-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--pdc-muted);
	opacity: 0.4;
	animation: pdc-blink 1.1s infinite ease-in-out;
}

.pdc-dot:nth-child(2) {
	animation-delay: 0.16s;
}

.pdc-dot:nth-child(3) {
	animation-delay: 0.32s;
}

@keyframes pdc-blink {
	0%, 80%, 100% {
		opacity: 0.4;
		transform: translateY(0);
	}
	40% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

/* --- Formulario de envío --- */
.pdc-root .pdc-form {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 12px;
	border-top: 1px solid var(--pdc-border);
	background: var(--pdc-surface);
}

/* Prefijado con .pdc-root para ganar a reglas del tema del tipo
   `input[type="text"]`, que tienen mayor especificidad que una clase suelta. */
.pdc-root .pdc-input {
	flex: 1;
	min-width: 0;
	width: auto;
	max-width: none;
	margin: 0;
	height: auto;
	padding: 10px 14px;
	border: 1px solid var(--pdc-border);
	border-radius: 999px;
	font-size: 0.95rem;
	font-family: inherit;
	line-height: 1.4;
	color: var(--pdc-ink);
	background: var(--pdc-surface);
	box-shadow: none;
	transition: border-color 0.15s ease;
}

.pdc-root .pdc-input:focus {
	outline: none;
	border-color: var(--pdc-brand);
	box-shadow: none;
}

.pdc-root .pdc-send {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: var(--pdc-brand);
	color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color 0.15s ease;
}

.pdc-root .pdc-send:hover {
	background: var(--pdc-brand-dark);
}

.pdc-root .pdc-send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* --- Estado ocupado (petición en curso) --- */
.pdc-busy .pdc-input,
.pdc-busy .pdc-send {
	opacity: 0.6;
}

/* --- Foco visible en elementos interactivos (incluido el log, que es
       enfocable con tabindex="0" para poder recorrerlo con el teclado) --- */
.pdc-root button:focus,
.pdc-root input:focus,
.pdc-root [tabindex]:focus {
	outline: 2px solid var(--pdc-brand);
	outline-offset: 2px;
}

.pdc-root button:focus:not(:focus-visible),
.pdc-root input:focus:not(:focus-visible),
.pdc-root [tabindex]:focus:not(:focus-visible) {
	outline: none;
}

.pdc-root button:focus-visible,
.pdc-root input:focus-visible,
.pdc-root [tabindex]:focus-visible {
	outline: 2px solid var(--pdc-brand);
	outline-offset: 2px;
}

/* El outline del log se dibuja hacia dentro para no salirse del panel. */
.pdc-log:focus,
.pdc-log:focus-visible {
	outline-offset: -2px;
}

/* --- Ocultar todo el widget en móvil si se ha desactivado --- */
.pdc-hide-mobile {
	display: block;
}

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 480px) {
	.pdc-root {
		bottom: 14px;
	}

	.pdc-pos-right {
		right: 14px;
	}

	.pdc-pos-left {
		left: 14px;
	}

	/* Mismo prefijo que la regla base para no perder por especificidad. */
	.pdc-root .pdc-toggle {
		width: 56px;
		height: 56px;
	}

	.pdc-panel {
		width: calc(100vw - 24px);
		height: calc(100vh - 110px);
		height: calc(100dvh - 110px);
		bottom: 70px;
	}
}

@media (max-width: 768px) {
	.pdc-hide-mobile {
		display: none;
	}
}

/* --- Respeto a reduce-motion: se anulan transiciones y animaciones --- */
@media (prefers-reduced-motion: reduce) {
	.pdc-root,
	.pdc-root *,
	.pdc-root *::before,
	.pdc-root *::after {
		transition: none !important;
		animation: none !important;
	}
}
