/**
 * OpenRouter AI Chatbot — front-end styles.
 * All rules are scoped to .orac-app to avoid theme collisions.
 */

.orac-app {
	--orac-primary: #2563eb;
	--orac-header-bg: #111827;
	--orac-header-text: #ffffff;
	--orac-user-bg: #2563eb;
	--orac-user-text: #ffffff;
	--orac-ai-bg: #f3f4f6;
	--orac-ai-text: #111827;
	--orac-panel-bg: #ffffff;
	--orac-radius: 16px;
	--orac-font-size: 14px;
	--orac-inline-height: 520px;
	--orac-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
	--orac-border: rgba(15, 23, 42, 0.1);
	--orac-muted: #6b7280;

	font-size: var(--orac-font-size);
	line-height: 1.55;
	color: var(--orac-ai-text);
	box-sizing: border-box;
}

.orac-app *,
.orac-app *::before,
.orac-app *::after {
	box-sizing: inherit;
}

/* -------------------------------------------------- floating launcher */
.orac-launcher {
	position: fixed;
	bottom: 22px;
	z-index: 999998;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--orac-primary);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 10px 25px rgba(15, 23, 42, 0.28);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.orac-pos-right .orac-launcher { right: 22px; }
.orac-pos-left .orac-launcher { left: 22px; }

.orac-launcher:hover,
.orac-launcher:focus-visible {
	transform: translateY(-2px);
	box-shadow: 0 14px 30px rgba(15, 23, 42, 0.34);
}

.orac-launcher svg {
	width: 28px;
	height: 28px;
}

.orac-launcher .orac-icon-close { display: none; }

.orac-app.is-open .orac-launcher .orac-icon-chat { display: none; }
.orac-app.is-open .orac-launcher .orac-icon-close { display: block; }

/* --------------------------------------------------------- the panel */
.orac-panel {
	display: flex;
	flex-direction: column;
	background: var(--orac-panel-bg);
	border-radius: var(--orac-radius);
	box-shadow: var(--orac-shadow);
	overflow: hidden;
	border: 1px solid var(--orac-border);
	font-size: var(--orac-font-size);
	color: var(--orac-ai-text);
}

.orac-panel[hidden] { display: none !important; }

.orac-mode-floating .orac-panel {
	position: fixed;
	bottom: 96px;
	z-index: 999999;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 140px);
	animation: orac-pop 0.18s ease-out;
}

.orac-pos-right.orac-mode-floating .orac-panel { right: 22px; }
.orac-pos-left.orac-mode-floating .orac-panel { left: 22px; }

.orac-mode-inline .orac-panel {
	width: 100%;
	height: var(--orac-inline-height);
	max-height: 85vh;
}

@keyframes orac-pop {
	from { opacity: 0; transform: translateY(10px) scale(0.98); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ------------------------------------------------------------ header */
.orac-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	background: var(--orac-header-bg);
	color: var(--orac-header-text);
	flex: 0 0 auto;
}

.orac-avatar {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.16);
	flex: 0 0 auto;
}

.orac-avatar svg { width: 18px; height: 18px; }

.orac-heading {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1 1 auto;
}

.orac-title {
	font-weight: 600;
	font-size: 1em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.orac-subtitle {
	font-size: 0.78em;
	opacity: 0.75;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.orac-header-actions {
	display: flex;
	gap: 4px;
	flex: 0 0 auto;
}

.orac-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: inherit;
	cursor: pointer;
	opacity: 0.75;
	transition: background 0.15s ease, opacity 0.15s ease;
}

.orac-icon-btn:hover,
.orac-icon-btn:focus-visible {
	background: rgba(255, 255, 255, 0.16);
	opacity: 1;
}

.orac-icon-btn svg { width: 16px; height: 16px; }

/* -------------------------------------------------------------- body */
.orac-body {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 14px 6px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--orac-panel-bg);
	scrollbar-width: thin;
}

.orac-messages {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.orac-msg {
	display: flex;
	max-width: 100%;
}

.orac-msg-user { justify-content: flex-end; }
.orac-msg-ai { justify-content: flex-start; }

.orac-bubble {
	position: relative;
	max-width: 86%;
	padding: 9px 13px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.orac-msg-user .orac-bubble {
	background: var(--orac-user-bg);
	color: var(--orac-user-text);
	border-bottom-right-radius: 4px;
}

.orac-msg-ai .orac-bubble {
	background: var(--orac-ai-bg);
	color: var(--orac-ai-text);
	border-bottom-left-radius: 4px;
}

.orac-bubble p { margin: 0 0 0.6em; }
.orac-bubble p:last-child { margin-bottom: 0; }
.orac-bubble ul,
.orac-bubble ol { margin: 0.4em 0 0.6em; padding-left: 1.3em; }
.orac-bubble li { margin: 0.15em 0; }
.orac-bubble a { color: var(--orac-primary); text-decoration: underline; }
.orac-msg-user .orac-bubble a { color: inherit; }
.orac-bubble code {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.9em;
	background: rgba(15, 23, 42, 0.08);
	padding: 1px 5px;
	border-radius: 5px;
}
.orac-bubble pre {
	margin: 0.5em 0;
	padding: 10px 12px;
	border-radius: 10px;
	background: rgba(15, 23, 42, 0.9);
	color: #f9fafb;
	overflow-x: auto;
	font-size: 0.86em;
}
.orac-bubble pre code {
	background: transparent;
	padding: 0;
	color: inherit;
	white-space: pre;
}
.orac-bubble h1,
.orac-bubble h2,
.orac-bubble h3 {
	margin: 0.5em 0 0.35em;
	font-size: 1.05em;
	font-weight: 700;
}

.orac-msg-error .orac-bubble {
	background: #fee2e2;
	color: #991b1b;
}

.orac-copy {
	position: absolute;
	top: -10px;
	right: 4px;
	padding: 1px 6px;
	font-size: 0.7em;
	border-radius: 6px;
	border: 1px solid var(--orac-border);
	background: var(--orac-panel-bg);
	color: var(--orac-muted);
	cursor: pointer;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.orac-msg-ai:hover .orac-copy,
.orac-copy:focus-visible { opacity: 1; }

/* typing dots */
.orac-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	height: 1.2em;
}

.orac-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.45;
	animation: orac-blink 1.2s infinite ease-in-out;
}

.orac-typing span:nth-child(2) { animation-delay: 0.18s; }
.orac-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes orac-blink {
	0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-2px); }
}

/* starter chips */
.orac-starters {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.orac-chip {
	padding: 6px 11px;
	font-size: 0.85em;
	border-radius: 999px;
	border: 1px solid var(--orac-border);
	background: transparent;
	color: var(--orac-ai-text);
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease;
}

.orac-chip:hover,
.orac-chip:focus-visible {
	border-color: var(--orac-primary);
	color: var(--orac-primary);
}

/* lead form */
.orac-lead {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 14px;
	border: 1px solid var(--orac-border);
	border-radius: 12px;
	background: var(--orac-ai-bg);
}

.orac-lead[hidden] { display: none !important; }
.orac-lead-title { font-size: 1em; }
.orac-lead-intro { margin: 0; font-size: 0.88em; color: var(--orac-muted); }

.orac-lead input {
	width: 100%;
	padding: 9px 11px;
	border: 1px solid var(--orac-border);
	border-radius: 9px;
	background: var(--orac-panel-bg);
	color: inherit;
	font-size: 0.92em;
}

.orac-lead input:focus {
	outline: 2px solid var(--orac-primary);
	outline-offset: 1px;
}

.orac-lead-error {
	margin: 0;
	font-size: 0.82em;
	color: #991b1b;
	min-height: 1em;
}

.orac-btn-primary {
	padding: 9px 14px;
	border: 0;
	border-radius: 9px;
	background: var(--orac-primary);
	color: #fff;
	font-size: 0.92em;
	font-weight: 600;
	cursor: pointer;
}

/* -------------------------------------------------------------- form */
.orac-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--orac-border);
	background: var(--orac-panel-bg);
	flex: 0 0 auto;
}

.orac-input {
	flex: 1 1 auto;
	resize: none;
	max-height: 120px;
	padding: 9px 12px;
	border: 1px solid var(--orac-border);
	border-radius: 12px;
	background: var(--orac-panel-bg);
	color: inherit;
	font: inherit;
	line-height: 1.4;
}

.orac-mode-inline .orac-input,
.orac-mode-floating .orac-input { background: var(--orac-panel-bg); }

.orac-input:focus {
	outline: 2px solid var(--orac-primary);
	outline-offset: 1px;
	border-color: transparent;
}

.orac-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	flex: 0 0 auto;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: var(--orac-primary);
	color: #fff;
	cursor: pointer;
	transition: filter 0.15s ease, opacity 0.15s ease;
}

.orac-send svg { width: 18px; height: 18px; }
.orac-send:hover { filter: brightness(1.06); }
.orac-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------------------------------------ footer */
.orac-footer {
	padding: 7px 12px;
	border-top: 1px solid var(--orac-border);
	font-size: 0.76em;
	color: var(--orac-muted);
	text-align: center;
	flex: 0 0 auto;
}

.orac-consent { display: block; opacity: 0.8; }

/* --------------------------------------------------------- utilities */
.orac-app .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

@media (max-width: 480px) {
	.orac-mode-floating .orac-panel {
		right: 8px;
		left: 8px;
		width: auto;
		height: calc(100vh - 120px);
		max-height: none;
		bottom: 84px;
	}

	.orac-pos-left.orac-mode-floating .orac-panel,
	.orac-pos-right.orac-mode-floating .orac-panel {
		right: 8px;
		left: 8px;
	}

	.orac-launcher { bottom: 16px; }
	.orac-pos-right .orac-launcher { right: 16px; }
	.orac-pos-left .orac-launcher { left: 16px; }
}

@media (prefers-reduced-motion: reduce) {
	.orac-app *,
	.orac-app *::before,
	.orac-app *::after {
		animation-duration: 0.001ms !important;
		transition-duration: 0.001ms !important;
	}
}
