/* ── Chat Toggle Button ── */
#aists-chat-toggle {
	position: fixed;
	bottom: 24px;
	right: 24px;
	width: 52px;
	height: 52px;
	background: #2271b1;
	color: #fff;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
	z-index: 99998;
	transition: transform 0.2s, background 0.2s;
}

#aists-chat-toggle:hover {
	background: #135e96;
	transform: scale(1.08);
}

#aists-chat-toggle .dashicons {
	font-size: 24px;
	width: 24px;
	height: 24px;
}

/* ── Chat Sidebar Panel ── */
#aists-chat-sidebar {
	position: fixed;
	top: 32px; /* Below WP admin bar */
	right: 0;
	width: 400px;
	height: calc(100vh - 32px);
	background: #fff;
	box-shadow: -4px 0 20px rgba(0, 0, 0, 0.12);
	z-index: 99999;
	display: flex;
	flex-direction: column;
	transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#aists-chat-sidebar.aists-chat-closed {
	transform: translateX(100%);
}

#aists-chat-sidebar.aists-chat-open {
	transform: translateX(0);
}

/* ── Header ── */
.aists-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: #1d2327;
	color: #fff;
	flex-shrink: 0;
}

.aists-chat-header-left {
	display: flex;
	align-items: center;
	gap: 4px;
}

.aists-chat-header-left .dashicons {
	color: #72aee6;
}

.aists-chat-header-right {
	display: flex;
	align-items: center;
	gap: 4px;
}

.aists-chat-mode-badge {
	background: #2271b1;
	color: #fff;
	font-size: 11px;
	padding: 2px 8px;
	border-radius: 10px;
	margin-left: 8px;
}

#aists-chat-mode-select {
	background: #32373c;
	color: #fff;
	border: 1px solid #50575e;
	border-radius: 4px;
	padding: 2px 6px;
	font-size: 12px;
	cursor: pointer;
}

.aists-chat-btn {
	background: none;
	border: none;
	color: #a7aaad;
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	display: flex;
	align-items: center;
}

.aists-chat-btn:hover {
	color: #fff;
	background: rgba(255, 255, 255, 0.1);
}

/* ── Context bar ── */
.aists-chat-context-bar {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 6px 16px;
	background: #e7f5e8;
	border-bottom: 1px solid #c3e6cb;
	font-size: 12px;
	color: #155724;
	flex-shrink: 0;
}

/* ── History bar ── */
#aists-chat-history-bar {
	padding: 8px 16px;
	border-bottom: 1px solid #e0e0e0;
	background: #f6f7f7;
	flex-shrink: 0;
}

#aists-chat-conversation-select {
	width: 100%;
	padding: 4px 8px;
	border: 1px solid #c3c4c7;
	border-radius: 4px;
	font-size: 12px;
	background: #fff;
}

/* ── Messages Area ── */
.aists-chat-body,
#aists-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
}

.aists-chat-welcome {
	background: #f0f6fc;
	border-radius: 8px;
	padding: 16px;
	margin-bottom: 12px;
	font-size: 13px;
	line-height: 1.5;
	color: #1d2327;
}

.aists-chat-welcome p:first-child {
	margin-top: 0;
}

.aists-chat-welcome p:last-child {
	margin-bottom: 0;
}

/* ── Messages ── */
.aists-chat-msg {
	margin-bottom: 12px;
	display: flex;
}

.aists-chat-msg-user {
	justify-content: flex-end;
}

.aists-chat-msg-assistant {
	justify-content: flex-start;
}

.aists-chat-msg-content {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 12px;
	font-size: 13px;
	line-height: 1.5;
	word-wrap: break-word;
}

.aists-chat-msg-user .aists-chat-msg-content {
	background: #2271b1;
	color: #fff;
	border-bottom-right-radius: 4px;
}

.aists-chat-msg-assistant .aists-chat-msg-content {
	background: #f0f0f1;
	color: #1d2327;
	border-bottom-left-radius: 4px;
}

.aists-chat-msg-assistant .aists-chat-msg-content strong {
	color: #1d2327;
}

.aists-chat-msg-assistant .aists-chat-msg-content code {
	background: #dcdcde;
	padding: 1px 4px;
	border-radius: 3px;
	font-size: 12px;
}

.aists-chat-msg-assistant .aists-chat-msg-content pre {
	background: #1d2327;
	color: #e0e0e0;
	padding: 10px;
	border-radius: 6px;
	overflow-x: auto;
	font-size: 12px;
	margin: 8px 0;
}

.aists-chat-msg-assistant .aists-chat-msg-content pre code {
	background: none;
	padding: 0;
	color: inherit;
}

/* ── Tool badges ── */
.aists-chat-tools {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	padding: 0 16px;
	margin-bottom: 12px;
}

.aists-chat-tool-badge {
	background: #e7f5e8;
	color: #1e7e34;
	font-size: 10px;
	padding: 2px 8px;
	border-radius: 10px;
	font-family: monospace;
}

/* ── Typing indicator ── */
.aists-chat-typing {
	padding: 8px 16px;
	font-size: 12px;
	color: #646970;
	display: flex;
	align-items: center;
	gap: 6px;
}

.aists-chat-typing span {
	width: 6px;
	height: 6px;
	background: #a7aaad;
	border-radius: 50%;
	display: inline-block;
	animation: aists-typing 1.4s infinite ease-in-out both;
}

.aists-chat-typing span:nth-child(1) { animation-delay: 0s; }
.aists-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.aists-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aists-typing {
	0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
	40% { transform: scale(1); opacity: 1; }
}

/* ── Input area ── */
.aists-chat-input-area {
	padding: 12px 16px;
	border-top: 1px solid #e0e0e0;
	background: #f6f7f7;
	flex-shrink: 0;
}

.aists-chat-input-wrapper {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	background: #fff;
	border: 1px solid #c3c4c7;
	border-radius: 8px;
	padding: 6px 8px 6px 12px;
	transition: border-color 0.2s;
}

.aists-chat-input-wrapper:focus-within {
	border-color: #2271b1;
	box-shadow: 0 0 0 1px #2271b1;
}

#aists-chat-input {
	flex: 1;
	border: none;
	outline: none;
	resize: none;
	font-size: 13px;
	line-height: 1.4;
	font-family: inherit;
	max-height: 120px;
	padding: 4px 0;
	background: transparent;
}

.aists-chat-send-btn {
	width: 32px;
	height: 32px;
	border: none;
	background: #2271b1;
	color: #fff;
	border-radius: 6px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.2s;
}

.aists-chat-send-btn:hover:not(:disabled) {
	background: #135e96;
}

.aists-chat-send-btn:disabled {
	background: #c3c4c7;
	cursor: not-allowed;
}

.aists-chat-send-btn .dashicons {
	font-size: 18px;
	width: 18px;
	height: 18px;
}

/* ── Responsive ── */
@media screen and (max-width: 782px) {
	#aists-chat-sidebar {
		width: 100%;
		top: 46px; /* Mobile admin bar */
		height: calc(100vh - 46px);
	}
}
