/* ===== ARIT Chat Widget ===== */

.arit-chat {
	position: fixed;
	bottom: 100px;
	right: 24px;
	width: 360px;
	max-height: 540px;
	background: #fff;
	border-radius: 18px;
	box-shadow: 0 8px 40px rgba(0,0,0,.18);
	display: flex;
	flex-direction: column;
	z-index: 9999;
	overflow: hidden;
	opacity: 0;
	transform: translateY(16px) scale(.97);
	pointer-events: none;
	transition: opacity .22s ease, transform .22s ease;
}

.arit-chat.is-open {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: all;
}

/* Header */
.arit-chat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	background: var(--brand, #1a5c3d);
	color: #fff;
	flex-shrink: 0;
}

.arit-chat__header-info {
	display: flex;
	align-items: center;
	gap: 10px;
}

.arit-chat__avatar {
	font-size: 22px;
	line-height: 1;
}

.arit-chat__title {
	font-size: 14px;
	font-weight: 700;
	line-height: 1.2;
}

.arit-chat__subtitle {
	font-size: 11px;
	opacity: .8;
	margin-top: 1px;
}

.arit-chat__close {
	background: none;
	border: none;
	color: rgba(255,255,255,.8);
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
	display: flex;
	align-items: center;
	transition: color .15s, background .15s;
}

.arit-chat__close:hover,
.arit-chat__close:focus-visible {
	color: #fff;
	background: rgba(255,255,255,.15);
	outline: none;
}

/* Messages */
.arit-chat__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}

.arit-chat__messages::-webkit-scrollbar { width: 4px; }
.arit-chat__messages::-webkit-scrollbar-track { background: transparent; }
.arit-chat__messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* Bubbles */
.arit-chat__bubble {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 13.5px;
	line-height: 1.55;
	word-break: break-word;
}

.arit-chat__bubble p {
	margin: 0;
}

.arit-chat__bubble p + p {
	margin-top: 6px;
}

.arit-chat__bubble ul,
.arit-chat__bubble ol {
	margin: 4px 0 4px 18px;
	padding: 0;
}

.arit-chat__bubble li {
	margin-bottom: 3px;
}

.arit-chat__bubble a {
	color: var(--brand, #1a5c3d);
	word-break: break-all;
}

.arit-chat__bubble--ai {
	background: #f0f4f2;
	color: #1a2e24;
	border-bottom-left-radius: 4px;
	align-self: flex-start;
}

.arit-chat__bubble--user {
	background: var(--brand, #1a5c3d);
	color: #fff;
	border-bottom-right-radius: 4px;
	align-self: flex-end;
}

.arit-chat__bubble--error {
	background: #fff3f3;
	color: #b00;
	border: 1px solid #fcc;
	align-self: flex-start;
}

/* Escalate button inside AI bubble — filled (inverse of chips) */
.arit-chat__escalate {
	display: inline-block;
	margin-top: 10px;
	padding: 6px 14px;
	border-radius: 20px;
	border: 1.5px solid var(--brand, #1a5c3d);
	background: var(--brand, #1a5c3d);
	color: #fff;
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	transition: background .15s, border-color .15s;
}

.arit-chat__escalate:hover,
.arit-chat__escalate:focus-visible {
	background: #14472f;
	border-color: #14472f;
	outline: none;
}

/* Typing indicator */
.arit-chat__typing {
	display: none;
	align-items: center;
	gap: 4px;
	padding: 0 16px 10px;
	flex-shrink: 0;
}

.arit-chat__typing.is-visible {
	display: flex;
}

.arit-chat__typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #bbb;
	animation: arit-chat-bounce .9s infinite;
}

.arit-chat__typing span:nth-child(2) { animation-delay: .15s; }
.arit-chat__typing span:nth-child(3) { animation-delay: .3s; }

@keyframes arit-chat-bounce {
	0%, 60%, 100% { transform: translateY(0); }
	30%            { transform: translateY(-5px); }
}

/* Form */
.arit-chat__form {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #eee;
	flex-shrink: 0;
}

.arit-chat__input {
	flex: 1;
	border: 1.5px solid #ddd;
	border-radius: 22px;
	padding: 9px 14px;
	font-size: 13.5px;
	line-height: 1.4;
	outline: none;
	transition: border-color .15s;
	font-family: inherit;
}

.arit-chat__input:focus {
	border-color: var(--brand, #1a5c3d);
}

.arit-chat__send {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--brand, #1a5c3d);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background .15s, transform .1s;
}

.arit-chat__send:hover { background: #14472f; }
.arit-chat__send:active { transform: scale(.93); }
.arit-chat__send:disabled { background: #aaa; cursor: default; }

/* hidden attribute ต้องชนะ display:flex เสมอ */
#arit-chat-intro[hidden],
#arit-chat-body[hidden] {
	display: none !important;
}

/* ===== Intro Form ===== */
.arit-chat__intro {
	padding: 20px 18px 18px;
	display: flex;
	flex-direction: column;
	gap: 4px;
	flex: 1;
	overflow-y: auto;
}

.arit-chat__body {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
	overflow: hidden;
}

.arit-chat__intro-desc {
	font-size: 13px;
	color: #555;
	margin: 0 0 14px;
}

.arit-chat__field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-bottom: 12px;
}

.arit-chat__field label {
	font-size: 12.5px;
	font-weight: 600;
	color: #333;
}

.arit-chat__field label span {
	color: #c0392b;
}

.arit-chat__field input {
	border: 1.5px solid #ddd;
	border-radius: 8px;
	padding: 9px 12px;
	font-size: 13.5px;
	outline: none;
	font-family: inherit;
	transition: border-color .15s;
}

.arit-chat__field input:focus {
	border-color: var(--brand, #1a5c3d);
}

.arit-chat__field input.has-error {
	border-color: #c0392b;
}

.arit-chat__intro-error {
	font-size: 12px;
	color: #c0392b;
	margin: 0 0 8px;
}

.arit-chat__intro-submit {
	width: 100%;
	padding: 11px;
	background: var(--brand, #1a5c3d);
	color: #fff;
	border: none;
	border-radius: 10px;
	font-size: 14px;
	font-weight: 700;
	cursor: pointer;
	font-family: inherit;
	transition: background .15s;
	margin-top: 4px;
}

.arit-chat__intro-submit:hover { background: #14472f; }

/* Suggestion chips */
.arit-chat__suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 10px;
}

.arit-chat__suggestion-chip {
	font-size: 12px;
	padding: 5px 11px;
	border: 1.5px solid var(--brand, #1a5c3d);
	border-radius: 20px;
	background: transparent;
	color: var(--brand, #1a5c3d);
	cursor: pointer;
	font-family: inherit;
	line-height: 1.4;
	transition: background .15s, color .15s;
	text-align: left;
}

.arit-chat__suggestion-chip:hover,
.arit-chat__suggestion-chip:focus-visible {
	background: var(--brand, #1a5c3d);
	color: #fff;
	outline: none;
}

/* Source badge */
.arit-chat__source-badge {
	display: inline-block;
	margin-top: 6px;
	padding: 2px 8px;
	border-radius: 20px;
	font-size: 10px;
	font-weight: 600;
	letter-spacing: .3px;
}
.arit-chat__source-badge.badge--kb       { background: #e6f4ec; color: #1a5c3d; }
.arit-chat__source-badge.badge--web      { background: #e8f0fe; color: #1a56db; }
.arit-chat__source-badge.badge--fallback { background: #fef3cd; color: #92600a; }

.arit-chat__disclaimer {
	font-size: 10px;
	color: #92600a;
	font-style: italic;
	margin: 4px 0 0;
	line-height: 1.4;
}

/* Vote buttons */
.arit-chat__vote {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px solid rgba(0,0,0,.07);
}

.arit-chat__vote-btn {
	width: 28px;
	height: 28px;
	border: 1.5px solid #d4d4d4;
	border-radius: 6px;
	background: transparent;
	color: #999;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: background .15s, border-color .15s, color .15s;
	flex-shrink: 0;
}

.arit-chat__vote-btn:hover:not(:disabled) {
	background: #ebebeb;
	border-color: #aaa;
	color: #444;
}

.arit-chat__vote-btn.is-selected.vote--up {
	background: #e8f5e9;
	border-color: #43a047;
	color: #43a047;
}

.arit-chat__vote-btn.is-selected.vote--down {
	background: #fce4ec;
	border-color: #e53935;
	color: #e53935;
}

.arit-chat__vote-btn:disabled {
	cursor: default;
	opacity: .55;
}

/* Mobile */
@media (max-width: 480px) {
	.arit-chat {
		right: 12px;
		left: 12px;
		width: auto;
		bottom: 80px;
		max-height: calc(100dvh - 100px);
	}
}
