*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
	/* Paleta Institucional CIMA (cima.ar) */
	--bg:			#eef3f8;
	--surface:		#ffffff;
	--header-bg:	#0f4c81;
	--bubble-in:	#f0f5fa;
	--bubble-out:	#d8eaf8;
	--text:			#162a3a;
	--muted:		#6c8294;
	--border:		#d5e1ec;
	--accent:		#0f4c81;
	--accent-light:	#0099cc;
	--agent:		#165a8a;
	--call:			#0099cc;
	--mltmd:		#2a9d8f;
	--online:		#28a745;
	--bgonl:		#1e7e34;
	--offline:		#dc3545;
	--btnpau:		#a71d2a;
	--red:			#e63946;
	--font-body:	'Plus Jakarta Sans', sans-serif;
	--font-serif:	'Fraunces', serif;
}

html, body { height: 100%; overflow: hidden; }

body {
	background: var(--bg);
	font-family: var(--font-body);
	font-size: 1rem;
	color: var(--text);
	display: flex;
	align-items: center;
	justify-content: center;
}

/* Textura sutil institucional */
body::before {
	content: '';
	position: fixed;
	inset: 0;
	background-image:
		repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(15, 76, 129, 0.03) 35px, rgba(15, 76, 129, 0.03) 70px);
	pointer-events: none;
}

.modal-overlay {
	display: none;
	position: fixed;
	top: 0; left: 0;
	width: 100%; height: 100%;
	background: rgba(15, 40, 65, 0.55);
	justify-content: center;
	align-items: center;
	z-index: 9999;
}

.modal-content {
	background: var(--surface);
	color: var(--text);
	padding: 24px;
	border-radius: 12px;
	border-top: 4px solid var(--accent);
	max-width: 320px;
	text-align: center;
	box-shadow: 0 10px 30px rgba(15, 76, 129, 0.15);
}

#mensajeError {
	color: var(--offline);
	font-weight: 600;
	margin-top: 12px;
	text-align: center;
}

#btnCerrarModal {
	background: var(--accent);
	color: #fff;
	border: none;
	padding: 8px 18px;
	font-size: 14px;
	font-weight: 500;
	border-radius: 8px;
	cursor: pointer;
	margin-top: 20px;
	transition: background 0.2s;
}
#btnCerrarModal:hover { background: var(--accent-light); }

#splash {
	height: 100vh;
	display: none;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
	gap: 12px;
	padding: 20px;
}

.splash-logo {
	width: 72px;
	height: 72px;
	border-radius: 14px;
	object-fit: contain;
	margin-bottom: 4px;
}

#splash h1 {
	color: var(--accent);
	font-weight: 600;
}

#splash p {
	color: var(--muted);
	font-size: 14px;
}

#btnEntrar {
	background: var(--accent);
	color: #fff;
	border: none;
	padding: 14px 32px;
	font-size: 16px;
	font-weight: 600;
	border-radius: 10px;
	cursor: pointer;
	margin-top: 10px;
	box-shadow: 0 4px 14px rgba(15, 76, 129, 0.22);
	transition: background 0.2s, transform 0.1s;
}
#btnEntrar:hover { background: var(--accent-light); }
#btnEntrar:active { transform: scale(0.98); }

/* Ventana principal del chat a pantalla completa */
.chat-window {
	position: fixed;
	inset: 0;
	width: 100vw;
	width: 100dvw;
	height: 100vh;
	height: 100dvh;
	max-width: 100%;
	max-height: 100%;
	background: var(--surface);
	border: none;
	border-radius: 0;
	display: none;
	flex-direction: column;
	overflow: hidden;
	box-shadow: none;
}

/* Header compacto en una sola línea */
.chat-header {
	padding: 10px 16px;
	min-height: 52px;
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	gap: 10px;
	background: var(--header-bg);
	color: #ffffff;
	flex-shrink: 0;
}

.header-logo-wrap {
	width: 32px !important;
	height: 32px !important;
	min-width: 32px;
	max-width: 32px;
	max-height: 32px;
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 8px;
	overflow: hidden;
}

.chat-header img,
.header-logo-wrap img,
.header-logo {
	width: 32px !important;
	height: 32px !important;
	max-width: 32px !important;
	max-height: 32px !important;
	object-fit: contain;
	display: block;
}

#splash img,
.splash-logo {
	width: 72px !important;
	height: 72px !important;
	max-width: 72px !important;
	max-height: 72px !important;
	border-radius: 14px;
	object-fit: contain;
	margin-bottom: 4px;
}

.avatar-wrap { position: relative; flex-shrink: 0; }

.avatar {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	background: var(--accent-light);
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-serif);
	font-style: italic;
	font-size: 18px;
	color: #fff;
	font-weight: 300;
	letter-spacing: -0.5px;
}

.online-dot, .offline-dot {
	position: absolute;
	bottom: -2px;
	right: -2px;
	width: 11px;
	height: 11px;
	border-radius: 50%;
	border: 2px solid var(--header-bg);
}
.online-dot  { background: var(--online); }
.offline-dot { background: var(--offline); }

.chat-info {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.chat-name {
	font-weight: 600;
	font-size: 15px;
	letter-spacing: -0.2px;
	color: #ffffff;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chat-status {
	font-size: 12px;
	color: #cce3f5;
	display: flex;
	align-items: center;
	gap: 5px;
	white-space: nowrap;
	flex-shrink: 0;
}

.status-on  { width: 7px; height: 7px; border-radius: 50%; background: var(--online); }
.status-off { width: 7px; height: 7px; border-radius: 50%; background: var(--offline); }

.header-close-btn {
	background: transparent;
	border: none;
	color: rgba(255, 255, 255, 0.42);
	width: 26px;
	height: 26px;
	border-radius: 50%;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	margin-left: 2px;
	transition: color 0.2s ease, background-color 0.2s ease;
}
.header-close-btn:hover,
.header-close-btn:active {
	color: rgba(255, 255, 255, 0.9);
	background: rgba(255, 255, 255, 0.12);
}

.header-actions {
	display: flex;
	gap: 5px;
	flex-direction: column;
	justify-content: flex-start;
	height: 680px;
	padding: 1em 3px;
}

.disable {
	pointer-events: none;
	background-color: #d9e2ec !important;
	border: 1px solid #bcccdc !important;
}

#carr { padding-left: 7px; }

.icon-dsc, .icon-call, .icon-trn, .icon-mlt, .icon-btn, .icon-pau, .icon-onl {
	margin-left: auto;
	color: #fff;
	border: none;
	border-radius: 6px;
	padding: 4px 12px;
	font-size: 12px;
	font-family: var(--font-body);
	cursor: pointer;
	width: 6.5em;
	height: 24.8px;
}

.icon-dsc { background: var(--offline); cursor: default; }
.icon-dsc:hover { background: var(--bg); color: var(--offline); border: 1px var(--offline) solid; }

.icon-call { background: var(--call); }
.icon-call:hover { background: var(--bg); color: var(--accent); border: 1px var(--call) solid; }

.icon-trn { background: var(--agent); }
.icon-trn:hover { background: var(--bg); color: var(--agent); border: 1px var(--agent) solid; }

.icon-mlt { background: var(--mltmd); }
.icon-mlt:hover { background: var(--bg); color: var(--text); border: 1px var(--mltmd) solid; }

.icon-btn { background: var(--accent); }
.icon-btn:hover { background: var(--bg); color: var(--accent); border: 1px var(--accent) solid; }
.icon-btn svg { width: 16px; height: 16px; }

.icon-pau { background: var(--offline); }
.icon-pau:hover { background: var(--bg); color: var(--offline); border: 1px var(--offline) solid; }

.icon-onl { background: var(--online); }
.icon-onl:hover { background: var(--bg); color: var(--online); border: 1px var(--bgonl) solid; }

.sub-bar {
	padding: 10px 20px;
	background: #e6f2fa;
	border-bottom: 1px solid var(--border);
	font-size: 12px;
	color: var(--accent);
	display: flex;
	align-items: center;
	gap: 8px;
	flex-shrink: 0;
}
.sub-bar.ok { background: #e8f6ee; border-bottom-color: #c3e6cb; color: #155724; }
.sub-bar.hidden { display: none; }
.sub-bar button {
	margin-left: auto;
	background: var(--accent);
	color: #fff;
	border: none;
	border-radius: 6px;
	padding: 4px 12px;
	font-size: 12px;
	font-family: var(--font-body);
	cursor: pointer;
}

/* Contenedor principal de pestañas y conversaciones */
.chat-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
	overflow: hidden;
}

/* Zona de mensajes */
.messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 14px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	scrollbar-width: thin;
	scrollbar-color: var(--border) transparent;
}

.date-sep {
	text-align: center;
	font-size: 11px;
	color: var(--muted);
	margin: 10px 0 8px;
	position: relative;
}
.date-sep::before, .date-sep::after {
	content: '';
	position: absolute;
	top: 50%;
	width: 28%;
	height: 1px;
	background: var(--border);
}
.date-sep::before { left: 0; }
.date-sep::after  { right: 0; }

/* Burbujas */
.msg-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	opacity: 0;
	transform: translateY(8px);
	animation: msgIn 0.25s ease forwards;
}
.msg-row.out { flex-direction: row-reverse; }

@keyframes msgIn {
	to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
	width: 28px;
	height: 28px;
	border-radius: 9px;
	background: var(--accent);
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-serif);
	font-style: italic;
	font-size: 12px;
	color: #fff;
	font-weight: 300;
}

.msg-row.same-sender .msg-avatar { visibility: hidden; }
.msg-row.same-sender { margin-top: -2px; }

.bubble {
	max-width: 100%;
	padding: 10px 14px;
	border-radius: 16px;
	line-height: 1.45;
	position: relative;
	word-break: break-word;
	font-size: 14px;
}

.msg-row:not(.out) .bubble {
	background: var(--bubble-in);
	color: var(--text);
	border: 1px solid #e1ecf5;
	border-bottom-left-radius: 2px;
	box-shadow: 0 1px 2px rgba(15, 76, 129, 0.05);
}

.msg-row.out .bubble {
	background: var(--bubble-out);
	color: var(--text);
	border: 1px solid #bedaf2;
	border-bottom-right-radius: 2px;
	box-shadow: 0 1px 2px rgba(15, 76, 129, 0.06);
}

.bubble-time {
	font-size: 10px;
	color: var(--muted);
	margin-top: 4px;
	text-align: right;
}

.typing-row { display: flex; align-items: flex-end; gap: 8px; }
.typing-bubble {
	background: var(--bubble-in);
	border: 1px solid #e1ecf5;
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	padding: 12px 16px;
	display: flex;
	gap: 4px;
}
.typing-bubble span {
	width: 6px; height: 6px;
	background: var(--accent-light);
	border-radius: 50%;
	animation: typingDot 1.2s ease-in-out infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
	30%           { transform: translateY(-5px); opacity: 1; }
}

/* Barra de vista previa de archivo adjunto */
.file-preview-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 14px;
	background: #e6f2fa;
	border-top: 1px solid var(--border);
	font-size: 12px;
	color: var(--accent);
	flex-shrink: 0;
}
.file-preview-bar.hidden {
	display: none;
}
.file-preview-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-weight: 500;
}
.file-preview-clear {
	background: transparent;
	border: none;
	color: var(--muted);
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	padding: 2px 6px;
	border-radius: 4px;
}
.file-preview-clear:hover {
	color: var(--offline);
	background: rgba(220, 53, 69, 0.1);
}

/* Input zone */
.input-zone {
	padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
	border-top: 1px solid var(--border);
	display: flex;
	gap: 10px;
	align-items: flex-end;
	background: #f8fbfe;
	flex-shrink: 0;
}

.input-wrap {
	flex: 1;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	display: flex;
	align-items: center;
	padding: 2px 8px 2px 12px;
	gap: 6px;
	transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within {
	border-color: var(--accent-light);
	box-shadow: 0 0 0 3px rgba(0, 153, 204, 0.12);
}

.attach-btn { cursor: pointer; display: flex; align-items: center; opacity: 0.75; transition: opacity 0.15s; }
.attach-btn:hover { opacity: 1; }
.attach-btn svg path { stroke: var(--accent); }
#fileInput { display: none; }

.msg-input {
	flex: 1;
	border: none;
	background: transparent;
	font-family: var(--font-body);
	font-size: 14px;
	color: var(--text);
	outline: none;
	padding: 7px 0;
	resize: none;
	max-height: 100px;
	line-height: 1.4;
}
.msg-input::placeholder { color: var(--muted); }

.btn-send {
	width: 38px; height: 38px;
	background: var(--accent);
	border: none;
	border-radius: 10px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.15s, transform 0.1s;
}
.btn-send:hover  { background: var(--accent-light); }
.btn-send:active { transform: scale(0.93); }
.btn-send svg    { width: 16px; height: 16px; fill: white; }

.welcome { text-align: center; padding: 24px 16px; color: var(--muted); }
.welcome-emoji { font-size: 36px; margin-bottom: 10px; }
.welcome p { font-size: 13px; line-height: 1.6; }

/* Notificación visual del sistema dentro del chat */
.push-badge {
	align-self: center;
	background: #e6f3fc;
	border: 1px solid #b8dcf5;
	border-radius: 10px;
	padding: 8px 14px;
	font-size: 12px;
	color: var(--accent);
	font-weight: 500;
	margin: 8px 0;
	display: flex;
	align-items: center;
	gap: 6px;
}

/* Barra de pestañas institucional (oculta si solo hay una conversación) */
.tabs-bar {
	display: flex;
	gap: 4px;
	padding: 10px 12px 0;
	border-bottom: 1px solid var(--border);
	overflow-x: auto;
	scrollbar-width: none;
	flex-shrink: 0;
	background: #f3f7fb;
}
.tabs-bar:not(:has(.tab:nth-child(2))) {
	display: none;
}
.tabs-bar::-webkit-scrollbar { display: none; }

.tab {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 7px 12px;
	border-radius: 8px 8px 0 0;
	font-size: 12px;
	font-weight: 600;
	color: var(--muted);
	cursor: pointer;
	white-space: nowrap;
	border: 1px solid transparent;
	border-bottom: none;
	transition: background 0.15s, color 0.15s;
	position: relative;
	bottom: -1px;
}
.tab:hover { background: #e6eef6; color: var(--accent); }
.tab.active {
	background: var(--surface);
	color: var(--accent);
	border-color: var(--border);
	border-top: 2px solid var(--accent-light);
	border-bottom-color: var(--surface);
}

.tab-badge {
	background: var(--accent-light);
	color: #fff;
	border-radius: 50%;
	padding: 2px;
	font-size: 10px;
	font-weight: 700;
	min-width: 17px;
	min-height: 17px;
	text-align: center;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	position: relative;
	overflow: hidden;
	transition: background 0.5s ease;
}
.tab-badge.hidden { display: none; }

.tab-close {
	width: 16px; height: 16px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 10px;
	color: var(--muted);
	margin-left: 2px;
}
.tab-close:hover { background: rgba(220, 53, 69, 0.15); color: var(--offline); }

/* Paneles de conversación */
.conversations-wrap { flex: 1; overflow: hidden; position: relative; background: var(--surface); }
.conv-panel { display: none; flex-direction: column; height: 100%; }
.conv-panel.active { display: flex; }
.conv-panel .messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

@keyframes tabPulse {
	0%, 100% { background: transparent; }
	50%      { background: rgba(0, 153, 204, 0.18); }
}

#templateMenu {
	display: none;
	position: absolute;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	width: 300px;
	max-height: 200px;
	min-height: 200px;
	overflow-y: auto;
	z-index: 1000;
	box-shadow: 0 8px 24px rgba(15, 76, 129, 0.12);
}
#templateMenu div { padding: 8px 12px; cursor: pointer; }
#templateMenu div.active { background: var(--accent); color: #ffffff; }

.category { font-weight: bold; background: #eef3f8; color: var(--accent); }
.category::after { content: " ▼"; float: right; }
.category.collapsed::after { content: " ▶"; }

.hidden { display: none; }
.visible { display: block; }
.invisible { visibility: hidden; }

#modalMsj, #modalTrn {
	position: fixed;
	top: 0; left: 0;
	width: 100%; height: 100%;
	background: rgba(15, 40, 65, 0.55);
	display: none;
	z-index: 9999;
	align-items: center;
	justify-content: center;
}

#modalMsj .contenido, #modalTrn .contenido {
	background: var(--surface);
	padding: 20px;
	border-radius: 12px;
	border-top: 4px solid var(--accent);
	min-width: 300px;
	max-width: 340px;
	text-align: center;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

#modalMsj .contenido > h3, #modalTrn .contenido > h3 {
	color: var(--accent);
	text-decoration: underline;
	margin-bottom: 0.5em;
}

#modalMsj .contenido .botones {
	display: flex;
	flex-direction: row;
	justify-content: center;
	gap: 10px;
}

#btnSiSP, #btnNoSP { padding: unset; margin: unset; }
#btnConfirmarTrn { margin-top: 1em; }

.overlay {
	background: var(--surface);
	display: none;
	padding: 20px;
	border-radius: 12px;
	max-width: 300px;
	text-align: center;
	align-items: center;
	flex-direction: column;
	gap: 12px;
}

.error-msg { color: var(--offline); font-size: 12px; margin-top: 8px; }

/* easyCHAT 2.0: acceso y áreas seguras */
#wa-external-box { max-height: 90dvh; overflow:auto; width:calc(100% - 32px); }
#splash { min-height:0; height:100dvh; overflow:auto; width:100%; }
#btnEntrar:disabled { opacity:.55; cursor:wait; }
#enlaceOriginal { width:min(90%,420px); padding:12px; border:1px solid var(--border); border-radius:8px; }
#btnRecuperar { background:var(--accent); color:white; padding:12px; border:0; border-radius:8px; }
.chat-header { padding-top:calc(10px + env(safe-area-inset-top,0px)); }

/* Asistente de permisos 2.0.4e */
#asistentePush[hidden], #diagPush[hidden] { display: none !important; }
#asistentePush { position: fixed; inset: 0; z-index: 1100; background: rgba(20,45,65,.55); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.asistente-push-card { box-sizing: border-box; width: 100%; max-width: 440px; max-height: 90dvh; overflow: auto; background: white; color: #162a3a; border-radius: 18px; border-top: 6px solid #145487; padding: 22px; text-align: center; }
.asistente-push-card h2 { color: #145487; font-size: 21px; margin: 0 0 12px; }
.asistente-push-card ol { text-align: left; padding-left: 24px; line-height: 1.5; }
.asistente-push-card li { margin: 12px 0; }
#btnRevisarPush { background: #145487; color: white; border: 0; border-radius: 10px; padding: 14px; width: 100%; font: inherit; font-weight: 600; }
#estadoAsistentePush { color: #a52b2b; font-size: 14px; }
