/**
 * MedChat Widget Styles
 * Self-contained floating chat widget CSS with CSS custom properties.
 */

:root .medchat-scope {
	/* Clinical Precision Design System Tokens */
	--mc-primary: #0056B3;
	--mc-primary-container: #e6eeff;
	--mc-on-primary: #ffffff;
	--mc-secondary: #006c49;
	--mc-surface: #f8f9ff;
	--mc-surface-container: #ffffff;
	--mc-on-surface: #0d1c2e;
	--mc-on-surface-variant: #424752;
	--mc-outline: #727784;
	--mc-outline-variant: #c2c6d4;
	--mc-error: #ba1a1a;
	--mc-success: #10B981;
	
	/* Layout & Spacing */
	--mc-radius-sm: 0.25rem;
	--mc-radius-md: 0.5rem;
	--mc-radius-lg: 1rem;
	--mc-radius-full: 9999px;
	
	/* Legacy mappings for compatibility */
	--medchat-primary: var(--mc-primary);
	--medchat-bg: var(--mc-surface-container);
	--medchat-text: var(--mc-on-surface);
	--medchat-user-bg: var(--mc-primary);
	--medchat-bot-bg: #eff4ff;
}

#medchat-widget-container {
	font-family: 'Lato', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
}

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

.medchat-scope {
	position: relative;
}

/* Floating bubble button */
.medchat-bubble {
	position: fixed;
	bottom: 24px;
	right: 24px;
	width: 60px;
	height: 60px;
	border-radius: var(--mc-radius-full);
	background-color: var(--mc-primary);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='28' height='28' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: center;
	cursor: pointer;
	z-index: 99999;
	box-shadow: 0 8px 24px rgba(0, 86, 179, 0.25);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.medchat-bubble:hover {
	transform: scale(1.08) translateY(-2px);
	box-shadow: 0 12px 32px rgba(0, 86, 179, 0.35);
}

/* Chat window */
.medchat-window {
	position: fixed;
	bottom: 100px;
	right: 24px;
	width: 380px;
	height: 600px;
	max-height: calc(100vh - 120px);
	background-color: var(--mc-surface-container);
	border-radius: var(--mc-radius-lg);
	box-shadow: 0 16px 48px rgba(13, 28, 46, 0.15);
	display: none;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(20px) scale(0.95);
	transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	border: 1px solid var(--mc-outline-variant);
	z-index: 99998;
}

.medchat-window.open {
	display: flex;
	opacity: 1;
	transform: translateY(0) scale(1);
}

/* Header */
.medchat-header {
	background-color: var(--mc-primary);
	color: var(--mc-on-primary);
	padding: 20px 24px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.medchat-header h3 {
	margin: 0;
	font-size: 18px;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.medchat-header .medchat-close {
	cursor: pointer;
	opacity: 0.8;
	font-size: 28px;
	line-height: 1;
	transition: opacity 0.2s ease;
}

.medchat-header .medchat-close:hover {
	opacity: 1;
}

/* Messages area */
.medchat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

/* Individual messages */
.medchat-message {
	max-width: 80%;
	padding: 10px 14px;
	font-size: 14px;
	line-height: 1.4;
	word-wrap: break-word;
}

.medchat-message.user {
	align-self: flex-end;
	background-color: var(--medchat-user-bg);
	color: white;
	border-radius: 12px 12px 0 12px;
}

.medchat-message.bot {
	align-self: flex-start;
	background-color: var(--medchat-bot-bg);
	color: #1a1a1a;
	border-radius: 12px 12px 12px 0;
	font-weight: 500;
}

/* Input row */
.medchat-input-row {
	border-top: 1px solid #e5e7eb;
	padding: 12px;
	display: flex;
	gap: 8px;
}

.medchat-input-row input {
	flex: 1;
	padding: 10px 14px;
	border: 1px solid #d1d5db;
	border-radius: 8px;
	font-size: 14px;
	font-family: inherit;
	transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.medchat-input-row input:focus {
	outline: none;
	border-color: var(--medchat-primary);
}

.medchat-input-row button {
	padding: 10px 18px;
	background-color: var(--medchat-primary);
	color: white;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	font-size: 14px;
	font-family: inherit;
	transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.medchat-input-row button:hover {
	filter: brightness(1.1);
}

/* Left position variant */
.medchat-position-left .medchat-bubble {
	right: auto;
	left: 20px;
}

.medchat-position-left .medchat-window {
	right: auto;
	left: 20px;
}

/* ============ Intake Mode Styles ============ */

.medchat-intake-step {
	padding: 16px;
	max-width: 100%;
	box-sizing: border-box;
	animation: medchat-fade-in 0.4s ease-out;
}

@keyframes medchat-fade-in {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: translateY(0); }
}

.medchat-intake-buttons {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin-top: 12px;
}

.medchat-intake-btn {
	width: 100%;
	padding: 14px 18px;
	background: #fff;
	border: 1.5px solid var(--mc-outline-variant);
	color: var(--mc-on-surface);
	border-radius: var(--mc-radius-md);
	cursor: pointer;
	font-weight: 600;
	font-size: 15px;
	text-align: left;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.medchat-intake-btn::after {
	content: '→';
	opacity: 0.3;
	transition: transform 0.2s ease, opacity 0.2s ease;
}

.medchat-intake-btn:hover {
	border-color: var(--mc-primary);
	background-color: var(--mc-primary-container);
	color: var(--mc-primary);
	transform: translateX(4px);
}

.medchat-intake-btn:hover::after {
	opacity: 1;
	transform: translateX(4px);
}

.medchat-service-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
	margin-top: 12px;
}

.medchat-service-grid .medchat-intake-btn {
	text-align: center;
	font-size: 14px;
	padding: 16px 12px;
	justify-content: center;
	flex-direction: column;
	gap: 4px;
}

.medchat-service-grid .medchat-intake-btn::after {
	display: none;
}

/* Date Strip */
.medchat-strip-header {
	text-transform: uppercase;
	letter-spacing: 0.1em;
	font-size: 11px;
	color: #0056B3;
	margin-bottom: 16px;
	font-weight: 700;
	display: block;
	text-align: left;
}

.medchat-date-strip {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 4px;
	margin: 16px 0;
	padding: 0 4px;
}

.medchat-date-pills {
	display: flex;
	gap: 6px;
	flex-wrap: nowrap;
	overflow-x: auto;
	flex: 1;
}

.medchat-date-pill {
	background: #fff;
	border: 1px solid var(--mc-outline-variant);
	border-radius: var(--mc-radius-md);
	padding: 12px 8px;
	flex: 1;
	min-width: 64px;
	text-align: center;
	cursor: pointer;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.medchat-date-pill .pill-day {
	font-size: 10px;
	text-transform: uppercase;
	color: #0056B3;
	font-weight: 700;
	letter-spacing: 0.05em;
}

.medchat-date-pill .pill-date {
	font-size: 20px;
	font-weight: 700;
	color: #1a1a1a;
	margin: 4px 0;
}

.medchat-date-pill .pill-month {
	font-size: 10px;
	color: #0056B3;
	text-transform: uppercase;
	font-weight: 600;
}

.medchat-date-pill:hover:not(.disabled):not(.selected) {
	border-color: var(--mc-primary);
	background: var(--mc-primary-container);
}

.medchat-date-pill.selected {
	background: var(--mc-primary);
	border-color: var(--mc-primary);
	box-shadow: 0 4px 12px rgba(0, 86, 179, 0.2);
	transform: translateY(-2px);
}

.medchat-date-pill.selected .pill-day,
.medchat-date-pill.selected .pill-date,
.medchat-date-pill.selected .pill-month {
	color: #fff;
}

.medchat-date-pill.disabled {
	opacity: 0.4;
	cursor: not-allowed;
	background: var(--mc-surface);
	border-style: dashed;
}

.medchat-strip-nav {
	width: 32px;
	height: 32px;
	border-radius: var(--mc-radius-full);
	border: 1px solid var(--mc-outline-variant);
	background: #fff;
	color: var(--mc-on-surface-variant);
	font-size: 14px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
}

.medchat-strip-nav:hover:not(:disabled) {
	background: var(--mc-surface);
	border-color: var(--mc-primary);
	color: var(--mc-primary);
}

.medchat-strip-nav:disabled {
	opacity: 0.3;
	cursor: not-allowed;
}

.medchat-strip-range {
	font-size: 12px;
	color: var(--mc-on-surface-variant);
	text-align: center;
	margin-top: 12px;
	font-weight: 500;
}

/* Slot Sections */
.medchat-slot-panel {
	margin-top: 20px;
	padding-top: 20px;
	border-top: 1px solid var(--mc-outline-variant);
}

.medchat-slot-section {
	margin-bottom: 20px;
}

.medchat-slot-heading {
	font-size: 13px;
	font-weight: 700;
	color: #0056B3;
	margin-bottom: 12px;
	display: flex;
	align-items: center;
	gap: 8px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.medchat-slot-heading::before {
	content: '';
	width: 4px;
	height: 14px;
	background: var(--mc-primary);
	border-radius: 2px;
}

.medchat-slot-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 10px;
}

.medchat-slot-chip {
	width: 100%;
	padding: 12px 8px;
	border: 1.5px solid var(--mc-outline-variant);
	border-radius: var(--mc-radius-md);
	background: #fff;
	color: var(--mc-on-surface);
	font-size: 14px;
	font-weight: 600;
	text-align: center;
	cursor: pointer;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.medchat-slot-chip:hover {
	background: var(--mc-primary-container);
	border-color: var(--mc-primary);
	color: var(--mc-primary);
	transform: translateY(-2px);
}

.medchat-slot-chip.selected {
	background: var(--mc-primary);
	border-color: var(--mc-primary);
	color: #fff;
	box-shadow: 0 4px 12px rgba(0, 86, 179, 0.2);
}

/* Intake form */
.medchat-intake-form {
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #fff;
	padding: 20px;
	border-radius: var(--mc-radius-lg);
	border: 1px solid var(--mc-outline-variant);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.medchat-intake-form input,
.medchat-intake-form textarea {
	width: 100%;
	padding: 12px 16px;
	border-radius: var(--mc-radius-md);
	border: 1px solid var(--mc-outline-variant);
	font-size: 15px;
	color: var(--mc-on-surface);
	background-color: var(--mc-surface);
	transition: all 0.2s ease;
}

.medchat-intake-form input:focus,
.medchat-intake-form textarea:focus {
	outline: none;
	border-color: var(--mc-primary);
	background-color: #fff;
	box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.1);
}

.medchat-intake-form button {
	width: 100%;
	padding: 14px;
	border: none;
	border-radius: var(--mc-radius-md);
	background: var(--mc-primary);
	color: #fff;
	font-weight: 700;
	font-size: 16px;
	cursor: pointer;
	margin-top: 10px;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.medchat-intake-form button:hover {
	filter: brightness(1.1);
	transform: translateY(-2px);
	box-shadow: 0 6px 16px rgba(0, 86, 179, 0.3);
}

/* Confirmation summary */
.medchat-confirm-summary {
	background: var(--mc-primary-container);
	border: 1px solid var(--mc-outline-variant);
	border-radius: var(--mc-radius-lg);
	padding: 16px 20px;
	margin-bottom: 12px;
	font-size: 14px;
	color: #1a1a1a;
	line-height: 1.8;
	font-weight: 500;
}

.medchat-confirm-summary strong {
	color: #0056B3;
	display: block;
	margin-bottom: 8px;
	font-weight: 600;
}

.medchat-closed-message {
	background: #dcfce7;
	border: 1px solid #bbf7d0;
	padding: 16px;
	border-radius: var(--mc-radius-lg);
	color: var(--mc-success);
	text-align: center;
	font-size: 15px;
	font-weight: 500;
}

.medchat-input-row.locked {
	display: none;
}

/* ============ End Intake Mode Styles ============ */

/* Responsive - mobile full screen */
@media (max-width: 480px) {
	.medchat-window,
	.medchat-position-left .medchat-window {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		bottom: auto;
		right: auto;
		border-radius: 0;
	}

	.medchat-position-left .medchat-bubble {
		left: 20px;
	}
}

/* Typing indicator */
.medchat-typing {
	display: flex;
	gap: 4px;
	padding: 12px 14px;
}

.medchat-typing span {
	display: inline-block;
	width: 8px;
	height: 8px;
	background-color: var(--medchat-text);
	border-radius: 50%;
	opacity: 0.4;
	animation: medchat-typing-blink 1.4s infinite both;
}

.medchat-typing span:nth-child(1) {
	animation-delay: 0s;
}

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

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

@keyframes medchat-typing-blink {
	0%, 80%, 100% {
		opacity: 0.4;
		transform: scale(0.8);
	}
	40% {
		opacity: 1;
		transform: scale(1);
	}
}

/* Typewriter effect caret */
.medchat-typing-message::after {
	content: '|';
	display: inline-block;
	animation: medchat-blink 1s step-end infinite;
	margin-left: 2px;
	color: var(--medchat-text);
}

@keyframes medchat-blink {
	0%, 100% { opacity: 1; }
	50% { opacity: 0; }
}

/* Template: Card variant */
.medchat-template-card .medchat-window {
	border-radius: 24px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
	border: 1px solid rgba(0,0,0,0.06);
}

.medchat-template-card .medchat-header {
	border-radius: 24px 24px 0 0;
}

.medchat-template-card .medchat-bubble {
	box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

/* Bubble pulse on new message */
@keyframes medchat-pulse {
	0% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4); }
	70% { box-shadow: 0 0 0 12px rgba(79, 70, 229, 0); }
	100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

.medchat-bubble.has-new {
	animation: medchat-pulse 2s infinite;
}