/* きいてね! ウィジェット */
.kiitene, .kiitene * { box-sizing: border-box; }
.kiitene {
	--kt-color: #ff7a45;
	--kt-bg: #ffffff;
	--kt-text: #1f2328;
	--kt-sub: #6b7280;
	--kt-line: #e8e8ec;
	--kt-bot: #f4f4f6;
	font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
	font-size: 14px;
	line-height: 1.65;
	color: var(--kt-text);
}
.kiitene button { font: inherit; cursor: pointer; }
.kiitene svg { width: 20px; height: 20px; display: block; }

/* フローティング */
.kiitene--float { position: fixed; bottom: 20px; right: 20px; z-index: 999999; }
.kiitene--left { left: 20px; right: auto; }
/* ボタンの位置に合わせて、ボタンの並び（文字の向き）を揃える */
.kiitene--float[data-h="left"] { text-align: left; }

.kt-launcher {
	display: flex; align-items: center; gap: 8px;
	background: var(--kt-color); color: #fff; border: 0;
	padding: 12px 18px 12px 14px; border-radius: 999px;
	box-shadow: 0 8px 24px rgba(0,0,0,.18);
	font-weight: 700; letter-spacing: .02em;
	transition: transform .15s ease, box-shadow .15s ease;
}
.kt-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,.22); }
.kt-launcher svg { width: 24px; height: 24px; flex: none; }
.kt-launcher-img { display: block; flex: none; object-fit: cover; }

/* アイコン＋文字 */
.kt-launcher--pill .kt-launcher-img { width: 30px; height: 30px; border-radius: 50%; background: #fff; margin: -4px 0 -4px -4px; }
.kt-launcher--pill.kt-launcher--s { padding: 8px 14px 8px 10px; font-size: 13px; }
.kt-launcher--pill.kt-launcher--s svg { width: 20px; height: 20px; }
.kt-launcher--pill.kt-launcher--s .kt-launcher-img { width: 24px; height: 24px; }
.kt-launcher--pill.kt-launcher--l { padding: 15px 24px 15px 18px; font-size: 17px; gap: 10px; }
.kt-launcher--pill.kt-launcher--l svg { width: 30px; height: 30px; }
.kt-launcher--pill.kt-launcher--l .kt-launcher-img { width: 40px; height: 40px; }

/* 丸いボタン */
.kt-launcher--circle { width: 60px; height: 60px; padding: 0; justify-content: center; border-radius: 50%; overflow: hidden; }
.kt-launcher--circle.kt-launcher--s { width: 50px; height: 50px; }
.kt-launcher--circle.kt-launcher--l { width: 76px; height: 76px; }
.kt-launcher--circle svg { width: 50%; height: 50%; }
.kt-launcher--circle .kt-launcher-img { width: 100%; height: 100%; }

/* 画像だけ（背景なし） */
.kt-launcher--image { background: none; padding: 0; border-radius: 0; box-shadow: none; filter: drop-shadow(0 6px 12px rgba(0,0,0,.25)); }
.kt-launcher--image:hover { box-shadow: none; filter: drop-shadow(0 10px 16px rgba(0,0,0,.3)); }
.kt-launcher--image .kt-launcher-img { width: 80px; height: auto; max-height: 120px; object-fit: contain; }
.kt-launcher--image.kt-launcher--s .kt-launcher-img { width: 60px; max-height: 90px; }
.kt-launcher--image.kt-launcher--l .kt-launcher-img { width: 110px; max-height: 160px; }
.kiitene--float.is-open .kt-launcher { display: none; }

.kt-panel {
	display: none; flex-direction: column;
	background: var(--kt-bg); border-radius: 18px; overflow: hidden;
	box-shadow: 0 16px 48px rgba(0,0,0,.22);
}
.kiitene--float .kt-panel { width: min(380px, calc(100vw - 24px)); height: min(620px, var(--kt-avail, calc(100vh - 40px))); }
.kiitene--float.is-open .kt-panel { display: flex; animation: kt-pop .18s ease-out; }
@keyframes kt-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.kiitene--inline { height: 100%; }
.kiitene--inline .kt-panel { display: flex; height: 100%; border: 1px solid var(--kt-line); box-shadow: none; }

/* ヘッダー */
.kt-header {
	display: flex; align-items: center; gap: 10px;
	padding: 12px 12px 12px 14px; background: var(--kt-color); color: #fff;
}
.kt-avatar {
	width: 36px; height: 36px; border-radius: 50%; flex: none;
	background: rgba(255,255,255,.22); display: grid; place-items: center; overflow: hidden;
}
.kt-avatar img { width: 100%; height: 100%; object-fit: cover; }
.kt-title { flex: 1; min-width: 0; line-height: 1.3; }
.kt-title b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kt-title small { opacity: .85; font-size: 11px; }
.kt-hbtn {
	background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 999px;
	height: 32px; display: flex; align-items: center; gap: 4px; padding: 0 10px; font-size: 12px; font-weight: 700;
}
.kt-hbtn:hover { background: rgba(255,255,255,.3); }
.kt-hbtn.kt-icon { width: 32px; padding: 0; justify-content: center; }
.kt-hbtn svg { width: 16px; height: 16px; }
.is-voicemode .kt-voicemode { background: #fff; color: var(--kt-color); }

/* ログ */
.kt-log { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.kt-row { display: flex; align-items: flex-end; gap: 4px; max-width: 88%; }
.kt-user { align-self: flex-end; }
.kt-assistant { align-self: flex-start; }
.kt-bubble { padding: 9px 13px; border-radius: 16px; word-break: break-word; }
.kt-user .kt-bubble { background: var(--kt-color); color: #fff; border-bottom-right-radius: 4px; }
.kt-assistant .kt-bubble { background: var(--kt-bot); border-bottom-left-radius: 4px; }
.kt-bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.kt-speak { background: none; border: 0; color: var(--kt-sub); padding: 4px; opacity: .6; }
.kt-speak:hover { opacity: 1; color: var(--kt-color); }
.kt-speak svg { width: 16px; height: 16px; }
.kt-note { align-self: center; font-size: 12px; color: #b42318; background: #fef3f2; padding: 6px 12px; border-radius: 10px; }

.kt-typing .kt-bubble { display: flex; gap: 4px; padding: 13px 14px; }
.kt-typing i { width: 7px; height: 7px; border-radius: 50%; background: #a0a3ab; animation: kt-dot 1.2s infinite; }
.kt-typing i:nth-child(2) { animation-delay: .15s; }
.kt-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes kt-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* 候補 */
.kt-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.kt-chip {
	background: #fff; border: 1px solid var(--kt-color); color: var(--kt-color);
	border-radius: 999px; padding: 5px 12px; font-size: 13px;
}
.kt-chip:hover { background: var(--kt-color); color: #fff; }

/* 音声バー */
.kt-voicebar { display: none; align-items: center; gap: 10px; margin: 0 12px 8px; padding: 10px 12px; border-radius: 12px; background: var(--kt-bot); cursor: pointer; }
.is-listening .kt-voicebar, .is-voicemode .kt-voicebar, .is-speaking .kt-voicebar { display: flex; }
.kt-voicetext { flex: 1; font-size: 13px; color: var(--kt-sub); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kt-stop { background: none; border: 1px solid var(--kt-line); border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--kt-sub); }
.kiitene:not(.is-voicemode) .kt-stop { display: none; }
.kt-wave { display: flex; align-items: center; gap: 3px; height: 20px; }
.kt-wave i { width: 3px; height: 6px; border-radius: 2px; background: var(--kt-color); }
.is-listening .kt-wave i, .is-speaking .kt-wave i { animation: kt-wave .9s ease-in-out infinite; }
.kt-wave i:nth-child(2) { animation-delay: .1s; }
.kt-wave i:nth-child(3) { animation-delay: .2s; }
.kt-wave i:nth-child(4) { animation-delay: .3s; }
.kt-wave i:nth-child(5) { animation-delay: .4s; }
@keyframes kt-wave { 0%, 100% { height: 6px; } 50% { height: 20px; } }

/* 入力欄 */
.kt-form { display: flex; align-items: flex-end; gap: 6px; padding: 10px 10px 8px; border-top: 1px solid var(--kt-line); }
.kt-input {
	flex: 1; resize: none; border: 1px solid var(--kt-line); border-radius: 20px;
	padding: 8px 14px; font: inherit; color: inherit; background: #fff; max-height: 120px; outline: none; line-height: 1.5;
	margin: 0; min-height: 0;
}
.kt-input:focus { border-color: var(--kt-color); }
.kt-mic, .kt-send {
	width: 38px; height: 38px; border-radius: 50%; border: 0; flex: none;
	display: grid; place-items: center; padding: 0;
}
.kt-mic { background: var(--kt-bot); color: var(--kt-sub); }
.kt-mic:hover { color: var(--kt-color); }
.is-listening .kt-mic { background: #e5484d; color: #fff; animation: kt-pulse 1.2s infinite; }
@keyframes kt-pulse { 0% { box-shadow: 0 0 0 0 rgba(229,72,77,.5); } 100% { box-shadow: 0 0 0 12px rgba(229,72,77,0); } }
.kt-send { background: var(--kt-color); color: #fff; }
.kt-send:disabled { opacity: .45; cursor: default; }

.kt-foot { font-size: 10.5px; color: var(--kt-sub); text-align: center; padding: 0 12px 10px; }
.kt-foot a { color: var(--kt-color); font-weight: 700; }

/* 問い合わせフォーム */
.kt-inq {
	align-self: stretch; border: 1px solid var(--kt-line); border-radius: 14px; padding: 12px 14px;
	display: flex; flex-direction: column; gap: 8px; background: #fffaf7;
}
.kt-inq label { display: flex; flex-direction: column; font-size: 12px; color: var(--kt-sub); gap: 2px; }
.kt-inq input, .kt-inq textarea {
	font: inherit; font-size: 14px; color: var(--kt-text); border: 1px solid var(--kt-line);
	border-radius: 8px; padding: 6px 10px; background: #fff; margin: 0;
}
.kt-inq .kt-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.kt-inq-actions { display: flex; gap: 8px; }
.kt-inq-actions button { border: 0; border-radius: 999px; padding: 6px 16px; font-weight: 700; }
.kt-inq-actions [type=submit] { background: var(--kt-color); color: #fff; }
.kt-inq-actions .kt-cancel { background: transparent; color: var(--kt-sub); }
.kt-inq.is-done p { margin: 0; font-size: 13px; }

/* スマホ：全画面 */
@media (max-width: 600px) {
	.kiitene--float.is-open { inset: 0; transform: none; }
	.kiitene--float .kt-panel { width: 100vw; height: 100dvh; border-radius: 0; }
	.kt-hbtn span { display: none; }
	.kt-voicemode { width: 32px; padding: 0; justify-content: center; }
	.kt-input { font-size: 16px; } /* iOSのズーム防止 */
}

@media (prefers-reduced-motion: reduce) {
	.kiitene * { animation: none !important; transition: none !important; }
}

/* ストリーミング中のカーソル */
.kt-streaming::after {
	content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px;
	vertical-align: -2px; background: currentColor; opacity: .5; animation: kt-blink 1s steps(2) infinite;
}
@keyframes kt-blink { 50% { opacity: 0; } }

.kt-credit { display: block; margin-top: 2px; opacity: .8; }

/* 動作記録（?kiitene_debug=1 のときだけ表示） */
.kt-debug { position: fixed; left: 8px; top: 8px; z-index: 1000000; width: min(520px, calc(100vw - 16px)); background: rgba(20,20,20,.92); color: #b9f6ca; border-radius: 8px; font: 11px/1.45 ui-monospace, Menlo, Consolas, monospace; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.kt-debug-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; color: #fff; font-weight: 700; border-bottom: 1px solid #444; }
.kt-debug-head button { font: inherit; padding: 2px 8px; border-radius: 4px; border: 0; cursor: pointer; }
.kt-debug pre { margin: 0; padding: 6px 8px; max-height: 40vh; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* Google 音声認識：マイクの音量に合わせて波形が動く */
.kiitene.is-stt.is-listening .kt-wave i { animation: none; height: calc(4px + 16px * var(--kt-level, 0)); transition: height .08s linear; }
.kiitene.is-stt.is-listening .kt-wave i:nth-child(2), .kiitene.is-stt.is-listening .kt-wave i:nth-child(4) { height: calc(4px + 12px * var(--kt-level, 0)); }
.kiitene.is-stt.is-listening .kt-mic { animation: none; box-shadow: 0 0 0 calc(10px * var(--kt-level, 0)) rgba(229,72,77,.25); }

/* 回答への評価 */
.kt-fb { align-self: flex-start; display: flex; align-items: center; gap: 4px; margin: -4px 0 2px 4px; font-size: 11px; color: var(--kt-sub); }
.kt-fb button { background: none; border: 1px solid var(--kt-line); border-radius: 999px; padding: 1px 8px; font-size: 12px; line-height: 1.6; cursor: pointer; }
.kt-fb button:hover { border-color: var(--kt-color); }
.kt-fb a { color: var(--kt-color); font-weight: 700; }
