/* Fisiomap Soporte — chatbot (estilo WhatsApp) */

#fs-chat-root {
	position: fixed;
	bottom: 20px;
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#fs-chat-root.fs-pos-right { right: 20px; }
#fs-chat-root.fs-pos-left  { left: 20px; }

/* ---------- Botón flotante ---------- */
#fs-launcher {
	width: var(--fs-launcher-size, 64px);
	height: var(--fs-launcher-size, 64px);
	border-radius: 50%;
	border: none;
	cursor: pointer;
	background: var(--fs-primary, #0a7d6c);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
	padding: 0;
	overflow: hidden;
	transition: transform 0.15s ease;
}
#fs-launcher:hover { transform: scale(1.06); }
#fs-launcher img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 50%;
	display: block;
}
#fs-launcher svg { width: 55%; height: 55%; }
#fs-chat-root.fs-open #fs-launcher { display: none; }

/* ---------- Panel ---------- */
#fs-panel {
	display: none;
	position: fixed;
	bottom: 20px;
	width: 380px;
	height: 600px;
	max-height: calc(100vh - 40px);
	background: var(--fs-chat-bg, #e5ddd5);
	border-radius: 16px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
	overflow: hidden;
	flex-direction: column;
}
#fs-chat-root.fs-pos-right #fs-panel { right: 20px; }
#fs-chat-root.fs-pos-left  #fs-panel { left: 20px; }
#fs-chat-root.fs-open #fs-panel { display: flex; }

/* ---------- Cabecera ---------- */
.fs-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 14px;
	background: var(--fs-header, #075e54);
	color: #fff;
	flex-shrink: 0;
}
.fs-back {
	display: none;
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
}
.fs-avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	object-fit: cover;
	background: rgba(255, 255, 255, 0.2);
	flex-shrink: 0;
}
.fs-avatar-fallback {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 22px;
}
.fs-header-txt { flex: 1; min-width: 0; }
.fs-header-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.fs-header-status { font-size: 12px; opacity: 0.85; }
.fs-close {
	background: none;
	border: none;
	color: #fff;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	padding: 2px 6px;
}

/* ---------- Mensajes ---------- */
.fs-msgs {
	flex: 1;
	overflow-y: auto;
	padding: 14px 12px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
}
.fs-row { display: flex; }
.fs-row-user { justify-content: flex-end; }
.fs-row-bot  { justify-content: flex-start; }

.fs-bubble {
	max-width: 82%;
	padding: 8px 12px 16px;
	border-radius: 10px;
	font-size: 14.5px;
	line-height: 1.45;
	color: var(--fs-text, #1f2937);
	position: relative;
	white-space: pre-wrap;
	word-wrap: break-word;
	box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
}
.fs-row-user .fs-bubble {
	background: var(--fs-user-bubble, #dcf8c6);
	border-bottom-right-radius: 3px;
}
.fs-row-bot .fs-bubble {
	background: var(--fs-bot-bubble, #ffffff);
	border-bottom-left-radius: 3px;
}
.fs-time {
	position: absolute;
	right: 8px;
	bottom: 3px;
	font-size: 10px;
	color: rgba(0, 0, 0, 0.4);
}
.fs-typing::after {
	content: "▍";
	animation: fs-blink 1s steps(1) infinite;
}
@keyframes fs-blink { 50% { opacity: 0; } }

/* ---------- Formato enriquecido (Markdown) en las burbujas ---------- */
.fs-md { display: block; }
.fs-bubble a {
	color: #075e54;
	text-decoration: underline;
	word-break: break-word;
}
.fs-row-user .fs-bubble a { color: #054d43; }
.fs-bubble strong { font-weight: 700; }
.fs-bubble em { font-style: italic; }
.fs-bubble code {
	background: rgba(0, 0, 0, 0.08);
	padding: 1px 5px;
	border-radius: 4px;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.9em;
}
.fs-bubble ul,
.fs-bubble ol {
	margin: 4px 0;
	padding-left: 20px;
}
.fs-bubble li { margin: 2px 0; }

/* ---------- Tarjetas / formularios en el chat ---------- */
.fs-card { padding: 10px 12px; width: 82%; }
.fs-options, .fs-form-actions {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.fs-opt {
	display: block;
	width: 100%;
	padding: 9px 14px;
	border: 1.5px solid var(--fs-primary, #0a7d6c);
	color: var(--fs-primary, #0a7d6c);
	background: #fff;
	border-radius: 999px;
	font-size: 14px;
	cursor: pointer;
	text-align: center;
	font-weight: 600;
}
.fs-opt-primary {
	background: var(--fs-primary, #0a7d6c);
	color: #fff;
}
.fs-opt:disabled { opacity: 0.6; cursor: wait; }
.fs-ticket-form { display: flex; flex-direction: column; gap: 8px; }
.fs-field {
	width: 100%;
	padding: 9px 12px;
	border: 1px solid #d1d5db;
	border-radius: 8px;
	font-size: 14px;
	box-sizing: border-box;
}
textarea.fs-field {
	resize: vertical;
	min-height: 60px;
	font-family: inherit;
}
.fs-form-error { color: #b32d2e; font-size: 13px; min-height: 1em; }

/* ---------- Chips rápidos ---------- */
.fs-quick {
	display: flex;
	gap: 8px;
	padding: 0 12px 8px;
	flex-wrap: wrap;
	flex-shrink: 0;
}
.fs-chip {
	border: 1px solid var(--fs-primary, #0a7d6c);
	color: var(--fs-primary, #0a7d6c);
	background: rgba(255, 255, 255, 0.9);
	border-radius: 999px;
	padding: 6px 14px;
	font-size: 13px;
	cursor: pointer;
}

/* ---------- Pie / input ---------- */
.fs-footer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 8px 10px;
	background: #f0f2f5;
	flex-shrink: 0;
}
.fs-input {
	flex: 1;
	resize: none;
	border: none;
	border-radius: 20px;
	padding: 10px 16px;
	font-size: 15px;
	line-height: 1.4;
	max-height: 120px;
	outline: none;
	background: #fff;
	color: #111;
	box-sizing: border-box;
	font-family: inherit;
}
.fs-send {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	border: none;
	background: var(--fs-primary, #0a7d6c);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.fs-send:disabled { opacity: 0.5; }

/* ---------- Vista "Mis tickets" dentro del modal ---------- */
.fs-tickets-btn {
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	display: flex;
	align-items: center;
	opacity: 0.9;
}
.fs-tickets-btn:hover { opacity: 1; }

.fs-tickets {
	display: none;
	flex: 1;
	overflow-y: auto;
	padding: 14px;
	background: #f7f7f7;
	flex-direction: column;
	gap: 10px;
	-webkit-overflow-scrolling: touch;
}
#fs-panel.fs-mode-tickets .fs-tickets { display: flex; }
#fs-panel.fs-mode-tickets .fs-msgs,
#fs-panel.fs-mode-tickets .fs-quick,
#fs-panel.fs-mode-tickets .fs-footer { display: none; }
#fs-panel.fs-mode-tickets .fs-back { display: block; }

.fs-t-intro, .fs-t-loading {
	margin: 0;
	font-size: 14px;
	color: #4b5563;
}

.fs-t-tabs { display: flex; gap: 8px; }
.fs-t-tab {
	flex: 1;
	padding: 8px 12px;
	border: 1.5px solid var(--fs-primary, #0a7d6c);
	background: #fff;
	color: var(--fs-primary, #0a7d6c);
	border-radius: 999px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
}
.fs-t-tab.is-active {
	background: var(--fs-primary, #0a7d6c);
	color: #fff;
}

.fs-t-item {
	display: block;
	width: 100%;
	text-align: left;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
	padding: 10px 14px;
	cursor: pointer;
	font-family: inherit;
	font-size: 14px;
	color: var(--fs-text, #1f2937);
}
.fs-t-item:hover { border-color: var(--fs-primary, #0a7d6c); }
.fs-t-item-top {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	margin-bottom: 2px;
}
.fs-t-subject { font-size: 14px; }
.fs-t-date { font-size: 12px; color: #9ca3af; margin-top: 2px; }

.fs-t-badge {
	padding: 2px 10px;
	border-radius: 999px;
	font-size: 11.5px;
	font-weight: 600;
	background: #f3f4f6;
	color: #374151;
	white-space: nowrap;
}
.fs-t-badge-abierto           { background: #fee2e2; color: #991b1b; }
.fs-t-badge-en-curso          { background: #fef3c7; color: #92400e; }
.fs-t-badge-esperando-cliente { background: #dbeafe; color: #1e40af; }
.fs-t-badge-resuelto          { background: #d1fae5; color: #065f46; }
.fs-t-badge-cerrado           { background: #e5e7eb; color: #4b5563; }

.fs-t-back {
	background: none;
	border: none;
	color: var(--fs-primary, #0a7d6c);
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	padding: 0;
	text-align: left;
}

.fs-t-download {
	display: inline-block;
	font-size: 13px;
	font-weight: 600;
	color: var(--fs-primary, #0a7d6c);
	text-decoration: none;
}
.fs-t-download:hover { text-decoration: underline; }

.fs-t-msg {
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
	padding: 10px 14px;
	font-size: 14px;
}
.fs-t-msg.is-agent {
	background: #f0fdf4;
	border-color: #bbf7d0;
}
.fs-t-msg-meta {
	font-size: 12px;
	color: #6b7280;
	font-weight: 600;
	margin-bottom: 4px;
}
.fs-t-msg-body { white-space: pre-wrap; }

.fs-tickets textarea.fs-field {
	resize: vertical;
	font-family: inherit;
	min-height: 70px;
}

/* ---------- Móvil: pantalla completa estilo WhatsApp ---------- */
@media (max-width: 768px) {
	#fs-panel {
		top: 0;
		left: 0 !important;
		right: 0 !important;
		bottom: 0;
		width: 100%;
		height: 100dvh; /* JS lo ajusta con visualViewport al abrir el teclado */
		max-height: none;
		border-radius: 0;
		transform-origin: top left;
	}
	.fs-back { display: block; }
	.fs-close { display: none; }
	.fs-bubble { max-width: 88%; }

	/* Evita el zoom automático de iOS al enfocar el campo */
	.fs-input { font-size: 16px; }
}

/* Bloquea el scroll de fondo con el chat abierto en móvil */
@media (max-width: 768px) {
	html.fs-lock, html.fs-lock body {
		overflow: hidden;
		height: 100%;
		overscroll-behavior: none;
	}
}

/* =====================================================================
 * Modo página (solo en /chat-soporte/): el chat se integra DENTRO del
 * contenido de la página, de modo que la cabecera, el pie y el menú del
 * tema (y con ellos el resto de acciones del plugin) siguen visibles.
 * El JS mueve el widget al contenedor del shortcode y fija el alto
 * disponible en la variable --fs-page-h. El resto de páginas (widget
 * flotante) no se ve afectado.
 * ================================================================== */
#fs-chat-root.fs-page-mode {
	position: relative;
	inset: auto;
	top: auto;
	left: auto !important;
	right: auto !important;
	bottom: auto;
	width: 100%;
	height: var(--fs-page-h, 75vh);
	z-index: auto;
	display: block;
}
#fs-chat-root.fs-page-mode #fs-launcher { display: none; }
#fs-chat-root.fs-page-mode .fs-close { display: none !important; }

#fs-chat-root.fs-page-mode #fs-panel {
	position: relative;
	inset: auto;
	top: auto;
	left: auto !important;
	right: auto !important;
	bottom: auto;
	width: 100%;
	height: 100%;
	max-height: none;
	border-radius: 14px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
	transform: none;
	overflow: hidden;
}

/* Móvil: con el chat abierto ocupa el 100% de la pantalla (fijo, estilo
   WhatsApp, con manejo del teclado). El «atrás» solo vuelve del histórico
   de tickets al chat (no cierra la página). */
@media (max-width: 768px) {
	#fs-chat-root.fs-page-mode {
		position: static;
		height: auto;
	}
	#fs-chat-root.fs-page-mode #fs-panel {
		position: fixed;
		top: 0;
		left: 0 !important;
		right: 0 !important;
		bottom: 0;
		width: 100%;
		height: 100dvh; /* el JS lo ajusta con visualViewport al abrir el teclado */
		max-height: none;
		border-radius: 0;
		box-shadow: none;
		z-index: 100000;
	}
	#fs-chat-root.fs-page-mode #fs-panel .fs-back { display: none; }
	#fs-chat-root.fs-page-mode #fs-panel.fs-mode-tickets .fs-back { display: block; }
}
