/**
 * One Chatbot - floating bubble styles.
 * Scoped under #one-chatbot-root so themes cannot bleed in easily.
 * Layout uses logical properties throughout, so the RTL mirror is automatic.
 */

#one-chatbot-root {
	--one-accent: #6b5bd6;
	--one-accent-ink: #ffffff;

	/* Soft lavender wash used by the header, launcher ring and send button. */
	--one-tint: #efedfc;
	--one-tint-strong: #c6c0f2;

	--one-surface: #ffffff;
	--one-canvas: #fbfaff;
	--one-ink: #1f2333;
	--one-ink-soft: #7a8090;
	--one-line: #ebe9f6;
	--one-online: #22c55e;

	--one-radius: 26px;
	--one-shadow: 0 18px 50px rgba(48, 40, 105, 0.16), 0 2px 8px rgba(48, 40, 105, 0.06);

	/*
	 * The widget is light in every context. This also stops a browser in dark
	 * mode applying its own dark UA styling to the textarea and scrollbars.
	 */
	color-scheme: light;

	position: fixed;
	bottom: 22px;
	z-index: 999999;
	font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.6;
	color: var(--one-ink);
}

#one-chatbot-root[data-position="right"] { right: 22px; }
#one-chatbot-root[data-position="left"] { left: 22px; }

#one-chatbot-root *,
#one-chatbot-root *::before,
#one-chatbot-root *::after {
	box-sizing: border-box;
}

/* ------------------------------------------------------------- launcher */

.one-launcher {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--one-surface);
	color: #3a3d4d;
	box-shadow: var(--one-shadow);
	cursor: pointer;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

/*
 * Physical, not logical. The root is dir="rtl" in Arabic, which would flip
 * margin-inline-start and park the launcher against the left edge of the panel
 * instead of under its right corner.
 */
#one-chatbot-root[data-position="right"] .one-launcher { margin-left: auto; }
#one-chatbot-root[data-position="left"] .one-launcher { margin-right: auto; }

.one-launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 22px 56px rgba(48, 40, 105, 0.24);
}

.one-launcher:focus-visible {
	outline: 3px solid var(--one-accent);
	outline-offset: 3px;
}

/* ---------------------------------------------------------------- panel */

.one-panel {
	display: flex;
	flex-direction: column;
	width: 412px;
	max-width: calc(100vw - 32px);
	height: 640px;
	max-height: calc(100vh - 130px);
	margin-bottom: 16px;
	overflow: hidden;
	background: var(--one-surface);
	border: 1px solid var(--one-line);
	border-radius: var(--one-radius);
	box-shadow: var(--one-shadow);
	animation: one-pop 0.2s ease-out;
}

.one-panel[hidden] { display: none; }

@keyframes one-pop {
	from { opacity: 0; transform: translateY(12px) scale(0.97); }
	to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.one-panel { animation: none; }
	.one-launcher { transition: none; }
	.one-bars i { animation: none !important; }
}

/* --------------------------------------------------------------- header */

.one-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 20px;
	background: linear-gradient(160deg, var(--one-tint) 0%, #f7f6fe 55%, var(--one-surface) 100%);
	border-bottom: 1px solid transparent;

	/*
	 * Fixed LTR layout regardless of language: the mark sits in the top-left
	 * corner and the close button in the top-right, directly above the
	 * launcher. Only the title text itself flips, via dir on .one-titles.
	 */
	direction: ltr;
}

.one-brand {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.one-titles {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	min-width: 0;
}

.one-title {
	font-weight: 700;
	font-size: 17px;
	line-height: 1.3;
	color: var(--one-ink);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.one-subtitle {
	display: flex;
	align-items: center;
	gap: 7px;
	font-size: 13px;
	color: var(--one-ink-soft);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Equaliser bars in the status line. */

.one-bars {
	display: inline-flex;
	align-items: flex-end;
	gap: 2px;
	height: 13px;
	flex-shrink: 0;
}

.one-bars i {
	width: 3px;
	height: 5px;
	border-radius: 2px;
	background: var(--one-online);
	animation: one-eq 1s ease-in-out infinite;
}

.one-bars i:nth-child(2) { animation-delay: 0.18s; }
.one-bars i:nth-child(3) { animation-delay: 0.36s; }

@keyframes one-eq {
	0%, 100% { height: 4px; opacity: 0.6; }
	50% { height: 13px; opacity: 1; }
}

/* Avatar with presence dot. */

.one-avatar {
	position: relative;
	flex-shrink: 0;
	line-height: 0;
	border-radius: 50%;
}

.one-logo {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	object-fit: cover;
}

.one-avatar-lg {
	width: 46px;
	height: 46px;
	filter: drop-shadow(0 3px 8px rgba(48, 40, 105, 0.18));
}

.one-avatar-sm {
	width: 34px;
	height: 34px;
}

/* The mark carries its own white field, so it needs none from the button. */
.one-launcher .one-logo {
	width: 52px;
	height: 52px;
}

.one-presence {
	position: absolute;
	inset-block-end: 1px;
	inset-inline-end: 1px;
	width: 11px;
	height: 11px;
	border: 2px solid var(--one-surface);
	border-radius: 50%;
	background: var(--one-online);
}

.one-header-actions {
	display: flex;
	gap: 4px;
	flex-shrink: 0;
}

.one-icon-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #5a5f70;
	cursor: pointer;
	transition: background 0.15s ease;
}

.one-icon-btn:hover { background: rgba(107, 91, 214, 0.1); }

.one-icon-btn:focus-visible {
	outline: 2px solid var(--one-accent);
	outline-offset: 1px;
}

/* ------------------------------------------------------------------ log */

.one-log {
	flex: 1;
	padding: 18px 18px 10px;

	/*
	 * Message rows stay LTR in both languages: the assistant keeps the left
	 * side with its avatar, the visitor keeps the right, the way Arabic chat
	 * apps do it. Text direction is set per bubble instead, so a mixed
	 * Arabic/English conversation still reads correctly.
	 */
	direction: ltr;

	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--one-canvas);
	scrollbar-width: thin;
	scrollbar-color: #dcd8ee transparent;
}

.one-log::-webkit-scrollbar { width: 7px; }
.one-log::-webkit-scrollbar-thumb { background: #dcd8ee; border-radius: 4px; }

.one-row {
	display: flex;
	align-items: flex-end;
	gap: 9px;
	margin-bottom: 14px;
}

.one-row-user { justify-content: flex-end; }

.one-bubble {
	max-width: 82%;
	padding: 12px 16px;
	border-radius: 20px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

/*
 * Tail corners are physical, not logical: rows are always LTR (see .one-log),
 * so the tail must not follow the bubble's own text direction.
 */
.one-bubble-user {
	background: var(--one-accent);
	color: var(--one-accent-ink);
	border-bottom-right-radius: 6px;
}

.one-bubble-bot {
	background: var(--one-surface);
	border: 1px solid var(--one-line);
	border-bottom-left-radius: 6px;
	box-shadow: 0 2px 10px rgba(48, 40, 105, 0.05);
}

.one-bubble-error {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	background: #fdf2f2;
	border: 1px solid #f3cccc;
	color: #8a1f1f;
}

.one-retry {
	padding: 4px 12px;
	border: 1px solid #dd9c9c;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 13px;
	cursor: pointer;
}

.one-bubble[dir="rtl"] { text-align: right; }
.one-bubble[dir="ltr"] { text-align: left; }

/* Markdown inside assistant bubbles. */

.one-bubble-bot > *:first-child { margin-top: 0; }
.one-bubble-bot > *:last-child { margin-bottom: 0; }

.one-bubble-bot p { margin: 0 0 10px; }

.one-bubble-bot h3,
.one-bubble-bot h4,
.one-bubble-bot h5,
.one-bubble-bot h6 {
	margin: 15px 0 7px;
	font-weight: 700;
	line-height: 1.4;
	color: var(--one-ink);
}

/* Headings must stay at or above the 15px body size to read as headings. */
.one-bubble-bot h3 { font-size: 17px; }
.one-bubble-bot h4 { font-size: 16px; }
.one-bubble-bot h5 { font-size: 15px; }
.one-bubble-bot h6 { font-size: 15px; color: var(--one-ink-soft); }

.one-bubble-bot ul,
.one-bubble-bot ol {
	margin: 0 0 10px;
	padding-inline-start: 22px;
}

.one-bubble-bot li { margin-bottom: 5px; }

.one-bubble-bot hr {
	margin: 14px 0;
	border: 0;
	border-top: 1px solid var(--one-line);
}

.one-bubble-bot blockquote {
	margin: 12px 0;
	padding: 10px 14px;
	border-inline-start: 3px solid var(--one-accent);
	background: var(--one-tint);
	border-radius: 0 10px 10px 0;
	color: #4d5163;
}

#one-chatbot-root[dir="rtl"] .one-bubble-bot blockquote { border-radius: 10px 0 0 10px; }

.one-bubble-bot blockquote p:last-child { margin-bottom: 0; }

.one-bubble-bot code {
	padding: 1px 6px;
	border-radius: 6px;
	background: rgba(107, 91, 214, 0.1);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.9em;
}

.one-bubble-bot pre {
	margin: 12px 0;
	padding: 12px 14px;
	overflow-x: auto;
	background: #22243a;
	color: #e8ecf5;
	border-radius: 12px;
}

.one-bubble-bot pre code {
	padding: 0;
	background: none;
	color: inherit;
}

.one-bubble-bot a {
	color: var(--one-accent);
	text-decoration: underline;
}

/* Typing indicator. */

.one-typing {
	display: flex;
	gap: 5px;
	padding: 15px 16px;
}

.one-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--one-accent);
	opacity: 0.4;
	animation: one-blink 1.3s infinite ease-in-out;
}

.one-typing span:nth-child(2) { animation-delay: 0.18s; }
.one-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes one-blink {
	0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
	30% { opacity: 0.95; transform: translateY(-4px); }
}

/* ------------------------------------------------------------- composer */

.one-composer {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px 18px;
	background: var(--one-surface);
}

.one-input {
	flex: 1;
	max-height: 120px;
	min-height: 52px;
	padding: 14px 20px;
	border: 1px solid var(--one-line);
	border-radius: 26px;
	background: var(--one-surface);
	color: var(--one-ink);
	font: inherit;
	line-height: 1.5;
	resize: none;
	box-shadow: 0 2px 10px rgba(48, 40, 105, 0.05);
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.one-input::placeholder { color: #a7abbb; }

.one-input:focus {
	outline: none;
	border-color: var(--one-tint-strong);
	box-shadow: 0 0 0 4px rgba(107, 91, 214, 0.12);
}

.one-input:disabled { opacity: 0.6; }

.one-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	flex-shrink: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--one-tint-strong);
	background: linear-gradient(145deg, var(--one-tint-strong), color-mix(in srgb, var(--one-accent) 55%, #ffffff));
	color: var(--one-accent-ink);
	cursor: pointer;
	box-shadow: 0 4px 14px rgba(107, 91, 214, 0.28);
	transition: transform 0.15s ease, filter 0.15s ease;
}

.one-send:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.04); }

.one-send:disabled {
	opacity: 0.5;
	cursor: default;
	box-shadow: none;
}

.one-send:focus-visible {
	outline: 3px solid var(--one-accent);
	outline-offset: 2px;
}

/*
 * The plane tilts upward and points along the reading direction. The mirror is
 * applied after the rotation, so RTL reads as up-and-left.
 */
.one-send svg { transform: rotate(-18deg); }
#one-chatbot-root[dir="rtl"] .one-send svg { transform: scaleX(-1) rotate(-18deg); }

/* Screen-reader-only labels (themes may not define this class). */

#one-chatbot-root .screen-reader-text {
	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;
}

/* ---------------------------------------------------------------- small */

@media (max-width: 480px) {
	#one-chatbot-root { bottom: 14px; }

	#one-chatbot-root[data-position="right"] { right: 14px; }
	#one-chatbot-root[data-position="left"] { left: 14px; }

	#one-chatbot-root.is-open { inset: 0; bottom: 0; }

	#one-chatbot-root.is-open .one-panel {
		width: 100vw;
		max-width: 100vw;
		height: 100dvh;
		max-height: 100dvh;
		margin: 0;
		border: 0;
		border-radius: 0;
	}

	#one-chatbot-root.is-open .one-launcher { display: none; }
}
