/* === Chat UI Variables === */
:root {
	--chat-primary-color: #d61518;
	--chat-primary-hover: #b31214;
	--chat-bg-color: #ffffff;
	--chat-text-color: #333333;
	--chat-bot-msg-bg: #eeeeee;
	--chat-user-msg-bg: #d61518;
	--chat-user-msg-text: #ffffff;
	--chat-border-color: #e5e7eb;
	--chat-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
	--chat-button-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
	--chat-font-family: "Inter", "Noto Sans JP", sans-serif;
	--chat-transition-speed: 0.3s;
}

/* === Floating Toggle Button === */
.circle-btn {
	position: fixed;
	right: 0;
	bottom: 10px;
	width: 140px;
	height: 140px;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 10000;
}

.chat-toggle-btn {
	position: fixed;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--chat-primary-color), #f63b3b);
	color: white;
	/* border: solid 1px #fff; */
	border: none;
	box-shadow: var(--chat-button-shadow);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition:
		transform var(--chat-transition-speed) cubic-bezier(0.175, 0.885, 0.32, 1.275),
		box-shadow var(--chat-transition-speed);
}

.circle-btn__svg {
	position: absolute;
	width: 100%;
	height: 100%;
	animation: rotate 10s linear infinite;
}

.circle-btn__svg textPath {
	font-size: 1rem;
	font-weight: bold;
	fill: var(--chat-primary-color) !important;
	text-shadow:
		1px 1px 0 rgba(255, 255, 255, 0.8),
		-1px -1px 0 rgba(255, 255, 255, 0.8),
		-1px 1px 0 rgba(255, 255, 255, 0.8),
		1px -1px 0 rgba(255, 255, 255, 0.8),
		0px 1px 0 rgba(255, 255, 255, 0.8),
		0-1px 0 rgba(255, 255, 255, 0.8),
		-1px 0 0 rgba(255, 255, 255, 0.8),
		1px 0 0 rgba(255, 255, 255, 0.8);
}

@keyframes rotate {
	from {
		transform: rotate(0deg);
	}
	to {
		transform: rotate(360deg);
	}
}

@media (hover: hover) and (pointer: fine) {
	.chat-toggle-btn:hover {
		transform: scale(1.1);
		box-shadow:
			0 10px 15px -3px rgba(0, 0, 0, 0.1),
			0 4px 6px -4px rgba(0, 0, 0, 0.1);
	}
}

.chat-toggle-btn svg {
	width: 28px;
	height: 28px;
	fill: currentColor;
	transition:
		opacity var(--chat-transition-speed) ease,
		transform var(--chat-transition-speed) ease;
}

.chat-toggle-btn .chat-icon-close {
	display: none;
	transform: rotate(-90deg);
}

.chat-ui-open .chat-toggle-btn .chat-icon-open {
	display: none;
}

.chat-ui-open .chat-toggle-btn .chat-icon-close {
	display: block;
	transform: rotate(0);
}

/* === Chat Window === */
.chat-window {
	position: fixed;
	bottom: 130px;
	right: 24px;
	width: 350px;
	max-width: calc(100vw - 48px);
	height: 500px;
	max-height: calc(100vh - 120px);
	background-color: var(--chat-bg-color);
	border-radius: 16px;
	box-shadow: var(--chat-shadow);
	z-index: 9998;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-family: var(--chat-font-family);
	opacity: 0;
	pointer-events: none;
	transform: translateY(20px) scale(0.95);
	transform-origin: bottom right;
	transition:
		opacity var(--chat-transition-speed) ease,
		transform var(--chat-transition-speed) cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-ui-open .chat-window {
	opacity: 1;
	pointer-events: all;
	transform: translateY(0) scale(1);
	z-index: 10000;
}

/* === Chat Header === */
.chat-header {
	padding: 16px 20px;
	background: var(--chat-primary-color);
	color: white;
	display: flex;
	align-items: center;
	border-bottom: 1px solid rgba(255, 255, 255, 0.1);
	position: relative; /* 追加: ×ボタンの絶対配置のため */
	flex-shrink: 0;
}

.chat-avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background-color: white;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: 12px;
	overflow: hidden;
	flex-shrink: 0;
}

.chat-avatar svg {
	width: 24px;
	height: 24px;
	fill: var(--chat-primary-color);
}

.chat-title-group {
	display: flex;
	flex-direction: column;
	flex-grow: 1; /* 追加: タイトルの領域を広げる */
}

.chat-title {
	font-size: 16px;
	font-weight: 600;
	margin: 0;
	line-height: 1.2;
}

.chat-subtitle {
	font-size: 12px;
	opacity: 0.8;
	margin-top: 4px;
}

/* ヘッダーの閉じるボタン (PC/SP共通) */
.chat-mobile-close {
	background: none;
	border: none;
	color: white;
	cursor: pointer;
	padding: 8px;
	display: flex; /* ブロックからflexに変更して中央揃え */
	align-items: center;
	justify-content: center;
	opacity: 0.8;
	transition: opacity var(--chat-transition-speed);
	margin-left: auto; /* 右寄せ */
}

@media (hover: hover) and (pointer: fine) {
	.chat-mobile-close:hover {
		opacity: 1;
	}
}

/* === Chat Body === */
.chat-body {
	flex: 1;
	padding: 20px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 16px;
	background-color: #f9fafb;
}

/* Custom Scrollbar for Chat Body */
.chat-body::-webkit-scrollbar {
	width: 6px;
}
.chat-body::-webkit-scrollbar-track {
	background: transparent;
}
.chat-body::-webkit-scrollbar-thumb {
	background-color: rgba(0, 0, 0, 0.2);
	border-radius: 10px;
}

/* === Messages === */
.chat-message-wrapper {
	display: flex;
	flex-direction: column;
	animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.chat-message-bot {
	align-items: flex-start;
}

.chat-message-user {
	align-items: flex-end;
}

.chat-bubble {
	max-width: 85%;
	padding: 12px 16px;
	border-radius: 18px;
	font-size: 14px;
	line-height: 1.5;
	color: var(--chat-text-color);
	position: relative;
	word-wrap: break-word;
}

.chat-message-bot .chat-bubble {
	background-color: var(--chat-bot-msg-bg);
	border-bottom-left-radius: 4px;
}

.chat-message-user .chat-bubble {
	background-color: var(--chat-user-msg-bg);
	color: var(--chat-user-msg-text);
	border-bottom-right-radius: 4px;
}

/* === Options Container === */
.chat-options-container {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-top: 12px;
	width: 100%;
}

.chat-option-btn {
	background-color: white;
	border: 1px solid var(--chat-primary-color);
	color: var(--chat-primary-color);
	padding: 10px 16px;
	border-radius: 20px;
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	text-align: left;
	transition: all 0.2s ease;
	font-family: inherit;
}

@media (hover: hover) and (pointer: fine) {
	.chat-option-btn:hover {
		background-color: var(--chat-primary-color);
		color: white;
	}
}

/* Link Button (Final Step) */
.chat-link-btn {
	display: inline-block;
	background-color: var(--chat-primary-color);
	color: white;
	text-decoration: none;
	padding: 12px 20px;
	border-radius: 50px;
	font-size: 14px;
	font-weight: 600;
	text-align: center;
	margin-top: 12px;
	transition: background-color 0.2s ease;
	width: 100%;
	box-sizing: border-box;
}

@media (hover: hover) and (pointer: fine) {
	.chat-link-btn:hover {
		background-color: var(--chat-primary-hover);
		color: white; /* Ensure it stays white on hover */
	}
}

/* === Loading Indicator === */
.chat-typing-indicator {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 12px 16px;
	background-color: var(--chat-bot-msg-bg);
	border-radius: 18px;
	border-bottom-left-radius: 4px;
	width: fit-content;
	display: none;
}

.chat-typing-indicator.active {
	display: flex;
}

.chat-typing-dot {
	width: 6px;
	height: 6px;
	background-color: #9ca3af;
	border-radius: 50%;
	animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-typing-dot:nth-child(1) {
	animation-delay: -0.32s;
}
.chat-typing-dot:nth-child(2) {
	animation-delay: -0.16s;
}

@keyframes typingBounce {
	0%,
	80%,
	100% {
		transform: scale(0);
	}
	40% {
		transform: scale(1);
	}
}

/* Responsive adjustments */
@media (max-width: 480px) {
	.chat-window {
		top: 0;
		left: 0;
		bottom: auto;
		right: auto;
		width: 100%;
		height: 100%; /* fallback */
		height: 100dvh;
		max-width: none;
		max-height: none;
		border-radius: 0;
	}

	.chat-toggle-btn {
		bottom: 20px;
		right: 20px;
	}

	.chat-ui-open .chat-toggle-btn {
		display: none; /* Hide toggle button when full screen on mobile */
	}

	.circle-btn {
		position: fixed;
		right: -5px;
		bottom: -5px;
		width: 110px;
		height: 110px;
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
