/* Khattab AI Chat — واجهة الشات */

.kac,
.kac-float {
	--kac-bg: #f3f7f8;
	--kac-surface: #ffffff;
	--kac-ink: #0f2230;
	--kac-muted: #566b7a;
	--kac-line: #d5e1e6;
	--kac-sea: #0e7c86;
	--kac-on-sea: #ffffff;
	--kac-user-bg: #0e7c86;
	--kac-user-ink: #ffffff;
	--kac-err: #b3261e;
}

.kac[data-theme="dark"],
.kac-float[data-theme="dark"] {
	--kac-bg: #0a141c;
	--kac-surface: #101f2a;
	--kac-ink: #e6f0f3;
	--kac-muted: #92a8b5;
	--kac-line: #1f3544;
	--kac-sea: #5cc8d1;
	--kac-on-sea: #062b30;
	--kac-user-bg: #174f5a;
	--kac-user-ink: #eaf7f9;
	--kac-err: #ff8a80;
}

@media (prefers-color-scheme: dark) {
	.kac[data-theme="auto"],
	.kac-float[data-theme="auto"] {
		--kac-bg: #0a141c;
		--kac-surface: #101f2a;
		--kac-ink: #e6f0f3;
		--kac-muted: #92a8b5;
		--kac-line: #1f3544;
		--kac-sea: #5cc8d1;
		--kac-on-sea: #062b30;
		--kac-user-bg: #174f5a;
		--kac-user-ink: #eaf7f9;
		--kac-err: #ff8a80;
	}
}

.kac,
.kac * {
	box-sizing: border-box;
}

.kac {
	display: flex;
	flex-direction: column;
	height: var(--kac-h, min(720px, 82vh));
	min-height: 420px;
	max-width: 820px;
	margin: 1.5rem auto;
	background: var(--kac-bg);
	color: var(--kac-ink);
	border: 1px solid var(--kac-line);
	border-radius: 18px;
	overflow: hidden;
	font-family: "Readex Pro", system-ui, "Segoe UI", Tahoma, sans-serif;
	font-size: 16px;
	line-height: 1.6;
}

.kac button,
.kac textarea {
	font-family: inherit;
	font-size: inherit;
}

/* الرأس */
.kac__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 18px;
	border-bottom: 1px solid var(--kac-line);
	background: var(--kac-surface);
}

.kac .kac__title {
	margin: 0;
	padding: 0;
	font-size: 1.02rem;
	font-weight: 600;
	line-height: 1.4;
	color: var(--kac-ink);
}

.kac__ghost {
	padding: 6px 12px;
	background: transparent;
	color: var(--kac-muted);
	border: 1px solid var(--kac-line);
	border-radius: 10px;
	font-size: 0.85rem;
	cursor: pointer;
}

.kac__ghost:hover {
	color: var(--kac-ink);
	border-color: var(--kac-muted);
}

/* السجل */
.kac__log {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 22px;
	padding: 22px 18px;
	overflow-y: auto;
	scroll-behavior: smooth;
}

.kac__empty {
	margin: auto;
	max-width: 460px;
	text-align: center;
}

.kac__welcome {
	margin: 0 0 16px;
	color: var(--kac-muted);
	line-height: 1.9;
}

.kac__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: center;
}

.kac__chip {
	padding: 8px 14px;
	background: var(--kac-surface);
	color: var(--kac-ink);
	border: 1px solid var(--kac-line);
	border-radius: 999px;
	font-size: 0.88rem;
	cursor: pointer;
}

.kac__chip:hover {
	border-color: var(--kac-sea);
	color: var(--kac-sea);
}

/* الرسائل */
.kac__msg {
	max-width: 100%;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.kac__msg--user {
	max-width: 82%;
	margin-left: auto;
	padding: 10px 14px;
	background: var(--kac-user-bg);
	color: var(--kac-user-ink);
	border-radius: 14px;
	border-bottom-right-radius: 4px;
	white-space: pre-wrap;
}

.kac__msg--bot {
	padding-inline-start: 14px;
	border-inline-start: 2px solid var(--kac-sea);
	line-height: 1.9;
}

.kac__msg--bot > :first-child {
	margin-top: 0;
}

.kac__msg--bot p,
.kac__msg--bot ul,
.kac__msg--bot ol {
	margin: 0 0 0.75em;
}

.kac__msg--bot ul,
.kac__msg--bot ol {
	padding-inline-start: 1.4em;
}

.kac__msg--bot code {
	padding: 1px 6px;
	background: var(--kac-surface);
	border: 1px solid var(--kac-line);
	border-radius: 6px;
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
	font-size: 0.88em;
}

.kac__msg--bot pre {
	margin: 0 0 0.75em;
	padding: 12px 14px;
	background: var(--kac-surface);
	border: 1px solid var(--kac-line);
	border-radius: 10px;
	overflow-x: auto;
	text-align: left;
}

.kac__msg--bot pre code {
	padding: 0;
	background: none;
	border: 0;
	font-size: 0.85rem;
	line-height: 1.6;
}

.kac__msg--err {
	border-inline-start-color: var(--kac-err);
	color: var(--kac-err);
}

.kac__msg--legal {
	border-inline-start-color: #a3791f;
}

.kac__msg--legal::before {
	content: "⚖️ مساعد قانوني متخصص — تحقق دائماً من النص الرسمي قبل الاعتماد على الإجابة";
	display: block;
	margin-bottom: 8px;
	color: #a3791f;
	font-size: 0.78rem;
	font-weight: 500;
}

/* مؤشر الكتابة: موجة صغيرة */
.kac__wave {
	display: inline-flex;
	align-items: flex-end;
	gap: 3px;
	height: 16px;
	vertical-align: middle;
}

.kac__wave i {
	display: block;
	width: 3px;
	height: 5px;
	background: var(--kac-sea);
	border-radius: 2px;
	animation: kac-wave 1s ease-in-out infinite;
}

.kac__wave i:nth-child(2) { animation-delay: 0.12s; }
.kac__wave i:nth-child(3) { animation-delay: 0.24s; }
.kac__wave i:nth-child(4) { animation-delay: 0.36s; }

@keyframes kac-wave {
	0%, 100% { height: 5px; }
	50% { height: 16px; }
}

/* النموذج */
.kac__form {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	padding: 12px 14px;
	border-top: 1px solid var(--kac-line);
	background: var(--kac-surface);
}

.kac__form textarea {
	flex: 1;
	min-height: 46px;
	max-height: 160px;
	margin: 0;
	padding: 11px 14px;
	background: var(--kac-bg);
	color: var(--kac-ink);
	border: 1px solid var(--kac-line);
	border-radius: 14px;
	resize: none;
	line-height: 1.6;
}

.kac__form textarea::placeholder {
	color: var(--kac-muted);
}

.kac__send {
	display: grid;
	place-items: center;
	flex: none;
	width: 46px;
	height: 46px;
	padding: 0;
	background: var(--kac-sea);
	color: var(--kac-on-sea);
	border: 0;
	border-radius: 14px;
	cursor: pointer;
}

.kac__send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.kac__ico-stop { display: none; }
.kac__send.is-stop .kac__ico-send { display: none; }
.kac__send.is-stop .kac__ico-stop { display: block; }

.kac__note {
	margin: 0;
	padding: 0 14px 10px;
	background: var(--kac-surface);
	color: var(--kac-muted);
	font-size: 0.75rem;
	text-align: center;
}

.kac__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.kac button:focus-visible,
.kac textarea:focus-visible {
	outline: 2px solid var(--kac-sea);
	outline-offset: 2px;
}

/* النافذة العائمة */
.kac-float {
	position: fixed;
	inset-inline-end: 20px;
	bottom: 20px;
	z-index: 99999;
}

.kac-fab {
	display: grid;
	place-items: center;
	width: 56px;
	height: 56px;
	padding: 0;
	background: #0e7c86;
	color: #ffffff;
	border: 0;
	border-radius: 50%;
	box-shadow: 0 6px 20px rgba(8, 40, 46, 0.35);
	cursor: pointer;
}

.kac-fab:focus-visible {
	outline: 3px solid #5cc8d1;
	outline-offset: 3px;
}

.kac-float .kac--float {
	display: none;
	position: absolute;
	inset-inline-end: 0;
	bottom: 68px;
	width: min(400px, calc(100vw - 24px));
	height: min(580px, calc(100vh - 110px));
	min-height: 0;
	margin: 0;
	box-shadow: 0 12px 40px rgba(8, 40, 46, 0.3);
}

.kac-float.is-open .kac--float {
	display: flex;
}

@media (max-width: 600px) {
	.kac--inline {
		margin: 0;
		border-radius: 0;
		border-inline: 0;
	}
	.kac__msg--user {
		max-width: 90%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.kac__wave i {
		animation: none;
		height: 10px;
	}
	.kac__log {
		scroll-behavior: auto;
	}
}

/* وضع الصفحة الكاملة (الرئيسية) */
.kac--page {
	height: calc(100vh - 150px);
	height: calc(100dvh - 150px);
	min-height: 480px;
	max-width: 880px;
	margin: 14px auto;
}

@media (max-width: 600px) {
	.kac--page {
		height: calc(100vh - 118px);
		height: calc(100dvh - 118px);
		margin: 0;
		border-radius: 0;
		border-inline: 0;
	}
}
