/**
 * vChat front-end styles.
 * Themeable via CSS custom properties set on the .vchat root (see widget.php).
 *
 * @package Vero\VChat
 */

.vchat {
	--vchat-font: inherit;
	--vchat-font-size: 15px;
	--vchat-msg-size: 15px;
	--vchat-title-size: 15px;
	--vchat-title-weight: 700;
	--vchat-primary: #2b6cb0;
	--vchat-launcher-bg: #2b6cb0;
	--vchat-launcher-color: #ffffff;
	--vchat-close-color: #ffffff;
	--vchat-header-bg: var(--vchat-primary);
	--vchat-header-text: #fff;
	--vchat-bot-bg: #f1f5f9;
	--vchat-bot-text: #0f172a;
	--vchat-user-bg: var(--vchat-primary);
	--vchat-user-text: #fff;
	--vchat-radius: 16px;
	--vchat-width: 380px;
	--vchat-max-height: 560px;
	--vchat-launcher-size: 60px;
	--vchat-offset-x: 20px;
	--vchat-offset-y: 20px;
	--vchat-offset-x-m: 12px;
	--vchat-offset-y-m: 12px;
	--vchat-z: 999999;

	--vchat-surface: #ffffff;
	--vchat-surface-2: #f8fafc;
	--vchat-text: #0f172a;
	--vchat-muted: #64748b;
	--vchat-border: #e2e8f0;
	--vchat-shadow: 0 20px 48px -12px rgba(15, 23, 42, 0.28), 0 8px 20px -8px rgba(15, 23, 42, 0.16);

	position: fixed;
	z-index: var(--vchat-z);
	font-family: var(--vchat-font);
	font-size: var(--vchat-font-size);
	line-height: 1.5;
	color: var(--vchat-text);
}

.vchat *,
.vchat *::before,
.vchat *::after {
	box-sizing: border-box;
}

/* Guarantee [hidden] wins over any theme rule that sets display on divs/buttons. */
.vchat[hidden],
.vchat [hidden] {
	display: none !important;
}

/* Defensive reset — themes love to style bare <button>/<input>. Keep our
   controls looking like ours regardless of the active theme. */
.vchat button,
.vchat input,
.vchat textarea {
	margin: 0;
	font-family: inherit;
	text-transform: none;
	letter-spacing: normal;
	text-shadow: none;
	min-height: 0;
	line-height: 1.4;
	width: auto;
}
.vchat button {
	box-shadow: none;
	text-decoration: none;
}

.vchat[data-vchat-resolved-theme="dark"] {
	--vchat-surface: #0f172a;
	--vchat-surface-2: #1e293b;
	--vchat-text: #e2e8f0;
	--vchat-muted: #94a3b8;
	--vchat-border: #334155;
	--vchat-bot-bg: #1e293b;
	--vchat-bot-text: #e2e8f0;
	--vchat-shadow: 0 20px 48px -12px rgba(0, 0, 0, 0.6), 0 8px 20px -8px rgba(0, 0, 0, 0.4);
}

/* ---------- Positioning ---------- */
.vchat--pos-bottom-right { right: var(--vchat-offset-x); bottom: var(--vchat-offset-y); }
.vchat--pos-bottom-left  { left: var(--vchat-offset-x);  bottom: var(--vchat-offset-y); }
.vchat--pos-top-right    { right: var(--vchat-offset-x); top: var(--vchat-offset-y); }
.vchat--pos-top-left     { left: var(--vchat-offset-x);  top: var(--vchat-offset-y); }

.vchat--inline {
	position: relative;
	inset: auto;
	z-index: auto;
	display: block;
	width: 100%;
	max-width: var(--vchat-width);
	margin: 0 auto;
}

/* ---------- Launcher ---------- */
.vchat__launcher {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0;
	width: var(--vchat-launcher-size);
	height: var(--vchat-launcher-size);
	min-width: var(--vchat-launcher-size);
	padding: 0 !important;
	border: 0 !important;
	border-radius: 999px !important;
	background: var(--vchat-launcher-bg) !important;
	color: var(--vchat-launcher-color) !important;
	cursor: pointer;
	box-shadow: var(--vchat-shadow);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.vchat__launcher:hover { transform: translateY(-2px); }
.vchat__launcher:focus-visible { outline: 3px solid var(--vchat-launcher-color); outline-offset: 3px; }
.vchat__launcher .vchat-icon { color: var(--vchat-launcher-color); }
.vchat__launcher .vchat-icon,
.vchat__launcher .vchat-icon-img { width: calc(var(--vchat-launcher-size) * 0.42); height: calc(var(--vchat-launcher-size) * 0.42); display: block; }
.vchat__launcher-icon { display: inline-flex; }
.vchat__launcher-icon--close { display: none; }
.vchat__launcher-label { font-weight: 600; white-space: nowrap; margin-inline: 8px 16px; }
/* Grow to a pill only when a label is present. */
.vchat__launcher--labeled { width: auto; padding: 0 4px 0 0 !important; }

/* Only one close affordance: the launcher becomes the chat icon when closed and
   is hidden while the panel is open — the header × closes the panel. */
.vchat.is-open .vchat__launcher { display: none !important; }
.vchat.is-open .vchat__panel { margin-top: 0; margin-bottom: 0; }

.vchat__badge {
	position: absolute;
	top: -4px;
	inset-inline-end: -4px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 10px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* ---------- Teaser ---------- */
.vchat__teaser {
	position: absolute;
	bottom: calc(var(--vchat-launcher-size) + 14px);
	inset-inline-end: 0;
	max-width: 260px;
	padding: 12px 32px 12px 14px;
	background: var(--vchat-surface);
	color: var(--vchat-text);
	border: 1px solid var(--vchat-border);
	border-radius: 14px;
	box-shadow: var(--vchat-shadow);
	animation: vchat-pop 0.25s ease;
}
.vchat--pos-bottom-left .vchat__teaser,
.vchat--pos-top-left .vchat__teaser { inset-inline-start: 0; inset-inline-end: auto; }
.vchat__teaser-dismiss {
	position: absolute;
	top: 4px;
	inset-inline-end: 6px;
	border: 0;
	background: none;
	font-size: 18px;
	line-height: 1;
	color: var(--vchat-muted);
	cursor: pointer;
}

/* ---------- Panel ---------- */
.vchat__panel {
	display: flex;
	flex-direction: column;
	width: var(--vchat-width);
	max-width: calc(100vw - 24px);
	height: var(--vchat-max-height);
	max-height: calc(100vh - var(--vchat-offset-y) - var(--vchat-launcher-size) - 32px);
	margin-top: 14px;
	background: var(--vchat-surface);
	border: 1px solid var(--vchat-border);
	border-radius: var(--vchat-radius);
	box-shadow: var(--vchat-shadow);
	overflow: hidden;
	transform-origin: bottom right;
	animation: vchat-panel-in 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}
.vchat--inline .vchat__panel {
	height: var(--vchat-max-height);
	margin: 0;
	animation: none;
}
.vchat--top-left .vchat__panel,
.vchat--pos-top-left .vchat__panel,
.vchat--pos-top-right .vchat__panel { margin-top: 0; margin-bottom: 14px; }

/* Popup mode: centered modal with backdrop */
.vchat--popup.is-open {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(15, 23, 42, 0.5);
	padding: 16px;
}
.vchat--popup .vchat__launcher { position: fixed; right: var(--vchat-offset-x); bottom: var(--vchat-offset-y); }
.vchat--popup.is-open .vchat__launcher { display: none; }
.vchat--popup .vchat__panel { margin: 0; }

.vchat__header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: var(--vchat-header-bg);
	color: var(--vchat-header-text);
}
.vchat__avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	object-fit: cover;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.vchat__avatar--placeholder .vchat-icon { width: 22px; height: 22px; }
.vchat__titles { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.vchat__title { font-weight: var(--vchat-title-weight); font-size: var(--vchat-title-size); }
.vchat__subtitle { font-size: 12px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vchat__close {
	margin-inline-start: auto;
	border: 0 !important;
	background: rgba(255, 255, 255, 0.15) !important;
	color: var(--vchat-close-color) !important;
	width: 30px !important;
	height: 30px !important;
	min-width: 0 !important;
	padding: 0 !important;
	border-radius: 8px !important;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: none;
}
.vchat__close:hover { background: rgba(255, 255, 255, 0.28) !important; }
.vchat__close svg { width: 20px; height: 20px; }

/* ---------- Stream ---------- */
.vchat__stream {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: var(--vchat-surface-2);
	scroll-behavior: smooth;
}
.vchat__msg { display: flex; }
.vchat__msg--user { justify-content: flex-end; }
.vchat__bubble {
	max-width: 78%;
	padding: 10px 13px;
	border-radius: 14px;
	background: var(--vchat-bot-bg);
	color: var(--vchat-bot-text);
	font-size: var(--vchat-msg-size);
	word-wrap: break-word;
	animation: vchat-msg-in 0.2s ease;
}
.vchat__bubble a { color: var(--vchat-primary); }
.vchat__msg--bot .vchat__bubble { border-bottom-left-radius: 4px; }
.vchat__msg--user .vchat__bubble {
	background: var(--vchat-user-bg);
	color: var(--vchat-user-text);
	border-bottom-right-radius: 4px;
}
.vchat__bubble img { border-radius: 8px; margin: 4px 0; }
.vchat__bubble p { margin: 0 0 8px; }
.vchat__bubble p:last-child { margin-bottom: 0; }

/* Typing indicator */
.vchat__typing .vchat__bubble { display: inline-flex; gap: 4px; padding: 12px 14px; }
.vchat__typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--vchat-muted);
	animation: vchat-blink 1.2s infinite ease-in-out;
}
.vchat__typing span:nth-child(2) { animation-delay: 0.2s; }
.vchat__typing span:nth-child(3) { animation-delay: 0.4s; }

/* ---------- Choices / consent / rating ---------- */
.vchat__choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.vchat__choices--stacked { flex-direction: column; align-items: stretch; }
.vchat__choices--dropdown { flex-direction: column; align-items: stretch; gap: 8px; }
.vchat__dropdown {
	width: 100% !important;
	padding: 10px 12px !important;
	border: 1px solid var(--vchat-border) !important;
	border-radius: 10px !important;
	background: var(--vchat-surface) !important;
	color: var(--vchat-text) !important;
	font: inherit;
	font-size: var(--vchat-msg-size);
}
.vchat__dropdown:focus { outline: none; border-color: var(--vchat-primary) !important; box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.25) !important; }
.vchat__dropdown-go { align-self: flex-start; }
.vchat__choice {
	border: 1px solid var(--vchat-primary) !important;
	background: transparent !important;
	color: var(--vchat-primary) !important;
	padding: 9px 16px !important;
	border-radius: 999px !important;
	cursor: pointer;
	font: inherit;
	font-weight: 600;
	white-space: normal;
	transition: background 0.15s ease, color 0.15s ease;
}
.vchat__choice:hover { background: var(--vchat-primary) !important; color: #fff !important; }
.vchat__choice:focus-visible { outline: 3px solid var(--vchat-primary); outline-offset: 2px; }

.vchat__consent { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.vchat__consent label { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--vchat-muted); }
.vchat__consent label.is-invalid span { color: #ef4444; }
.vchat__consent-continue { align-self: flex-start; }

.vchat__rating { display: flex; gap: 6px; margin-top: 6px; }
.vchat__rating-btn {
	border: 1px solid var(--vchat-border);
	background: var(--vchat-surface);
	color: #f59e0b;
	width: 40px;
	height: 40px;
	border-radius: 10px;
	font-size: 18px;
	cursor: pointer;
}
.vchat__rating-btn:hover { background: var(--vchat-surface-2); }

.vchat__file, .vchat__handoff { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.vchat__handoff-btn { text-decoration: none; }

/* ---------- Input bar ---------- */
.vchat__inputbar {
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--vchat-border);
	background: var(--vchat-surface);
	padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.vchat__field-wrap { flex: 1; }
.vchat__input {
	width: 100% !important;
	padding: 10px 12px !important;
	border: 1px solid var(--vchat-border) !important;
	border-radius: 10px !important;
	font: inherit;
	background: var(--vchat-surface) !important;
	color: var(--vchat-text) !important;
}
.vchat__input:focus { outline: none; border-color: var(--vchat-primary) !important; box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.25) !important; }
.vchat__input.is-invalid { border-color: #ef4444 !important; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18) !important; }
.vchat__hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.vchat__send {
	border: 0 !important;
	background: var(--vchat-primary) !important;
	color: #fff !important;
	padding: 0 18px !important;
	min-height: 40px;
	border-radius: 10px !important;
	font: inherit;
	font-weight: 600;
	text-transform: none !important;
	cursor: pointer;
	flex: none;
}
.vchat__send:hover { filter: brightness(1.05); }
.vchat.is-busy .vchat__send { opacity: 0.6; pointer-events: none; }

.vchat__footer {
	padding: 8px 14px;
	font-size: 11px;
	color: var(--vchat-muted);
	text-align: center;
	background: var(--vchat-surface);
	border-top: 1px solid var(--vchat-border);
}

.vchat__restart {
	margin-top: 12px;
	align-self: flex-start;
	display: inline-flex;
	align-items: center;
	gap: 7px;
	border: 0 !important;
	background: var(--vchat-primary) !important;
	color: #fff !important;
	padding: 9px 18px !important;
	border-radius: 999px !important;
	font: inherit;
	font-weight: 600;
	text-transform: none !important;
	cursor: pointer;
	box-shadow: 0 4px 12px -4px rgba(43, 108, 176, 0.5);
	transition: filter 0.15s ease;
}
.vchat__restart:hover { filter: brightness(1.06); }
.vchat__restart svg { width: 15px; height: 15px; flex: none; }

.vchat__choice.is-chosen {
	background: var(--vchat-primary) !important;
	color: #fff !important;
}

.vchat__back-row { display: flex; margin-top: 2px; }
.vchat__back {
	border: 0 !important;
	background: transparent !important;
	color: var(--vchat-muted) !important;
	padding: 4px 6px !important;
	font: inherit;
	font-size: 12px;
	cursor: pointer;
}
.vchat__back:hover { color: var(--vchat-primary) !important; text-decoration: underline; }
.vchat__back span { font-size: 15px; line-height: 1; }

.vchat__skip-row { display: flex; justify-content: flex-end; margin-top: 2px; }
.vchat__skip {
	border: 0 !important;
	background: transparent !important;
	color: var(--vchat-muted) !important;
	padding: 4px 8px !important;
	font: inherit;
	font-size: 12px;
	text-decoration: underline;
	cursor: pointer;
}
.vchat__skip:hover { color: var(--vchat-primary) !important; }

.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;
}

/* ---------- RTL ---------- */
.vchat--rtl { direction: rtl; }
.vchat--rtl .vchat__msg--user { justify-content: flex-start; }
.vchat--rtl .vchat__msg--bot { justify-content: flex-end; }
.vchat--rtl .vchat__panel { transform-origin: bottom left; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
	.vchat:not(.vchat--inline) {
		right: var(--vchat-offset-x-m) !important;
		left: var(--vchat-offset-x-m) !important;
		bottom: var(--vchat-offset-y-m) !important;
	}
	.vchat__panel {
		width: 100%;
		max-width: none;
		height: 72vh;
		max-height: calc(100vh - 90px);
	}
	.vchat--popup.is-open .vchat__panel { height: 88vh; }
	.vchat__launcher-label { display: none; }
}

/* ---------- Motion ---------- */
@keyframes vchat-panel-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes vchat-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes vchat-pop { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes vchat-blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
	.vchat, .vchat * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
