/* AI Chat Assistant - ウィジェットスタイル */

#aica-root {
	--aica-primary: #2563eb;
	--aica-ink: #1f2937;
	--aica-panel-bg: #f7f8fa;
	position: fixed;
	right: 22px;
	bottom: 22px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
	font-size: 14px;
	line-height: 1.65;
	color: var(--aica-ink);
}

/* box-sizing は通常の詳細度で確実に適用 */
#aica-root,
#aica-root *,
#aica-root *::before,
#aica-root *::after {
	box-sizing: border-box;
}

/*
 * margin/padding のリセットは :where() で詳細度を0にする。
 * `#aica-root *` はID詳細度(1,0,0)を持ち、`.aica-messages { padding }` などの
 * クラス指定(0,1,0)を必ず上書きしてしまう。その結果ウィジェット内の余白が
 * すべて0になる(いわゆる四方ゼロ)。:where() で詳細度0にすることで、
 * テーマ由来の余白はリセットしつつ、各コンポーネントの余白指定を活かす。
 */
:where(#aica-root) *,
:where(#aica-root) *::before,
:where(#aica-root) *::after {
	margin: 0;
	padding: 0;
}

/* ---------- 起動ボタン(アイコン) ---------- */

.aica-launcher {
	display: flex;
	align-items: center;
	gap: 11px;
	height: 60px;
	padding: 0 20px 0 11px;
	border: none;
	border-radius: 34px;
	background-color: var(--aica-primary);
	background-image: linear-gradient(140deg, rgba(255, 255, 255, 0.2), rgba(0, 0, 0, 0.16));
	color: #fff;
	cursor: pointer;
	box-shadow: 0 10px 28px -6px color-mix(in srgb, var(--aica-primary) 55%, transparent), 0 4px 10px rgba(0, 0, 0, 0.18);
	transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
}

.aica-launcher:hover {
	transform: translateY(-2px) scale(1.03);
	box-shadow: 0 18px 36px -8px color-mix(in srgb, var(--aica-primary) 65%, transparent), 0 6px 14px rgba(0, 0, 0, 0.2);
}

.aica-launcher:focus-visible {
	outline: 3px solid var(--aica-primary);
	outline-offset: 2px;
}

/* 「AI」バッジ */
.aica-launcher-badge {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: #fff;
	color: var(--aica-primary);
	font-weight: 800;
	font-size: 15px;
	letter-spacing: 0.02em;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
}

.aica-launcher-labels {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	line-height: 1.25;
	text-align: left;
	white-space: nowrap;
}

.aica-launcher-title { font-size: 14.5px; font-weight: 700; }
.aica-launcher-sub { font-size: 10.5px; font-weight: 500; opacity: 0.9; margin-top: 1px; }

/* キャラクター設定時: バッジをアバター画像にする */
.aica-launcher-badge-img { padding: 2px; overflow: hidden; }
.aica-launcher-badge-img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 50%;
	display: block;
}

/* パネルを開いている間はランチャーを隠す(閉じるとまた出る) */
.aica-open .aica-launcher { display: none; }

/* ---------- パネル ---------- */

.aica-panel {
	position: absolute;
	right: 0;
	bottom: 78px;
	width: 384px;
	max-width: calc(100vw - 44px);
	height: 566px;
	max-height: calc(100vh - 130px);
	display: flex;
	flex-direction: column;
	background: var(--aica-panel-bg);
	border-radius: 20px;
	box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.32), 0 8px 20px -8px rgba(15, 23, 42, 0.18);
	overflow: hidden;
	transform-origin: bottom right;
	animation: aica-pop 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* hidden属性を確実に効かせる(display指定が[hidden]を上書きしないように) */
.aica-panel[hidden] { display: none; }

@keyframes aica-pop {
	from { opacity: 0; transform: translateY(14px) scale(0.96); }
	to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.aica-panel { animation: none; }
	.aica-launcher { transition: none; }
	.aica-teaser { animation: none; }
}

/* ---------- プロアクティブ ティーザー(v2.20) ---------- */

.aica-teaser {
	position: absolute;
	right: 0;
	bottom: 78px;
	max-width: min(280px, calc(100vw - 44px));
	display: flex;
	align-items: flex-start;
	background: var(--aica-panel-bg);
	border-left: 3px solid var(--aica-primary);
	border-radius: 14px;
	box-shadow: 0 16px 40px -10px rgba(15, 23, 42, 0.28), 0 6px 16px -6px rgba(15, 23, 42, 0.16);
	transform-origin: bottom right;
	animation: aica-pop 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.aica-teaser[hidden] { display: none; }

/* パネルを開いている間はティーザーも隠す(JSでも畳むが保険) */
.aica-open .aica-teaser { display: none; }

.aica-teaser-body {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	border: none;
	background: none;
	text-align: left;
	font-size: 13.5px;
	line-height: 1.5;
	color: #1f2937;
	padding: 12px 4px 12px 14px;
	cursor: pointer;
	font-family: inherit;
}

.aica-teaser-body .aica-msg-avatar {
	width: 28px;
	height: 28px;
	flex-shrink: 0;
}

.aica-teaser-close {
	border: none;
	background: none;
	color: #9ca3af;
	padding: 8px;
	cursor: pointer;
	flex-shrink: 0;
	line-height: 0;
	border-radius: 50%;
}

.aica-teaser-close:hover { color: var(--aica-primary); }

/* ---------- ヘッダー ---------- */

.aica-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 15px 16px 15px 18px;
	background-color: var(--aica-primary);
	background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.18));
	color: #fff;
	box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
	position: relative;
	z-index: 2;
}

.aica-header-title {
	display: flex;
	align-items: center;
	gap: 10px;
	font-weight: 700;
	font-size: 15.5px;
	min-width: 0;
}

.aica-title-text {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aica-header-avatar {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	object-fit: cover;
	border: 2px solid rgba(255, 255, 255, 0.7);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
	background: #fff;
	flex-shrink: 0;
}

.aica-status-dot {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.35);
	flex-shrink: 0;
}

.aica-header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
}

.aica-reset,
.aica-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border: none;
	border-radius: 9px;
	background: rgba(255, 255, 255, 0.14);
	color: #fff;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease;
}

.aica-reset:hover,
.aica-close:hover { background: rgba(255, 255, 255, 0.32); }
.aica-close:hover { transform: rotate(90deg); }
.aica-reset:focus-visible,
.aica-close:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ---------- メッセージ領域 ---------- */

.aica-messages {
	flex: 1;
	overflow-y: auto;
	padding: 20px 18px;
	background: linear-gradient(180deg, #fbfcfe 0%, var(--aica-panel-bg) 100%);
	display: flex;
	flex-direction: column;
	gap: 12px;
	overscroll-behavior: contain;
}

.aica-messages::-webkit-scrollbar { width: 8px; }
.aica-messages::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.28); border-radius: 8px; }
.aica-messages::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.45); }

.aica-msg { display: flex; align-items: flex-end; }
.aica-msg-user { justify-content: flex-end; }
.aica-msg-assistant { justify-content: flex-start; }

.aica-bubble {
	max-width: 80%;
	padding: 11px 15px;
	border-radius: 18px;
	word-break: break-word;
	overflow-wrap: anywhere;
	white-space: normal;
	line-height: 1.6;
}

.aica-msg-assistant .aica-bubble {
	background: #fff;
	border: 1px solid #eef0f4;
	border-bottom-left-radius: 5px;
	box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.1);
}

.aica-msg-user .aica-bubble {
	background-color: var(--aica-primary);
	background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.08));
	color: #fff;
	border-bottom-right-radius: 5px;
	box-shadow: 0 3px 10px -3px color-mix(in srgb, var(--aica-primary) 55%, transparent);
}

.aica-msg-error .aica-bubble {
	background: #fef2f2;
	border: 1px solid #fecaca;
	color: #b91c1c;
	box-shadow: none;
}

.aica-msg-avatar {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
	align-self: flex-end;
	margin-right: 8px;
	border: 1px solid #e5e7eb;
	background: #fff;
	box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

/* お問い合わせ誘導ボタン */
.aica-contact-row { margin-top: 0; }
.aica-contact-row.aica-with-avatar { margin-left: 38px; } /* アバター幅30px+余白8px分 */

.aica-contact-btn {
	display: inline-block;
	padding: 10px 18px;
	border-radius: 12px;
	background-color: var(--aica-primary);
	background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.08));
	color: #fff !important;
	text-decoration: none !important;
	font-size: 13px;
	font-weight: 600;
	box-shadow: 0 4px 12px -3px color-mix(in srgb, var(--aica-primary) 55%, transparent);
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.aica-contact-btn:hover {
	transform: translateY(-1px);
	box-shadow: 0 8px 18px -4px color-mix(in srgb, var(--aica-primary) 60%, transparent);
}

/* 会話型フォームの併設ボタン(v2.21)。<button>用のリセット+誘導ボタンと同じ見た目 */
.aica-form-start-btn {
	border: none;
	cursor: pointer;
	font-family: inherit;
	margin-left: 8px;
}

/* 回答フィードバック(👍👎) */
.aica-feedback {
	display: flex;
	gap: 2px;
	align-self: flex-end;
	margin-left: 5px;
	flex-shrink: 0;
}

.aica-fb-btn {
	border: none;
	background: transparent;
	cursor: pointer;
	font-size: 14px;
	line-height: 1;
	padding: 4px 5px;
	border-radius: 7px;
	filter: grayscale(1);
	opacity: 0.6;
	transition: opacity 0.15s ease, background 0.15s ease;
}

.aica-fb-btn:hover {
	background: #eef0f4;
	filter: none;
	opacity: 1;
}

.aica-fb-active {
	background: #eef0f4;
	filter: none;
	opacity: 1;
}

/* ホバーできる端末では通常時は隠し、吹き出しホバーで表示(評価済みは常時表示) */
@media (hover: hover) {
	.aica-feedback { opacity: 0; transition: opacity 0.15s ease; }
	.aica-msg:hover .aica-feedback,
	.aica-feedback.aica-fb-has-rating { opacity: 1; }
}

/* 回答の参照元表示 */
.aica-sources {
	font-size: 11px;
	color: #94a3b8;
	margin-top: 1px;
	padding-left: 3px;
}

.aica-sources.aica-with-avatar { margin-left: 38px; }

/* シナリオ選択肢ボタン */
.aica-choices {
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
	margin-top: 3px;
}

.aica-choices.aica-with-avatar { margin-left: 38px; }

.aica-choice {
	display: inline-block;
	padding: 8px 15px;
	border: 1.5px solid var(--aica-primary);
	border-radius: 999px;
	background: #fff;
	color: var(--aica-primary) !important;
	text-decoration: none !important;
	font-size: 13px;
	font-weight: 500;
	line-height: 1.4;
	cursor: pointer;
	box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
	transition: background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.aica-choice:hover {
	background: var(--aica-primary);
	color: #fff !important;
	transform: translateY(-1px);
}

/* 入力中インジケーター */
.aica-typing .aica-bubble {
	display: flex;
	gap: 5px;
	align-items: center;
	padding: 14px 16px;
}

.aica-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9ca3af;
	animation: aica-bounce 1.2s infinite;
}

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

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

@media (prefers-reduced-motion: reduce) {
	.aica-dot { animation: none; opacity: 0.7; }
}

/* ---------- 入力欄 ---------- */

.aica-input-row {
	display: flex;
	align-items: flex-end;
	gap: 9px;
	padding: 12px 14px;
	background: #fff;
	border-top: 1px solid #eef0f4;
}

.aica-input {
	flex: 1;
	resize: none;
	border: 1.5px solid #e2e6ec;
	border-radius: 14px;
	padding: 10px 14px;
	font: inherit;
	line-height: 1.5;
	color: inherit;
	background: #f8fafc;
	max-height: 96px;
	overflow-y: auto;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.aica-input:focus {
	outline: none;
	background: #fff;
	border-color: var(--aica-primary);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--aica-primary) 18%, transparent);
}

.aica-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	border: none;
	border-radius: 13px;
	background-color: var(--aica-primary);
	background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.1));
	color: #fff;
	cursor: pointer;
	flex-shrink: 0;
	box-shadow: 0 4px 12px -3px color-mix(in srgb, var(--aica-primary) 50%, transparent);
	transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.aica-send:not(:disabled):hover {
	transform: translateY(-1px);
	box-shadow: 0 8px 16px -4px color-mix(in srgb, var(--aica-primary) 55%, transparent);
}

.aica-send:disabled {
	opacity: 0.4;
	cursor: default;
	box-shadow: none;
}

/* ---------- フッター ---------- */

.aica-footer {
	padding: 8px 14px 11px;
	background: #fff;
	font-size: 11px;
	color: #9aa3b2;
	text-align: center;
	line-height: 1.5;
}

/* ---------- モバイル対応 ---------- */

@media (max-width: 480px) {
	#aica-root {
		right: 14px;
		bottom: 14px;
	}

	.aica-panel {
		position: fixed;
		right: 0;
		left: 0;
		bottom: 0;
		width: 100%;
		max-width: 100%;
		height: 82vh;
		max-height: 82vh;
		border-radius: 20px 20px 0 0;
	}
}


/* ---------- 有人ライブ引き継ぎ(v2.18) ---------- */
.aica-system {
	text-align: center;
	font-size: 11px;
	color: #8a8f98;
	margin: 10px 0;
}
.aica-handoff-btn {
	border-style: dashed !important;
}
.aica-msg-operator .aica-bubble {
	border-left: 3px solid #00a32a;
}
.aica-op-badge {
	display: inline-block;
	font-size: 10px;
	font-weight: 700;
	color: #00a32a;
	margin-bottom: 4px;
}
