/*
 * Capital Pulse Chat.
 *
 * Colour follows the investment plugin's theme where that is loaded, and
 * falls back to a neutral blue elsewhere, so the widget matches the site
 * rather than announcing itself.
 */

.cpchat {
	--cpchat-accent: var(--adminuiux-theme-1, #3a1fd6);
	--cpchat-accent-rgb: var(--adminuiux-theme-1-rgb, 58, 31, 214);
	--cpchat-surface: #fff;
	--cpchat-border: rgba(0, 0, 0, .1);
	--cpchat-text: #1f2430;
	--cpchat-muted: #6c757d;
	font-size: 14px;
	line-height: 1.55;
}

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

.cpchat-floating {
	position: fixed;
	right: 1rem;
	bottom: 1rem;
	z-index: 1050;
}

.cpchat-launcher {
	display: inline-flex;
	align-items: center;
	gap: .5rem;
	background: var(--cpchat-accent);
	color: #fff;
	border: 0;
	border-radius: 999px;
	padding: .7rem 1.15rem;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

.cpchat-launcher:hover { filter: brightness(.95); }

/* Sit above the app's own mobile bar */
@media (max-width: 991.98px) {
	.cpchat-floating { bottom: 5.5rem; }
	.cpchat-launcher-text { display: none; }
	.cpchat-launcher { padding: .8rem; }
}

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

.cpchat-floating .cpchat-panel {
	position: fixed;
	right: 1rem;
	bottom: 4.75rem;
	width: min(370px, calc(100vw - 2rem));
	max-height: min(560px, calc(100vh - 7rem));
}

.cpchat-panel {
	display: flex;
	flex-direction: column;
	background: var(--cpchat-surface);
	border: 1px solid var(--cpchat-border);
	border-radius: 14px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, .16);
	overflow: hidden;
	color: var(--cpchat-text);
}

.cpchat-inline .cpchat-panel {
	box-shadow: none;
	height: 480px;
}

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

@media (max-width: 991.98px) {
	.cpchat-floating .cpchat-panel { bottom: 9.5rem; }
}

.cpchat-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: .5rem;
	background: var(--cpchat-accent);
	color: #fff;
	padding: .85rem 1rem;
}

.cpchat-title { margin: 0; font-weight: 600; }
.cpchat-sub { margin: .1rem 0 0; font-size: .8rem; opacity: .85; }

.cpchat-close {
	background: none;
	border: 0;
	color: #fff;
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
	opacity: .8;
	padding: 0 .2rem;
}

.cpchat-close:hover { opacity: 1; }

/* ------------------------------------------------------------ log ---- */

.cpchat-log {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: .6rem;
	min-height: 200px;
}

.cpchat-msg {
	max-width: 85%;
	padding: .6rem .8rem;
	border-radius: 12px;
	word-wrap: break-word;
}

.cpchat-msg p { margin: 0 0 .5rem; }
.cpchat-msg p:last-child { margin-bottom: 0; }

.cpchat-bot {
	align-self: flex-start;
	background: rgba(var(--cpchat-accent-rgb), .08);
	border-bottom-left-radius: 4px;
}

.cpchat-user {
	align-self: flex-end;
	background: var(--cpchat-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.cpchat-msg a { color: inherit; text-decoration: underline; }

.cpchat-link {
	display: inline-block;
	margin-top: .5rem;
	font-weight: 600;
	color: var(--cpchat-accent);
	text-decoration: none;
}

.cpchat-link:hover { text-decoration: underline; }

/* Suggested questions */
.cpchat-chips {
	display: flex;
	flex-wrap: wrap;
	gap: .35rem;
	margin-top: .25rem;
}

.cpchat-chip {
	background: none;
	border: 1px solid var(--cpchat-border);
	border-radius: 999px;
	padding: .3rem .7rem;
	font: inherit;
	font-size: .8rem;
    cursor: pointer;
	color: var(--cpchat-text);
	text-align: left;
}

.cpchat-chip:hover {
	border-color: var(--cpchat-accent);
	color: var(--cpchat-accent);
}

.cpchat-typing { opacity: .6; font-style: italic; }

/* ----------------------------------------------------------- form ---- */

.cpchat-form {
	display: flex;
	gap: .4rem;
	padding: .65rem;
	border-top: 1px solid var(--cpchat-border);
}

.cpchat-input {
	flex: 1;
	border: 1px solid var(--cpchat-border);
	border-radius: 999px;
	padding: .55rem .9rem;
	font: inherit;
	color: var(--cpchat-text);
	background: var(--cpchat-surface);
}

.cpchat-input:focus {
	outline: 2px solid var(--cpchat-accent);
	outline-offset: 1px;
}

.cpchat-send {
	background: var(--cpchat-accent);
	color: #fff;
	border: 0;
	border-radius: 50%;
	width: 38px;
	height: 38px;
	cursor: pointer;
	flex: 0 0 auto;
}

.cpchat-foot {
	margin: 0;
	padding: 0 1rem .7rem;
	font-size: .72rem;
	color: var(--cpchat-muted);
	text-align: center;
}

/* Dark mode, when the theme is in it */
[data-bs-theme="dark"] .cpchat {
	--cpchat-surface: #171c2e;
	--cpchat-border: rgba(255, 255, 255, .14);
	--cpchat-text: #e6e8ef;
}

/* Both routes to a person sit under the answer, side by side */
.cpchat-link { margin-right: .9rem; }

.cpchat-link-wa { color: #25d366; }

/* ------------------------------------------------------------------
   Responsive pass
   ------------------------------------------------------------------ */

/* On a phone the panel takes the screen rather than floating in a corner,
   which is what a chat is expected to do there. */
@media (max-width: 575.98px) {
	.cpchat-floating .cpchat-panel {
		right: .5rem;
		left: .5rem;
		width: auto;
		bottom: 4.5rem;
		max-height: calc(100vh - 7rem);
	}

	.cpchat-msg { max-width: 92%; }
	.cpchat-log { padding: .75rem; }
	.cpchat-chip { font-size: .78rem; }
}

/* Very short screens, such as a phone in landscape */
@media (max-height: 520px) {
	.cpchat-floating .cpchat-panel {
		max-height: calc(100vh - 5rem);
	}

	.cpchat-log { min-height: 120px; }
}

/* Answers can contain links and long words */
.cpchat-msg {
	overflow-wrap: anywhere;
}

.cpchat-inline .cpchat-panel {
	height: min(480px, 70vh);
}

/* The launcher icon is inline SVG, not an icon font.
   The widget loads on every page including ones that carry no icon
   font at all, where a font-based glyph rendered as an empty circle. */
.cpchat-icon,
.cpchat-launcher svg,
.cpchat-send svg {
	flex: 0 0 auto;
	vertical-align: -.125em;
}

.cpchat-launcher svg { margin-right: .35rem; }

.cpchat-launcher:only-child svg,
.cpchat-launcher svg:only-child { margin-right: 0; }
