/* AI Chat floating button */
#ai-chat-btn {
	position: fixed;
	bottom: 24px;
	right: 24px;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: var(--brand);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	z-index: 8;
	box-shadow: 0 2px 8px rgba(0,0,0,0.25);
	font-size: 20px;
	transition: transform 0.15s, background 0.15s;
}
#ai-chat-btn:hover {
	transform: scale(1.08);
	background: var(--brand-dark);
}
#ai-chat-btn.active {
	display: none;
}

/* AI Chat panel */
#ai-chat-panel {
	position: fixed;
	bottom: 24px;
	right: 24px;
	width: 400px;
	height: 520px;
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 4px 24px rgba(0,0,0,0.18);
	z-index: 9;
	display: none;
	flex-direction: column;
	overflow: hidden;
	font-size: 14px;
}
#ai-chat-panel.open {
	display: flex;
}

/* Header */
.ai-chat-header {
	background: var(--brand);
	color: #fff;
	padding: 12px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}
.ai-chat-title {
	font-weight: 600;
	font-size: 14px;
}
.ai-chat-title i {
	margin-right: 6px;
}
.ai-chat-actions i {
	cursor: pointer;
	margin-left: 14px;
	opacity: 0.8;
	font-size: 14px;
}
.ai-chat-actions i:hover {
	opacity: 1;
}

/* Messages area */
.ai-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

/* Message bubbles */
.ai-msg {
	padding: 10px 14px;
	border-radius: 10px;
	max-width: 85%;
	word-wrap: break-word;
	line-height: 1.5;
}
.ai-msg-user {
	background: var(--brand);
	color: #fff;
	align-self: flex-end;
	border-bottom-right-radius: 3px;
}
.ai-msg-assistant {
	background: var(--grey7);
	color: var(--text-dark);
	align-self: flex-start;
	border-bottom-left-radius: 3px;
}
.ai-msg-assistant pre {
	background: var(--grey6);
	padding: 8px 10px;
	border-radius: 6px;
	overflow-x: auto;
	margin: 6px 0;
	font-size: 13px;
}
.ai-msg-assistant code {
	background: var(--grey6);
	padding: 1px 4px;
	border-radius: 3px;
	font-size: 13px;
}
.ai-msg-assistant pre code {
	background: none;
	padding: 0;
}
.ai-msg-error {
	background: var(--danger-light);
	color: var(--danger-dark);
	align-self: center;
	font-size: 13px;
	text-align: center;
}

/* Welcome message */
.ai-welcome {
	color: var(--grey2);
	text-align: center;
	padding: 40px 20px;
	font-size: 15px;
}

/* Status line (tool calls, thinking) */
.ai-status {
	color: var(--grey2);
	font-size: 12px;
	padding: 4px 0;
	display: flex;
	align-items: center;
	gap: 6px;
}
.ai-spinner {
	width: 14px;
	height: 14px;
	border: 0;
}

/* Ask user inline input */
.ai-ask-user {
	display: flex;
	gap: 8px;
	padding: 4px 0;
}
.ai-ask-input {
	flex: 1;
	padding: 8px 10px;
	border: 1px solid var(--grey4);
	border-radius: 6px;
	font-size: 13px;
	outline: none;
}
.ai-ask-input:focus {
	border-color: var(--brand);
}

/* Redirect link */
.ai-redirect-link {
	color: var(--brand);
	font-weight: 600;
	text-decoration: none;
}
.ai-redirect-link:hover {
	text-decoration: underline;
}

.ai-table-proposal {
	max-width: 100%;
}
.ai-proposal-title {
	font-weight: 600;
	margin-bottom: 8px;
}
.ai-proposal-subtitle {
	font-size: 12px;
	color: var(--grey2);
	margin-bottom: 10px;
}
.ai-proposal-row {
	margin-bottom: 6px;
}
.ai-proposal-list {
	margin-bottom: 8px;
}
.ai-proposal-item {
	font-family: monospace;
	font-size: 12px;
	padding: 4px 8px;
	background: var(--grey6);
	border-radius: 6px;
	margin-bottom: 4px;
	white-space: pre-wrap;
	word-break: break-word;
}
.ai-proposal-meta {
	font-size: 12px;
	color: var(--grey2);
	margin-top: 4px;
}
.ai-proposal-done {
	font-size: 12px;
	color: var(--grey2);
}
.ai-proposal-note {
	margin-top: 8px;
	font-size: 12px;
	color: var(--grey2);
}
.ai-proposal-actions {
	margin-top: 10px;
	display: flex;
	gap: 8px;
}
.ai-proposal-modal {
	max-width: 100%;
}
.ai-proposal-modal-summary {
	font-weight: 600;
	font-size: 16px;
	margin-bottom: 10px;
}
.ai-proposal-diff-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 16px;
	margin-top: 8px;
	margin-bottom: 12px;
	align-items: start;
}
.ai-proposal-diff-col {
	min-width: 0;
}
.ai-proposal-diff-head {
	font-weight: 600;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-light);
	margin-bottom: 8px;
}
.ai-proposal-json {
	background: #fff;
	border: 1px solid var(--grey5);
	border-radius: 8px;
	padding: 12px;
	font-size: 12px;
	line-height: 1.45;
	overflow: auto;
	max-height: 48dvh;
	margin-top: 8px;
	color: var(--text-dark);
	font-family: monospace;
	white-space: pre-wrap;
	word-break: break-word;
}
.ai-proposal-json-before {
	background: #ffffff;
}
.ai-proposal-json-after {
	background: #ffffff;
}
.ai-proposal-diff-text {
	padding: 0;
}
.ai-proposal-diff-text .diff-line {
	display: block;
	padding: 2px 10px;
	margin: 0;
}
.ai-proposal-diff-text .diff-line.same {
	background: transparent;
	color: var(--text-dark);
}
.ai-proposal-diff-text .diff-line.del {
	background: #fff1f1;
	color: #8a1f1f;
}
.ai-proposal-diff-text .diff-line.add {
	background: #f1fff1;
	color: #1f6b2a;
}
.ai-proposal-diff-text .diff-line.empty {
	color: var(--grey3);
}

/* Input area */
.ai-chat-input {
	border-top: 1px solid var(--grey5);
	padding: 12px;
	display: flex;
	gap: 8px;
	flex-shrink: 0;
	background: #fff;
}
.ai-chat-input textarea {
	flex: 1;
	border: 1px solid var(--grey4);
	border-radius: 8px;
	padding: 8px 12px;
	font-size: 14px;
	font-family: var(--font-family);
	resize: none;
	outline: none;
	max-height: 120px;
	line-height: 1.4;
}
.ai-chat-input textarea:focus {
	border-color: var(--brand);
}
.ai-chat-send {
	background: var(--brand);
	color: #fff;
	border: none;
	border-radius: 8px;
	width: 38px;
	height: 38px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	font-size: 14px;
	transition: background 0.15s;
}
.ai-chat-stop {
	background: var(--danger);
	color: #fff;
	border: none;
	border-radius: 8px;
	width: 38px;
	height: 38px;
	cursor: pointer;
	display: none;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	font-size: 12px;
	transition: background 0.15s;
}
.ai-chat-stop.visible {
	display: flex;
}
.ai-chat-stop:hover {
	background: var(--danger-dark);
}
.ai-chat-stop:disabled {
	display: none;
	cursor: default;
}
.ai-chat-send:hover {
	background: var(--brand-dark);
}
.ai-chat-send:disabled {
	opacity: 0.5;
	cursor: default;
}

/* Mobile responsive */
@media (max-width: 480px) {
	#ai-chat-panel {
		width: calc(100vw - 16px);
		height: calc(100dvh - 80px);
		bottom: 8px;
		right: 8px;
		border-radius: 10px;
	}
	#ai-chat-btn {
		bottom: 16px;
		right: 16px;
	}
	.ai-proposal-diff-grid {
		grid-template-columns: 1fr;
	}
}
