/**
 * Invictus chat widget styles.
 */

#invictus-chat-root {
	--ich-bg: #ffffff;
	--ich-fg: #111827;
	--ich-muted: #6b7280;
	--ich-border: #e5e7eb;
	--ich-input-bg: #ffffff;
	--ich-input-border: #d1d5db;
	--ich-input-focus: #2563eb;
	--ich-primary: #111827;
	--ich-primary-fg: #ffffff;
	--ich-accent: #2563eb;
	--ich-bubble-user: #2563eb;
	--ich-bubble-user-fg: #ffffff;
	--ich-bubble-agent: #f3f4f6;
	--ich-bubble-agent-fg: #111827;
	--ich-danger: #b91c1c;
	--ich-shadow: 0 16px 40px rgba(0, 0, 0, .22);
	--ich-radius: 16px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--ich-fg);
}

:where(#invictus-chat-root),
:where(#invictus-chat-root) *,
:where(#invictus-chat-root) *::before,
:where(#invictus-chat-root) *::after {
	box-sizing: border-box;
}

:where(#invictus-chat-root) button {
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	font-family: inherit;
	color: inherit;
	line-height: normal;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	-webkit-appearance: none;
	appearance: none;
	cursor: pointer;
}

:where(#invictus-chat-root) input,
:where(#invictus-chat-root) textarea {
	font-family: inherit;
	color: var(--ich-fg);
	letter-spacing: normal;
	text-transform: none;
	-webkit-appearance: none;
	appearance: none;
	box-shadow: none;
}

:where(#invictus-chat-root) p { margin: 0; }

:where(#invictus-chat-root) svg {
	display: inline-block;
	flex-shrink: 0;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

:where(#invictus-chat-root) svg :is(path, line, circle, rect, polyline, polygon) {
	fill: none;
	stroke: currentColor;
}

/* ----------------------- panel ----------------------- */

.invictus-chat-panel {
	position: fixed;
	inset: 0;
	z-index: 99999;
	background: rgba(15, 23, 42, .12);
	display: flex;
	justify-content: flex-end;
	align-items: flex-end;
	padding: 24px;
	opacity: 0;
	pointer-events: none;
	transition: opacity .15s ease;
}

.invictus-chat-panel.is-open {
	opacity: 1;
	pointer-events: auto;
}

.invictus-chat-panel__card {
	width: 100%;
	max-width: 400px;
	height: min(640px, calc(100vh - 48px));
	background: var(--ich-bg);
	border-radius: var(--ich-radius);
	box-shadow: var(--ich-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform: translateY(12px) scale(.99);
	transition: transform .18s ease;
}

.invictus-chat-panel.is-open .invictus-chat-panel__card {
	transform: translateY(0) scale(1);
}

/* ----------------------- header ----------------------- */

.invictus-chat-panel__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	border-bottom: 1px solid var(--ich-border);
	background: linear-gradient(180deg, #fafafa 0%, #ffffff 100%);
}

.invictus-chat-panel__heading {
	flex: 1;
	min-width: 0;
}

.invictus-chat-panel__title {
	margin: 0;
	font-weight: 700;
	font-size: 15px;
	line-height: 1.3;
}

.invictus-chat-panel__status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin-top: 2px;
	font-weight: 400;
	font-size: 12px;
	line-height: 1.2;
	color: var(--ich-muted);
}

.invictus-chat-panel__dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #d1d5db;
	flex-shrink: 0;
}

.invictus-chat-panel__status[data-status="online"] .invictus-chat-panel__dot {
	background: #10b981;
	box-shadow: 0 0 0 0 rgba(16, 185, 129, .55);
	animation: invictus-chat-pulse 2s infinite;
}

@keyframes invictus-chat-pulse {
	0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, .45); }
	70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
	100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.invictus-chat-panel__status[data-status="connecting"] .invictus-chat-panel__dot {
	background: #f59e0b;
}

.invictus-chat-panel__status[data-status="offline"] .invictus-chat-panel__dot,
.invictus-chat-panel__status[data-status="error"] .invictus-chat-panel__dot {
	background: #ef4444;
}

.invictus-chat-panel__status[data-status="error"] {
	color: var(--ich-danger);
}

/* Selectors prefixed with the root id to win specificity over the
   parent theme's button rules (which otherwise paint pink borders /
   backgrounds onto our buttons). */

#invictus-chat-root .invictus-chat-close {
	flex: 0 0 auto;
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--ich-muted);
	background: transparent;
	border: 0;
	border-radius: 6px;
	transition: background .12s ease, color .12s ease;
}

#invictus-chat-root .invictus-chat-close:hover { color: var(--ich-fg); background: rgba(0,0,0,.06); }
#invictus-chat-root .invictus-chat-close:focus-visible { outline: 2px solid var(--ich-accent); outline-offset: 2px; }
#invictus-chat-root .invictus-chat-close svg { display: block; }

/* ----------------------- messages ----------------------- */

.invictus-chat-messages {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #fafafa;
	scrollbar-width: thin;
}

.invictus-chat-empty {
	margin: auto 8px;
	padding: 14px 16px;
	border-radius: 12px;
	background: var(--ich-bubble-agent);
	color: var(--ich-muted);
	font-weight: 400;
	font-size: 14px;
	line-height: 1.45;
	max-width: 85%;
	align-self: flex-start;
}

.invictus-chat-msg {
	display: flex;
	flex-direction: column;
	gap: 2px;
	max-width: 85%;
	animation: invictus-chat-msg-in .18s ease both;
}

@keyframes invictus-chat-msg-in {
	from { opacity: 0; transform: translateY(4px); }
	to { opacity: 1; transform: translateY(0); }
}

.invictus-chat-msg--user {
	align-self: flex-end;
	align-items: flex-end;
}

.invictus-chat-msg--agent {
	align-self: flex-start;
	align-items: flex-start;
}

.invictus-chat-msg__bubble {
	padding: 10px 14px;
	border-radius: 16px;
	font-weight: 400;
	font-size: 14px;
	line-height: 1.45;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.invictus-chat-msg--user .invictus-chat-msg__bubble {
	background: var(--ich-bubble-user);
	color: var(--ich-bubble-user-fg);
	border-bottom-right-radius: 4px;
}

.invictus-chat-msg--agent .invictus-chat-msg__bubble {
	background: var(--ich-bubble-agent);
	color: var(--ich-bubble-agent-fg);
	border-bottom-left-radius: 4px;
}

.invictus-chat-msg.is-pending .invictus-chat-msg__bubble {
	opacity: .55;
}

.invictus-chat-msg__time {
	font-weight: 400;
	font-size: 11px;
	line-height: 1.2;
	color: var(--ich-muted);
	padding: 0 6px;
}

/* ----------------------- composer ----------------------- */

.invictus-chat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--ich-border);
	background: var(--ich-bg);
}

.invictus-chat-input {
	flex: 1;
	min-height: 40px;
	max-height: 140px;
	padding: 10px 12px;
	border: 1px solid var(--ich-input-border);
	border-radius: 10px;
	resize: none;
	font-weight: 400;
	font-size: 14px;
	line-height: 1.4;
	background: var(--ich-input-bg);
	transition: border-color .12s ease, box-shadow .12s ease;
}

.invictus-chat-input:focus {
	border-color: var(--ich-input-focus);
	outline: 0;
	box-shadow: 0 0 0 3px rgba(37, 99, 235, .18);
}

#invictus-chat-root .invictus-chat-send {
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: var(--ich-accent);
	color: #fff;
	transition: background .12s ease, opacity .12s ease, transform .1s ease;
}

#invictus-chat-root .invictus-chat-send:hover:not(:disabled) {
	background: #1d4ed8;
	transform: scale(1.05);
}

#invictus-chat-root .invictus-chat-send:disabled {
	opacity: .45;
	cursor: not-allowed;
}

#invictus-chat-root .invictus-chat-send:focus-visible {
	outline: 2px solid var(--ich-accent);
	outline-offset: 2px;
}

/* ----------------------- mobile ----------------------- */

@media (max-width: 640px) {
	.invictus-chat-panel {
		padding: 0;
		align-items: stretch;
		justify-content: stretch;
	}

	.invictus-chat-panel__card {
		max-width: 100%;
		height: 100vh;
		max-height: 100vh;
		border-radius: 0;
		transform: translateY(100%);
	}

	.invictus-chat-panel.is-open .invictus-chat-panel__card {
		transform: translateY(0);
	}
}

body.invictus-chat-open {
	overflow: hidden;
}
