/**
 * AI Front Desk — Public interactive receptionist widget
 * Mobile-first, premium, accessible. Not a chatbot aesthetic.
 */

.aifd-root {
	--aifd-primary: #0f766e;
	--aifd-primary-hover: #0d9488;
	--aifd-accent: #14b8a6;
	--aifd-bg: #ffffff;
	--aifd-surface: #f8fafc;
	--aifd-surface-2: #f1f5f9;
	--aifd-text: #0f172a;
	--aifd-muted: #64748b;
	--aifd-border: #e2e8f0;
	--aifd-user-bg: #0f766e;
	--aifd-user-text: #ffffff;
	--aifd-assistant-bg: #f1f5f9;
	--aifd-assistant-text: #0f172a;
	--aifd-danger: #dc2626;
	--aifd-success: #059669;
	--aifd-radius: 16px;
	--aifd-radius-sm: 12px;
	--aifd-shadow: 0 8px 30px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.06);
	--aifd-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--aifd-z: 999999;
	font-family: var(--aifd-font);
	font-size: 15px;
	line-height: 1.45;
	color: var(--aifd-text);
	box-sizing: border-box;
	-webkit-font-smoothing: antialiased;
}

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

.aifd-root[data-theme="dark"] {
	--aifd-bg: #0b1220;
	--aifd-surface: #111827;
	--aifd-surface-2: #1f2937;
	--aifd-text: #f8fafc;
	--aifd-muted: #94a3b8;
	--aifd-border: #1f2937;
	--aifd-assistant-bg: #1f2937;
	--aifd-assistant-text: #f8fafc;
	--aifd-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

/* Launcher */
.aifd-launcher {
	position: fixed;
	z-index: var(--aifd-z);
	bottom: 20px;
	right: 20px;
	width: 60px;
	height: 60px;
	border: none;
	border-radius: 999px;
	background: var(--aifd-primary);
	color: #fff;
	box-shadow: var(--aifd-shadow);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.2s ease, background 0.2s ease;
	padding: 0;
}

.aifd-root[data-position="bottom-left"] .aifd-launcher,
.aifd-root[data-position="bottom-left"] .aifd-panel {
	right: auto;
	left: 20px;
}

.aifd-launcher:hover {
	background: var(--aifd-primary-hover);
	transform: scale(1.04);
}

.aifd-launcher:focus-visible {
	outline: 3px solid var(--aifd-accent);
	outline-offset: 3px;
}

.aifd-launcher svg {
	width: 26px;
	height: 26px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.aifd-launcher.is-open svg.aifd-icon-open {
	display: none;
}

.aifd-launcher:not(.is-open) svg.aifd-icon-close {
	display: none;
}

.aifd-launcher-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 999px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* Panel */
.aifd-panel {
	position: fixed;
	z-index: calc(var(--aifd-z) + 1);
	bottom: 92px;
	right: 20px;
	width: min(400px, calc(100vw - 24px));
	height: min(640px, calc(100vh - 120px));
	background: var(--aifd-bg);
	border-radius: var(--aifd-radius);
	box-shadow: var(--aifd-shadow);
	border: 1px solid var(--aifd-border);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	pointer-events: none;
	transform: translateY(12px) scale(0.98);
	transition: opacity 0.22s ease, transform 0.22s ease;
}

.aifd-root[data-size="small"] .aifd-panel {
	width: min(340px, calc(100vw - 24px));
	height: min(520px, calc(100vh - 120px));
}

.aifd-root[data-size="large"] .aifd-panel {
	width: min(440px, calc(100vw - 24px));
	height: min(720px, calc(100vh - 100px));
}

.aifd-panel.is-open {
	opacity: 1;
	pointer-events: auto;
	transform: translateY(0) scale(1);
}

.aifd-root[data-animation="fade"] .aifd-panel {
	transform: none;
}

.aifd-root[data-animation="scale"] .aifd-panel {
	transform: scale(0.9);
}

.aifd-root[data-animation="scale"] .aifd-panel.is-open {
	transform: scale(1);
}

/* Header */
.aifd-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--aifd-primary), var(--aifd-accent));
	color: #fff;
	flex-shrink: 0;
}

.aifd-avatar {
	width: 40px;
	height: 40px;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	flex-shrink: 0;
	font-weight: 700;
	font-size: 15px;
}

.aifd-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.aifd-header-meta {
	flex: 1;
	min-width: 0;
}

.aifd-header-name {
	font-weight: 700;
	font-size: 15px;
	margin: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aifd-header-sub {
	margin: 2px 0 0;
	font-size: 12px;
	opacity: 0.9;
	display: flex;
	align-items: center;
	gap: 6px;
}

.aifd-online-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #86efac;
	box-shadow: 0 0 0 2px rgba(134, 239, 172, 0.35);
}

.aifd-header-actions {
	display: flex;
	gap: 4px;
}

.aifd-icon-btn {
	width: 32px;
	height: 32px;
	border: none;
	background: rgba(255, 255, 255, 0.15);
	color: #fff;
	border-radius: 8px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.aifd-icon-btn:hover {
	background: rgba(255, 255, 255, 0.25);
}

.aifd-icon-btn svg {
	width: 16px;
	height: 16px;
	stroke: currentColor;
	fill: none;
	stroke-width: 2;
	stroke-linecap: round;
}

/* Progress */
.aifd-progress {
	height: 3px;
	background: var(--aifd-surface-2);
	flex-shrink: 0;
}

.aifd-progress-bar {
	height: 100%;
	width: 0%;
	background: var(--aifd-accent);
	transition: width 0.35s ease;
}

/* Messages */
.aifd-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: var(--aifd-surface);
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
}

.aifd-msg {
	display: flex;
	flex-direction: column;
	max-width: 92%;
	animation: aifd-msg-in 0.25s ease;
}

@keyframes aifd-msg-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.aifd-msg--user {
	align-self: flex-end;
	align-items: flex-end;
}

.aifd-msg--assistant {
	align-self: flex-start;
	align-items: flex-start;
}

.aifd-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.aifd-msg--user .aifd-bubble {
	background: var(--aifd-user-bg);
	color: var(--aifd-user-text);
	border-bottom-right-radius: 4px;
}

.aifd-msg--assistant .aifd-bubble {
	background: var(--aifd-bg);
	color: var(--aifd-assistant-text);
	border: 1px solid var(--aifd-border);
	border-bottom-left-radius: 4px;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.aifd-bubble p {
	margin: 0 0 0.5em;
}

.aifd-bubble p:last-child {
	margin-bottom: 0;
}

.aifd-bubble strong {
	font-weight: 650;
}

.aifd-bubble code {
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 0.9em;
	background: var(--aifd-surface-2);
	padding: 1px 5px;
	border-radius: 4px;
}

.aifd-bubble ul,
.aifd-bubble ol {
	margin: 0.4em 0;
	padding-left: 1.2em;
}

.aifd-msg-time {
	font-size: 11px;
	color: var(--aifd-muted);
	margin-top: 4px;
	padding: 0 4px;
}

.aifd-msg-actions {
	display: flex;
	gap: 4px;
	margin-top: 4px;
	opacity: 0;
	transition: opacity 0.15s;
}

.aifd-msg:hover .aifd-msg-actions {
	opacity: 1;
}

.aifd-react-btn {
	border: none;
	background: transparent;
	cursor: pointer;
	font-size: 14px;
	padding: 2px 4px;
	border-radius: 6px;
	line-height: 1;
}

.aifd-react-btn:hover {
	background: var(--aifd-surface-2);
}

/* Typing */
.aifd-typing {
	display: inline-flex;
	gap: 4px;
	align-items: center;
	padding: 12px 16px;
}

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

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

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

@keyframes aifd-bounce {
	0%,
	80%,
	100% {
		transform: translateY(0);
		opacity: 0.4;
	}
	40% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* Component shells */
.aifd-component {
	margin-top: 8px;
	width: 100%;
	max-width: 320px;
}

.aifd-component-title {
	font-size: 12px;
	font-weight: 600;
	color: var(--aifd-muted);
	margin: 0 0 8px;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

/* Buttons / quick replies */
.aifd-btn-grid {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.aifd-choice-btn {
	appearance: none;
	border: 1px solid var(--aifd-border);
	background: var(--aifd-bg);
	color: var(--aifd-text);
	padding: 10px 14px;
	border-radius: 999px;
	font-size: 14px;
	font-weight: 550;
	cursor: pointer;
	transition: border-color 0.15s, background 0.15s, transform 0.1s;
	font-family: inherit;
	line-height: 1.3;
	text-align: left;
}

.aifd-choice-btn:hover:not(:disabled) {
	border-color: var(--aifd-primary);
	background: color-mix(in srgb, var(--aifd-primary) 8%, white);
	transform: translateY(-1px);
}

.aifd-choice-btn:disabled {
	opacity: 0.55;
	cursor: default;
}

.aifd-choice-btn.is-primary,
.aifd-choice-btn[data-style="primary"] {
	background: var(--aifd-primary);
	border-color: var(--aifd-primary);
	color: #fff;
}

.aifd-choice-btn.is-primary:hover:not(:disabled),
.aifd-choice-btn[data-style="primary"]:hover:not(:disabled) {
	background: var(--aifd-primary-hover);
}

.aifd-quick-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

/* Cards */
.aifd-card {
	background: var(--aifd-bg);
	border: 1px solid var(--aifd-border);
	border-radius: var(--aifd-radius-sm);
	padding: 14px;
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.aifd-card-title {
	font-weight: 700;
	margin: 0 0 6px;
	font-size: 15px;
}

.aifd-card-body {
	color: var(--aifd-muted);
	font-size: 14px;
	margin: 0 0 10px;
}

.aifd-card-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

/* Confirmation */
.aifd-confirm {
	border-left: 3px solid var(--aifd-success);
}

.aifd-confirm[data-status="success"] {
	background: color-mix(in srgb, var(--aifd-success) 8%, white);
}

.aifd-confirm-list {
	list-style: none;
	margin: 0 0 12px;
	padding: 0;
	font-size: 13px;
}

.aifd-confirm-list li {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 4px 0;
	border-bottom: 1px dashed var(--aifd-border);
}

.aifd-confirm-list span {
	color: var(--aifd-muted);
}

/* Calendar */
.aifd-calendar {
	background: var(--aifd-bg);
	border: 1px solid var(--aifd-border);
	border-radius: var(--aifd-radius-sm);
	padding: 12px;
}

.aifd-cal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 10px;
	font-weight: 650;
	font-size: 14px;
}

.aifd-cal-nav {
	border: none;
	background: var(--aifd-surface-2);
	width: 28px;
	height: 28px;
	border-radius: 8px;
	cursor: pointer;
	color: var(--aifd-text);
	font-size: 16px;
	line-height: 1;
}

.aifd-cal-grid {
	display: grid;
	grid-template-columns: repeat(7, 1fr);
	gap: 4px;
	text-align: center;
}

.aifd-cal-dow {
	font-size: 11px;
	color: var(--aifd-muted);
	font-weight: 600;
	padding: 4px 0;
}

.aifd-cal-day {
	border: none;
	background: transparent;
	border-radius: 8px;
	height: 34px;
	font-size: 13px;
	cursor: pointer;
	color: var(--aifd-text);
	font-family: inherit;
	position: relative;
}

.aifd-cal-day:disabled {
	color: var(--aifd-muted);
	opacity: 0.35;
	cursor: default;
}

.aifd-cal-day.is-available:not(:disabled) {
	background: color-mix(in srgb, var(--aifd-primary) 12%, transparent);
	font-weight: 650;
	color: var(--aifd-primary);
}

.aifd-cal-day.is-available:hover:not(:disabled) {
	background: var(--aifd-primary);
	color: #fff;
}

.aifd-cal-day.is-selected {
	background: var(--aifd-primary) !important;
	color: #fff !important;
}

/* Time slots */
.aifd-slots {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.aifd-slot-btn {
	border: 1px solid var(--aifd-border);
	background: var(--aifd-bg);
	border-radius: 10px;
	padding: 12px 10px;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	font-family: inherit;
	color: var(--aifd-text);
	transition: border-color 0.15s, background 0.15s;
}

.aifd-slot-btn:hover:not(:disabled) {
	border-color: var(--aifd-primary);
	background: color-mix(in srgb, var(--aifd-primary) 8%, white);
}

/* Inputs inside conversation */
.aifd-inline-form {
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
}

.aifd-inline-input {
	width: 100%;
	border: 1px solid var(--aifd-border);
	border-radius: 10px;
	padding: 11px 12px;
	font-size: 15px;
	font-family: inherit;
	background: var(--aifd-bg);
	color: var(--aifd-text);
}

.aifd-inline-input:focus {
	outline: none;
	border-color: var(--aifd-primary);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--aifd-primary) 20%, transparent);
}

.aifd-inline-submit {
	align-self: flex-start;
	border: none;
	background: var(--aifd-primary);
	color: #fff;
	border-radius: 999px;
	padding: 10px 16px;
	font-weight: 600;
	font-size: 14px;
	cursor: pointer;
	font-family: inherit;
}

.aifd-inline-submit:disabled {
	opacity: 0.5;
	cursor: default;
}

/* Upload */
.aifd-upload {
	border: 1.5px dashed var(--aifd-border);
	border-radius: var(--aifd-radius-sm);
	padding: 16px;
	text-align: center;
	background: var(--aifd-bg);
	cursor: pointer;
}

.aifd-upload:hover {
	border-color: var(--aifd-primary);
}

.aifd-upload input {
	display: none;
}

.aifd-upload-label {
	font-size: 13px;
	color: var(--aifd-muted);
}

.aifd-upload-preview {
	margin-top: 8px;
	max-width: 100%;
	border-radius: 8px;
}

/* Dropdown */
.aifd-select {
	width: 100%;
	border: 1px solid var(--aifd-border);
	border-radius: 10px;
	padding: 11px 12px;
	font-size: 14px;
	font-family: inherit;
	background: var(--aifd-bg);
	color: var(--aifd-text);
}

/* Rating */
.aifd-rating {
	display: flex;
	gap: 6px;
}

.aifd-star {
	border: none;
	background: transparent;
	font-size: 24px;
	cursor: pointer;
	color: #cbd5e1;
	padding: 0;
	line-height: 1;
}

.aifd-star.is-on {
	color: #f59e0b;
}

/* Composer */
.aifd-composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--aifd-border);
	background: var(--aifd-bg);
	flex-shrink: 0;
}

.aifd-composer-input {
	flex: 1;
	min-height: 42px;
	max-height: 120px;
	resize: none;
	border: 1px solid var(--aifd-border);
	border-radius: 12px;
	padding: 10px 12px;
	font-size: 15px;
	font-family: inherit;
	background: var(--aifd-surface);
	color: var(--aifd-text);
	line-height: 1.4;
}

.aifd-composer-input:focus {
	outline: none;
	border-color: var(--aifd-primary);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--aifd-primary) 18%, transparent);
}

.aifd-composer-send,
.aifd-composer-attach {
	width: 42px;
	height: 42px;
	border: none;
	border-radius: 12px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	background: var(--aifd-primary);
	color: #fff;
}

.aifd-composer-attach {
	background: var(--aifd-surface-2);
	color: var(--aifd-text);
}

.aifd-composer-send:disabled {
	opacity: 0.45;
	cursor: default;
}

.aifd-composer-send svg,
.aifd-composer-attach svg {
	width: 18px;
	height: 18px;
	stroke: currentColor;
	fill: none;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.aifd-composer-hint {
	font-size: 11px;
	color: var(--aifd-muted);
	text-align: center;
	padding: 0 12px 10px;
	background: var(--aifd-bg);
}

/* Mobile full-screen-ish */
@media (max-width: 480px) {
	.aifd-panel {
		bottom: 0;
		right: 0;
		left: 0;
		width: 100vw;
		height: 100dvh;
		max-height: 100dvh;
		border-radius: 0;
		border: none;
	}

	.aifd-root[data-position="bottom-left"] .aifd-panel {
		left: 0;
	}

	.aifd-launcher {
		bottom: 16px;
		right: 16px;
	}

	.aifd-root[data-position="bottom-left"] .aifd-launcher {
		left: 16px;
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.aifd-panel,
	.aifd-msg,
	.aifd-launcher,
	.aifd-typing span {
		animation: none !important;
		transition: none !important;
	}
}

/* Screen-reader only */
.aifd-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	border: 0;
}
