/* Floating chat button */
#llm-chat-button {
	position: fixed;
	bottom: 24px;
	right: 24px;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background-color: #3273dc;
	color: white;
	border: none;
	cursor: pointer;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color 0.2s, transform 0.2s;
}

#llm-chat-button:hover {
	background-color: #2366d1;
	transform: scale(1.05);
}

#llm-chat-button ion-icon {
	font-size: 26px;
}

/* Chat panel */
#llm-chat-panel {
	position: fixed;
	bottom: 92px;
	right: 24px;
	width: 420px;
	max-height: 70vh;
	background: white;
	border-radius: 12px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
	z-index: 1000;
	display: none;
	flex-direction: column;
	overflow: hidden;
}

#llm-chat-panel.is-active {
	display: flex;
}

/* Chat header */
#llm-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background-color: #3273dc;
	color: white;
	font-weight: 600;
	font-size: 0.95rem;
	flex-shrink: 0;
}

#llm-chat-header-actions {
	display: flex;
	align-items: center;
	gap: 8px;
}

#llm-chat-new {
	background: none;
	border: none;
	color: white;
	cursor: pointer;
	font-size: 20px;
	padding: 0;
	line-height: 1;
	opacity: 0.8;
	display: flex;
	align-items: center;
}

#llm-chat-new:hover {
	opacity: 1;
}

#llm-chat-header-close {
	background: none;
	border: none;
	color: white;
	cursor: pointer;
	font-size: 20px;
	padding: 0;
	line-height: 1;
	opacity: 0.8;
}

#llm-chat-header-close:hover {
	opacity: 1;
}

/* Chat messages area */
#llm-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	min-height: 200px;
	max-height: calc(70vh - 130px);
}

.llm-chat-message {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 12px;
	font-size: 0.9rem;
	line-height: 1.5;
	word-wrap: break-word;
}

.llm-chat-message.user {
	align-self: flex-end;
	background-color: #3273dc;
	color: white;
	border-bottom-right-radius: 4px;
}

.llm-chat-message.assistant {
	align-self: flex-start;
	background-color: #f0f0f0;
	color: #333;
	border-bottom-left-radius: 4px;
}

.llm-chat-message.assistant p {
	margin: 0 0 8px 0;
}

.llm-chat-message.assistant p:last-child {
	margin-bottom: 0;
}

.llm-chat-message.assistant ul,
.llm-chat-message.assistant ol {
	margin: 4px 0 8px 20px;
	padding: 0;
}

.llm-chat-message.assistant li {
	margin-bottom: 2px;
}

.llm-chat-message.assistant strong {
	font-weight: 600;
}

.llm-chat-message.assistant code {
	background-color: #e0e0e0;
	padding: 1px 4px;
	border-radius: 3px;
	font-size: 0.85em;
}

.llm-chat-message.assistant pre {
	background-color: #e0e0e0;
	padding: 8px;
	border-radius: 4px;
	overflow-x: auto;
	margin: 4px 0;
}

.llm-chat-message.assistant table {
	border-collapse: collapse;
	margin: 8px 0;
	font-size: 0.85em;
	width: 100%;
}

.llm-chat-message.assistant th,
.llm-chat-message.assistant td {
	border: 1px solid #ccc;
	padding: 4px 8px;
	text-align: left;
}

.llm-chat-message.assistant th {
	background-color: #e0e0e0;
}

.llm-chat-message.assistant h1,
.llm-chat-message.assistant h2,
.llm-chat-message.assistant h3,
.llm-chat-message.assistant h4 {
	font-weight: 600;
	margin: 8px 0 4px 0;
}

.llm-chat-message.assistant h1 { font-size: 1.1em; }
.llm-chat-message.assistant h2 { font-size: 1.05em; }
.llm-chat-message.assistant h3 { font-size: 1.0em; }

.llm-chat-thinking {
	align-self: flex-start;
	padding: 10px 14px;
	font-size: 0.9rem;
	color: #888;
	font-style: italic;
}

/* Chat input area */
#llm-chat-input-area {
	display: flex;
	align-items: flex-end;
	padding: 12px;
	border-top: 1px solid #e8e8e8;
	gap: 8px;
	flex-shrink: 0;
}

#llm-chat-input {
	flex: 1;
	resize: none;
	border: 1px solid #ddd;
	border-radius: 8px;
	padding: 8px 12px;
	font-size: 0.9rem;
	font-family: inherit;
	max-height: 100px;
	min-height: 38px;
	line-height: 1.4;
	outline: none;
}

#llm-chat-input:focus {
	border-color: #3273dc;
}

#llm-chat-send {
	background-color: #3273dc;
	color: white;
	border: none;
	border-radius: 8px;
	padding: 8px 16px;
	cursor: pointer;
	font-size: 0.9rem;
	font-weight: 500;
	white-space: nowrap;
	height: 38px;
	transition: background-color 0.2s;
}

#llm-chat-send:hover {
	background-color: #2366d1;
}

#llm-chat-send:disabled {
	background-color: #a0a0a0;
	cursor: not-allowed;
}

/* Explain figure buttons */
.llm-figure-explain-btn {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: none;
	border: 1px solid #ccc;
	border-radius: 4px;
	padding: 4px 10px;
	cursor: pointer;
	color: #666;
	font-size: 0.8rem;
	margin-top: 8px;
	transition: color 0.2s, border-color 0.2s;
}

.llm-figure-explain-btn:hover {
	color: #3273dc;
	border-color: #3273dc;
}

.llm-figure-explain-btn ion-icon {
	font-size: 16px;
}

/* Inline explanation panel (replaces modal) */
.llm-explain-inline {
	border: 1px solid #d5d5d5;
	border-radius: 8px;
	background: #fafafa;
	margin: 12px 0;
	overflow: hidden;
}

.llm-explain-inline.is-hidden {
	display: none;
}

.llm-explain-inline-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 16px;
	background-color: #f0f0f0;
	border-bottom: 1px solid #d5d5d5;
}

.llm-explain-inline-title {
	font-size: 0.95rem;
	font-weight: 600;
	color: #333;
}

.llm-explain-inline-close {
	background: none;
	border: none;
	font-size: 20px;
	cursor: pointer;
	color: #666;
	line-height: 1;
	padding: 0;
}

.llm-explain-inline-close:hover {
	color: #333;
}

.llm-explain-inline-body {
	padding: 16px;
	font-size: 0.9rem;
	line-height: 1.6;
	color: #333;
}

.llm-explain-inline-body p {
	margin: 0 0 10px 0;
}

.llm-explain-inline-body p:last-child {
	margin-bottom: 0;
}

.llm-explain-inline-body ul,
.llm-explain-inline-body ol {
	margin: 4px 0 10px 20px;
	padding: 0;
}

.llm-explain-inline-body li {
	margin-bottom: 4px;
}

.llm-explain-inline-body strong {
	font-weight: 600;
}

.llm-explain-inline-body code {
	background-color: #e8e8e8;
	padding: 1px 4px;
	border-radius: 3px;
	font-size: 0.85em;
}

.llm-explain-inline-body table {
	border-collapse: collapse;
	margin: 8px 0;
	font-size: 0.85em;
	width: 100%;
}

.llm-explain-inline-body th,
.llm-explain-inline-body td {
	border: 1px solid #ccc;
	padding: 4px 8px;
	text-align: left;
}

.llm-explain-inline-body th {
	background-color: #e8e8e8;
}

.llm-explain-inline-body h1,
.llm-explain-inline-body h2,
.llm-explain-inline-body h3,
.llm-explain-inline-body h4 {
	font-weight: 600;
	margin: 8px 0 4px 0;
}

.llm-explain-inline-body h1 { font-size: 1.1em; }
.llm-explain-inline-body h2 { font-size: 1.05em; }
.llm-explain-inline-body h3 { font-size: 1.0em; }

/* Reasoning toggle (collapsed by default) */
.llm-reasoning {
	margin-bottom: 12px;
	border: 1px solid #ddd;
	border-radius: 6px;
	overflow: hidden;
}

.llm-reasoning summary {
	padding: 6px 12px;
	background-color: #e8e8e8;
	cursor: pointer;
	font-size: 0.8rem;
	font-weight: 500;
	color: #666;
	user-select: none;
}

.llm-reasoning summary:hover {
	background-color: #ddd;
	color: #444;
}

.llm-reasoning > :not(summary) {
	padding: 0 12px;
}

.llm-reasoning p {
	font-size: 0.85rem;
	color: #555;
	line-height: 1.5;
}

/* Loading spinner */
.llm-explain-spinner {
	display: flex;
	align-items: center;
	gap: 10px;
	color: #888;
	font-style: italic;
}

.llm-explain-spinner::before {
	content: "";
	display: inline-block;
	width: 20px;
	height: 20px;
	border: 2px solid #ddd;
	border-top-color: #3273dc;
	border-radius: 50%;
	animation: llm-spin 0.8s linear infinite;
}

@keyframes llm-spin {
	to { transform: rotate(360deg); }
}

/* Responsive */
@media screen and (max-width: 480px) {
	#llm-chat-panel {
		width: calc(100vw - 16px);
		right: 8px;
		bottom: 80px;
		max-height: 60vh;
	}

	#llm-chat-button {
		bottom: 16px;
		right: 16px;
		width: 48px;
		height: 48px;
	}

	#llm-chat-button ion-icon {
		font-size: 22px;
	}
}
