/* ============================================================================
   UV-DTF AI Chat widget — "Степан"
   Floating button (FAB) + slide-in modal. Self-contained — no theme conflicts.
   ============================================================================ */

.uvdtf-chat-fab {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 2147483645;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 18px 14px 14px;
	background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
	color: #fff;
	border: 0;
	border-radius: 50px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	font-size: 15px;
	font-weight: 600;
	box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15);
	cursor: pointer;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.uvdtf-chat-fab:hover {
	transform: translateY(-2px);
	box-shadow: 0 10px 28px rgba(124, 58, 237, 0.5), 0 4px 8px rgba(0, 0, 0, 0.2);
}
.uvdtf-chat-fab__icon {
	width: 28px;
	height: 28px;
	background: rgba(255, 255, 255, 0.2);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 16px;
	overflow: hidden;
}
.uvdtf-chat-fab__icon--img { background: transparent; padding: 0; }
.uvdtf-chat-fab__icon--img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 50%;
	display: block;
}
.uvdtf-chat-fab--hidden { display: none; }

/* Unread dot */
.uvdtf-chat-fab__dot {
	position: absolute;
	top: 8px;
	right: 8px;
	width: 12px;
	height: 12px;
	background: #ef4444;
	border-radius: 50%;
	border: 2px solid #fff;
	display: none;
}
.uvdtf-chat-fab.has-unread .uvdtf-chat-fab__dot { display: block; }

/* === Modal panel === */
.uvdtf-chat {
	position: fixed;
	right: 20px;
	bottom: 20px;
	width: 380px;
	max-width: calc(100vw - 40px);
	height: 600px;
	max-height: calc(100vh - 40px);
	z-index: 2147483646;
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 8px 20px rgba(0, 0, 0, 0.15);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	font-size: 14px;
	color: #1f2937;
	animation: uvdtfChatSlideIn 0.25s ease;
}
@keyframes uvdtfChatSlideIn {
	from { opacity: 0; transform: translateY(20px) scale(0.95); }
	to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.uvdtf-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
	color: #fff;
}
.uvdtf-chat__avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	flex-shrink: 0;
	overflow: hidden;
}
.uvdtf-chat__avatar--img { background: transparent; }
.uvdtf-chat__avatar--img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 50%;
	display: block;
}
.uvdtf-chat__title {
	flex: 1;
	min-width: 0;
}
.uvdtf-chat__title strong {
	display: block;
	font-size: 15px;
}
.uvdtf-chat__title small {
	display: block;
	font-size: 12px;
	opacity: 0.85;
}
.uvdtf-chat__close {
	background: rgba(255, 255, 255, 0.15);
	border: 0;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	color: #fff;
	font-size: 18px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}
.uvdtf-chat__close:hover { background: rgba(255, 255, 255, 0.25); }

.uvdtf-chat__body {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	background: #f9fafb;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.uvdtf-chat__msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 14px;
	line-height: 1.45;
	white-space: pre-wrap;
	word-wrap: break-word;
}
.uvdtf-chat__msg--user {
	align-self: flex-end;
	background: #7c3aed;
	color: #fff;
	border-bottom-right-radius: 4px;
}
.uvdtf-chat__msg--failed {
	opacity: 0.55;
	position: relative;
	text-decoration: line-through;
	text-decoration-color: rgba(255,255,255,0.6);
}
.uvdtf-chat__msg--failed::after {
	content: '✗ не дійшло';
	position: absolute;
	bottom: -16px;
	right: 4px;
	font-size: 10px;
	color: #b91c1c;
	font-weight: 500;
	text-decoration: none;
}
.uvdtf-chat__msg--bot {
	align-self: flex-start;
	background: #fff;
	color: #1f2937;
	border: 1px solid #e5e7eb;
	border-bottom-left-radius: 4px;
}
.uvdtf-chat__msg--bot p { margin: 0 0 6px; }
.uvdtf-chat__msg--bot p:last-child { margin-bottom: 0; }
.uvdtf-chat__msg--bot ul,
.uvdtf-chat__msg--bot ol { margin: 6px 0; padding-left: 22px; }
.uvdtf-chat__msg--bot li { margin: 2px 0; }
.uvdtf-chat__msg--bot a { color: #7c3aed; }
.uvdtf-chat__msg--bot mark,
.uvdtf-chat__msg mark {
	background: linear-gradient(180deg, transparent 55%, #fef08a 55%);
	color: #78350f;
	padding: 0 3px;
	border-radius: 2px;
	font-weight: 600;
}
.uvdtf-chat__msg--bot code {
	background: #f3f4f6;
	padding: 1px 5px;
	border-radius: 3px;
	font-family: ui-monospace, "SF Mono", Consolas, monospace;
	font-size: 0.92em;
}

.uvdtf-chat__msg--system {
	align-self: center;
	background: #fef3c7;
	color: #78350f;
	font-size: 12px;
	padding: 6px 12px;
	border-radius: 12px;
}

.uvdtf-chat__typing {
	align-self: flex-start;
	display: flex;
	gap: 4px;
	padding: 12px 14px;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 14px;
	border-bottom-left-radius: 4px;
}
.uvdtf-chat__typing span {
	width: 7px;
	height: 7px;
	background: #9ca3af;
	border-radius: 50%;
	animation: uvdtfChatTyping 1.2s infinite ease-in-out;
}
.uvdtf-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.uvdtf-chat__typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes uvdtfChatTyping {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
	30%           { transform: translateY(-4px); opacity: 1; }
}

.uvdtf-chat__footer {
	padding: 12px;
	border-top: 1px solid #e5e7eb;
	background: #fff;
	display: flex;
	gap: 8px;
	align-items: flex-end;
}
.uvdtf-chat__input {
	flex: 1;
	border: 1px solid #d1d5db;
	border-radius: 22px;
	padding: 10px 14px;
	font-family: inherit;
	font-size: 14px;
	resize: none;
	max-height: 120px;
	min-height: 22px;
	outline: none;
	transition: border-color 0.15s ease;
	line-height: 1.4;
}
.uvdtf-chat__input:focus { border-color: #7c3aed; }

/* === Upload row (above input) === */
.uvdtf-chat__upload {
	padding: 10px 12px 0;
	background: #fff;
	border-top: 1px solid #f3f4f6;
}
.uvdtf-chat__upload--hidden { display: none !important; }

.uvdtf-chat__attach {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	padding: 10px 14px;
	background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
	color: #5b21b6;
	border: 2px dashed #a78bfa;
	border-radius: 12px;
	cursor: pointer;
	font-family: inherit;
	text-align: left;
	transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.uvdtf-chat__attach:hover:not(:disabled) {
	background: linear-gradient(135deg, #f3e8ff 0%, #e9d5ff 100%);
	border-color: #7c3aed;
}
.uvdtf-chat__attach:active:not(:disabled) { transform: scale(0.99); }
.uvdtf-chat__attach:disabled { opacity: 0.55; cursor: not-allowed; }

.uvdtf-chat__attach-icon {
	font-size: 22px;
	flex-shrink: 0;
	width: 38px;
	height: 38px;
	background: rgba(124, 58, 237, 0.12);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
}
.uvdtf-chat__attach-text {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1;
}
.uvdtf-chat__attach-label {
	font-weight: 600;
	font-size: 14px;
	color: #4c1d95;
}
.uvdtf-chat__attach-hint {
	font-size: 11px;
	color: #6b7280;
}

/* Native file input must NEVER be visible — themes (XStore, Astra тощо)
   часто перебивають [hidden] своїми правилами на input[type=file]. */
.uvdtf-chat__file,
input.uvdtf-chat__file[type="file"] {
	display: none !important;
	position: absolute !important;
	left: -9999px !important;
	width: 1px !important;
	height: 1px !important;
	opacity: 0 !important;
}

.uvdtf-chat__send {
	background: #7c3aed;
	color: #fff;
	border: 0;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 18px;
	flex-shrink: 0;
	transition: background 0.15s ease;
}
.uvdtf-chat__send:hover:not(:disabled) { background: #6d28d9; }
.uvdtf-chat__send:disabled {
	background: #d1d5db;
	cursor: not-allowed;
}

/* === Voice: mic button (footer, left of textarea) === */
.uvdtf-chat__mic {
	background: #f3f4f6;
	color: #374151;
	border: 0;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 18px;
	flex-shrink: 0;
	transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.uvdtf-chat__mic:hover:not(:disabled) { background: #e5e7eb; }
.uvdtf-chat__mic:disabled { opacity: 0.55; cursor: not-allowed; }
.uvdtf-chat__mic--recording {
	background: #ef4444;
	color: #fff;
	animation: uvdtf-mic-pulse 1.1s ease-in-out infinite;
}
.uvdtf-chat__mic--recording:hover:not(:disabled) { background: #dc2626; }
.uvdtf-chat__mic--processing {
	background: #fde68a;
	color: #92400e;
}
@keyframes uvdtf-mic-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
	50%      { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* === Voice: TTS toggle (header, left of close) === */
.uvdtf-chat__tts {
	background: rgba(255, 255, 255, 0.15);
	border: 0;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	color: #fff;
	font-size: 16px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: 6px;
	transition: background 0.15s ease;
}
.uvdtf-chat__tts:hover { background: rgba(255, 255, 255, 0.25); }
.uvdtf-chat__tts--on {
	background: #10b981;
	color: #fff;
}
.uvdtf-chat__tts--on:hover { background: #059669; }

.uvdtf-chat__disclaimer {
	font-size: 11px;
	color: #6b7280;
	text-align: center;
	padding: 6px 12px 10px;
	background: #fff;
	border-top: 1px solid #f3f4f6;
}

.uvdtf-chat__error {
	align-self: center;
	background: #fee2e2;
	color: #991b1b;
	font-size: 12px;
	padding: 8px 14px;
	border-radius: 8px;
	max-width: 90%;
	text-align: center;
}

/* === File attachment bubble === */
.uvdtf-chat__msg.uvdtf-chat__attachment {
	padding: 8px 12px;
	background: #6d28d9;
}
.uvdtf-chat__attachment-row {
	display: flex;
	align-items: center;
	gap: 10px;
}
.uvdtf-chat__attachment-icon {
	font-size: 22px;
	flex-shrink: 0;
}
.uvdtf-chat__attachment-info {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1;
}
.uvdtf-chat__attachment-name {
	font-weight: 600;
	font-size: 13px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.uvdtf-chat__attachment-size {
	font-size: 11px;
	opacity: 0.85;
}
.uvdtf-chat__attachment-status {
	font-size: 11px;
	padding: 2px 8px;
	background: rgba(255, 255, 255, 0.2);
	border-radius: 999px;
	flex-shrink: 0;
}
.uvdtf-chat__attachment-status--done {
	background: rgba(34, 197, 94, 0.3);
}

/* === Mobile === */
@media (max-width: 600px) {
	.uvdtf-chat {
		right: 10px;
		bottom: 70px;
		left: 10px;
		top: auto;
		width: auto;
		height: 520px;
		max-height: calc(100vh - 100px);
		max-width: none;
		border-radius: 16px;
		transition: height 0.25s ease, top 0.25s ease;
	}
	/* Після першої репліки клієнта — розгортаємо на майже повний екран
	   щоб було зручно вести довшу розмову. */
	.uvdtf-chat.uvdtf-chat--expanded {
		top: 60px;
		height: auto;
	}
	.uvdtf-chat-fab {
		right: 180px;
		bottom: 75px;
		padding: 12px 16px 12px 12px;
		font-size: 14px;
	}
}
