/* ==========================================================================
   Side panel de conversa com a IA.
   Recolhido: uma faixa estreita no canto direito.
   Expandido: ocupa até 70% da tela, abrindo da direita para a esquerda.
   ========================================================================== */

/* Reserva a faixa de 48px do assistente recolhido para que o conteúdo
   principal não fique por baixo dela. Só aplica quando o painel existe
   (usuário autenticado). Elementos fixed — navbar/sidebar — se posicionam
   pela viewport e não são afetados por este padding. Quando expandido, o
   painel sobrepõe o conteúdo de propósito (não empurra). */
body:has(#chat-sidepanel) {
	padding-right: 48px;
}

#chat-sidepanel {
	position: fixed;
	top: 0;
	right: 0;
	height: 100vh;
	width: 48px;
	max-width: 100vw;
	background: #ffffff;
	border-left: 1px solid #e0e0e0;
	box-shadow: -2px 0 12px rgba(0, 0, 0, .12);
	display: flex;
	flex-direction: column;
	z-index: 1090;
	transition: width .32s cubic-bezier(.22, .61, .36, 1);
	overflow: hidden;
}

#chat-sidepanel.chat-expanded {
	width: 70vw;
}

/* Faixa recolhida: preenche todo o painel estreito e abre a conversa.
   Some ao expandir (quem passa a comandar o recolher é o header azul). */
.chat-launcher {
	flex: 1 1 auto;
	width: 48px;
	height: 100%;
	border: none;
	background: #2f6f9f;
	color: #fff;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 0;
	transition: background .2s ease;
}

.chat-launcher:hover {
	background: #285f88;
}

.chat-launcher .chat-launcher-icon {
	font-size: 20px;
}

.chat-launcher .chat-launcher-label {
	writing-mode: vertical-rl;
	transform: rotate(180deg);
	font-size: 12px;
	letter-spacing: 1px;
	text-transform: uppercase;
	font-weight: 600;
}

#chat-sidepanel.chat-expanded .chat-launcher {
	display: none;
}

/* Corpo do chat: só aparece quando expandido. */
.chat-body {
	flex: 1 1 auto;
	min-width: 0;
	display: none;
	flex-direction: column;
	height: 100%;
}

#chat-sidepanel.chat-expanded .chat-body {
	display: flex;
}

/* O header azul é o próprio controle para recolher o painel. */
.chat-header {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: #2f6f9f;
	color: #fff;
	cursor: pointer;
}

.chat-header h4 {
	margin: 0;
	font-size: 16px;
	font-weight: 600;
}

.chat-header .chat-close {
	background: none;
	border: none;
	color: #fff;
	font-size: 20px;
	cursor: pointer;
	line-height: 1;
	opacity: .85;
}

.chat-header .chat-close:hover {
	opacity: 1;
}

.chat-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: #f7f9fb;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.chat-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.5;
	white-space: pre-line;
	word-wrap: break-word;
}

.chat-msg-user {
	align-self: flex-end;
	background: #2f6f9f;
	color: #fff;
	border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
	align-self: flex-start;
	background: #ffffff;
	color: #333;
	border: 1px solid #e5e9ee;
	border-bottom-left-radius: 4px;
}

.chat-msg-error {
	align-self: center;
	background: #fdecea;
	color: #a4262c;
	border: 1px solid #f3c9c6;
	font-size: 13px;
}

.chat-typing {
	align-self: flex-start;
	color: #7a8791;
	font-size: 13px;
	font-style: italic;
}

/* Fontes consultadas pela IA, renderizadas como links para a busca indexada. */
.chat-sources {
	align-self: flex-start;
	max-width: 85%;
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: -4px;
}

.chat-sources-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: .6px;
	color: #7a8791;
	font-weight: 600;
}

.chat-source-link {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	width: fit-content;
	max-width: 100%;
	font-size: 13px;
	color: #2f6f9f;
	background: #eef4f9;
	border: 1px solid #d7e3ee;
	border-radius: 14px;
	padding: 5px 12px;
	text-decoration: none;
	line-height: 1.3;
}

.chat-source-link:hover,
.chat-source-link:focus {
	background: #e2edf6;
	color: #285f88;
	text-decoration: none;
}

.chat-source-link .fas {
	font-size: 12px;
	flex: 0 0 auto;
}

.chat-empty {
	margin: auto;
	text-align: center;
	color: #9aa5ad;
	font-size: 14px;
	padding: 0 20px;
}

.chat-input {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid #e5e9ee;
	background: #fff;
}

.chat-input textarea {
	flex: 1 1 auto;
	resize: none;
	max-height: 120px;
	min-height: 40px;
	padding: 9px 12px;
	border: 1px solid #cfd6dd;
	border-radius: 20px;
	font-size: 14px;
	line-height: 1.4;
	outline: none;
}

.chat-input textarea:focus {
	border-color: #2f6f9f;
}

.chat-input .chat-send {
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 50%;
	background: #2f6f9f;
	color: #fff;
	font-size: 16px;
	cursor: pointer;
	transition: background .2s ease;
}

.chat-input .chat-send:hover {
	background: #285f88;
}

.chat-input .chat-send:disabled {
	background: #b9c4cd;
	cursor: not-allowed;
}

/* Em telas pequenas o painel expandido ocupa quase toda a largura. */
@media (max-width: 768px) {
	#chat-sidepanel.chat-expanded {
		width: 100vw;
	}
}
