/**
 * TTHM Agent — public chat widget.
 *
 * All rules are scoped under .tthm-agent- so the fully-custom block theme's
 * styles are neither affected by nor inherited into the widget in unexpected
 * ways. The accent color is driven by the --tthm-accent custom property set
 * inline from settings.
 */

.tthm-agent-root {
	--tthm-accent: #0b5cad;
	--tthm-radius: 14px;
	position: fixed;
	z-index: 2147483000;
	bottom: 20px;
}
.tthm-agent-root.tthm-agent-bottom-right { right: 20px; }
.tthm-agent-root.tthm-agent-bottom-left { left: 20px; }

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

/* Launcher */
.tthm-agent-launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: 0;
	background: var(--tthm-accent);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba( 0, 0, 0, 0.22 );
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform .15s ease, box-shadow .15s ease;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.tthm-agent-launcher:hover { transform: translateY( -2px ); box-shadow: 0 10px 26px rgba( 0, 0, 0, 0.28 ); }
.tthm-agent-launcher:focus-visible { outline: 3px solid var(--tthm-accent); outline-offset: 3px; }
.tthm-agent-launcher svg { width: 28px; height: 28px; fill: currentColor; }

/* Panel */
.tthm-agent-panel {
	position: absolute;
	bottom: 76px;
	width: 380px;
	max-width: calc( 100vw - 40px );
	height: 560px;
	max-height: calc( 100vh - 120px );
	background: #fff;
	border-radius: var(--tthm-radius);
	box-shadow: 0 18px 50px rgba( 0, 0, 0, 0.28 );
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	color: #1d2327;
}
.tthm-agent-root.tthm-agent-bottom-right .tthm-agent-panel { right: 0; }
.tthm-agent-root.tthm-agent-bottom-left .tthm-agent-panel { left: 0; }

.tthm-agent-panel[hidden] { display: none; }

/* Header */
.tthm-agent-header {
	background: var(--tthm-accent);
	color: #fff;
	padding: 16px 18px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex: 0 0 auto;
}
.tthm-agent-header h2 {
	margin: 0;
	font-size: 16px;
	font-weight: 700;
	color: #fff;
	line-height: 1.2;
}
.tthm-agent-header-actions {
	display: flex;
	align-items: center;
	gap: 2px;
}

.tthm-agent-iconbtn,
.tthm-agent-close {
	background: transparent;
	border: 0;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
	line-height: 0;
}
.tthm-agent-iconbtn:hover,
.tthm-agent-close:hover { background: rgba( 255, 255, 255, 0.18 ); }
.tthm-agent-iconbtn:focus-visible,
.tthm-agent-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.tthm-agent-iconbtn svg,
.tthm-agent-close svg { width: 20px; height: 20px; fill: currentColor; }

/* [hidden] is only a UA rule, so an author display rule would otherwise win. */
.tthm-agent-iconbtn[hidden] { display: none; }

.tthm-agent-restart svg { width: 18px; height: 18px; }

/* Restart confirmation */
.tthm-agent-confirm {
	flex: 0 0 auto;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 10px 12px;
	background: #fff8e5;
	border-top: 1px solid #f0dfae;
}
.tthm-agent-confirm[hidden] { display: none; }
.tthm-agent-confirm-text {
	margin: 0;
	flex: 1 1 150px;
	font-size: 13px;
	line-height: 1.35;
	color: #5c4813;
}
.tthm-agent-confirm-actions {
	display: flex;
	gap: 6px;
	flex: 0 0 auto;
}
.tthm-agent-btn {
	border-radius: 8px;
	padding: 6px 12px;
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
}
.tthm-agent-btn-ghost {
	background: transparent;
	border: 1px solid #cbb87e;
	color: #5c4813;
}
.tthm-agent-btn-ghost:hover { background: rgba( 0, 0, 0, 0.05 ); }
.tthm-agent-btn-solid {
	background: var(--tthm-accent);
	border: 1px solid var(--tthm-accent);
	color: #fff;
}
.tthm-agent-btn-solid:hover { filter: brightness( 1.08 ); }
.tthm-agent-btn:focus-visible { outline: 3px solid var(--tthm-accent); outline-offset: 2px; }

/* Messages */
.tthm-agent-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: #f6f7f9;
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.tthm-agent-msg {
	max-width: 84%;
	padding: 10px 13px;
	border-radius: 12px;
	line-height: 1.45;
	white-space: pre-wrap;
	word-wrap: break-word;
}
.tthm-agent-msg-bot {
	align-self: flex-start;
	background: #fff;
	border: 1px solid #e2e4e7;
	border-bottom-left-radius: 4px;
}
.tthm-agent-msg-user {
	align-self: flex-end;
	background: var(--tthm-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

/* Typing indicator */
.tthm-agent-typing {
	align-self: flex-start;
	display: inline-flex;
	gap: 4px;
	padding: 12px 14px;
	background: #fff;
	border: 1px solid #e2e4e7;
	border-radius: 12px;
}
.tthm-agent-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9aa0a6;
	animation: tthm-bounce 1.2s infinite ease-in-out;
}
.tthm-agent-typing span:nth-child( 2 ) { animation-delay: .2s; }
.tthm-agent-typing span:nth-child( 3 ) { animation-delay: .4s; }
@keyframes tthm-bounce {
	0%, 60%, 100% { transform: translateY( 0 ); opacity: .5; }
	30% { transform: translateY( -5px ); opacity: 1; }
}

/* Composer */
.tthm-agent-composer {
	flex: 0 0 auto;
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid #e2e4e7;
	background: #fff;
}
.tthm-agent-composer textarea {
	flex: 1 1 auto;
	resize: none;
	border: 1px solid #cfd3d7;
	border-radius: 10px;
	padding: 10px 12px;
	font: inherit;
	line-height: 1.4;
	max-height: 120px;
	color: #1d2327;
	background: #fff;
}
.tthm-agent-composer textarea:focus-visible {
	outline: 2px solid var(--tthm-accent);
	outline-offset: 0;
	border-color: var(--tthm-accent);
}
.tthm-agent-send {
	flex: 0 0 auto;
	background: var(--tthm-accent);
	color: #fff;
	border: 0;
	border-radius: 10px;
	padding: 0 16px;
	cursor: pointer;
	font-weight: 600;
}
.tthm-agent-send:disabled { opacity: .5; cursor: default; }
.tthm-agent-send:focus-visible { outline: 3px solid var(--tthm-accent); outline-offset: 2px; }

.tthm-agent-footnote {
	font-size: 11px;
	color: #6a7077;
	text-align: center;
	padding: 0 12px 10px;
	background: #fff;
}

/* Mobile: full screen below 640px */
@media screen and ( max-width: 640px ) {
	.tthm-agent-panel {
		position: fixed;
		inset: 0;
		width: 100vw;
		height: 100vh;
		max-width: 100vw;
		max-height: 100vh;
		border-radius: 0;
	}
	.tthm-agent-root.tthm-agent-bottom-right .tthm-agent-panel,
	.tthm-agent-root.tthm-agent-bottom-left .tthm-agent-panel { right: 0; left: 0; }
}

@media ( prefers-reduced-motion: reduce ) {
	.tthm-agent-launcher, .tthm-agent-typing span { transition: none; animation: none; }
}
