/* ==========================================================================
   EC Wiki — custom-chat.css
   Chat widget: floating pill, chat panel, messages, sources, markdown
   rendered elements, cursor fixes, clickable nudge. Loaded everywhere.
   ========================================================================== */

/* ==========================================================================
   CHAT WIDGET — floating panel, global
   ========================================================================== */

.rsgdxwiki-floating-pill--chat {
	background: var(--rsgdxwiki-color-chat-button);
	border-color: var(--rsgdxwiki-color-chat-button);
	color: #fff;
}

.rsgdxwiki-floating-pill--chat i {
	color: #fff;
}

.rsgdxwiki-floating-pill--chat:hover {
	background: var(--rsgdxwiki-color-chat-button-hover);
	border-color: var(--rsgdxwiki-color-chat-button-hover);
}

.rsgdxwiki-chat-panel {
	position: fixed;
	bottom: calc(var(--rsgdxwiki-space-6) + 52px + var(--rsgdxwiki-space-3));
	right: var(--rsgdxwiki-space-6);
	width: 420px;
	max-height: calc(100vh - 120px);
	height: calc(100vh - 120px);
	background: var(--rsgdxwiki-color-surface);
	border: 1px solid var(--rsgdxwiki-color-border-light);
	border-radius: var(--rsgdxwiki-radius-lg);
	box-shadow: 0 8px 32px rgba(0,0,0,0.45);
	display: flex;
	flex-direction: column;
	z-index: 160;
	overflow: hidden;
}

.rsgdxwiki-chat-panel[hidden] {
	display: none;
}

.rsgdxwiki-chat-panel__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--rsgdxwiki-space-4);
	background: var(--rsgdxwiki-color-chat-button);
	color: #fff;
}

.rsgdxwiki-chat-panel__header-info {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: var(--rsgdxwiki-text-sm);
	font-weight: 700;
}

.rsgdxwiki-chat-panel__close {
	background: none;
	border: none;
	color: rgba(255,255,255,0.8);
	cursor: pointer;
	font-size: 16px;
	display: flex;
	padding: 4px;
	transition: color var(--rsgdxwiki-transition);
}

.rsgdxwiki-chat-panel__close:hover {
	color: #fff;
}

.rsgdxwiki-chat-panel__messages {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: var(--rsgdxwiki-space-4);
	display: flex;
	flex-direction: column;
	gap: var(--rsgdxwiki-space-3);
}

.rsgdxwiki-chat-msg {
	max-width: 88%;
	border-radius: var(--rsgdxwiki-radius-md);
	padding: var(--rsgdxwiki-space-3) var(--rsgdxwiki-space-4);
	font-size: var(--rsgdxwiki-text-sm);
	line-height: 1.6;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.rsgdxwiki-chat-link {
	color: var(--rsgdxwiki-color-blue-light);
	text-decoration: underline;
	overflow-wrap: anywhere;
}

.rsgdxwiki-chat-link:hover {
	color: var(--rsgdxwiki-color-blue);
}

.rsgdxwiki-chat-msg p {
	margin: 0;
}

.rsgdxwiki-chat-msg--user {
	background: var(--rsgdxwiki-color-chat-button);
	color: #fff;
	align-self: flex-end;
	border-bottom-right-radius: 4px;
}

.rsgdxwiki-chat-msg--assistant {
	background: var(--rsgdxwiki-color-surface-high);
	color: var(--rsgdxwiki-color-text);
	align-self: flex-start;
	border-bottom-left-radius: 4px;
}

.rsgdxwiki-chat-msg__image {
	display: block;
	max-width: 100%;
	max-height: 160px;
	border-radius: var(--rsgdxwiki-radius-sm, 6px);
	margin-top: var(--rsgdxwiki-space-2);
	object-fit: cover;
}

/* --- Typing bubble --- */
.rsgdxwiki-chat-msg--typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: var(--rsgdxwiki-space-3) var(--rsgdxwiki-space-4);
}

.rsgdxwiki-chat-typing-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--rsgdxwiki-color-text-muted);
	opacity: 0.5;
	animation: rsgdxwiki-typing-bounce 1.1s infinite ease-in-out;
}

.rsgdxwiki-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.rsgdxwiki-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes rsgdxwiki-typing-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30%           { transform: translateY(-4px); opacity: 1; }
}

/* --- Image attach preview --- */
.rsgdxwiki-chat-panel__image-preview {
	position: relative;
	display: inline-flex;
	margin: 0 var(--rsgdxwiki-space-4);
	padding-top: var(--rsgdxwiki-space-2);
}

.rsgdxwiki-chat-panel__image-preview[hidden] {
	display: none;
}

.rsgdxwiki-chat-panel__image-preview img {
	max-height: 70px;
	max-width: 120px;
	border-radius: var(--rsgdxwiki-radius-sm, 6px);
	object-fit: cover;
	border: 1px solid var(--rsgdxwiki-color-border-light);
}

.rsgdxwiki-chat-panel__image-remove {
	position: absolute;
	top: -4px;
	right: -8px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: var(--rsgdxwiki-color-surface);
	border: 1px solid var(--rsgdxwiki-color-border-light);
	color: var(--rsgdxwiki-color-text-muted);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 10px;
	padding: 0;
}

.rsgdxwiki-chat-panel__image-remove:hover {
	color: var(--rsgdxwiki-color-text);
}

.rsgdxwiki-chat-panel__attach {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: transparent;
	border: 1px solid var(--rsgdxwiki-color-border-light);
	color: var(--rsgdxwiki-color-text-muted);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 14px;
	flex-shrink: 0;
	transition: background var(--rsgdxwiki-transition), color var(--rsgdxwiki-transition);
}

.rsgdxwiki-chat-panel__attach:hover {
	background: var(--rsgdxwiki-color-surface-high);
	color: var(--rsgdxwiki-color-text);
}

.rsgdxwiki-chat-panel__sources {
	padding: var(--rsgdxwiki-space-3) var(--rsgdxwiki-space-4);
	border-top: 1px solid var(--rsgdxwiki-color-border);
	background: var(--rsgdxwiki-color-surface-high);
	max-height: 160px;
	overflow-y: auto;
	flex-shrink: 0;
}

.rsgdxwiki-chat-panel__sources-label {
	font-size: var(--rsgdxwiki-text-xs);
	font-weight: 700;
	color: var(--rsgdxwiki-color-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.4px;
	margin: 0 0 6px;
	display: flex;
	align-items: center;
	gap: 6px;
}

.rsgdxwiki-chat-source-link {
	display: block;
	font-size: var(--rsgdxwiki-text-xs);
	color: var(--rsgdxwiki-color-blue-light);
	text-decoration: none;
	padding: 3px 0;
}

.rsgdxwiki-chat-source-link:hover {
	text-decoration: underline;
}

.rsgdxwiki-chat-panel__sources.is-prominent {
	background: var(--rsgdxwiki-color-blue-faint);
	border-color: rgba(114,174,230,0.3);
}

.rsgdxwiki-chat-panel__input-wrap {
	display: flex;
	align-items: flex-end;
	gap: var(--rsgdxwiki-space-2);
	padding: var(--rsgdxwiki-space-3) var(--rsgdxwiki-space-4);
	border-top: 1px solid var(--rsgdxwiki-color-border);
	background: var(--rsgdxwiki-color-surface);
}

.rsgdxwiki-chat-panel__input {
	flex: 1;
	background: var(--rsgdxwiki-color-surface-high);
	border: 1px solid var(--rsgdxwiki-color-border-light);
	border-radius: var(--rsgdxwiki-radius-md);
	color: var(--rsgdxwiki-color-text);
	font-size: var(--rsgdxwiki-text-sm);
	font-family: var(--rsgdxwiki-font-sans, inherit);
	padding: 8px 12px;
	resize: none;
	line-height: 1.5;
	min-height: 38px;
	max-height: 120px;
	overflow-y: auto;
}

.rsgdxwiki-chat-panel__input::placeholder {
	color: var(--rsgdxwiki-color-text-muted);
	opacity: 1;
}

.rsgdxwiki-chat-panel__input:focus {
	outline: none;
	border-color: var(--rsgdxwiki-color-blue);
}

.rsgdxwiki-chat-panel__send {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: var(--rsgdxwiki-color-chat-button);
	border: none;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 14px;
	flex-shrink: 0;
	transition: background var(--rsgdxwiki-transition);
}

.rsgdxwiki-chat-panel__send:hover {
	background: var(--rsgdxwiki-color-chat-button-hover);
}

.rsgdxwiki-chat-panel__send:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.rsgdxwiki-chat-panel__footer {
	padding: 6px var(--rsgdxwiki-space-4);
	font-size: 10px;
	color: var(--rsgdxwiki-color-text-subtle);
	text-align: center;
	border-top: 1px solid var(--rsgdxwiki-color-border);
}

@media (max-width: 480px) {
	.rsgdxwiki-chat-panel {
		width: calc(100vw - var(--rsgdxwiki-space-4) * 2);
		right: var(--rsgdxwiki-space-4);
	}
}

/* --- Icon-only chat pill variant (used beside jump nav on single-training) --- */
.rsgdxwiki-floating-pill--icon-only {
	padding: 12px 14px;
}

.rsgdxwiki-floating-pill--icon-only span {
	display: none;
}

/* --- Shift jump nav left when chat pill is also present --- */
.rsgdxwiki-floating-bar--with-chat {
	right: calc(var(--rsgdxwiki-space-6) + 52px + var(--rsgdxwiki-space-3));
}

/* --- Chat markdown rendered elements --- */
.rsgdxwiki-chat-msg--assistant p {
	margin: 0 0 8px;
}

.rsgdxwiki-chat-msg--assistant p:last-child {
	margin-bottom: 0;
}

.rsgdxwiki-chat-h {
	font-size: var(--rsgdxwiki-text-sm);
	font-weight: 700;
	color: var(--rsgdxwiki-color-text);
	margin: 10px 0 4px;
	padding: 0;
}

.rsgdxwiki-chat-hr {
	border: none;
	border-top: 1px solid var(--rsgdxwiki-color-border);
	margin: 8px 0;
}

.rsgdxwiki-chat-list {
	margin: 6px 0 8px 18px;
	padding: 0;
}

.rsgdxwiki-chat-list li {
	margin-bottom: 4px;
	font-size: var(--rsgdxwiki-text-sm);
	line-height: 1.5;
}

.rsgdxwiki-chat-code {
	background: rgba(0,0,0,0.25);
	border-radius: 3px;
	padding: 1px 5px;
	font-family: monospace;
	font-size: 12px;
}

.rsgdxwiki-chat-table-wrap {
	overflow-x: auto;
	margin: 10px 0;
	border-radius: var(--rsgdxwiki-radius-sm, 6px);
	border: 1px solid var(--rsgdxwiki-color-border);
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
}

.rsgdxwiki-chat-table-wrap::-webkit-scrollbar {
	height: 6px;
}

.rsgdxwiki-chat-table-wrap::-webkit-scrollbar-thumb {
	background: var(--rsgdxwiki-color-border-light);
	border-radius: 3px;
}

.rsgdxwiki-chat-table {
	width: auto;
	min-width: 100%;
	border-collapse: collapse;
	font-size: var(--rsgdxwiki-text-xs);
	margin: 0;
}

.rsgdxwiki-chat-table th,
.rsgdxwiki-chat-table td {
	border: 1px solid var(--rsgdxwiki-color-border);
	padding: 7px 12px;
	text-align: left;
	white-space: nowrap;
}

.rsgdxwiki-chat-table th {
	background: var(--rsgdxwiki-color-surface-high);
	font-weight: 700;
	position: sticky;
	top: 0;
}

.rsgdxwiki-chat-table tr:nth-child(even) td {
	background: rgba(255,255,255,0.02);
}

@media (max-width: 480px) {
	.rsgdxwiki-chat-panel {
		width: calc(100vw - var(--rsgdxwiki-space-4) * 2);
		right: var(--rsgdxwiki-space-4);
		height: calc(100vh - 100px);
		max-height: calc(100vh - 100px);
	}
}

/* --- Chat cursor fixes --- */
.rsgdxwiki-chat-panel,
.rsgdxwiki-chat-panel__messages,
.rsgdxwiki-chat-msg,
.rsgdxwiki-chat-panel__sources,
.rsgdxwiki-chat-panel__footer {
	cursor: default;
}

.rsgdxwiki-chat-panel__input {
	cursor: text;
}

.rsgdxwiki-chat-panel__send:not(:disabled) {
	cursor: pointer;
}

.rsgdxwiki-chat-source-link {
	cursor: pointer;
}

/* --- Clickable chatbot nudge --- */
.rsgdxwiki-chatbot-nudge--clickable {
	cursor: pointer;
	border: none;
	width: 100%;
	text-align: left;
	transition: background var(--rsgdxwiki-transition), border-color var(--rsgdxwiki-transition);
}

.rsgdxwiki-chatbot-nudge--clickable:hover {
	background: var(--rsgdxwiki-color-surface-high);
	border-color: var(--rsgdxwiki-color-blue);
}

.rsgdxwiki-chatbot-nudge--prominent.rsgdxwiki-chatbot-nudge--clickable:hover {
	background: rgba(114, 174, 230, 0.15);
}

.rsgdxwiki-chatbot-nudge__cta {
	margin-left: auto;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: var(--rsgdxwiki-text-xs);
	font-weight: 600;
	color: var(--rsgdxwiki-color-blue-light);
	white-space: nowrap;
	flex-shrink: 0;
}