/* ===================================================================
 * DIGI MIRROR — AI Chat Widget — Stylesheet v2
 *
 * v2 changes (from v1):
 *   - Added .dm-chat-typed-* styles for email/tel input mode
 *   - Validation states (red border, hint text)
 *   - "Type something else" link below typed input
 *
 * Soft Minimal Tech aesthetic. Reuses theme tokens (var(--bg) etc.)
 * Light / dark theme automatic via [data-theme] on <html>.
 * =================================================================== */

.dm-chat {
	--dmc-bubble: 56px;
	--dmc-panel-w: 380px;
	--dmc-panel-max-h: min(70vh, 640px);
	--dmc-radius-panel: 16px;
	--dmc-radius-msg: 16px;
	--dmc-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
	--dmc-online: #00FF88;
	--dmc-action: #FF00FF;
	--dmc-shadow-rest: 0 4px 16px rgba(10, 10, 10, 0.08);
	--dmc-shadow-elevated: 0 16px 48px rgba(10, 10, 10, 0.16);

	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 9999;
	font-family: var(--font-body, 'Inter', system-ui, sans-serif);
}

[data-theme="dark"] .dm-chat {
	--dmc-shadow-rest: 0 4px 16px rgba(0, 0, 0, 0.4);
	--dmc-shadow-elevated: 0 16px 48px rgba(0, 0, 0, 0.7);
}

/* States: hidden (default) | visible (bubble shown) | open (panel shown) */
.dm-chat[data-state="hidden"] { display: none; }

/* ==================================================
 * Bubble (closed state)
 * ================================================== */

.dm-chat-bubble {
	width: var(--dmc-bubble);
	height: var(--dmc-bubble);
	border-radius: 50%;
	background: var(--bg);
	border: 1px solid var(--hairline);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--dmc-shadow-rest);
	position: relative;
	color: var(--text);
	padding: 0;
	opacity: 0;
	transform: translateY(8px) scale(0.96);
	transition: opacity var(--dmc-transition),
	            transform var(--dmc-transition),
	            box-shadow var(--dmc-transition);
	pointer-events: none;
}

.dm-chat[data-state="visible"] .dm-chat-bubble,
.dm-chat[data-state="open"]    .dm-chat-bubble {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

.dm-chat-bubble:hover {
	transform: translateY(-2px);
	box-shadow: var(--dmc-shadow-elevated);
}

.dm-chat-bubble-icon {
	width: 24px;
	height: 24px;
	stroke: currentColor;
	fill: none;
	stroke-width: 1.5;
}

.dm-chat-bubble-dot {
	position: absolute;
	top: 8px;
	right: 8px;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--dmc-online);
	box-shadow: 0 0 0 2px var(--bg);
	pointer-events: none;
}

.dm-chat-bubble-dot::after {
	content: '';
	position: absolute;
	inset: -3px;
	border-radius: 50%;
	background: var(--dmc-online);
	opacity: 0.4;
	animation: dm-chat-pulse 2.4s ease-in-out infinite;
}

@keyframes dm-chat-pulse {
	0%, 100% { transform: scale(1);   opacity: 0.4; }
	50%      { transform: scale(1.8); opacity: 0;   }
}

/* Hide bubble when panel is open (panel anchors to where bubble was) */
.dm-chat[data-state="open"] .dm-chat-bubble {
	opacity: 0;
	pointer-events: none;
}

/* ==================================================
 * Panel (open state)
 * ================================================== */

.dm-chat-panel {
	position: absolute;
	bottom: 0;
	right: 0;
	width: var(--dmc-panel-w);
	max-height: var(--dmc-panel-max-h);
	height: var(--dmc-panel-max-h);
	background: var(--bg);
	border: 1px solid var(--hairline);
	border-radius: var(--dmc-radius-panel);
	box-shadow: var(--dmc-shadow-elevated);
	display: none;
	flex-direction: column;
	overflow: hidden;
	transform-origin: bottom right;
}

.dm-chat[data-state="open"] .dm-chat-panel {
	display: flex;
	animation: dm-chat-open 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dm-chat-open {
	from { opacity: 0; transform: translateY(12px) scale(0.95); }
	to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ==================================================
 * Header
 * ================================================== */

.dm-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	border-bottom: 1px solid var(--hairline);
	flex-shrink: 0;
	background: var(--bg);
}

.dm-chat-header-meta {
	display: flex;
	align-items: center;
	gap: 10px;
}

.dm-chat-pulse {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--dmc-online);
	box-shadow: 0 0 0 4px rgba(0, 255, 136, 0.15);
	flex-shrink: 0;
}

.dm-chat-title {
	font-weight: 600;
	font-size: 14px;
	color: var(--text);
	letter-spacing: -0.01em;
}

.dm-chat-status {
	font-family: var(--font-mono, 'JetBrains Mono', monospace);
	font-size: 10px;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.dm-chat-close {
	width: 32px;
	height: 32px;
	border-radius: 8px;
	background: transparent;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--text-muted);
	padding: 0;
	transition: background var(--dmc-transition), color var(--dmc-transition);
}

.dm-chat-close:hover {
	background: var(--hairline);
	color: var(--text);
}

/* ==================================================
 * Body — message list
 * ================================================== */

.dm-chat-body {
	flex: 1;
	overflow-y: auto;
	padding: 20px 16px 8px;
	display: flex;
	flex-direction: column;
	gap: 14px;
	scroll-behavior: smooth;
}

.dm-chat-body::-webkit-scrollbar       { width: 6px; }
.dm-chat-body::-webkit-scrollbar-track { background: transparent; }
.dm-chat-body::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 3px; }

.dm-chat-msg {
	max-width: 88%;
	font-size: 14px;
	line-height: 1.55;
	white-space: pre-wrap;
	word-wrap: break-word;
	animation: dm-chat-msg-in 240ms ease-out;
}

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

.dm-chat-msg-bot {
	align-self: flex-start;
	color: var(--text);
}

.dm-chat-msg-user {
	align-self: flex-end;
	background: var(--text);
	color: var(--bg);
	padding: 9px 13px;
	border-radius: var(--dmc-radius-msg) var(--dmc-radius-msg) 4px var(--dmc-radius-msg);
}

/* ==================================================
 * Typing indicator
 * ================================================== */

.dm-chat-typing {
	display: none;
	align-items: center;
	gap: 4px;
	padding: 0 16px 8px;
	flex-shrink: 0;
}

.dm-chat[data-loading="true"] .dm-chat-typing {
	display: flex;
}

.dm-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--text-muted);
	opacity: 0.4;
	animation: dm-chat-typing-dot 1.4s ease-in-out infinite;
}

.dm-chat-typing span:nth-child(2) { animation-delay: 0.16s; }
.dm-chat-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dm-chat-typing-dot {
	0%, 60%, 100% { opacity: 0.3; transform: translateY(0);    }
	30%           { opacity: 1;   transform: translateY(-4px); }
}

/* ==================================================
 * Footer — input + send
 * ================================================== */

.dm-chat-footer {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	padding: 12px 14px 12px 16px;
	border-top: 1px solid var(--hairline);
	flex-shrink: 0;
	background: var(--bg);
}

.dm-chat-input {
	flex: 1;
	resize: none;
	border: none;
	background: transparent;
	color: var(--text);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	max-height: 100px;
	overflow-y: auto;
	outline: none;
	padding: 8px 0;
	-webkit-text-size-adjust: 100%;
}

.dm-chat-input::placeholder {
	color: var(--text-muted);
}

.dm-chat-send {
	width: 36px;
	height: 36px;
	border-radius: 8px;
	background: var(--text);
	color: var(--bg);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	padding: 0;
	transition: background var(--dmc-transition), opacity var(--dmc-transition);
}

.dm-chat-send svg { stroke: currentColor; fill: none; }
.dm-chat-send:hover:not(:disabled) { background: var(--dmc-action); }
.dm-chat-send:disabled { opacity: 0.25; cursor: not-allowed; }

/* ==================================================
 * Disclaimer
 * ================================================== */

.dm-chat-disclaimer {
	padding: 8px 16px 12px;
	font-family: var(--font-mono, 'JetBrains Mono', monospace);
	font-size: 9px;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: 0.08em;
	text-align: center;
	border-top: 1px solid var(--hairline);
	flex-shrink: 0;
	background: var(--bg);
}

/* ==================================================
 * Lead-saved state — input frozen, confirm tag
 * ================================================== */

.dm-chat[data-saved="true"] .dm-chat-input,
.dm-chat[data-saved="true"] .dm-chat-send {
	pointer-events: none;
	opacity: 0.3;
}

.dm-chat[data-saved="true"] .dm-chat-disclaimer {
	color: var(--dmc-online);
}

/* ==================================================
 * Typed input mode (email / tel)
 * ================================================== */

.dm-chat-typed {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 4px;
	min-width: 0;
}

.dm-chat-typed-input {
	width: 100%;
	border: 1px solid var(--hairline);
	background: var(--bg);
	color: var(--text);
	font-family: inherit;
	font-size: 14px;
	padding: 9px 12px;
	border-radius: 8px;
	outline: none;
	transition: border-color var(--dmc-transition);
	-webkit-text-size-adjust: 100%;
	box-sizing: border-box;
}

.dm-chat-typed-input::placeholder {
	color: var(--text-muted);
}

.dm-chat-typed-input:focus {
	border-color: var(--text);
}

.dm-chat-typed-input.dm-chat-typed-error {
	border-color: #FF4500;
}

.dm-chat-typed-skip {
	align-self: flex-start;
	background: transparent;
	border: none;
	padding: 0;
	color: var(--text-muted);
	font-family: var(--font-mono, 'JetBrains Mono', monospace);
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	text-decoration: underline;
	text-underline-offset: 2px;
	cursor: pointer;
	transition: color var(--dmc-transition);
}

.dm-chat-typed-skip:hover {
	color: var(--text);
}

.dm-chat-typed-hint {
	font-size: 11px;
	color: #FF4500;
	line-height: 1.3;
}

/* ==================================================
 * Mobile
 * ================================================== */

@media (max-width: 480px) {
	.dm-chat {
		bottom: 16px;
		right: 16px;
	}

	.dm-chat-panel {
		width: calc(100vw - 32px);
		max-width: 380px;
		max-height: 80vh;
		height: 80vh;
	}
}

@media (max-width: 768px) {
	.dm-chat-input,
	.dm-chat-typed-input {
		font-size: 16px; /* iOS zoom prevention */
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.dm-chat-bubble-dot::after,
	.dm-chat-typing span {
		animation: none;
	}
	.dm-chat[data-state="open"] .dm-chat-panel {
		animation: none;
	}
}
