/* JapanConnect AI Chat Widget */

#jc-ai-chat,
#jc-ai-chat * {
	box-sizing: border-box;
}

#jc-ai-chat {
	--jc-chat-accent: #0f6db4; /* wp_add_inline_style で上書き */
	--jc-chat-offset-x: 20px;
	--jc-chat-offset-y: 20px;
	--jc-chat-bg: #ffffff;
	--jc-chat-text: #1f2937;
	--jc-chat-muted: #6b7280;
	--jc-chat-user-bubble: var(--jc-chat-accent);
	--jc-chat-ai-bubble: #f3f4f6;
	position: fixed;
	bottom: var(--jc-chat-offset-y);
	right: var(--jc-chat-offset-x);
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
	font-size: 14px;
	line-height: 1.6;
}

/* 左下表示 */
#jc-ai-chat.jc-pos-left {
	right: auto;
	left: var(--jc-chat-offset-x);
}
#jc-ai-chat.jc-pos-left .jc-chat-panel {
	right: auto;
	left: 0;
}

/* hidden属性を確実に効かせる(テーマCSSやdisplay:flexに負けないように) */
#jc-ai-chat .jc-chat-panel[hidden] {
	display: none !important;
}

/* ---- ティーザーラベル ---- */
#jc-ai-chat .jc-chat-teaser {
	position: absolute;
	bottom: 12px;
	right: 66px;
	white-space: nowrap;
	padding: 9px 14px;
	border: none;
	border-radius: 999px;
	background: #ffffff;
	color: var(--jc-chat-text);
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 3px 14px rgba(0, 0, 0, 0.18);
	opacity: 0;
	animation: jc-teaser-in 0.35s ease 1.2s forwards, jc-teaser-bob 4s ease-in-out 2s infinite;
}
#jc-ai-chat .jc-chat-teaser::after {
	content: '';
	position: absolute;
	right: -5px;
	top: 50%;
	width: 10px;
	height: 10px;
	background: #ffffff;
	transform: translateY(-50%) rotate(45deg);
	box-shadow: 3px -3px 6px rgba(0, 0, 0, 0.05);
}
#jc-ai-chat .jc-chat-teaser:hover {
	box-shadow: 0 5px 18px rgba(0, 0, 0, 0.24);
}
#jc-ai-chat.jc-pos-left .jc-chat-teaser {
	right: auto;
	left: 66px;
}
#jc-ai-chat.jc-pos-left .jc-chat-teaser::after {
	right: auto;
	left: -5px;
}
@keyframes jc-teaser-in {
	from { opacity: 0; transform: translateX(8px); }
	to   { opacity: 1; transform: translateX(0); }
}
@keyframes jc-teaser-bob {
	0%, 100% { transform: translateY(0); }
	50% { transform: translateY(-3px); }
}

/* ---- トグルボタン ---- */
#jc-ai-chat .jc-chat-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: var(--jc-chat-accent);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#jc-ai-chat .jc-chat-toggle:hover {
	transform: scale(1.06);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
#jc-ai-chat .jc-chat-toggle:focus-visible {
	outline: 3px solid var(--jc-chat-accent);
	outline-offset: 3px;
}
#jc-ai-chat .jc-icon-close { display: none; }
#jc-ai-chat.jc-open .jc-icon-chat { display: none; }
#jc-ai-chat.jc-open .jc-icon-close { display: block; }

/* ---- パネル ---- */
#jc-ai-chat .jc-chat-panel {
	position: absolute;
	bottom: 72px;
	right: 0;
	width: 370px;
	max-width: calc(100vw - 40px);
	height: 540px;
	max-height: calc(100vh - 120px);
	display: flex;
	flex-direction: column;
	background: var(--jc-chat-bg);
	border-radius: 16px;
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
	overflow: hidden;
	animation: jc-panel-in 0.2s ease;
}
@keyframes jc-panel-in {
	from { opacity: 0; transform: translateY(8px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ---- ヘッダー ---- */
#jc-ai-chat .jc-chat-header {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 14px 16px;
	background: var(--jc-chat-accent);
	color: #fff;
	font-weight: 600;
	font-size: 15px;
}
#jc-ai-chat .jc-chat-status {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
	flex-shrink: 0;
}
#jc-ai-chat .jc-chat-title {
	flex: 1;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
#jc-ai-chat .jc-chat-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	flex-shrink: 0;
}
#jc-ai-chat .jc-chat-actions button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	border: none;
	border-radius: 6px;
	background: transparent;
	color: #fff;
	cursor: pointer;
	opacity: 0.85;
	transition: background 0.15s ease, opacity 0.15s ease;
}
#jc-ai-chat .jc-chat-actions button:hover {
	background: rgba(255, 255, 255, 0.18);
	opacity: 1;
}
#jc-ai-chat .jc-chat-actions button:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 1px;
}

/* ---- 拡大表示 ---- */
#jc-ai-chat.jc-large .jc-chat-panel {
	width: 550px;
	height: 780px;
}
#jc-ai-chat .jc-chat-panel {
	transition: width 0.2s ease, height 0.2s ease;
}
#jc-ai-chat .jc-icon-collapse { display: none; }
#jc-ai-chat.jc-large .jc-icon-expand { display: none; }
#jc-ai-chat.jc-large .jc-icon-collapse { display: block; }

/* ---- メッセージ ---- */
#jc-ai-chat .jc-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	-webkit-overflow-scrolling: touch;
}
#jc-ai-chat .jc-msg {
	display: flex;
}
#jc-ai-chat .jc-msg-user { justify-content: flex-end; }
#jc-ai-chat .jc-msg-assistant { justify-content: flex-start; }

#jc-ai-chat .jc-msg-bubble {
	max-width: 82%;
	padding: 9px 13px;
	border-radius: 14px;
	color: var(--jc-chat-text);
	word-break: break-word;
	overflow-wrap: anywhere;
}
#jc-ai-chat .jc-msg-user .jc-msg-bubble {
	background: var(--jc-chat-user-bubble);
	color: #fff;
	border-bottom-right-radius: 4px;
}
#jc-ai-chat .jc-msg-assistant .jc-msg-bubble {
	background: var(--jc-chat-ai-bubble);
	border-bottom-left-radius: 4px;
}
#jc-ai-chat .jc-msg-bubble a {
	color: inherit;
	text-decoration: underline;
}
#jc-ai-chat .jc-msg-img {
	display: block;
	max-width: 100%;
	border-radius: 8px;
	margin: 6px 0 2px;
	border: 1px solid #e5e7eb;
}
#jc-ai-chat .jc-msg-in {
	animation: jc-msg-in 0.18s ease;
}
@keyframes jc-msg-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ---- タイピングインジケーター ---- */
#jc-ai-chat .jc-typing .jc-msg-bubble {
	display: flex;
	gap: 4px;
	padding: 13px 15px;
}
#jc-ai-chat .jc-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--jc-chat-muted);
	animation: jc-bounce 1.2s infinite;
}
#jc-ai-chat .jc-typing span:nth-child(2) { animation-delay: 0.15s; }
#jc-ai-chat .jc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes jc-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- 入力フォーム ---- */
#jc-ai-chat .jc-chat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #e5e7eb;
}
#jc-ai-chat .jc-chat-input {
	flex: 1;
	border: 1px solid #d1d5db;
	border-radius: 10px;
	padding: 9px 12px;
	font: inherit;
	font-size: 16px; /* 重要: iOSは16px未満の入力欄にフォーカスするとページを自動ズームし、ズームが残留する */
	color: var(--jc-chat-text);
	resize: none;
	max-height: 120px;
	background: #fff;
}
#jc-ai-chat .jc-chat-input:focus {
	outline: none;
	border-color: var(--jc-chat-accent);
	box-shadow: 0 0 0 2px color-mix(in srgb, var(--jc-chat-accent) 25%, transparent);
}
#jc-ai-chat .jc-chat-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 10px;
	background: var(--jc-chat-accent);
	color: #fff;
	cursor: pointer;
	flex-shrink: 0;
	transition: opacity 0.15s ease;
}
#jc-ai-chat .jc-chat-send:disabled {
	opacity: 0.45;
	cursor: default;
}
#jc-ai-chat .jc-chat-send:focus-visible {
	outline: 3px solid var(--jc-chat-accent);
	outline-offset: 2px;
}

/* ---- フッター ---- */
#jc-ai-chat .jc-chat-footer {
	padding: 6px 12px 9px;
	text-align: center;
	font-size: 11px;
	color: var(--jc-chat-muted);
}

/* ---- モバイル: フルスクリーンシート ---- */
/* ---- モバイル: ボトムシート(通常) ⇄ フルスクリーン(拡大) ---- */
@media (max-width: 480px) {
	#jc-ai-chat .jc-chat-panel {
		position: fixed;
		left: 0;
		right: auto;
		bottom: 0;
		/* ページに横はみ出しがあってもビューポート幅にピン留めする */
		width: 100vw;
		max-width: 100vw;
		height: 65vh;
		height: 65svh; /* iOS SafariのURLバー伸縮でもはみ出さない最小可視領域基準 */
		max-height: 100svh;
		border-radius: 16px 16px 0 0;
		transition: none;
	}
	#jc-ai-chat.jc-large .jc-chat-panel {
		height: 100vh;
		height: 100svh;
		height: 100dvh;
		border-radius: 0;
	}
	/* パネル表示中は右下ボタンを隠す(閉じるはヘッダーの✕で) */
	#jc-ai-chat.jc-open .jc-chat-toggle {
		display: none;
	}
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
	#jc-ai-chat .jc-chat-panel,
	#jc-ai-chat .jc-msg-in,
	#jc-ai-chat .jc-typing span {
		animation: none;
	}
	#jc-ai-chat .jc-chat-teaser {
		animation: none;
		opacity: 1;
	}
}

/* ---- チャット表示中は背面ページのスクロールをロック(モバイル) ---- */
@media (max-width: 480px) {
	body.jc-ai-chat-open {
		overflow: hidden;
		touch-action: none;
	}
	body.jc-ai-chat-open .jc-chat-messages {
		touch-action: pan-y;
	}
	body.jc-ai-chat-open .jc-chat-input {
		touch-action: auto;
	}
}

/* ---- キオスクモード(専用全画面ページ) ---- */
#jc-ai-chat.jc-kiosk-mode .jc-chat-toggle,
#jc-ai-chat.jc-kiosk-mode .jc-chat-teaser,
#jc-ai-chat.jc-kiosk-mode .jc-chat-close,
#jc-ai-chat.jc-kiosk-mode .jc-chat-resize {
	display: none !important;
}
#jc-ai-chat.jc-kiosk-mode .jc-chat-panel {
	position: fixed;
	inset: 0;
	width: 100vw;
	max-width: 100vw;
	height: 100vh;
	height: 100svh;
	height: 100dvh;
	max-height: none;
	border-radius: 0;
}
#jc-ai-chat.jc-kiosk-mode {
	font-size: 16px; /* タッチパネル向けに大きめ */
}
#jc-ai-chat.jc-kiosk-mode .jc-chat-header {
	font-size: 17px;
	padding: 18px 20px;
}
#jc-ai-chat.jc-kiosk-mode .jc-chat-send {
	width: 48px;
	height: 48px;
}
