/* Chatbot AI untuk SLiMS — tombol dan jendela percakapan. Warna dan posisi diatur dari halaman Pengaturan. */
:root {
	--cas-accent: #0f766e;
	--cas-on-accent: #ffffff;
	--cas-right: 24px;
	--cas-bottom: 24px;
	--cas-ink: #1b2530;
	--cas-muted: #5d6b78;
	--cas-surface: #ffffff;
	--cas-soft: #f1f4f3;
	--cas-line: #dde3e1;
}

.cas-launcher {
	position: fixed;
	right: max(8px, min(var(--cas-right), calc(100vw - 64px)));
	bottom: var(--cas-bottom);
	z-index: 99990;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--cas-accent);
	color: var(--cas-on-accent);
	box-shadow: 0 6px 18px rgba(16, 32, 28, 0.28);
	cursor: pointer;
	transition: transform 0.15s ease;
}
.cas-launcher:hover { transform: translateY(-2px); }
.cas-launcher:focus-visible,
.cas-panel button:focus-visible,
.cas-panel a:focus-visible {
	outline: 3px solid var(--cas-accent);
	outline-offset: 3px;
}
.cas-launcher svg { display: block; }
.cas-launcher .cas-icon-close { display: none; }
.cas-launcher[aria-expanded="true"] .cas-icon-chat { display: none; }
.cas-launcher[aria-expanded="true"] .cas-icon-close { display: block; }
.cas-preview { pointer-events: none; }

.cas-panel {
	position: fixed;
	right: max(8px, min(var(--cas-right), calc(100vw - 380px)));
	bottom: calc(var(--cas-bottom) + 68px);
	z-index: 99991;
	display: flex;
	flex-direction: column;
	width: 372px;
	max-width: calc(100vw - 16px);
	height: min(560px, calc(100vh - var(--cas-bottom) - 84px));
	min-height: 280px;
	box-sizing: border-box;
	overflow: hidden;
	border: 1px solid var(--cas-line);
	border-radius: 16px 16px 4px 16px;
	background: var(--cas-surface);
	color: var(--cas-ink);
	box-shadow: 0 18px 48px rgba(16, 32, 28, 0.22);
	font-family: inherit;
	font-size: 15px;
	line-height: 1.5;
	text-align: left;
	transform-origin: bottom right;
	animation: cas-open 0.16s ease-out;
}
.cas-panel[hidden] { display: none; }
.cas-panel *, .cas-panel *::before, .cas-panel *::after { box-sizing: border-box; }
@keyframes cas-open {
	from { opacity: 0; transform: translateY(8px) scale(0.97); }
	to { opacity: 1; transform: none; }
}

.cas-head {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 10px 12px 16px;
	background: var(--cas-accent);
	color: var(--cas-on-accent);
}
.cas-title {
	flex: 1;
	min-width: 0;
	margin: 0;
	overflow: hidden;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.3;
	white-space: nowrap;
	text-overflow: ellipsis;
}
.cas-head button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: inherit;
	cursor: pointer;
}
.cas-head button:hover { background: rgba(255, 255, 255, 0.18); }
.cas-head button:focus-visible { outline-color: var(--cas-on-accent); outline-offset: -2px; }

.cas-log {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
}
.cas-msg {
	max-width: 86%;
	margin: 0;
	font-size: 15px;
	line-height: 1.5;
	padding: 9px 13px;
	border-radius: 14px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}
.cas-msg-bot {
	align-self: flex-start;
	border-bottom-left-radius: 4px;
	background: var(--cas-soft);
}
.cas-msg-user {
	align-self: flex-end;
	border-bottom-right-radius: 4px;
	background: var(--cas-accent);
	color: var(--cas-on-accent);
}
.cas-msg-error {
	align-self: flex-start;
	border: 1px solid #e3b4b4;
	background: #fdf3f3;
	color: #8a1f1f;
}
.cas-msg a { color: inherit; text-decoration: underline; }
.cas-cite {
	margin-left: 1px;
	color: var(--cas-muted);
	font-size: 0.72em;
	font-weight: 600;
}
.cas-sources {
	display: block;
	margin: 8px 0 0;
	padding: 8px 0 0;
	border-top: 1px solid var(--cas-line);
	color: var(--cas-muted);
	font-size: 13px;
	white-space: normal;
}
.cas-sources a, .cas-source-plain { display: block; margin-top: 3px; color: var(--cas-ink); }

.cas-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.cas-typing i {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--cas-muted);
	animation: cas-blink 1.2s infinite ease-in-out;
}
.cas-typing i:nth-child(2) { animation-delay: 0.2s; }
.cas-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes cas-blink {
	0%, 80%, 100% { opacity: 0.25; }
	40% { opacity: 1; }
}

.cas-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin: 0;
	padding: 10px 12px 12px;
	border-top: 1px solid var(--cas-line);
	background: var(--cas-surface);
}
.cas-form textarea {
	flex: 1;
	width: auto;
	height: auto;
	box-sizing: border-box;
	min-height: 42px;
	max-height: 120px;
	margin: 0;
	padding: 9px 12px;
	border: 1px solid var(--cas-line);
	border-radius: 12px;
	background: var(--cas-surface);
	color: var(--cas-ink);
	font: inherit;
	line-height: 1.4;
	resize: none;
	box-shadow: none;
}
.cas-form textarea:focus {
	border-color: var(--cas-accent);
	outline: 2px solid var(--cas-accent);
	outline-offset: 0;
}
.cas-form button {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: var(--cas-accent);
	color: var(--cas-on-accent);
	cursor: pointer;
}
.cas-form button:disabled { opacity: 0.45; cursor: default; }
.cas-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

@media (max-width: 480px) {
	.cas-panel {
		left: 8px;
		right: 8px;
		width: auto;
		max-width: none;
		height: min(72vh, calc(100vh - var(--cas-bottom) - 84px));
		border-radius: 16px;
	}
}
@media (prefers-reduced-motion: reduce) {
	.cas-panel, .cas-typing i { animation: none; }
	.cas-launcher { transition: none; }
}
