/**
 * Dental AI Assistant — chat widget.
 *
 * Mobile-first. Everything is scoped under .dai-root and uses explicit values so
 * an opinionated theme cannot bleed into the widget.
 */

.dai-root {
	--dai-teal: #00796b;
	--dai-teal-dark: #00695c;
	--dai-teal-soft: #e0f2f1;
	--dai-navy: #1a237e;
	--dai-navy-soft: #3949ab;
	--dai-surface: #ffffff;
	--dai-clinical: #f5f7f8;
	--dai-border: #e1e6e9;
	--dai-muted: #5f6f77;
	--dai-online: #2e9e5b;
	--dai-radius: 20px;
	--dai-radius-bubble: 16px;
	--dai-font: "Inter", "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

	position: fixed;
	z-index: 99999;
	inset: auto 0 0 auto;
	font-family: var(--dai-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--dai-navy);
	-webkit-font-smoothing: antialiased;
}

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

/* :where() keeps the reset at zero added specificity so the component rules
   below — .dai-chip, .dai-send and friends — still win. */
.dai-root :where(button) {
	font-family: inherit;
	cursor: pointer;
	border: 0;
	background: none;
	padding: 0;
	color: inherit;
}

.dai-root :where(svg) {
	display: block;
	width: 100%;
	height: 100%;
}

.dai-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

/* ---------------------------------------------------------------- Launcher */

/*
 * Mobile is the base case: a round icon button, nothing else. A pill with the
 * assistant's name in it eats a strip of a phone screen for a label nobody
 * needs to read twice — the chat bubble says what it is.
 */
.dai-launcher {
	position: fixed;
	right: 16px;
	bottom: 16px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0;
	width: 56px;
	height: 56px;
	padding: 0;
	border-radius: 50%;
	background: var(--dai-teal);
	color: #fff;
	font-size: 15px;
	font-weight: 600;
	letter-spacing: 0.01em;
	box-shadow: 0 4px 16px rgba(26, 35, 126, 0.18);
	transition: background-color 0.18s ease, transform 0.18s ease;
}

.dai-launcher:hover {
	background: var(--dai-teal-dark);
}

.dai-launcher:active {
	transform: scale(0.97);
}

.dai-launcher:focus-visible {
	outline: 3px solid var(--dai-navy);
	outline-offset: 2px;
}

.dai-launcher-icon {
	width: 24px;
	height: 24px;
	flex: none;
}

/*
 * On a phone the button is the assistant's face, with the chat bubble reduced
 * to a badge on the rim — a bare portrait does not read as "tap me to talk",
 * and a bare bubble is plainer than it needs to be.
 */
.dai-launcher-avatar {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	overflow: hidden;
	background: var(--dai-teal-soft);
}

.dai-launcher-avatar .dai-avatar-img {
	width: 100%;
	height: 100%;
}

.dai-launcher-icon {
	position: absolute;
	right: -1px;
	bottom: -1px;
	box-sizing: border-box;
	width: 22px;
	height: 22px;
	padding: 4px;
	border-radius: 50%;
	background: var(--dai-teal);
	box-shadow: 0 0 0 2px #fff;
}

/*
 * Hidden rather than removed: the icon is aria-hidden, so this span is the
 * button's accessible name.
 */
.dai-launcher-label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

.dai-root.is-open .dai-launcher {
	opacity: 0;
	pointer-events: none;
	transform: scale(0.8);
}

/* ------------------------------------------------------------------- Panel */

.dai-panel {
	position: fixed;
	right: 12px;
	bottom: 12px;
	left: 12px;
	display: flex;
	flex-direction: column;
	max-height: calc(100dvh - 24px);
	height: 82dvh;
	overflow: hidden;
	background: var(--dai-surface);
	border: 1px solid var(--dai-border);
	border-radius: var(--dai-radius);
	box-shadow: 0 8px 32px rgba(26, 35, 126, 0.14);
}

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

.dai-root.is-open .dai-panel {
	animation: dai-rise 0.22s ease-out;
}

@keyframes dai-rise {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
}

/* ------------------------------------------------------------------ Header */

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

.dai-avatar {
	width: 44px;
	height: 44px;
	flex: none;
	border-radius: 50%;
	overflow: hidden;
	background: var(--dai-teal-soft);
}

.dai-avatar-img {
	width: 44px;
	height: 44px;
	object-fit: cover;
	border-radius: 50%;
}

.dai-identity {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1;
}

.dai-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--dai-navy);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.dai-status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	color: var(--dai-muted);
}

.dai-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--dai-online);
	flex: none;
}

.dai-root.is-busy .dai-dot {
	animation: dai-pulse 1.2s ease-in-out infinite;
}

@keyframes dai-pulse {
	50% {
		opacity: 0.35;
	}
}

.dai-close {
	width: 36px;
	height: 36px;
	flex: none;
	padding: 7px;
	border-radius: 50%;
	color: var(--dai-muted);
	transition: background-color 0.15s ease, color 0.15s ease;
}

.dai-close:hover {
	background: var(--dai-clinical);
	color: var(--dai-navy);
}

.dai-close:focus-visible {
	outline: 2px solid var(--dai-teal);
	outline-offset: 1px;
}

/* --------------------------------------------------------------- Chat flow */

.dai-log {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 18px 16px 8px;
	background: var(--dai-clinical);
	scrollbar-width: thin;
}

.dai-langs {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 18px;
}

.dai-chip {
	padding: 7px 14px;
	border: 1px solid var(--dai-border);
	border-radius: 999px;
	background: var(--dai-surface);
	font-size: 13px;
	font-weight: 500;
	color: var(--dai-muted);
	transition: all 0.15s ease;
}

.dai-chip:hover {
	border-color: var(--dai-teal);
	color: var(--dai-teal);
}

.dai-chip.is-active {
	background: var(--dai-teal);
	border-color: var(--dai-teal);
	color: #fff;
}

.dai-chip:focus-visible {
	outline: 2px solid var(--dai-navy);
	outline-offset: 2px;
}

.dai-messages {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.dai-msg {
	max-width: 84%;
	padding: 11px 15px;
	border-radius: var(--dai-radius-bubble);
	font-size: 15px;
	color: var(--dai-navy);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.dai-msg-assistant {
	align-self: flex-start;
	background: var(--dai-teal-soft);
	border-bottom-left-radius: 6px;
}

.dai-msg-user {
	align-self: flex-end;
	background: var(--dai-surface);
	border: 1px solid var(--dai-border);
	border-bottom-right-radius: 6px;
}

.dai-msg-error {
	align-self: flex-start;
	background: #fdecec;
	border: 1px solid #f5c6c6;
	color: #8c1d18;
	border-bottom-left-radius: 6px;
}

.dai-msg a {
	color: var(--dai-teal-dark);
	text-decoration: underline;
}

/* Typing indicator */

.dai-typing {
	align-self: flex-start;
	display: flex;
	gap: 5px;
	padding: 15px;
	border-radius: var(--dai-radius-bubble);
	border-bottom-left-radius: 6px;
	background: var(--dai-teal-soft);
}

.dai-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--dai-teal);
	animation: dai-bounce 1.1s ease-in-out infinite;
}

.dai-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.dai-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes dai-bounce {
	0%,
	60%,
	100% {
		opacity: 0.35;
		transform: translateY(0);
	}
	30% {
		opacity: 1;
		transform: translateY(-4px);
	}
}

/* --------------------------------------------------------------- Composer */

.dai-composer {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	flex: none;
	padding: 12px 14px 6px;
	background: var(--dai-surface);
	border-top: 1px solid var(--dai-border);
}

.dai-field {
	position: relative;
	flex: 1;
	display: flex;
	align-items: flex-end;
	border: 1px solid var(--dai-border);
	border-radius: 24px;
	background: var(--dai-clinical);
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dai-field:focus-within {
	border-color: var(--dai-teal);
	background: var(--dai-surface);
}

.dai-input {
	flex: 1;
	max-height: 120px;
	padding: 12px 6px 12px 18px;
	border: 0;
	background: none;
	resize: none;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.4;
	color: var(--dai-navy);
	outline: none;
}

.dai-input::placeholder {
	color: var(--dai-muted);
	opacity: 1;
}

.dai-mic {
	width: 40px;
	height: 44px;
	flex: none;
	padding: 11px 12px 11px 4px;
	color: var(--dai-muted);
	transition: color 0.15s ease;
}

.dai-mic:hover {
	color: var(--dai-teal);
}

.dai-mic.is-recording {
	color: #c62828;
	animation: dai-pulse 1s ease-in-out infinite;
}

.dai-mic:focus-visible,
.dai-send:focus-visible {
	outline: 2px solid var(--dai-navy);
	outline-offset: 2px;
}

.dai-send {
	width: 44px;
	height: 44px;
	flex: none;
	padding: 11px;
	border-radius: 50%;
	background: var(--dai-teal);
	color: #fff;
	transition: background-color 0.15s ease, opacity 0.15s ease;
}

.dai-send:hover:not(:disabled) {
	background: var(--dai-teal-dark);
}

.dai-send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.dai-disclaimer {
	flex: none;
	margin: 0;
	padding: 4px 18px 12px;
	background: var(--dai-surface);
	font-size: 11px;
	line-height: 1.4;
	color: var(--dai-muted);
	text-align: center;
}

/* ----------------------------------------------------------------- Desktop */

@media (min-width: 600px) {
	.dai-panel {
		right: 24px;
		bottom: 24px;
		left: auto;
		width: 396px;
		height: min(660px, calc(100dvh - 48px));
	}

	.dai-launcher {
		right: 24px;
		bottom: 24px;
		width: auto;
		gap: 10px;
		padding: 0 20px 0 16px;
		border-radius: 28px;
	}

	.dai-launcher-label {
		position: static;
		width: auto;
		height: auto;
		overflow: visible;
		clip: auto;
	}

	.dai-launcher-avatar {
		display: none;
	}

	.dai-launcher-icon {
		position: static;
		width: 24px;
		height: 24px;
		padding: 0;
		border-radius: 0;
		background: none;
		box-shadow: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dai-root * {
		animation: none !important;
		transition: none !important;
	}
}
