/**
 * Cozy Telegram Chat — frontend styles.
 */

.cozy-chat-widget {
	--cozy-chat-primary: #1e88e5;
	--cozy-chat-primary-dark: #1565c0;
	--cozy-chat-bg: #ffffff;
	--cozy-chat-text: #1a1a1a;
	--cozy-chat-muted: #6b7280;
	--cozy-chat-border: #e5e7eb;
	--cozy-chat-manager-bg: #f3f4f6;
	--cozy-chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
	font-size: 14px;
	line-height: 1.45;
	color: var(--cozy-chat-text);
	box-sizing: border-box;
}

.cozy-chat-widget *,
.cozy-chat-widget *::before,
.cozy-chat-widget *::after {
	box-sizing: border-box;
}

/* Floating widget */
.cozy-chat-widget--floating {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99990;
}

.cozy-chat-widget--inline {
	position: relative;
	max-width: 340px;
	margin: 20px 0;
}

.cozy-chat-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: var(--cozy-chat-primary);
	color: #fff;
	cursor: pointer;
	box-shadow: var(--cozy-chat-shadow);
	transition: background 0.2s, transform 0.2s;
	position: relative;
}

.cozy-chat-toggle:hover {
	background: var(--cozy-chat-primary-dark);
	transform: scale(1.05);
}

.cozy-chat-toggle__icon--close {
	display: none;
}

.cozy-chat-widget.is-open .cozy-chat-toggle__icon--open {
	display: none;
}

.cozy-chat-widget.is-open .cozy-chat-toggle__icon--close {
	display: block;
}

.cozy-chat-toggle__badge {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 12px;
	height: 12px;
	background: #ef4444;
	border: 2px solid #fff;
	border-radius: 50%;
	animation: cozy-chat-pulse 2s ease-in-out infinite;
}

.cozy-chat-toggle__badge[hidden] {
	display: none !important;
}

@keyframes cozy-chat-pulse {
	0%, 100% { transform: scale(1); opacity: 1; }
	50% { transform: scale(1.15); opacity: 0.85; }
}

.cozy-chat-panel {
	display: flex;
	flex-direction: column;
	width: 340px;
	max-width: calc(100vw - 24px);
	height: 480px;
	max-height: calc(100vh - 100px);
	background: var(--cozy-chat-bg);
	border-radius: 12px;
	box-shadow: var(--cozy-chat-shadow);
	overflow: hidden;
}

.cozy-chat-widget--floating .cozy-chat-panel {
	position: absolute;
	right: 0;
	bottom: 68px;
}

.cozy-chat-widget--floating .cozy-chat-panel[hidden] {
	display: none !important;
}

.cozy-chat-widget--inline .cozy-chat-panel {
	width: 100%;
	height: 420px;
}

.cozy-chat-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
	padding: 16px;
	background: var(--cozy-chat-primary);
	color: #fff;
}

.cozy-chat-header__title {
	display: block;
	font-size: 16px;
	font-weight: 600;
	margin: 0 0 4px;
}

.cozy-chat-header__subtitle {
	margin: 0;
	font-size: 13px;
	opacity: 0.9;
}

.cozy-chat-close {
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	border: none;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	padding: 0;
}

.cozy-chat-close:hover {
	background: rgba(255, 255, 255, 0.35);
}

.cozy-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: #fafafa;
}

.cozy-chat-message {
	max-width: 85%;
	padding: 8px 12px;
	border-radius: 12px;
	word-wrap: break-word;
	white-space: pre-wrap;
}

.cozy-chat-message--customer {
	align-self: flex-end;
	background: var(--cozy-chat-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.cozy-chat-message--manager {
	align-self: flex-start;
	background: var(--cozy-chat-manager-bg);
	color: var(--cozy-chat-text);
	border-bottom-left-radius: 4px;
}

.cozy-chat-message--system {
	align-self: center;
	background: transparent;
	color: var(--cozy-chat-muted);
	font-size: 12px;
	padding: 4px 8px;
}

.cozy-chat-message__time {
	display: block;
	margin-top: 4px;
	font-size: 11px;
	opacity: 0.7;
}

.cozy-chat-form {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--cozy-chat-border);
	background: var(--cozy-chat-bg);
}

.cozy-chat-input {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid var(--cozy-chat-border);
	border-radius: 8px;
	resize: none;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
}

.cozy-chat-input:focus {
	outline: none;
	border-color: var(--cozy-chat-primary);
	box-shadow: 0 0 0 2px rgba(30, 136, 229, 0.2);
}

.cozy-chat-send {
	align-self: flex-end;
	padding: 8px 20px;
	border: none;
	border-radius: 8px;
	background: var(--cozy-chat-primary);
	color: #fff;
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	transition: background 0.2s;
}

.cozy-chat-send:hover:not(:disabled) {
	background: var(--cozy-chat-primary-dark);
}

.cozy-chat-send:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.cozy-chat-error {
	padding: 8px 12px;
	background: #fef2f2;
	color: #b91c1c;
	font-size: 13px;
	border-top: 1px solid #fecaca;
}

.cozy-chat-error[hidden] {
	display: none !important;
}

@media (max-width: 480px) {
	.cozy-chat-widget--floating {
		right: 12px;
		bottom: 12px;
	}

	.cozy-chat-widget--floating .cozy-chat-panel {
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: 100%;
		border-radius: 12px 12px 0 0;
	}

	.cozy-chat-widget--floating.is-open .cozy-chat-toggle {
		display: none;
	}
}
