/* =============================================================
   Widget Chat AI CodingMa — dipakai di beranda DAN dashboard.
   Warna sengaja ditulis eksplisit (coklat kayu) supaya tampil sama
   di halaman mana pun, tanpa bergantung variabel tema halaman.
   ============================================================= */

.cm-ai,
.cm-ai *,
.cm-ai *::before,
.cm-ai *::after { box-sizing: border-box; }

.cm-ai-bubble {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 999;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(160deg, #b8814f 0%, #97663d 100%);
	color: #fdf7f0;
	cursor: pointer;
	box-shadow: 0 8px 22px -6px rgba(120, 78, 45, 0.55);
	transition: transform .18s ease, box-shadow .18s ease;
}
.cm-ai-bubble:hover {
	transform: translateY(-3px) scale(1.05);
	box-shadow: 0 12px 26px -6px rgba(120, 78, 45, 0.65);
}
.cm-ai.is-open .cm-ai-bubble { display: none; }

.cm-ai-panel {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 1000;
	display: flex;
	flex-direction: column;
	width: 360px;
	max-width: calc(100vw - 28px);
	height: 520px;
	max-height: calc(100vh - 40px);
	min-height: 0;
	background: #fbf6ef;
	border: 1px solid #e0cbba;
	border-radius: 16px;
	box-shadow: 0 24px 60px -18px rgba(63, 45, 31, 0.38);
	overflow: hidden;
	font-family: "Poppins", system-ui, sans-serif;
	font-size: .92rem;
	line-height: 1.5;
	color: #3f2d1f;
	text-align: left;
}
.cm-ai-panel[hidden] { display: none; }

.cm-ai-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 12px 14px;
	background: linear-gradient(160deg, #b8814f 0%, #97663d 100%);
	color: #fdf7f0;
	flex: 0 0 auto;
}
.cm-ai-head-text { min-width: 0; }
.cm-ai-head strong { display: block; font-size: .95rem; line-height: 1.25; }
.cm-ai-head-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	flex: 0 0 auto;
}
.cm-ai-reset {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	background: transparent;
	border: 0;
	border-radius: 8px;
	color: #fdf7f0;
	cursor: pointer;
	opacity: .85;
}
.cm-ai-reset:hover { opacity: 1; background: rgba(255, 255, 255, .16); }
.cm-ai-close {
	background: transparent;
	border: 0;
	color: #fdf7f0;
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
	padding: 0;
	width: 28px;
	height: 28px;
	border-radius: 8px;
	flex: 0 0 auto;
}
.cm-ai-close:hover { background: rgba(255, 255, 255, .16); }

.cm-ai-log {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: #f6ece1;
	scrollbar-width: thin;
	scrollbar-color: #d3a274 transparent;
}
.cm-ai-log::-webkit-scrollbar { width: 8px; }
.cm-ai-log::-webkit-scrollbar-track { background: transparent; }
.cm-ai-log::-webkit-scrollbar-thumb {
	background: #d3a274;
	border-radius: 999px;
}
.cm-ai-log::-webkit-scrollbar-thumb:hover { background: #b8814f; }

.cm-ai-welcome {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.cm-ai-welcome[hidden] { display: none; }

.cm-ai-msg {
	max-width: 88%;
	padding: 8px 11px;
	border-radius: 12px;
	line-height: 1.45;
	font-size: .88rem;
	/* pre-wrap membuat indentasi HTML (tab + enter) ikut tampil sebagai spasi. */
	white-space: normal;
	text-align: left;
	word-break: break-word;
	overflow-wrap: anywhere;
}
.cm-ai-bot {
	align-self: flex-start;
	background: #fbf6ef;
	border: 1px solid #e0cbba;
	color: #3f2d1f;
	border-bottom-left-radius: 4px;
}
.cm-ai-user {
	align-self: flex-end;
	background: linear-gradient(160deg, #b8814f 0%, #97663d 100%);
	color: #fdf7f0;
	border-bottom-right-radius: 4px;
}
.cm-ai-msg.is-typing { color: #7a6350; font-style: italic; }

/* Isi jawaban AI (markdown ringan) */
.cm-ai-msg > div { margin: 0; }
.cm-ai-msg > div + div { margin-top: 4px; }
.cm-ai-msg .cm-ai-h { font-weight: 700; margin-top: 6px; }
.cm-ai-msg ol,
.cm-ai-msg ul {
	margin: 4px 0;
	padding-left: 18px;
}
.cm-ai-msg li { margin: 2px 0; }
.cm-ai-msg code {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: .82em;
	background: #f2e6d9;
	border: 1px solid #e0cbba;
	border-radius: 4px;
	padding: 1px 4px;
	word-break: break-word;
}
.cm-ai-msg a {
	color: #97663d;
	text-decoration: underline;
	word-break: break-word;
}
.cm-ai-msg a:hover { color: #b8814f; }
.cm-ai-user a { color: #fdf7f0; }
.cm-ai-msg .cm-ai-quote {
	border-left: 3px solid #d3a274;
	padding-left: 8px;
	color: #7a6350;
	margin: 4px 0;
}

.cm-ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.cm-ai-chip {
	background: #fbf6ef;
	border: 1px solid #e0cbba;
	border-radius: 999px;
	padding: 5px 10px;
	font-size: .75rem;
	line-height: 1.3;
	cursor: pointer;
	color: #3f2d1f;
	font-family: inherit;
}
.cm-ai-chip:hover {
	border-color: #b8814f;
	color: #97663d;
	background: #f2e6d9;
}

.cm-ai-form {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px;
	border-top: 1px solid #e0cbba;
	background: #fbf6ef;
	flex: 0 0 auto;
}
/* Selector dinaikkan kekhususannya supaya tidak ditimpa aturan global
   `input, select { width:100%; padding:12px }` di halaman lain. */
.cm-ai .cm-ai-form textarea#cm-ai-input {
	flex: 1 1 auto;
	width: auto;
	min-width: 0;
	max-width: none;
	height: 38px;
	min-height: 38px;
	max-height: 110px;
	margin: 0;
	padding: 8px 11px;
	border: 1px solid #e0cbba;
	border-radius: 12px;
	background: #fffdfa;
	color: #3f2d1f;
	font-family: inherit;
	font-size: .88rem;
	line-height: 1.45;
	resize: none;
	overflow-y: hidden;
	scrollbar-width: none;
	box-shadow: none;
}
.cm-ai .cm-ai-form textarea#cm-ai-input::-webkit-scrollbar { width: 0; height: 0; }
.cm-ai .cm-ai-form textarea#cm-ai-input:focus {
	outline: none;
	border-color: #b8814f;
	box-shadow: 0 0 0 3px rgba(184, 129, 79, .18);
}
.cm-ai .cm-ai-form button#cm-ai-send {
	flex: 0 0 38px;
	width: 38px;
	height: 38px;
	min-width: 38px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(160deg, #b8814f 0%, #97663d 100%);
	color: #fdf7f0;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity .15s ease, transform .15s ease;
}
.cm-ai .cm-ai-form button#cm-ai-send:hover:not(:disabled) { transform: scale(1.05); }
.cm-ai .cm-ai-form button#cm-ai-send:disabled { opacity: .45; cursor: default; }

@media (max-width: 640px) {
	.cm-ai-bubble { width: 50px; height: 50px; right: 14px; bottom: 14px; }
	.cm-ai-panel {
		right: 8px;
		left: 8px;
		bottom: 8px;
		width: auto;
		height: calc(100dvh - 16px);
		max-height: calc(100dvh - 16px);
	}
}
