/**
 * Estilos do frontend — Acodecs Tutor Avatar
 * Prefixo CSS: .acd-
 *
 * Estrutura:
 * 1. Variáveis CSS (tokens de design)
 * 2. Trigger (botão flutuante)
 * 3. Painel expandido
 * 4. Cabeçalho do painel
 * 5. Abas de navegação
 * 6. Corpo e balão de fala
 * 7. Rodapé e controles TTS
 * 8. Variantes de posição
 * 9. Animações
 * 10. Dark Mode
 * 11. Responsividade mobile
 *
 * Desenvolvido por Acodecs Tech
 */

/* =========================================================================
   1. Variáveis CSS — tokens de design
   ========================================================================= */
:root {
	/* Cores principais (sobrescritas via inline style pelo PHP) */
	--acd-primary:        #4C6FD1;
	--acd-primary-light:  #7a97e0;
	--acd-primary-dark:   #3457b3;

	/* Cores de interface */
	--acd-text:           #1a202c;
	--acd-text-muted:     #718096;
	--acd-text-light:     #a0aec0;
	--acd-bg:             #ffffff;
	--acd-bg-secondary:   #f7fafc;
	--acd-border:         #e2e8f0;
	--acd-success:        #38a169;
	--acd-danger:         #e53e3e;

	/* Sombras */
	--acd-shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
	--acd-shadow:         0 4px 16px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.08);
	--acd-shadow-lg:      0 20px 40px rgba(0,0,0,.15), 0 8px 16px rgba(0,0,0,.1);

	/* Arredondamento */
	--acd-radius-sm:      6px;
	--acd-radius:         12px;
	--acd-radius-lg:      16px;
	--acd-radius-full:    9999px;

	/* Z-index */
	--acd-z:              9999;

	/* Dimensões do painel */
	--acd-panel-width:    380px;
	--acd-panel-max-height: 520px;

	/* Dimensões do trigger */
	--acd-trigger-size:   64px;

	/* Transições */
	--acd-transition:     .25s cubic-bezier(.4, 0, .2, 1);
}

/* =========================================================================
   2. Trigger — botão flutuante circular
   ========================================================================= */

/* Container principal do avatar */
.acd-wrapper {
	position: fixed;
	z-index: var(--acd-z);
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	box-sizing: border-box;
}

.acd-wrapper *,
.acd-wrapper *::before,
.acd-wrapper *::after {
	box-sizing: border-box;
}

/* Botão flutuante */
.acd-trigger {
	position: relative;
	width: var(--acd-trigger-size);
	height: var(--acd-trigger-size);
	border-radius: var(--acd-radius-full);
	background: var(--acd-primary);
	border: 3px solid #fff;
	cursor: pointer;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--acd-shadow);
	transition: transform var(--acd-transition), box-shadow var(--acd-transition);
	animation: acd-pulse-border 3s ease-in-out infinite;
	outline: none;
}

.acd-trigger:hover {
	transform: scale(1.08);
	box-shadow: var(--acd-shadow-lg);
}

.acd-trigger:focus-visible {
	outline: 3px solid var(--acd-primary-light);
	outline-offset: 3px;
}

.acd-trigger:active {
	transform: scale(.96);
}

/* Imagem interna do trigger */
.acd-trigger-img {
	width: 100%;
	height: 100%;
	border-radius: var(--acd-radius-full);
	object-fit: cover;
	display: block;
}

/* Indicador de pulso (ponto animado) */
.acd-badge-pulse {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 12px;
	height: 12px;
	background: var(--acd-success);
	border-radius: var(--acd-radius-full);
	border: 2px solid #fff;
	animation: acd-pulse 2s ease-in-out infinite;
}

/* Tooltip do trigger */
.acd-trigger-tooltip {
	position: absolute;
	bottom: calc(100% + 10px);
	left: 50%;
	transform: translateX(-50%);
	background: var(--acd-text);
	color: #fff;
	font-size: 12px;
	padding: 5px 10px;
	border-radius: var(--acd-radius-sm);
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	transition: opacity var(--acd-transition);
}

.acd-trigger-tooltip::after {
	content: '';
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	border: 5px solid transparent;
	border-top-color: var(--acd-text);
}

.acd-trigger:hover .acd-trigger-tooltip {
	opacity: 1;
}

/* =========================================================================
   3. Painel expandido
   ========================================================================= */

.acd-panel {
	position: absolute;
	width: var(--acd-panel-width);
	max-height: var(--acd-panel-max-height);
	background: var(--acd-bg);
	border-radius: var(--acd-radius-lg);
	box-shadow: var(--acd-shadow-lg);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	/* Estado inicial: oculto e escalonado */
	opacity: 0;
	transform: scale(.9) translateY(10px);
	transform-origin: bottom right;
	pointer-events: none;
	transition:
		opacity var(--acd-transition),
		transform var(--acd-transition);
	border: 1px solid var(--acd-border);
}

/* Estado aberto do painel */
.acd-panel.acd-panel--open {
	opacity: 1;
	transform: scale(1) translateY(0);
	pointer-events: all;
}

/* =========================================================================
   4. Cabeçalho do painel
   ========================================================================= */

.acd-panel-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: var(--acd-primary);
	color: #fff;
	flex-shrink: 0;
}

.acd-header-left {
	display: flex;
	align-items: center;
	gap: 10px;
	flex: 1;
	min-width: 0; /* Evita overflow do texto */
}

/* Avatar pequeno no header */
.acd-header-avatar {
	width: 40px;
	height: 40px;
	border-radius: var(--acd-radius-full);
	object-fit: cover;
	flex-shrink: 0;
	border: 2px solid rgba(255,255,255,.4);
}

.acd-header-info {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.acd-title {
	font-size: .9rem;
	font-weight: 700;
	color: #fff;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	display: block;
}

.acd-subtitle {
	font-size: .75rem;
	color: rgba(255,255,255,.8);
}

/* Indicador de status "online" */
.acd-header-status {
	display: flex;
	align-items: center;
	gap: 5px;
	flex-shrink: 0;
}

.acd-status-dot {
	width: 8px;
	height: 8px;
	background: #68d391;
	border-radius: var(--acd-radius-full);
	animation: acd-pulse 2s infinite;
}

.acd-status-text {
	font-size: .75rem;
	color: rgba(255,255,255,.8);
}

/* Botão fechar */
.acd-btn-close {
	background: rgba(255,255,255,.15);
	border: none;
	border-radius: var(--acd-radius-sm);
	width: 30px;
	height: 30px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	color: #fff;
	flex-shrink: 0;
	transition: background var(--acd-transition);
	padding: 0;
}

.acd-btn-close:hover {
	background: rgba(255,255,255,.3);
}

.acd-btn-close:focus-visible {
	outline: 2px solid rgba(255,255,255,.6);
	outline-offset: 2px;
}

/* =========================================================================
   5. Navegação por abas
   ========================================================================= */

.acd-tabs {
	display: flex;
	background: var(--acd-bg-secondary);
	border-bottom: 1px solid var(--acd-border);
	flex-shrink: 0;
	overflow-x: auto;
	scrollbar-width: none; /* Firefox */
}

.acd-tabs::-webkit-scrollbar {
	display: none;
}

.acd-tab {
	background: none;
	border: none;
	border-bottom: 2px solid transparent;
	padding: 10px 14px;
	font-size: .8rem;
	font-weight: 600;
	color: var(--acd-text-muted);
	cursor: pointer;
	white-space: nowrap;
	transition: color var(--acd-transition), border-color var(--acd-transition);
	flex-shrink: 0;
}

.acd-tab:hover {
	color: var(--acd-primary);
}

.acd-tab.active,
.acd-tab[aria-selected="true"] {
	color: var(--acd-primary);
	border-bottom-color: var(--acd-primary);
}

.acd-tab:focus-visible {
	outline: 2px solid var(--acd-primary-light);
	outline-offset: -2px;
}

/* =========================================================================
   6. Corpo do painel e balão de fala
   ========================================================================= */

.acd-panel-body {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	scrollbar-width: thin;
	scrollbar-color: var(--acd-border) transparent;
}

.acd-panel-body::-webkit-scrollbar {
	width: 4px;
}

.acd-panel-body::-webkit-scrollbar-track {
	background: transparent;
}

.acd-panel-body::-webkit-scrollbar-thumb {
	background: var(--acd-border);
	border-radius: var(--acd-radius-full);
}

/* Balão de fala */
.acd-speech-bubble {
	position: relative;
	background: var(--acd-bg-secondary);
	border: 1px solid var(--acd-border);
	border-radius: var(--acd-radius);
	padding: 16px;
	min-height: 80px;
}

/* Seta do balão de fala (aponta para o avatar) */
.acd-speech-bubble::before {
	content: '';
	position: absolute;
	bottom: -10px;
	left: 24px;
	width: 18px;
	height: 18px;
	background: var(--acd-bg-secondary);
	border-right: 1px solid var(--acd-border);
	border-bottom: 1px solid var(--acd-border);
	transform: rotate(45deg);
}

/* Área de conteúdo dinâmico */
.acd-content {
	color: var(--acd-text);
	font-size: .875rem;
	line-height: 1.7;
}

.acd-content p {
	margin: 0 0 10px;
}

.acd-content p:last-child {
	margin-bottom: 0;
}

.acd-content ul,
.acd-content ol {
	padding-left: 18px;
	margin: 8px 0;
}

.acd-content li {
	margin-bottom: 4px;
}

.acd-content strong {
	color: var(--acd-primary-dark);
}

/* Seções de conteúdo dentro do painel */
.acd-content-section {
	margin-bottom: 16px;
}

.acd-content-section:last-child {
	margin-bottom: 0;
}

.acd-content-section-title {
	font-size: .75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .06em;
	color: var(--acd-text-muted);
	margin: 0 0 6px;
}

/* Pill de duração */
.acd-duration-badge {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	background: var(--acd-primary);
	color: #fff;
	font-size: .75rem;
	font-weight: 600;
	padding: 3px 10px;
	border-radius: var(--acd-radius-full);
	margin-top: 4px;
}

/* Aviso importante */
.acd-aviso {
	background: #fffbeb;
	border: 1px solid #f6e05e;
	border-left: 3px solid #d69e2e;
	border-radius: var(--acd-radius-sm);
	padding: 10px 12px;
	font-size: .85rem;
	color: #744210;
	margin-top: 8px;
}

/* Lista de materiais */
.acd-materiais-list {
	list-style: none;
	padding: 0;
	margin: 0;
}

.acd-materiais-list li {
	margin-bottom: 6px;
}

.acd-materiais-list a {
	display: flex;
	align-items: center;
	gap: 6px;
	color: var(--acd-primary);
	text-decoration: none;
	font-size: .875rem;
	padding: 6px 10px;
	border-radius: var(--acd-radius-sm);
	background: rgba(76, 111, 209, .06);
	transition: background var(--acd-transition);
}

.acd-materiais-list a:hover {
	background: rgba(76, 111, 209, .14);
	text-decoration: underline;
}

/* Mensagem de conteúdo vazio */
.acd-empty-message {
	color: var(--acd-text-muted);
	font-style: italic;
	font-size: .85rem;
	text-align: center;
	padding: 16px 0;
}

/* Indicador de carregamento (3 pontos) */
.acd-loading {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 5px;
	padding: 20px;
}

.acd-loading-dot {
	width: 8px;
	height: 8px;
	background: var(--acd-primary);
	border-radius: var(--acd-radius-full);
	animation: acd-loading-bounce .8s ease-in-out infinite;
}

.acd-loading-dot:nth-child(2) { animation-delay: .15s; }
.acd-loading-dot:nth-child(3) { animation-delay: .3s; }

/* =========================================================================
   7. Rodapé e controles TTS
   ========================================================================= */

.acd-panel-footer {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 16px;
	border-top: 1px solid var(--acd-border);
	background: var(--acd-bg);
	flex-shrink: 0;
}

/* Botões do rodapé */
.acd-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 14px;
	border-radius: var(--acd-radius-sm);
	font-size: .8rem;
	font-weight: 600;
	cursor: pointer;
	border: none;
	transition: background var(--acd-transition), transform var(--acd-transition);
}

.acd-btn:focus-visible {
	outline: 2px solid var(--acd-primary-light);
	outline-offset: 2px;
}

.acd-btn:active {
	transform: scale(.97);
}

/* Botão "Ouvir" */
.acd-btn-tts {
	background: var(--acd-primary);
	color: #fff;
}

.acd-btn-tts:hover {
	background: var(--acd-primary-dark);
}

/* Botão "Parar" */
.acd-btn-stop {
	background: var(--acd-danger);
	color: #fff;
}

.acd-btn-stop:hover {
	background: #c53030;
}

/* Indicador visual de leitura ativa (barras animadas) */
.acd-tts-indicator {
	display: flex;
	align-items: flex-end;
	gap: 3px;
	height: 20px;
	margin-left: auto;
}

.acd-tts-bar {
	width: 3px;
	background: var(--acd-primary);
	border-radius: 2px;
	animation: acd-tts-wave .8s ease-in-out infinite;
}

.acd-tts-bar:nth-child(1) { height: 60%; animation-delay: 0s; }
.acd-tts-bar:nth-child(2) { height: 100%; animation-delay: .15s; }
.acd-tts-bar:nth-child(3) { height: 70%; animation-delay: .3s; }
.acd-tts-bar:nth-child(4) { height: 40%; animation-delay: .45s; }

/* =========================================================================
   8. Variantes de posição
   ========================================================================= */

/* Flutuante — canto inferior direito (padrão) */
.acd-position-floating-right {
	bottom: 24px;
	right: 24px;
}

.acd-position-floating-right .acd-panel {
	bottom: calc(var(--acd-trigger-size) + 12px);
	right: 0;
	transform-origin: bottom right;
}

/* Flutuante — canto inferior esquerdo */
.acd-position-floating-left {
	bottom: 24px;
	left: 24px;
}

.acd-position-floating-left .acd-panel {
	bottom: calc(var(--acd-trigger-size) + 12px);
	left: 0;
	transform-origin: bottom left;
}

/* Embutido abaixo do conteúdo */
.acd-position-inline-bottom {
	position: relative;
	bottom: auto;
	right: auto;
	display: block;
	margin-top: 32px;
}

.acd-position-inline-bottom .acd-trigger {
	display: none; /* Modo inline não tem trigger flutuante */
}

.acd-position-inline-bottom .acd-panel {
	position: relative;
	bottom: auto;
	right: auto;
	width: 100%;
	max-width: 100%;
	transform: none;
	transform-origin: top center;
	border-radius: var(--acd-radius);
}

.acd-position-inline-bottom .acd-panel.acd-panel--open {
	transform: none;
}

/* Barra lateral direita */
.acd-position-sidebar-right {
	top: 120px;
	right: 0;
}

.acd-position-sidebar-right .acd-trigger {
	border-radius: var(--acd-radius) 0 0 var(--acd-radius);
	width: 48px;
	height: 56px;
}

.acd-position-sidebar-right .acd-panel {
	top: 0;
	right: calc(var(--acd-trigger-size) + 4px);
	transform-origin: top right;
}

/* =========================================================================
   9. Animações com @keyframes
   ========================================================================= */

/* Pulso do indicador verde do trigger */
@keyframes acd-pulse {
	0%, 100% { transform: scale(1); opacity: 1; }
	50%       { transform: scale(1.4); opacity: .7; }
}

/* Borda pulsante do trigger */
@keyframes acd-pulse-border {
	0%, 100% { box-shadow: 0 0 0 0 rgba(76, 111, 209, .4), var(--acd-shadow); }
	50%       { box-shadow: 0 0 0 8px rgba(76, 111, 209, 0), var(--acd-shadow); }
}

/* Ondas do indicador TTS */
@keyframes acd-tts-wave {
	0%, 100% { transform: scaleY(.6); }
	50%       { transform: scaleY(1); }
}

/* Indicador de carregamento */
@keyframes acd-loading-bounce {
	0%, 100% { transform: translateY(0); }
	50%       { transform: translateY(-6px); }
}

/* Transição de entrada do conteúdo ao trocar de aba */
@keyframes acd-fade-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: translateY(0); }
}

.acd-content-animate {
	animation: acd-fade-in .2s ease forwards;
}

/* =========================================================================
   10. Dark Mode
   ========================================================================= */

@media (prefers-color-scheme: dark) {
	:root {
		--acd-text:           #f0f4f8;
		--acd-text-muted:     #a0aec0;
		--acd-bg:             #1a202c;
		--acd-bg-secondary:   #2d3748;
		--acd-border:         #4a5568;
	}

	.acd-panel {
		border-color: #4a5568;
	}

	.acd-speech-bubble {
		border-color: #4a5568;
	}

	.acd-aviso {
		background: #3d3200;
		border-color: #b7791f;
		color: #fbd38d;
	}

	.acd-materiais-list a {
		background: rgba(76, 111, 209, .15);
	}

	.acd-materiais-list a:hover {
		background: rgba(76, 111, 209, .28);
	}
}

/* =========================================================================
   11. Responsividade — mobile first
   ========================================================================= */

@media (max-width: 768px) {
	/* Em mobile, o painel abre em tela cheia */
	.acd-panel {
		position: fixed !important;
		inset: 0 !important;
		width: 100vw !important;
		max-height: 100dvh !important;
		border-radius: 0 !important;
		transform-origin: center bottom !important;
	}

	/* Quando aberto em mobile, força display correto */
	.acd-panel.acd-panel--open {
		transform: translateY(0) !important;
	}

	/* Estado inicial no mobile: slide de baixo para cima */
	.acd-panel {
		transform: translateY(100%) !important;
	}

	.acd-panel.acd-panel--open {
		transform: translateY(0) !important;
	}

	/* Ajuste do wrapper no mobile */
	.acd-wrapper {
		bottom: 16px !important;
		right: 16px !important;
		left: auto !important;
		top: auto !important;
	}

	/* Painel do tipo inline adapta ao mobile */
	.acd-position-inline-bottom {
		position: fixed !important;
		bottom: 0 !important;
		left: 0 !important;
		right: 0 !important;
	}

	/* Cabeçalho maior no mobile para melhor toque */
	.acd-panel-header {
		padding: 16px 18px;
	}

	/* Abas com texto menor no mobile */
	.acd-tab {
		font-size: .75rem;
		padding: 10px 12px;
	}

	/* Botão fechar maior (área de toque) */
	.acd-btn-close {
		width: 36px;
		height: 36px;
	}

	/* Botões TTS empilhados no rodapé mobile */
	.acd-panel-footer {
		flex-wrap: wrap;
		gap: 6px;
	}

	.acd-btn {
		flex: 1;
		justify-content: center;
	}
}

@media (max-width: 480px) {
	/* Trigger um pouco menor em telas muito pequenas */
	:root {
		--acd-trigger-size: 56px;
	}
}

/* ==========================================================================
   CHAT COM IA
   ========================================================================== */

/* Área do chat — ocupa o mesmo espaço que o speech-bubble */
.acd-chat-area {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
	border-top: 1px solid rgba(0,0,0,.08);
}

/* Lista de mensagens com scroll */
.acd-chat-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 12px 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-height: 160px;
	max-height: 240px;
}

/* Bolha de mensagem */
.acd-chat-msg {
	max-width: 82%;
	padding: 9px 13px;
	border-radius: 16px;
	font-size: .85rem;
	line-height: 1.45;
	word-break: break-word;
}

/* Mensagem do aluno — à direita */
.acd-chat-msg--user {
	align-self: flex-end;
	background: var(--acd-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

/* Mensagem do assistente — à esquerda */
.acd-chat-msg--assistant {
	align-self: flex-start;
	background: #f0f2f5;
	color: #1a202c;
	border-bottom-left-radius: 4px;
}

/* Mensagem de erro */
.acd-chat-msg--error {
	align-self: flex-start;
	background: #fff5f5;
	color: #c53030;
	border: 1px solid #fed7d7;
	border-bottom-left-radius: 4px;
}

/* Indicador de digitação (três pontos pulsantes) */
.acd-chat-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 10px 14px;
}
.acd-chat-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #a0aec0;
	animation: acdChatDot 1.2s infinite ease-in-out;
}
.acd-chat-typing span:nth-child(2) { animation-delay: .2s; }
.acd-chat-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes acdChatDot {
	0%, 80%, 100% { transform: scale(.6); opacity: .4; }
	40%           { transform: scale(1);  opacity: 1;  }
}

/* Área de input */
.acd-chat-input-wrap {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid rgba(0,0,0,.08);
	background: #fff;
}

.acd-chat-input {
	flex: 1;
	padding: 8px 12px;
	border: 1px solid #e2e8f0;
	border-radius: 20px;
	font-size: .85rem;
	outline: none;
	transition: border-color .2s;
}
.acd-chat-input:focus {
	border-color: var(--acd-primary);
}

.acd-chat-send {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	border: none;
	background: var(--acd-primary);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background .2s, transform .1s;
}
.acd-chat-send:hover  { background: var(--acd-primary-dark); }
.acd-chat-send:active { transform: scale(.93); }
