/* Kiwosan Chat. Usa los tokens de marca del tema (brand.css) con valores de reserva. */
#kchat {
	--kc-bg: var(--ks-bg, #050505);
	--kc-surface: var(--ks-surface-2, #111);
	--kc-surface-2: var(--ks-surface-3, #1a1a1a);
	--kc-border: var(--ks-border-strong, #333);
	--kc-text: var(--ks-text, #fff);
	--kc-text-2: var(--ks-text-2, #bbb);
	--kc-text-3: var(--ks-text-3, #888);
	--kc-accent: var(--ks-lime, #c8ff00);
	--kc-on-accent: var(--ks-on-lime, #050505);
	--kc-font: var(--ks-font-body, 'DM Sans', system-ui, sans-serif);
	--kc-font-head: var(--ks-font-head, 'Space Grotesk', system-ui, sans-serif);
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99990;
	font-family: var(--kc-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--kc-text);
}
#kchat *, #kchat *::before, #kchat *::after { box-sizing: border-box; }
#kchat svg { width: 20px; height: 20px; display: block; }
#kchat button { font: inherit; cursor: pointer; }

.kchat-launcher {
	width: 56px;
	height: 56px;
	border-radius: 999px;
	border: 0;
	background: var(--kc-accent);
	color: var(--kc-on-accent);
	display: grid;
	place-items: center;
	box-shadow: 0 8px 28px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .06);
	transition: transform .15s ease;
	margin-left: auto;
}
.kchat-launcher:hover { transform: scale(1.05); }
.kchat-launcher svg { width: 26px !important; height: 26px !important; }
.kchat-launcher:focus-visible, #kchat button:focus-visible, #kchat a:focus-visible, .kchat-form textarea:focus-visible {
	outline: 2px solid var(--kc-accent);
	outline-offset: 2px;
}

.kchat-panel {
	position: absolute;
	right: 0;
	bottom: 72px;
	width: 380px;
	height: min(620px, calc(100vh - 120px));
	display: flex;
	flex-direction: column;
	background: var(--kc-bg);
	border: 1px solid var(--kc-border);
	border-radius: 20px;
	overflow: hidden;
	box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.kchat-panel[hidden] { display: none; }

.kchat-head {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 14px 10px 14px 18px;
	border-bottom: 1px solid var(--kc-border);
	background: var(--kc-surface);
}
.kchat-title { flex: 1; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.kchat-title strong { font-family: var(--kc-font-head); font-size: 16px; }
.kchat-sub { color: var(--kc-text-3); font-size: 12px; }
.kchat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kc-accent); align-self: center; flex: none; }
.kchat-icon {
	width: 36px; height: 36px;
	display: grid; place-items: center;
	border: 0; border-radius: 10px;
	background: transparent; color: var(--kc-text-2);
}
.kchat-icon:hover { background: var(--kc-surface-2); color: var(--kc-text); }

.kchat-log {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	overscroll-behavior: contain;
}
.kchat-msg { display: flex; flex-direction: column; max-width: 88%; }
.kchat-user { align-self: flex-end; align-items: flex-end; }
.kchat-assistant { align-self: flex-start; }
.kchat-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	overflow-wrap: anywhere;
}
.kchat-user .kchat-bubble { background: var(--kc-accent); color: var(--kc-on-accent); border-bottom-right-radius: 4px; }
.kchat-assistant .kchat-bubble { background: var(--kc-surface-2); border-bottom-left-radius: 4px; }
.kchat-assistant.is-error .kchat-bubble { border: 1px solid #a33; }
.kchat-bubble p { margin: 0 0 8px; }
.kchat-bubble p:last-child, .kchat-bubble ul:last-child, .kchat-bubble ol:last-child { margin-bottom: 0; }
.kchat-bubble ul, .kchat-bubble ol { margin: 0 0 8px; padding-left: 20px; }
.kchat-bubble li { margin: 2px 0; }
.kchat-bubble a { color: var(--kc-accent); text-decoration: underline; text-underline-offset: 2px; }
.kchat-user .kchat-bubble a { color: inherit; }
.kchat-bubble code { background: rgba(255, 255, 255, .08); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.kchat-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 12px; align-items: center; }
.kchat-sources span { color: var(--kc-text-3); }
.kchat-sources a {
	color: var(--kc-text-2);
	border: 1px solid var(--kc-border);
	border-radius: 999px;
	padding: 3px 10px;
	text-decoration: none;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.kchat-sources a:hover { color: var(--kc-text); border-color: var(--kc-text-3); }

.kchat-fb { display: flex; gap: 2px; margin-top: 4px; }
.kchat-fb button {
	border: 0; background: transparent; color: var(--kc-text-3);
	width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
}
.kchat-fb svg { width: 15px !important; height: 15px !important; }
.kchat-fb button:hover { color: var(--kc-text); background: var(--kc-surface-2); }
.kchat-fb button[aria-pressed="true"] { color: var(--kc-accent); }

.kchat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.kchat-chips button {
	border: 1px solid var(--kc-border);
	background: transparent;
	color: var(--kc-text);
	border-radius: 999px;
	padding: 6px 12px;
	font-size: 13px;
	text-align: left;
}
.kchat-chips button:hover { border-color: var(--kc-accent); color: var(--kc-accent); }

.kchat-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.kchat-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--kc-text-3); animation: kchat-blink 1.2s infinite ease-in-out; }
.kchat-typing i:nth-child(2) { animation-delay: .15s; }
.kchat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes kchat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.kchat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin: 0;
	padding: 12px;
	border-top: 1px solid var(--kc-border);
	background: var(--kc-surface);
}
.kchat-form textarea {
	flex: 1;
	resize: none;
	min-height: 44px;
	max-height: 120px;
	padding: 11px 14px;
	border: 1px solid var(--kc-border);
	border-radius: 14px;
	background: var(--kc-bg);
	color: var(--kc-text);
	font: inherit;
	line-height: 1.4;
	margin: 0;
}
.kchat-form textarea::placeholder { color: var(--kc-text-3); }
.kchat-send {
	width: 44px; height: 44px; flex: none;
	border: 0; border-radius: 999px;
	background: var(--kc-accent); color: var(--kc-on-accent);
	display: grid; place-items: center;
}
.kchat-send:disabled { opacity: .5; cursor: progress; }
.kchat-foot { margin: 0; padding: 0 14px 10px; background: var(--kc-surface); color: var(--kc-text-3); font-size: 11px; text-align: center; }

@media (max-width: 640px) {
	#kchat { right: 16px; bottom: 16px; }
	#kchat.is-open .kchat-launcher { display: none; }
	.kchat-panel {
		position: fixed;
		inset: 0;
		width: auto;
		height: 100%;
		height: 100dvh;
		border-radius: 0;
		border: 0;
	}
	.kchat-form textarea { font-size: 16px; } /* evita el zoom de iOS */
}
@media (prefers-reduced-motion: reduce) {
	.kchat-launcher, .kchat-typing i { transition: none; animation: none; }
}
