/**
 * CKYHS Chat Widget Styles
 *
 * Covers: floating widget, inline chat, age gate, messages,
 * typing indicator, input area, and responsive design.
 *
 * @package CKYHS_Chat
 */

/* ── 1. CSS Variables ── */
:root {
	--ckyhs-chat-blue: #2E3656;
	--ckyhs-chat-blue-dark: #1B2035;
	--ckyhs-chat-red: #C81E55;
	--ckyhs-chat-white: #ffffff;
	--ckyhs-chat-gray-50: #F1F2F2;
	--ckyhs-chat-gray-100: #F1F2F2;
	--ckyhs-chat-gray-200: #C9C5BB;
	--ckyhs-chat-gray-300: #C9C5BB;
	--ckyhs-chat-gray-500: #666666;
	--ckyhs-chat-gray-700: #231F20;
	--ckyhs-chat-gray-900: #231F20;
	--ckyhs-chat-error: #dc2626;
	--ckyhs-chat-error-bg: #fef2f2;
	--ckyhs-chat-radius: 12px;
	--ckyhs-chat-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
	--ckyhs-chat-font: 'Times New Roman', Georgia, serif;
	--ckyhs-chat-heading-font: 'Open Sans', 'Segoe UI', Arial, sans-serif;
}

/* ── 2. Floating widget wrapper ── */
.ckyhs-chat--floating {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 99999;
	font-family: var(--ckyhs-chat-font);
}

/* ── 3. Toggle button ── */
.ckyhs-chat__toggle {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: none;
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
	cursor: pointer;
	box-shadow: var(--ckyhs-chat-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.4rem;
	transition: background 0.2s ease, transform 0.2s ease;
	position: relative;
	z-index: 2;
}

.ckyhs-chat__toggle:hover {
	background: var(--ckyhs-chat-blue-dark);
	transform: scale(1.05);
}

.ckyhs-chat__toggle:focus-visible {
	outline: 3px solid var(--ckyhs-chat-blue);
	outline-offset: 3px;
}

.ckyhs-chat__toggle-icon--close {
	display: none;
}

.ckyhs-chat--open .ckyhs-chat__toggle-icon--open {
	display: none;
}

.ckyhs-chat--open .ckyhs-chat__toggle-icon--close {
	display: inline;
}

/* ── 4. Chat panel (floating) ── */
.ckyhs-chat--floating .ckyhs-chat__panel {
	position: absolute;
	bottom: 72px;
	right: 0;
	width: 380px;
	max-height: 520px;
	background: var(--ckyhs-chat-white);
	border-radius: var(--ckyhs-chat-radius);
	box-shadow: var(--ckyhs-chat-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: ckyhsChatSlideUp 0.25s ease-out;
}

@keyframes ckyhsChatSlideUp {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ── 5. Inline chat ── */
.ckyhs-chat--inline {
	max-width: 720px;
	margin: 0 auto;
	background: var(--ckyhs-chat-white);
	border: 1px solid var(--ckyhs-chat-gray-200);
	border-radius: var(--ckyhs-chat-radius);
	box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	min-height: 480px;
	font-family: var(--ckyhs-chat-font);
}

/* ── 6. Header ── */
.ckyhs-chat__header {
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
	padding: 14px 18px;
	display: flex;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}

.ckyhs-chat__header-icon {
	font-size: 1.1rem;
	opacity: 0.9;
}

.ckyhs-chat__header-title {
	font-family: var(--ckyhs-chat-heading-font);
	font-size: 0.95rem;
	font-weight: 800;
	letter-spacing: 0.01em;
}

/* ── 7. Messages area ── */
.ckyhs-chat__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: var(--ckyhs-chat-gray-50);
	min-height: 200px;
	max-height: 360px;
}

.ckyhs-chat--inline .ckyhs-chat__messages {
	max-height: none;
	min-height: 320px;
}

/* Scrollbar */
.ckyhs-chat__messages::-webkit-scrollbar {
	width: 6px;
}

.ckyhs-chat__messages::-webkit-scrollbar-track {
	background: transparent;
}

.ckyhs-chat__messages::-webkit-scrollbar-thumb {
	background: var(--ckyhs-chat-gray-300);
	border-radius: 3px;
}

/* ── 8. Message bubbles ── */
.ckyhs-chat__message {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	max-width: 85%;
}

.ckyhs-chat__message--bot {
	align-self: flex-start;
}

.ckyhs-chat__message--user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.ckyhs-chat__message--error {
	align-self: center;
	max-width: 90%;
}

.ckyhs-chat__avatar {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.75rem;
	flex-shrink: 0;
	margin-top: 2px;
}

.ckyhs-chat__avatar--bot {
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
}

.ckyhs-chat__bubble {
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 0.9rem;
	line-height: 1.5;
	word-break: break-word;
}

.ckyhs-chat__bubble--bot {
	background: var(--ckyhs-chat-white);
	color: var(--ckyhs-chat-gray-900);
	border: 1px solid var(--ckyhs-chat-gray-200);
	border-top-left-radius: 4px;
}

.ckyhs-chat__bubble--bot a {
	color: var(--ckyhs-chat-blue);
	text-decoration: underline;
}

.ckyhs-chat__bubble--bot a[target="_blank"]::after {
	content: " \2197";
	font-size: 0.75em;
	text-decoration: none;
}

.ckyhs-chat__bubble--user {
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
	border-top-right-radius: 4px;
}

.ckyhs-chat__bubble--error {
	background: var(--ckyhs-chat-error-bg);
	color: var(--ckyhs-chat-error);
	border: 1px solid #fecaca;
	border-radius: 10px;
	font-size: 0.85rem;
	text-align: center;
}

/* ── 9. Suggested questions ── */
.ckyhs-chat__suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 4px 0;
}

.ckyhs-chat__suggestion {
	background: var(--ckyhs-chat-white);
	color: var(--ckyhs-chat-blue);
	border: 1px solid var(--ckyhs-chat-blue);
	border-radius: 18px;
	padding: 7px 14px;
	font-size: 0.8rem;
	font-family: var(--ckyhs-chat-font);
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
	line-height: 1.3;
}

.ckyhs-chat__suggestion:hover {
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
}

.ckyhs-chat__suggestion:focus-visible {
	outline: 3px solid var(--ckyhs-chat-blue);
	outline-offset: 2px;
}

/* ── 10. Typing indicator ── */
.ckyhs-chat__typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 12px 18px;
}

.ckyhs-chat__typing-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--ckyhs-chat-gray-300);
	animation: ckyhsChatBounce 1.4s infinite ease-in-out both;
}

.ckyhs-chat__typing-dot:nth-child(1) {
	animation-delay: 0s;
}

.ckyhs-chat__typing-dot:nth-child(2) {
	animation-delay: 0.16s;
}

.ckyhs-chat__typing-dot:nth-child(3) {
	animation-delay: 0.32s;
}

@keyframes ckyhsChatBounce {
	0%, 80%, 100% {
		transform: scale(0.6);
		opacity: 0.4;
	}
	40% {
		transform: scale(1);
		opacity: 1;
	}
}

/* ── 10. Input area ── */
.ckyhs-chat__input-area {
	border-top: 1px solid var(--ckyhs-chat-gray-200);
	padding: 12px 14px 8px;
	background: var(--ckyhs-chat-white);
	flex-shrink: 0;
}

.ckyhs-chat__input-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
}

.ckyhs-chat__input {
	flex: 1;
	border: 1px solid var(--ckyhs-chat-gray-300);
	border-radius: 20px;
	padding: 10px 16px;
	font-size: 0.9rem;
	font-family: var(--ckyhs-chat-font);
	resize: none;
	outline: none;
	line-height: 1.4;
	min-height: 2.8em;
	max-height: 120px;
	transition: border-color 0.2s;
}

.ckyhs-chat__input:focus {
	border-color: var(--ckyhs-chat-blue);
	box-shadow: 0 0 0 2px rgba(0, 61, 165, 0.15);
}

.ckyhs-chat__input:disabled {
	background: var(--ckyhs-chat-gray-100);
	cursor: not-allowed;
}

.ckyhs-chat__send {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.85rem;
	flex-shrink: 0;
	transition: background 0.2s, opacity 0.2s;
}

.ckyhs-chat__send:hover:not(:disabled) {
	background: var(--ckyhs-chat-blue-dark);
}

.ckyhs-chat__send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.ckyhs-chat__send:focus-visible {
	outline: 3px solid var(--ckyhs-chat-blue);
	outline-offset: 2px;
}

.ckyhs-chat__char-count {
	display: block;
	text-align: right;
	font-size: 0.7rem;
	color: var(--ckyhs-chat-gray-500);
	padding: 4px 4px 0;
}

.ckyhs-chat__char-count--warn {
	color: var(--ckyhs-chat-red);
	font-weight: 600;
}

/* ── 11. Age gate overlay ── */
.ckyhs-chat__age-gate {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 32px 24px;
	flex: 1;
}

.ckyhs-chat__age-gate-icon {
	font-size: 2.5rem;
	color: var(--ckyhs-chat-blue);
	margin-bottom: 16px;
}

.ckyhs-chat__age-gate-title {
	font-family: var(--ckyhs-chat-heading-font);
	font-size: 1.15rem;
	font-weight: 800;
	color: var(--ckyhs-chat-gray-900);
	margin: 0 0 12px;
}

.ckyhs-chat__age-gate-text {
	font-size: 0.9rem;
	color: var(--ckyhs-chat-gray-700);
	line-height: 1.6;
	margin: 0 0 20px;
	max-width: 320px;
}

.ckyhs-chat__age-gate-confirm {
	background: var(--ckyhs-chat-blue);
	color: var(--ckyhs-chat-white);
	border: none;
	border-radius: 24px;
	padding: 12px 28px;
	font-family: var(--ckyhs-chat-heading-font);
	font-size: 0.95rem;
	font-weight: 800;
	cursor: pointer;
	transition: background 0.2s, transform 0.15s;
}

.ckyhs-chat__age-gate-confirm:hover {
	background: var(--ckyhs-chat-blue-dark);
	transform: translateY(-1px);
}

.ckyhs-chat__age-gate-confirm:focus-visible {
	outline: 3px solid var(--ckyhs-chat-blue);
	outline-offset: 3px;
}

.ckyhs-chat__age-gate-note {
	font-size: 0.75rem;
	color: var(--ckyhs-chat-gray-500);
	margin: 16px 0 0;
	max-width: 280px;
}

/* ── 12. Message limit notices ── */
.ckyhs-chat__limit-warning {
	text-align: center;
	font-size: 0.75rem;
	color: #92400e;
	background: #fffbeb;
	border: 1px solid #fde68a;
	border-radius: 8px;
	padding: 6px 12px;
	line-height: 1.4;
}

.ckyhs-chat__limit-reached {
	text-align: center;
	font-size: 0.85rem;
	color: var(--ckyhs-chat-gray-700);
	background: var(--ckyhs-chat-gray-100);
	border: 1px solid var(--ckyhs-chat-gray-300);
	border-radius: 10px;
	padding: 14px 16px;
	line-height: 1.5;
}

.ckyhs-chat__limit-reached a {
	color: var(--ckyhs-chat-blue);
	text-decoration: underline;
}

/* ── 13. Unavailable fallback ── */
.ckyhs-chat-unavailable {
	padding: 24px;
	text-align: center;
	color: var(--ckyhs-chat-gray-700);
	font-size: 0.95rem;
	background: var(--ckyhs-chat-gray-100);
	border-radius: var(--ckyhs-chat-radius);
	border: 1px solid var(--ckyhs-chat-gray-200);
}

/* ── 13. Responsive ── */
@media (max-width: 480px) {
	.ckyhs-chat--floating {
		bottom: 16px;
		right: 16px;
	}

	.ckyhs-chat--floating .ckyhs-chat__panel {
		width: calc(100vw - 32px);
		max-height: calc(100vh - 160px);
		right: -8px;
		bottom: 68px;
	}

	.ckyhs-chat__toggle {
		width: 52px;
		height: 52px;
		font-size: 1.2rem;
	}

	.ckyhs-chat__messages {
		padding: 12px;
	}

	.ckyhs-chat__message {
		max-width: 92%;
	}

	.ckyhs-chat__age-gate {
		padding: 24px 16px;
	}
}

/* ── 14. Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
	.ckyhs-chat__typing-dot {
		animation: none;
		opacity: 0.6;
	}

	.ckyhs-chat--floating .ckyhs-chat__panel {
		animation: none;
	}

	.ckyhs-chat__toggle,
	.ckyhs-chat__age-gate-confirm,
	.ckyhs-chat__send {
		transition: none;
	}
}

/* ── 15. Hidden attribute support ── */
.ckyhs-chat__panel[hidden] {
	display: none !important;
}

/* ── 16. Print ── */
@media print {
	.ckyhs-chat--floating {
		display: none !important;
	}
}
