/**
 * SimpleChatBot widget styles.
 *
 * Everything is namespaced under `.scb` and resets the properties themes
 * usually leak into buttons, inputs and lists. No Shadow DOM: plain, defensive
 * CSS keeps the widget debuggable and themeable through custom properties.
 */

.scb {
	--scb-primary: #2563eb;
	--scb-on-primary: #ffffff;
	--scb-bg: #ffffff;
	/* Brand colour made readable as TEXT on the panel background (computed in Widget.php). */
	--scb-accent: var(--scb-accent-light, var(--scb-primary));
	--scb-surface: #f5f6f8;
	--scb-fg: #16181d;
	--scb-muted: #5c6270;
	--scb-border: #e3e6ec;
	--scb-danger: #b42318;
	--scb-radius: 16px;
	--scb-shadow: 0 1px 2px rgba(16, 18, 23, .06), 0 12px 32px rgba(16, 18, 23, .14);
	--scb-width: 384px;

	box-sizing: border-box;
	color: var(--scb-fg);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.55;
	text-align: left;
	/* Visitor text, model replies and raw URLs are arbitrary: never let one long
	   token widen a bubble, a chip or the panel itself. Inherited on purpose. */
	overflow-wrap: anywhere;
	-webkit-font-smoothing: antialiased;
}

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

.scb--floating {
	position: fixed;
	bottom: max(20px, env(safe-area-inset-bottom));
	z-index: 99990;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
}

.scb--floating.scb--right {
	right: max(20px, env(safe-area-inset-right));
}

.scb--floating.scb--left {
	left: max(20px, env(safe-area-inset-left));
	align-items: flex-start;
}

.scb--inline {
	display: block;
	width: 100%;
	max-width: var(--scb-width);
	margin: 24px 0;
}

/* ------------------------------------------------------------------ resets */

/*
 * Themes that shout (`button { border: 3px solid … !important }`) would
 * otherwise repaint every control in the widget, so the reset shouts back on
 * exactly the properties they tend to force, and the few painted surfaces
 * below re-assert themselves the same way.
 */
.scb button {
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 0 !important;
	background: none !important;
	color: inherit !important;
	font: inherit !important;
	line-height: inherit !important;
	text-align: inherit;
	text-transform: none !important;
	letter-spacing: normal !important;
	text-shadow: none !important;
	box-shadow: none !important;
	min-width: 0 !important;
	max-width: 100%;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.scb input,
.scb textarea {
	margin: 0;
	font: inherit;
	color: inherit;
	background: none;
	-webkit-appearance: none;
	appearance: none;
}

.scb p {
	margin: 0;
}

.scb ul {
	margin: 0;
	padding: 0 0 0 1.25em;
	list-style: disc outside;
}

.scb ol {
	margin: 0;
	padding: 0 0 0 1.35em;
	list-style: decimal outside;
}

.scb a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.scb :focus-visible {
	outline: 2px solid var(--scb-accent);
	outline-offset: 2px;
	border-radius: 6px;
}

.scb-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.scb-hp {
	position: absolute !important;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.scb-icon {
	width: 20px;
	height: 20px;
	flex: none;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.7;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.scb-icon--inline {
	width: 16px;
	height: 16px;
}

/* --------------------------------------------------------------- launcher */

.scb .scb-launcher {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	flex: none;
	border-radius: 999px !important;
	background: var(--scb-primary) !important;
	color: var(--scb-on-primary) !important;
	box-shadow: var(--scb-shadow) !important;
	transition: transform .18s ease, box-shadow .18s ease;
}

.scb-launcher .scb-icon {
	width: 24px;
	height: 24px;
}

.scb .scb-launcher:hover {
	transform: translateY(-1px);
}

.scb.scb--open .scb-launcher {
	transform: scale(.94);
}

/* ----------------------------------------------------------------- teaser */

.scb-teaser {
	display: flex;
	align-items: flex-start;
	gap: 4px;
	max-width: min(280px, calc(100vw - 48px));
	padding: 4px 4px 4px 14px;
	border: 1px solid var(--scb-border);
	border-radius: var(--scb-radius);
	background: var(--scb-bg);
	box-shadow: var(--scb-shadow);
	animation: scb-rise .3s ease both;
}

/* A class-level `display` (some carry !important against hostile themes) beats the UA `[hidden]`
   rule, so hidden always wins inside the widget. */
.scb [hidden] {
	display: none !important;
}

/* A class-level `display` beats the UA `[hidden]` rule, so restate it. */
.scb-teaser[hidden] {
	display: none;
}

.scb .scb-teaser-open {
	min-width: 0 !important;
	padding: 8px 0 !important;
	font-size: 14px !important;
	min-height: 44px;
}

.scb-teaser-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	flex: none;
	margin-top: 4px !important;
	border-radius: 8px !important;
	color: var(--scb-muted) !important;
}

.scb .scb-teaser-close:hover {
	background: var(--scb-surface) !important;
}

@keyframes scb-rise {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: none; }
}

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

.scb-panel {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--scb-border);
	border-radius: 20px;
	background: var(--scb-bg);
}

.scb--floating .scb-panel {
	width: min(var(--scb-width), calc(100vw - 32px));
	height: min(620px, calc(100dvh - 140px));
	box-shadow: var(--scb-shadow);
	animation: scb-rise .22s ease both;
}

.scb--inline .scb-panel {
	height: min(560px, 80vh);
	box-shadow: 0 1px 2px rgba(16, 18, 23, .05);
}

.scb-panel[hidden] {
	display: none;
}

.scb-header {
	display: flex;
	flex: none;
	align-items: center;
	gap: 12px;
	padding: 14px 12px 14px 18px;
	border-bottom: 1px solid var(--scb-border);
	background: var(--scb-bg);
}

.scb-id {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	flex: 1;
}

.scb-avatar {
	width: 36px;
	height: 36px;
	flex: none;
	border-radius: 999px;
	object-fit: cover;
	background: var(--scb-surface);
}

.scb-titles {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.scb-title {
	font-weight: 600;
	font-size: 15px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.scb-subtitle {
	font-size: 12.5px;
	color: var(--scb-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.scb-header-actions {
	display: flex;
	flex: none;
	gap: 2px;
}

.scb-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	flex: none;
	border-radius: 10px !important;
	color: var(--scb-muted) !important;
}

.scb .scb-icon-btn:hover {
	background: var(--scb-surface) !important;
	color: var(--scb-fg) !important;
}

/* ------------------------------------------------------------------ views */

.scb-view {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
	min-height: 0;
	overflow: hidden;
}

.scb-view[hidden] {
	display: none;
}

.scb-log {
	display: flex;
	flex-direction: column;
	gap: 14px;
	flex: 1;
	/* Keeps a readable sliver of conversation when a short panel is dominated
	   by the chip rail; the rail shrinks past its cap instead. */
	min-height: 72px;
	padding: 18px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.scb-row {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 8px;
	min-width: 0;
	max-width: 92%;
}

.scb-row--user {
	align-self: flex-end;
	align-items: flex-end;
	max-width: 84%;
}

.scb-bubble {
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-width: 0;
	max-width: 100%;
	padding: 11px 14px;
	border-radius: var(--scb-radius);
}

.scb-bubble--bot {
	background: var(--scb-surface);
	border-bottom-left-radius: 6px;
}

.scb-bubble--user {
	background: var(--scb-primary);
	color: var(--scb-on-primary);
	border-bottom-right-radius: 6px;
}

.scb-p + .scb-p {
	margin-top: -2px;
}

.scb-list {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.scb-code {
	padding: 1px 5px;
	border-radius: 5px;
	background: rgba(16, 18, 23, .07);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: .9em;
}

.scb-bubble--user .scb-code {
	background: rgba(255, 255, 255, .22);
}

/* ---------------------------------------------------------------- sources */

.scb-sources {
	display: flex;
	flex-direction: column;
	gap: 3px;
	padding-top: 9px;
	border-top: 1px solid var(--scb-border);
}

.scb-sources-label {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--scb-muted);
}

.scb .scb-sources-list {
	list-style: none;
	padding: 0;
	font-size: 13.5px;
}

.scb-sources-list a {
	color: var(--scb-accent);
}

/* --------------------------------------------------------------- feedback */

.scb-feedback {
	display: flex;
	align-items: center;
	gap: 2px;
	margin-top: 2px;
	margin-left: -8px;
}

.scb-vote {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	flex: none;
	border-radius: 8px !important;
	color: var(--scb-muted) !important;
}

.scb-vote .scb-icon {
	width: 17px;
	height: 17px;
}

.scb-vote--down .scb-icon {
	transform: rotate(180deg);
}

.scb .scb-vote:hover {
	background: rgba(16, 18, 23, .06) !important;
	color: var(--scb-fg) !important;
}

.scb .scb-vote[aria-pressed="true"] {
	color: var(--scb-accent) !important;
}

.scb-vote[aria-pressed="true"] .scb-icon {
	fill: color-mix(in srgb, var(--scb-primary) 18%, transparent);
}

.scb-feedback-note {
	font-size: 12.5px;
	color: var(--scb-muted);
	padding-left: 6px;
}

/* ---------------------------------------------------------------- typing */

.scb-dots {
	display: inline-flex;
	gap: 4px;
	padding: 3px 0;
}

.scb-dots i {
	width: 6px;
	height: 6px;
	border-radius: 999px;
	background: var(--scb-muted);
	opacity: .45;
	animation: scb-pulse 1.1s infinite ease-in-out;
}

.scb-dots i:nth-child(2) { animation-delay: .15s; }
.scb-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes scb-pulse {
	0%, 60%, 100% { opacity: .35; transform: none; }
	30% { opacity: 1; transform: translateY(-2px); }
}

.scb-notice {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	min-width: 0;
	max-width: 100%;
	gap: 10px;
	padding: 12px 14px;
	border: 1px solid var(--scb-border);
	border-radius: var(--scb-radius);
	font-size: 14px;
	color: var(--scb-muted);
}

/* ------------------------------------------------------------------ chips */

/*
 * Six long suggestions must not push the composer and the footer out of the
 * panel, so the chip rail is capped and scrolls on its own.
 */
.scb-chips {
	display: flex;
	flex: 0 1 auto;
	flex-wrap: wrap;
	gap: 8px;
	min-height: 0;
	max-height: 40%;
	padding: 0 18px 14px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.scb-chips[hidden] {
	display: none;
}

.scb .scb-chip {
	max-width: 100%;
	padding: 9px 14px !important;
	min-height: 40px;
	border: 1px solid var(--scb-border) !important;
	border-radius: 999px !important;
	background: var(--scb-bg) !important;
	font-size: 13.5px !important;
	color: var(--scb-fg) !important;
	text-align: left;
	transition: border-color .15s ease, background .15s ease;
}

.scb .scb-chip:hover {
	border-color: var(--scb-primary) !important;
	background: var(--scb-surface) !important;
}

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

.scb-composer {
	display: flex;
	flex: none;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 12px 12px 16px;
	border-top: 1px solid var(--scb-border);
}

.scb-input {
	flex: 1;
	min-width: 0;
	max-height: 140px;
	padding: 10px 2px;
	border: 0;
	background: none;
	resize: none;
	overflow-y: auto;
	line-height: 1.5;
}

.scb-input:focus:not(:focus-visible) {
	outline: none;
}

.scb-input::placeholder {
	color: var(--scb-muted);
	opacity: 1;
	/* A long placeholder would wrap and be cut in half by the one-row box. */
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.scb .scb-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	flex: none;
	border-radius: 12px !important;
	background: var(--scb-primary) !important;
	color: var(--scb-on-primary) !important;
	transition: opacity .15s ease;
}

.scb-send[disabled] {
	opacity: .35;
	cursor: default;
}

.scb-send .scb-icon {
	fill: currentColor;
	stroke-width: 0;
	transform: translateX(-1px);
}

/* ----------------------------------------------------------------- footer */

.scb-footer {
	display: flex;
	flex: none;
	flex-direction: column;
	min-width: 0;
	gap: 6px;
	padding: 0 16px 14px;
}

.scb-link[hidden] {
	display: none;
}

.scb .scb-link {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	align-self: flex-start;
	max-width: 100%;
	min-height: 44px;
	font-size: 13.5px !important;
	font-weight: 500 !important;
	color: var(--scb-accent) !important;
}

.scb-link .scb-icon {
	width: 16px;
	height: 16px;
}

.scb-link:hover span {
	text-decoration: underline;
	text-underline-offset: 2px;
}

.scb-disclosure {
	font-size: 11.5px;
	line-height: 1.45;
	color: var(--scb-muted);
}

/* ------------------------------------------------------------------ forms */

.scb-view--form {
	overflow-y: auto;
	overscroll-behavior: contain;
}

.scb-form-head {
	padding: 6px 12px 0;
}

.scb-form {
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding: 16px 18px 22px;
}

.scb-intro {
	font-size: 14px;
	color: var(--scb-muted);
}

.scb-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.scb-label {
	font-size: 13px;
	font-weight: 600;
}

.scb-control {
	width: 100%;
	min-height: 44px;
	padding: 10px 12px;
	border: 1px solid var(--scb-border);
	border-radius: 10px;
	background: var(--scb-bg);
	line-height: 1.5;
	resize: vertical;
}

.scb-control:focus {
	outline: none;
	border-color: var(--scb-primary);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--scb-primary) 22%, transparent);
}

.scb-control[aria-invalid="true"] {
	border-color: var(--scb-danger);
}

.scb-control[type="file"] {
	padding: 9px 12px;
	font-size: 13.5px;
}

.scb-hint {
	font-size: 12px;
	color: var(--scb-muted);
}

.scb-error {
	font-size: 12.5px;
	color: var(--scb-danger);
}

.scb-field--check {
	flex-direction: row;
	align-items: flex-start;
	gap: 10px;
}

.scb-check {
	width: 18px;
	height: 18px;
	margin-top: 3px;
	flex: none;
	accent-color: var(--scb-primary);
	-webkit-appearance: auto;
	appearance: auto;
}

.scb-check-label {
	min-width: 0;
	font-size: 13px;
	color: var(--scb-muted);
}

.scb-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 2px;
}

.scb .scb-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	max-width: 100%;
	min-height: 44px;
	padding: 10px 18px !important;
	border-radius: 12px !important;
	font-size: 14px !important;
	font-weight: 500 !important;
}

.scb .scb-btn--primary {
	background: var(--scb-primary) !important;
	color: var(--scb-on-primary) !important;
}

.scb-btn--primary[disabled] {
	opacity: .55;
	cursor: default;
}

.scb .scb-btn--ghost {
	border: 1px solid var(--scb-border) !important;
	color: var(--scb-fg) !important;
}

.scb .scb-btn--soft {
	min-height: 40px;
	padding: 8px 14px !important;
	border: 1px solid var(--scb-border) !important;
	font-size: 13.5px !important;
	color: var(--scb-fg) !important;
	background: var(--scb-bg) !important;
}

.scb .scb-btn--soft:hover,
.scb .scb-btn--ghost:hover {
	background: var(--scb-surface) !important;
}

.scb-status {
	font-size: 13.5px;
	color: var(--scb-muted);
}

.scb-status--error {
	color: var(--scb-danger);
}

.scb-done {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 14px;
	padding: 28px 18px;
}

.scb-done-text {
	font-size: 15px;
}

/* ------------------------------------------------------------ dark scheme */

@media (prefers-color-scheme: dark) {
	.scb {
		--scb-bg: #16181d;
		--scb-accent: var(--scb-accent-dark, var(--scb-primary));
		--scb-surface: #22252c;
		--scb-fg: #eceef2;
		--scb-muted: #9aa1ae;
		--scb-border: #343a47;
		--scb-danger: #ff9b90;
		--scb-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
	}

	.scb-code {
		background: rgba(255, 255, 255, .1);
	}

	.scb .scb-vote:hover {
		background: rgba(255, 255, 255, .08) !important;
	}
}

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

@media (max-width: 480px) {
	.scb--floating {
		bottom: max(16px, env(safe-area-inset-bottom));
	}

	.scb--floating.scb--right {
		right: max(16px, env(safe-area-inset-right));
	}

	.scb--floating.scb--left {
		left: max(16px, env(safe-area-inset-left));
	}

	.scb--inline {
		max-width: 100%;
	}

	.scb-log,
	.scb-chips,
	.scb-footer {
		padding-left: 14px;
		padding-right: 14px;
	}

	.scb-row {
		max-width: 96%;
	}

	/* Thumb-sized targets: the desktop sizes are too small for a phone. */
	.scb .scb-chip,
	.scb .scb-btn--soft {
		min-height: 44px;
	}

	.scb-vote {
		width: 44px;
		height: 44px;
	}

	.scb-feedback {
		margin-left: -12px;
	}

	.scb-teaser-close {
		width: 44px;
		height: 44px;
		margin-top: 0 !important;
	}
}

/*
 * Phones, and any window too short to host a floating panel (landscape
 * phones): the panel takes the viewport instead of hanging off its edges.
 */
@media (max-width: 480px), (max-height: 520px) {
	.scb--floating.scb--open {
		inset: 0;
		align-items: stretch;
		gap: 0;
	}

	.scb--floating.scb--open .scb-panel {
		width: 100%;
		height: 100dvh;
		max-height: 100dvh;
		border: 0;
		border-radius: 0;
		padding-bottom: env(safe-area-inset-bottom);
		padding-left: env(safe-area-inset-left);
		padding-right: env(safe-area-inset-right);
	}

	.scb--floating.scb--open .scb-launcher,
	.scb--floating.scb--open .scb-teaser {
		display: none;
	}
}

/* ------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
	.scb *,
	.scb *::before,
	.scb *::after {
		animation-duration: .01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: .01ms !important;
	}

	.scb-launcher:hover,
	.scb--open .scb-launcher {
		transform: none;
	}
}
