.aicw {
	--aicw-color: #2563eb;
	--aicw-bg: #ffffff;
	--aicw-text: #1f2937;
	--aicw-muted: #6b7280;
	--aicw-bubble: #f3f4f6;
	--aicw-border: #e5e7eb;
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 2147483000;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
	font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
	font-size: 15px;
	line-height: 1.6;
	color: var(--aicw-text);
}

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

/* ---------- 呼び出しボタン ---------- */

.aicw-launcher {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	font: inherit;
}

.aicw-launcher-label {
	position: relative;
	padding: 10px 16px;
	border-radius: 999px;
	background: var(--aicw-bg);
	color: var(--aicw-text);
	font-weight: 600;
	font-size: 14px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
	white-space: nowrap;
	animation: aicw-pop 0.4s ease-out 0.6s both;
}

.aicw-launcher-icon {
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--aicw-color);
	color: #fff;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
	transition: transform 0.15s ease;
}

.aicw-launcher:hover .aicw-launcher-icon {
	transform: scale(1.06);
}

.aicw-launcher:focus-visible .aicw-launcher-icon {
	outline: 3px solid var(--aicw-color);
	outline-offset: 3px;
}

.aicw-is-open .aicw-launcher-label {
	display: none;
}

@keyframes aicw-pop {
	from { opacity: 0; transform: translateY(6px) scale(0.95); }
	to { opacity: 1; transform: none; }
}

/* ---------- チャット窓 ---------- */

.aicw-panel {
	display: flex;
	flex-direction: column;
	width: 370px;
	height: min(560px, calc(100vh - 120px));
	border-radius: 16px;
	background: var(--aicw-bg);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
	overflow: hidden;
	animation: aicw-pop 0.2s ease-out both;
}

.aicw-panel[hidden] {
	display: none;
}

.aicw-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	background: var(--aicw-color);
	color: #fff;
}

.aicw-title {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 700;
}

.aicw-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
}

.aicw-close {
	width: 32px;
	height: 32px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: #fff;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
}

.aicw-close:hover {
	background: rgba(255, 255, 255, 0.15);
}

.aicw-log {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.aicw-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 14px;
	white-space: pre-wrap;
	word-break: break-word;
	overflow-wrap: anywhere;
}

.aicw-msg a {
	color: inherit;
	text-decoration: underline;
}

.aicw-msg-assistant {
	align-self: flex-start;
	background: var(--aicw-bubble);
	border-bottom-left-radius: 4px;
}

.aicw-msg-assistant a {
	color: var(--aicw-color);
}

.aicw-msg-user {
	align-self: flex-end;
	background: var(--aicw-color);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.aicw-msg-error {
	align-self: center;
	max-width: 100%;
	background: #fef2f2;
	color: #b91c1c;
	font-size: 13px;
}

.aicw-typing {
	display: flex;
	gap: 4px;
	padding: 14px;
}

.aicw-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aicw-muted);
	animation: aicw-blink 1.2s infinite ease-in-out;
}

.aicw-typing span:nth-child(2) { animation-delay: 0.2s; }
.aicw-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aicw-blink {
	0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}

.aicw-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin: 0;
	padding: 10px 12px;
	border-top: 1px solid var(--aicw-border);
}

.aicw-input {
	flex: 1;
	min-height: 40px;
	max-height: 120px;
	margin: 0;
	padding: 9px 12px;
	border: 1px solid var(--aicw-border);
	border-radius: 10px;
	background: #fff;
	color: var(--aicw-text);
	font: inherit;
	font-size: 16px; /* iPhone で入力時に拡大されないように */
	line-height: 1.4;
	resize: none;
	overflow-y: hidden;
}

.aicw-input:focus {
	outline: 2px solid var(--aicw-color);
	outline-offset: -1px;
	border-color: transparent;
}

.aicw-send {
	display: grid;
	place-items: center;
	flex: none;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 10px;
	background: var(--aicw-color);
	color: #fff;
	cursor: pointer;
}

.aicw-send:disabled {
	opacity: 0.5;
	cursor: default;
}

.aicw-note {
	padding: 0 12px 8px;
	color: var(--aicw-muted);
	font-size: 11px;
	text-align: center;
}

/* ---------- スマホ ---------- */

@media (max-width: 480px) {
	.aicw {
		right: 12px;
		bottom: 12px;
	}
	.aicw-launcher-label {
		font-size: 13px;
		padding: 8px 12px;
	}
	.aicw.aicw-is-open {
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		gap: 0;
	}
	.aicw-is-open .aicw-panel {
		width: 100%;
		height: 100%;
		border-radius: 0;
	}
	.aicw-is-open .aicw-launcher {
		display: none;
	}
}

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