/**
 * Travelers Route ナビ — チャットボットウィジェット。
 *
 * サイトのデザイン言語（frost-child）に準拠:
 * - 見出し: セリフ（Playfair Display / Noto Serif JP）、本文 UI: Inter / Noto Sans JP
 * - ボタン: 角丸 2px・letter-spacing・accent → hover で primary（theme.json の button と同じ）
 * - カード: 左 3px アクセントボーダー + hover で浮き上がり（.tr-toc / .tr-category-card と同型）
 * - スクロールバー: 細身・rule 色（style.css のサイト共通スタイルと同型）
 */
.trcb-launcher,
.trcb-panel,
.trcb-hint {
	--trcb-primary: var(--wp--preset--color--tr-primary, #1f3a5f);
	--trcb-accent: var(--wp--preset--color--tr-accent, #2a8e89);
	--trcb-ink: var(--wp--preset--color--tr-ink, #1a2332);
	--trcb-ink-soft: var(--wp--preset--color--tr-ink-soft, #4a5160);
	--trcb-muted: var(--wp--preset--color--tr-muted, #6f6862);
	--trcb-surface: var(--wp--preset--color--tr-surface, #ffffff);
	--trcb-surface-soft: var(--wp--preset--color--tr-surface-soft, #fafaf9);
	--trcb-surface-deep: var(--wp--preset--color--tr-surface-deep, #f2f1ed);
	--trcb-rule: var(--wp--preset--color--tr-rule, #e5e3dd);
	--trcb-font: var(--wp--preset--font-family--inter, 'Inter', 'Noto Sans JP', sans-serif);
	--trcb-serif: var(--wp--preset--font-family--playfair, 'Playfair Display', 'Noto Serif JP', serif);
	font-family: var(--trcb-font);
	box-sizing: border-box;
}

.trcb-panel *,
.trcb-panel *::before,
.trcb-panel *::after {
	box-sizing: border-box;
}

/* ---------- launcher ---------- */

.trcb-launcher {
	position: fixed;
	right: 20px;
	bottom: 20px;
	/* ★Cookie バナー（99988）より下。バナーは画面右下に出るため、ランチャーとヒントが
	   同意/拒否ボタンの上に乗ると押せなくなる（モバイル実測: 拒否ボタンの押下点3/3が
	   遮られていた）。同意取得を妨げないことを優先し、バナー表示中はチャット側を譲る。
	   パネル(.trcb-panel)は開いたら最前面でよいので 99991 のまま。 */
	z-index: 99987;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: var(--trcb-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 16px rgba(26, 35, 50, 0.22);
	transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.trcb-launcher:hover,
.trcb-launcher:focus-visible {
	background: var(--trcb-primary);
	transform: translateY(-2px);
	box-shadow: 0 8px 24px rgba(26, 35, 50, 0.28);
}

.trcb-launcher.trcb-hidden {
	display: none;
}

/* スクロール中は縮めて薄くする（chatbot.js の bindScrollShrink）。
   固定要素なのでモバイルではカードの右下に必ず重なり、本文が読めない箇所ができる。
   位置を動かすと「いつもの場所」が失われるため、指が動いている間だけ譲る。
   指が止まれば 450ms で 56px へ戻るので、タップ領域は実質損なわれない。 */
.trcb-launcher.is-scrolling {
	transform: scale(0.62);
	opacity: 0.5;
	box-shadow: none;
}

/* ---------- ヒント（ランチャーの左横に表示。真上は目次 FAB の定位置のため） ---------- */

.trcb-hint {
	position: fixed;
	right: 88px;
	bottom: 33px;
	z-index: 99987;   /* ランチャーと同じ理由で Cookie バナーより下げる */
	display: flex;
	align-items: stretch;
	background: var(--trcb-surface);
	border: 1px solid var(--trcb-rule);
	border-left: 3px solid var(--trcb-accent);
	border-radius: 6px;
	box-shadow: 0 6px 20px rgba(26, 35, 50, 0.16);
	color: var(--trcb-ink);
	font-size: 12.5px;
	font-weight: 500;
	white-space: nowrap;
	animation: trcb-in 0.25s ease-out;
}

.trcb-hint-main {
	border: none;
	background: transparent;
	font: inherit;
	color: inherit;
	cursor: pointer;
	padding: 9px 4px 9px 14px;
}

.trcb-hint-close {
	border: none;
	background: transparent;
	color: var(--trcb-muted);
	cursor: pointer;
	font-size: 15px;
	line-height: 1;
	padding: 9px 10px 9px 6px;
	transition: color 0.15s ease;
}

.trcb-hint-close:hover,
.trcb-hint-close:focus-visible {
	color: var(--trcb-ink);
}

/* ランチャー側を指す吹き出しの矢印 */
.trcb-hint::after {
	content: '';
	position: absolute;
	right: -6px;
	top: 50%;
	width: 10px;
	height: 10px;
	transform: translateY(-50%) rotate(45deg);
	background: var(--trcb-surface);
	border-top: 1px solid var(--trcb-rule);
	border-right: 1px solid var(--trcb-rule);
}

/* ---------- backdrop（モバイルのみ表示・タップで閉じる） ---------- */

.trcb-backdrop {
	display: none;
}

@media (max-width: 600px) {
	.trcb-backdrop:not([hidden]) {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 99990;
		background: rgba(26, 35, 50, 0.35);
	}
}

/* ---------- panel ---------- */

/* display: flex が UA の [hidden] { display: none } より優先されるため、
 * hidden 属性での開閉を author CSS 側でも明示する（× / Esc で閉じるための必須ルール） */
.trcb-panel[hidden] {
	display: none;
}

.trcb-panel {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99991;
	width: 372px;
	max-width: calc(100vw - 40px);
	height: 580px;
	max-height: calc(100vh - 40px);
	max-height: calc(100dvh - 40px);
	display: flex;
	flex-direction: column;
	background: var(--trcb-surface);
	border: 1px solid var(--trcb-rule);
	border-top: 3px solid var(--trcb-accent);
	border-radius: 4px;
	box-shadow: 0 12px 40px rgba(26, 35, 50, 0.18);
	overflow: hidden;
	font-size: 14px;
	line-height: 1.7;
	color: var(--trcb-ink);
	outline: none;
}

/* ---------- header（サイトヘッダーと同型: 白地 + セリフロゴ + 下罫線） ---------- */

.trcb-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px 12px;
	background: var(--trcb-surface);
	border-bottom: 1px solid var(--trcb-rule);
	flex-shrink: 0;
}

.trcb-heading {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.trcb-title {
	font-family: var(--trcb-serif);
	font-size: 17px;
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.005em;
	color: var(--trcb-ink);
}

.trcb-subtitle {
	font-size: 11px;
	font-weight: 500;
	letter-spacing: 0.12em;
	color: var(--trcb-accent);
}

.trcb-actions {
	display: flex;
	gap: 4px;
	flex-shrink: 0;
}

.trcb-icon-btn {
	width: 30px;
	height: 30px;
	border: none;
	border-radius: 2px;
	background: transparent;
	color: var(--trcb-ink-soft);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.trcb-icon-btn:hover,
.trcb-icon-btn:focus-visible {
	background: var(--trcb-surface-deep);
	color: var(--trcb-ink);
}

/* ---------- messages ---------- */

.trcb-messages {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 14px;
	background: var(--trcb-surface-soft);
	display: flex;
	flex-direction: column;
	gap: 8px;
	scrollbar-width: thin;
	scrollbar-color: var(--trcb-rule) transparent;
}

.trcb-messages::-webkit-scrollbar {
	width: 6px;
}

.trcb-messages::-webkit-scrollbar-track {
	background: transparent;
}

.trcb-messages::-webkit-scrollbar-thumb {
	background: var(--trcb-rule);
	border-radius: 2px;
}

.trcb-messages::-webkit-scrollbar-thumb:hover {
	background: var(--trcb-muted);
}

.trcb-msg {
	max-width: 86%;
	padding: 9px 13px;
	border-radius: 4px;
	white-space: pre-wrap;
	word-break: break-word;
	animation: trcb-in 0.2s ease-out;
}

.trcb-bot {
	position: relative;
	align-self: flex-start;
	margin-left: 34px;
	background: var(--trcb-surface);
	border: 1px solid var(--trcb-rule);
	color: var(--trcb-ink);
}

/* ボット発言グループの先頭にだけアバター（セリフ体 T モノグラム） */
.trcb-bot.trcb-first::before {
	content: 'T';
	position: absolute;
	left: -34px;
	top: 0;
	width: 26px;
	height: 26px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--trcb-primary);
	border-radius: 50%;
	color: #fff;
	font-family: var(--trcb-serif);
	font-size: 14px;
	font-weight: 700;
	line-height: 1;
}

.trcb-user {
	align-self: flex-end;
	background: var(--trcb-primary);
	color: #fff;
}

@keyframes trcb-in {
	from {
		opacity: 0;
		transform: translateY(4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ---------- タイピングインジケータ ---------- */

.trcb-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	min-height: 38px;
}

.trcb-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--trcb-muted);
	animation: trcb-bounce 1.1s ease-in-out infinite;
}

.trcb-dot:nth-child(2) {
	animation-delay: 0.15s;
}

.trcb-dot:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes trcb-bounce {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.5;
	}
	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* ---------- link cards（.tr-toc / .tr-category-card と同型: 左アクセント + 浮き上がり） ---------- */

.trcb-links,
.trcb-asp {
	display: flex;
	flex-direction: column;
	gap: 6px;
	align-self: stretch;
	animation: trcb-in 0.2s ease-out;
}

.trcb-link-card {
	display: block;
	position: relative;
	padding: 10px 30px 10px 12px;
	background: var(--trcb-surface);
	border: 1px solid var(--trcb-rule);
	border-left: 3px solid var(--trcb-accent);
	border-radius: 0 2px 2px 0;
	color: var(--trcb-ink);
	text-decoration: none;
	font-size: 13px;
	font-weight: 500;
	line-height: 1.55;
	transition: transform 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.trcb-link-card::after {
	content: '→';
	position: absolute;
	right: 11px;
	top: 50%;
	transform: translateY(-50%);
	color: var(--trcb-accent);
	font-weight: 700;
	transition: transform 0.2s ease;
}

.trcb-link-card:hover,
.trcb-link-card:focus-visible {
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(26, 35, 50, 0.08);
	color: var(--trcb-accent);
}

.trcb-link-card:hover::after {
	transform: translateY(-50%) translateX(2px);
}

/* ---------- ASP ボタン（theme.json の button と同型: accent → hover primary・角丸 2px） ---------- */

.trcb-asp-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 11px 13px;
	background: var(--trcb-accent);
	border-radius: 2px;
	color: #fff;
	text-decoration: none;
	font-size: 12.5px;
	font-weight: 600;
	letter-spacing: 0.05em;
	line-height: 1.5;
	transition: background-color 0.2s ease;
}

.trcb-asp-btn:hover,
.trcb-asp-btn:focus-visible {
	background: var(--trcb-primary);
	color: #fff;
}

.trcb-pr-badge {
	flex-shrink: 0;
	font-size: 9.5px;
	font-weight: 700;
	letter-spacing: 0.08em;
	padding: 2px 5px;
	border-radius: 2px;
	background: rgba(255, 255, 255, 0.92);
	color: var(--trcb-ink);
}

/* ---------- 選択肢チップ（会話フロー内・.tr-value-prop と同型のピル） ---------- */

.trcb-choices {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	align-self: stretch;
	padding: 2px 0 0;
	animation: trcb-in 0.2s ease-out;
}

.trcb-choice {
	padding: 8px 14px;
	border: 1px solid var(--trcb-rule);
	border-radius: 999px;
	background: var(--trcb-surface);
	color: var(--trcb-primary);
	font-size: 12.5px;
	font-weight: 500;
	font-family: inherit;
	line-height: 1.5;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.trcb-choice:hover,
.trcb-choice:focus-visible {
	background: var(--trcb-accent);
	border-color: var(--trcb-accent);
	color: #fff;
	transform: translateY(-1px);
}

/* 質問例チップ（押すと自由入力として送信される） */
.trcb-choice.trcb-example {
	border-style: dashed;
	background: transparent;
	color: var(--trcb-ink-soft);
}

.trcb-choice.trcb-example:hover,
.trcb-choice.trcb-example:focus-visible {
	border-style: solid;
	background: var(--trcb-accent);
	border-color: var(--trcb-accent);
	color: #fff;
}

/* ---------- フィードバック（役に立った？） ---------- */

.trcb-feedback {
	flex-basis: 100%;
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 4px;
	padding-top: 8px;
	border-top: 1px dashed var(--trcb-rule);
}

.trcb-feedback-label {
	font-size: 11px;
	color: var(--trcb-muted);
}

.trcb-feedback-btn {
	width: 30px;
	height: 30px;
	border: 1px solid var(--trcb-rule);
	border-radius: 999px;
	background: var(--trcb-surface);
	font-size: 14px;
	line-height: 1;
	cursor: pointer;
	transition: transform 0.15s ease, border-color 0.15s ease;
}

.trcb-feedback-btn:hover,
.trcb-feedback-btn:focus-visible {
	transform: translateY(-1px);
	border-color: var(--trcb-accent);
}

/* ---------- input ---------- */

.trcb-form {
	flex-shrink: 0;
	display: flex;
	gap: 8px;
	padding: 10px 14px;
	background: var(--trcb-surface);
	border-top: 1px solid var(--trcb-rule);
}

.trcb-input {
	flex: 1;
	min-width: 0;
	padding: 9px 12px;
	border: 1px solid var(--trcb-rule);
	border-radius: 2px;
	font-size: 13px;
	font-family: inherit;
	line-height: 1.5;
	color: var(--trcb-ink);
	background: var(--trcb-surface);
}

.trcb-input::placeholder {
	color: var(--trcb-muted);
}

.trcb-input:focus {
	outline: 2px solid var(--trcb-accent);
	outline-offset: -1px;
}

.trcb-send {
	flex-shrink: 0;
	padding: 9px 16px;
	border: none;
	border-radius: 2px;
	background: var(--trcb-accent);
	color: #fff;
	font-size: 12.5px;
	font-weight: 600;
	font-family: inherit;
	letter-spacing: 0.05em;
	cursor: pointer;
	transition: background-color 0.2s ease, opacity 0.2s ease;
}

/* 入力が空の間は減光して状態を伝える（無効化はしない: Enter 送信を妨げないため） */
.trcb-send.trcb-idle {
	opacity: 0.45;
}

.trcb-send:hover,
.trcb-send:focus-visible {
	background: var(--trcb-primary);
	opacity: 1;
}

/* ---------- footer note ---------- */

.trcb-foot {
	flex-shrink: 0;
	padding: 7px 14px;
	background: var(--trcb-surface-deep);
	border-top: 1px solid var(--trcb-rule);
	color: var(--trcb-muted);
	font-size: 11px;
	line-height: 1.55;
	letter-spacing: 0.01em;
}

/* ---------- mobile（ボトムシート） ---------- */

@media (max-width: 600px) {
	.trcb-panel {
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		max-width: 100%;
		height: 88vh;
		height: 88dvh;
		max-height: none;
		border-radius: 10px 10px 0 0;
		border-left: none;
		border-right: none;
		border-bottom: none;
	}

	/* タップターゲット 44px 確保（サイトのモバイル UX 方針と同様） */
	.trcb-choice {
		padding: 12px 16px;
		font-size: 13px;
		min-height: 44px;
	}

	.trcb-input,
	.trcb-send {
		padding-top: 11px;
		padding-bottom: 11px;
	}
}

/* ---------- reduced motion（サイト共通方針に準拠） ---------- */

@media (prefers-reduced-motion: reduce) {
	.trcb-launcher,
	.trcb-msg,
	.trcb-links,
	.trcb-asp,
	.trcb-choice,
	.trcb-choices,
	.trcb-link-card,
	.trcb-hint,
	.trcb-dot {
		animation: none;
		transition: none;
	}
}
