/* ── Chat Modal ── */

.chat-modal-content {
	width: 640px;
	max-width: 95vw;
	max-height: 80vh;
	padding: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.chat-modal-header {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
	padding: var(--space-sm) var(--space-md);
	border-bottom: 1px solid var(--border);
	flex-shrink: 0;
}

.chat-modal-title {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
	font-size: var(--font-sm);
	font-weight: 700;
	color: var(--text);
	margin: 0;
}

.chat-modal-status {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
	margin-left: var(--space-md);
}

.chat-modal-status-dot {
	width: 6px;
	height: 6px;
	border-radius: var(--radius-round);
	background: var(--text-dim);
	transition: background var(--transition-base);
}

.chat-modal-status-dot.online {
	background: var(--positive);
	box-shadow: 0 0 4px rgba(8, 153, 129, 0.5);
}

.chat-modal-status-dot.offline {
	background: var(--negative);
}

.chat-modal-status-dot.checking {
	background: var(--warning);
	animation: chatModalPulse 1.5s infinite;
}

@keyframes chatModalPulse {
	0%,
	100% {
		opacity: 1;
	}
	50% {
		opacity: 0.4;
	}
}

.chat-modal-model {
	font-size: var(--font-xs);
	color: var(--text-dim);
	font-family: var(--font-mono);
	margin-left: auto;
	background: var(--bg-surface);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: 2px 6px;
	cursor: pointer;
	max-width: 200px;
}
.chat-modal-model:hover {
	border-color: var(--accent);
}
.chat-modal-model:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ── Messages ── */

.chat-modal-body {
	flex: 1;
	overflow-y: auto;
	padding: var(--space-md);
	display: flex;
	flex-direction: column;
	gap: var(--space-sm);
	min-height: 0;
	scroll-behavior: smooth;
	background: var(--bg);
}

/* Welcome */

.chat-modal-welcome {
	text-align: center;
	padding: var(--space-xl) var(--space-md);
	max-width: 400px;
	margin: auto;
}

.chat-modal-welcome-icon {
	font-size: 36px;
	margin-bottom: var(--space-sm);
}

.chat-modal-welcome-title {
	font-size: var(--font-lg);
	font-weight: 700;
	color: var(--text);
	margin-bottom: var(--space-xs);
}

.chat-modal-welcome-text {
	font-size: var(--font-sm);
	color: var(--text-secondary);
	line-height: 1.6;
	margin-bottom: var(--space-md);
}

.chat-modal-welcome-hints {
	display: flex;
	flex-direction: column;
	gap: var(--space-xs);
	align-items: center;
}

.chat-modal-welcome-hint {
	font-size: var(--font-xs);
	color: var(--text-muted);
	background: var(--bg-elevated);
	padding: var(--space-xs) var(--space-sm);
	border-radius: var(--radius-md);
	border: 1px solid var(--border);
}

/* Message bubbles */

.chat-modal-msg {
	display: flex;
	gap: var(--space-xs);
	max-width: 85%;
	animation: chatMsgIn 0.2s ease-out;
}

@keyframes chatMsgIn {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.chat-modal-msg.user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.chat-modal-msg.assistant {
	align-self: flex-start;
}

.chat-modal-msg.system {
	align-self: center;
	max-width: 100%;
}

.chat-modal-msg-avatar {
	width: 26px;
	height: 26px;
	border-radius: var(--radius-round);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	flex-shrink: 0;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
}

.chat-modal-msg.user .chat-modal-msg-avatar {
	background: var(--accent);
	color: var(--bg);
	border-color: var(--accent);
}

.chat-modal-msg-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-xs);
	min-width: 0;
}

.chat-modal-msg.user .chat-modal-msg-body {
	align-items: flex-end;
}

.chat-modal-msg-bubble {
	padding: var(--space-xs) var(--space-sm);
	border-radius: var(--radius-md);
	font-size: var(--font-sm);
	line-height: 1.6;
	word-wrap: break-word;
	overflow-wrap: break-word;
	white-space: pre-wrap;
}

.chat-modal-msg.user .chat-modal-msg-bubble {
	background: var(--accent);
	color: var(--bg);
	border-bottom-right-radius: var(--radius-sm);
}

.chat-modal-msg.assistant .chat-modal-msg-bubble {
	background: var(--bg-elevated);
	color: var(--text);
	border: 1px solid var(--border);
	border-bottom-left-radius: var(--radius-sm);
}

.chat-modal-msg.system .chat-modal-msg-bubble {
	background: transparent;
	color: var(--text-muted);
	border: 1px solid var(--border);
	font-size: var(--font-xs);
	text-align: center;
	padding: var(--space-xs) var(--space-sm);
}

/* Tool call indicator */

.chat-modal-tool-call {
	display: flex;
	align-items: center;
	gap: var(--space-xs);
	padding: var(--space-xs) var(--space-sm);
	font-size: var(--font-xs);
	color: var(--text-muted);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	animation: chatMsgIn 0.2s ease-out;
	align-self: flex-start;
	max-width: 90%;
}

.chat-modal-tool-call .spinner {
	width: 10px;
	height: 10px;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: var(--radius-round);
	animation: chatModalSpin 0.8s linear infinite;
	flex-shrink: 0;
}

@keyframes chatModalSpin {
	to {
		transform: rotate(360deg);
	}
}

.chat-modal-tool-call.done {
	border-color: var(--positive);
	color: var(--positive);
}

.chat-modal-tool-call.done .spinner {
	border-color: var(--positive);
	border-top-color: var(--positive);
	animation: none;
}

.chat-modal-tool-result {
	margin-left: auto;
	font-size: var(--font-xs);
	color: var(--positive);
}

/* Typing */

.chat-modal-typing {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
	padding: var(--space-xs) var(--space-sm);
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	border-bottom-left-radius: var(--radius-sm);
	align-self: flex-start;
}

.chat-modal-typing-dots {
	display: flex;
	gap: 3px;
}

.chat-modal-typing-dot {
	width: 5px;
	height: 5px;
	border-radius: var(--radius-round);
	background: var(--text-muted);
	animation: chatTypingBounce 1.4s infinite;
}

.chat-modal-typing-dot:nth-child(2) {
	animation-delay: 0.2s;
}
.chat-modal-typing-dot:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes chatTypingBounce {
	0%,
	60%,
	100% {
		transform: translateY(0);
	}
	30% {
		transform: translateY(-3px);
	}
}

.chat-modal-typing-label {
	font-size: var(--font-xs);
	color: var(--text-muted);
}

/* ── Input ── */

.chat-modal-input-area {
	border-top: 1px solid var(--border);
	padding: var(--space-sm) var(--space-md);
	background: var(--bg-elevated);
	flex-shrink: 0;
}

.chat-modal-input-row {
	display: flex;
	gap: var(--space-xs);
	align-items: flex-end;
}

.chat-modal-input {
	flex: 1;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: var(--space-xs) var(--space-sm);
	font-family: var(--font-sans);
	font-size: var(--font-sm);
	color: var(--text);
	resize: none;
	min-height: 36px;
	max-height: 120px;
	line-height: 1.5;
	transition: border-color var(--transition-fast);
}

.chat-modal-input:focus {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
	border-color: var(--accent);
}

.chat-modal-input::placeholder {
	color: var(--text-dim);
}

.chat-modal-send-btn {
	width: 36px;
	height: 36px;
	border-radius: var(--radius-md);
	background: var(--accent);
	color: var(--bg);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: all var(--transition-fast);
	padding: 0;
}

.chat-modal-send-btn:hover:not(:disabled) {
	filter: brightness(1.2);
}

.chat-modal-send-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.chat-modal-send-btn svg {
	width: 16px;
	height: 16px;
}

.chat-modal-input-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: var(--space-xs);
	padding: 0 var(--space-xs);
}

.chat-modal-input-hint {
	font-size: var(--font-xs);
	color: var(--text-dim);
}

.chat-modal-tokens {
	font-size: var(--font-xs);
	color: var(--text-dim);
	font-family: var(--font-mono);
}

/* ── Footer shortcuts bar ── */

.chat-modal-footer {
	display: flex;
	align-items: center;
	gap: var(--space-md);
	padding: var(--space-xs) var(--space-md);
	border-top: 1px solid var(--border);
	background: var(--bg-elevated);
	flex-shrink: 0;
	flex-wrap: wrap;
}

.chat-modal-examples {
	display: flex;
	gap: var(--space-xs);
	flex-wrap: wrap;
	flex: 1;
}

.chat-modal-example-btn {
	background: transparent;
	border: 1px solid var(--border);
	color: var(--text-dim);
	padding: 2px var(--space-sm);
	font-size: var(--font-xs);
	font-weight: 500;
	border-radius: var(--radius-sm);
	cursor: pointer;
	transition: all var(--transition-fast);
	white-space: nowrap;
}

.chat-modal-example-btn:hover {
	border-color: var(--accent);
	color: var(--text);
	background: var(--surface);
}

.chat-modal-clear-btn {
	background: transparent;
	border: 1px solid transparent;
	color: var(--text-dim);
	padding: 2px var(--space-sm);
	font-size: var(--font-xs);
	border-radius: var(--radius-sm);
	cursor: pointer;
	transition: all var(--transition-fast);
	flex-shrink: 0;
}

.chat-modal-clear-btn:hover {
	color: var(--negative);
	border-color: var(--negative);
}

/* ── Markdown formatting ── */

.chat-modal-msg-bubble strong {
	font-weight: 700;
}

.chat-modal-msg-bubble em {
	font-style: italic;
}

.chat-modal-msg-bubble code {
	font-family: var(--font-mono);
	font-size: var(--font-xs);
	background: var(--bg);
	padding: 1px var(--space-xs);
	border-radius: var(--radius-sm);
	color: var(--positive);
}

.chat-modal-msg-bubble pre {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: var(--space-sm);
	margin: var(--space-xs) 0;
	overflow-x: auto;
	font-size: var(--font-xs);
}

.chat-modal-msg-bubble pre code {
	background: none;
	padding: 0;
	color: var(--text);
}

.chat-modal-msg-bubble .positive {
	color: var(--positive);
}
.chat-modal-msg-bubble .negative {
	color: var(--negative);
}
.chat-modal-msg-bubble .accent {
	color: var(--accent);
}

/* ── Responsive ── */

@media (max-width: 600px) {
	.chat-modal-content {
		width: 100%;
		max-width: 100vw;
		max-height: 100vh;
		border-radius: 0;
	}

	.chat-modal-body {
		padding: var(--space-sm);
	}

	.chat-modal-msg {
		max-width: 92%;
	}

	.chat-modal-examples {
		display: none;
	}
}
