/* Trapdoor Chat widget. Colours come from --tdc-primary / --tdc-on-primary set inline by the plugin. */
.tdc-root {
	--tdc-radius: 16px;
	--tdc-bg: #ffffff;
	--tdc-text: #1f2937;
	--tdc-muted: #6b7280;
	--tdc-bubble: #f1f3f5;
	--tdc-border: #e5e7eb;
	position: fixed;
	z-index: 99999;
	right: max(20px, env(safe-area-inset-right));
	bottom: max(20px, env(safe-area-inset-bottom));
	font: inherit;
	font-size: 15px;
	line-height: 1.45;
	color: var(--tdc-text);
	text-align: left;
}
.tdc-root *, .tdc-root *::before, .tdc-root *::after { box-sizing: border-box; }
.tdc-root p, .tdc-root h2, .tdc-root ul, .tdc-root li { margin: 0; padding: 0; }

/* Launcher */
.tdc-launcher {
	position: relative;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--tdc-primary);
	color: var(--tdc-on-primary);
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform .15s ease;
}
.tdc-launcher:hover { transform: scale(1.05); }
.tdc-launcher:focus-visible { outline: 3px solid var(--tdc-primary); outline-offset: 3px; }
.tdc-launcher svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tdc-launcher .tdc-icon-close { display: none; }
.tdc-launcher-open .tdc-icon-chat { display: none; }
.tdc-launcher-open .tdc-icon-close { display: block; }

/* Panel */
.tdc-panel {
	position: absolute;
	right: 0;
	bottom: 72px;
	width: 370px;
	max-width: calc(100vw - 40px);
	height: 600px;
	max-height: calc(100vh - 110px);
	background: var(--tdc-bg);
	border-radius: var(--tdc-radius);
	box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: tdc-in .18s ease-out;
}
.tdc-panel[hidden] { display: none !important; }
@keyframes tdc-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.tdc-header {
	background: var(--tdc-primary);
	color: var(--tdc-on-primary);
	padding: 14px 12px 14px 16px;
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
}
.tdc-title { font-size: 17px; font-weight: 700; line-height: 1.3; color: inherit; }
.tdc-subtitle { margin-top: 2px; font-size: 13px; opacity: .85; }
.tdc-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.tdc-reset, .tdc-close {
	background: transparent;
	border: 0;
	color: inherit;
	cursor: pointer;
	border-radius: 8px;
	min-height: 36px;
	min-width: 36px;
	padding: 6px 8px;
	font: inherit;
	font-size: 12px;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.tdc-reset:hover, .tdc-close:hover { background: rgba(255, 255, 255, .18); }
.tdc-reset:focus-visible, .tdc-close:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
.tdc-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Messages */
.tdc-log {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
}
.tdc-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 14px;
	overflow-wrap: anywhere;
	word-wrap: break-word;
}
.tdc-msg-assistant { align-self: flex-start; background: var(--tdc-bubble); border-bottom-left-radius: 4px; }
.tdc-msg-user { align-self: flex-end; background: var(--tdc-primary); color: var(--tdc-on-primary); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.tdc-msg-error { background: #fdecea; color: #7f1d1d; }
.tdc-msg p + p { margin-top: 8px; }
.tdc-msg ul { list-style: disc; margin: 6px 0 6px 0; padding-left: 18px; line-height: inherit; }
.tdc-msg li { margin: 2px 0; }
.tdc-msg a { color: inherit; text-decoration: underline; }
.tdc-msg strong { font-weight: 700; }

.tdc-typing { padding: 12px 14px; }
.tdc-typing span {
	display: inline-block;
	width: 7px;
	height: 7px;
	margin: 0 2px;
	border-radius: 50%;
	background: var(--tdc-muted);
	animation: tdc-blink 1.2s infinite;
}
.tdc-typing span:nth-child(2) { animation-delay: .2s; }
.tdc-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes tdc-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Composer */
.tdc-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--tdc-border);
	background: var(--tdc-bg);
}
.tdc-input {
	flex: 1;
	resize: none;
	border: 1px solid var(--tdc-border);
	border-radius: 12px;
	padding: 11px 12px;
	font: inherit;
	font-size: 15px;
	line-height: 1.4;
	min-height: 44px;
	max-height: 120px;
	color: var(--tdc-text);
	background: #fff;
	margin: 0;
}
.tdc-input:focus { outline: 2px solid var(--tdc-primary); outline-offset: 1px; border-color: transparent; }
.tdc-send {
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--tdc-primary);
	color: var(--tdc-on-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.tdc-send:disabled { opacity: .5; cursor: default; }
.tdc-send:focus-visible { outline: 2px solid var(--tdc-primary); outline-offset: 2px; }
.tdc-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Phones: full-screen panel, launcher hidden while open */
@media (max-width: 480px) {
	.tdc-root { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
	.tdc-panel {
		position: fixed;
		inset: 0;
		width: auto;
		max-width: none;
		height: auto;
		max-height: none;
		border-radius: 0;
	}
	.tdc-header { padding-top: max(14px, env(safe-area-inset-top)); }
	.tdc-form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
	.tdc-launcher-open { display: none; }
	body.tdc-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
	.tdc-panel { animation: none; }
	.tdc-launcher { transition: none; }
	.tdc-log { scroll-behavior: auto; }
	.tdc-typing span { animation: none; opacity: .6; }
}
