/* ═══════════════════════════════════════════════════
 * Steely AI Chat Widget — Styles
 * Dark theme matching steelyai.com design system
 * ═══════════════════════════════════════════════════ */

:root {
	--sai-chat-bg: #0a0f1c;
	--sai-chat-surface: #111827;
	--sai-chat-surface-2: #1e293b;
	--sai-chat-border: rgba(99, 102, 241, .15);
	--sai-chat-text: #e2e8f0;
	--sai-chat-text-dim: #94a3b8;
	--sai-chat-accent: #6366f1;
	--sai-chat-accent-2: #8b5cf6;
	--sai-chat-cyan: #22d3ee;
	--sai-chat-radius: 16px;
	--sai-chat-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	--sai-chat-font-ar: 'Tajawal', 'Inter', sans-serif;
	--sai-chat-width: 400px;
	--sai-chat-height: 560px;
}

/* ─── Floating Toggle Button ─── */
.sai-chat-toggle {
	position: fixed;
	bottom: 110px;
	right: 28px;
	z-index: 9998;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: none;
	cursor: pointer;
	background: linear-gradient(135deg, var(--sai-chat-accent), var(--sai-chat-accent-2));
	color: #fff;
	box-shadow:
		0 4px 24px rgba(99, 102, 241, .4),
		0 0 0 0 rgba(99, 102, 241, .3);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all .3s cubic-bezier(.4, 0, .2, 1);
	animation: sai-pulse 3s ease-in-out infinite;
}

.sai-chat-toggle:hover {
	transform: scale(1.1);
	box-shadow: 0 6px 32px rgba(99, 102, 241, .55);
}

.sai-chat-toggle.sai-open {
	animation: none;
	transform: rotate(0deg);
	opacity: 0;
	pointer-events: none;
	visibility: hidden;
}

.sai-chat-toggle svg {
	width: 28px;
	height: 28px;
	transition: transform .3s ease;
}

.sai-chat-toggle.sai-open .sai-icon-chat {
	display: none;
}

.sai-chat-toggle:not(.sai-open) .sai-icon-close {
	display: none;
}

/* Unread badge */
.sai-chat-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	display: none;
	align-items: center;
	justify-content: center;
	border: 2px solid #fff;
}

.sai-chat-badge.sai-show {
	display: flex;
}

@keyframes sai-pulse {
	0%, 100% { box-shadow: 0 4px 24px rgba(99, 102, 241, .4), 0 0 0 0 rgba(99, 102, 241, .25); }
	50% { box-shadow: 0 4px 24px rgba(99, 102, 241, .4), 0 0 0 12px rgba(99, 102, 241, 0); }
}

/* ─── Chat Window ─── */
.sai-chat-window {
	position: fixed;
	bottom: 110px;
	right: 28px;
	z-index: 9997;
	width: var(--sai-chat-width);
	height: var(--sai-chat-height);
	border-radius: var(--sai-chat-radius);
	background: var(--sai-chat-bg);
	border: 1px solid var(--sai-chat-border);
	box-shadow:
		0 24px 64px rgba(0, 0, 0, .5),
		0 0 0 1px rgba(99, 102, 241, .08);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-family: var(--sai-chat-font);
	opacity: 0;
	visibility: hidden;
	transform: translateY(20px) scale(.95);
	transition: all .35s cubic-bezier(.4, 0, .2, 1);
}

.sai-chat-window.sai-visible {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

/* ─── Header ─── */
.sai-chat-header {
	background: linear-gradient(135deg, var(--sai-chat-accent), var(--sai-chat-accent-2));
	padding: 16px 20px;
	display: flex;
	align-items: center;
	gap: 12px;
	flex-shrink: 0;
}

.sai-chat-avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, .15);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.sai-chat-avatar svg {
	width: 22px;
	height: 22px;
	color: #fff;
}

.sai-chat-header-info {
	flex: 1;
	min-width: 0;
}

.sai-chat-header-title {
	color: #fff;
	font-size: 15px;
	font-weight: 700;
	line-height: 1.2;
	margin: 0;
}

.sai-chat-header-subtitle {
	color: rgba(255, 255, 255, .75);
	font-size: 12px;
	line-height: 1.3;
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
}

.sai-chat-header-subtitle::before {
	content: '';
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #34d399;
	flex-shrink: 0;
	animation: sai-glow 2s ease-in-out infinite;
}

@keyframes sai-glow {
	0%, 100% { opacity: 1; }
	50% { opacity: .5; }
}

.sai-chat-header-actions {
	display: flex;
	gap: 4px;
}

.sai-chat-header-btn {
	background: rgba(255, 255, 255, .12);
	border: none;
	border-radius: 8px;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	color: #fff;
	transition: background .2s;
}

.sai-chat-header-btn:hover {
	background: rgba(255, 255, 255, .25);
}

.sai-chat-header-btn svg {
	width: 16px;
	height: 16px;
}

/* ─── Messages Area ─── */
.sai-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: var(--sai-chat-bg);
	scrollbar-width: thin;
	scrollbar-color: var(--sai-chat-surface-2) transparent;
}

.sai-chat-messages::-webkit-scrollbar {
	width: 5px;
}

.sai-chat-messages::-webkit-scrollbar-track {
	background: transparent;
}

.sai-chat-messages::-webkit-scrollbar-thumb {
	background: var(--sai-chat-surface-2);
	border-radius: 3px;
}

/* Message Bubble */
.sai-msg {
	display: flex;
	flex-direction: column;
	max-width: 85%;
	animation: sai-msg-in .3s cubic-bezier(.4, 0, .2, 1);
}

@keyframes sai-msg-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

.sai-msg--user {
	align-self: flex-end;
}

.sai-msg--assistant {
	align-self: flex-start;
}

.sai-msg__bubble {
	padding: 12px 16px;
	border-radius: 16px;
	font-size: 14px;
	line-height: 1.65;
	word-break: break-word;
	color: var(--sai-chat-text);
}

.sai-msg--user .sai-msg__bubble {
	background: linear-gradient(135deg, var(--sai-chat-accent), var(--sai-chat-accent-2));
	color: #fff;
	border-bottom-right-radius: 4px;
}

.sai-msg--assistant .sai-msg__bubble {
	background: var(--sai-chat-surface);
	border: 1px solid var(--sai-chat-border);
	border-bottom-left-radius: 4px;
}

/* Markdown inside assistant bubbles */
.sai-msg--assistant .sai-msg__bubble strong,
.sai-msg--assistant .sai-msg__bubble b {
	color: #fff;
	font-weight: 600;
}

.sai-msg--assistant .sai-msg__bubble ul,
.sai-msg--assistant .sai-msg__bubble ol {
	margin: 6px 0;
	padding-left: 18px;
}

.sai-msg--assistant .sai-msg__bubble li {
	margin-bottom: 3px;
}

.sai-msg--assistant .sai-msg__bubble code {
	background: rgba(99, 102, 241, .15);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 13px;
	font-family: 'JetBrains Mono', monospace;
}

.sai-msg--assistant .sai-msg__bubble a {
	color: var(--sai-chat-cyan);
	text-decoration: underline;
}

.sai-msg__time {
	font-size: 11px;
	color: var(--sai-chat-text-dim);
	margin-top: 4px;
	padding: 0 4px;
}

.sai-msg--user .sai-msg__time {
	text-align: right;
}

/* RTL message support */
.sai-msg__bubble[dir="rtl"] {
	font-family: var(--sai-chat-font-ar);
	text-align: right;
}

.sai-msg__bubble[dir="rtl"] ul,
.sai-msg__bubble[dir="rtl"] ol {
	padding-left: 0;
	padding-right: 18px;
}

/* ─── Typing Indicator ─── */
.sai-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 14px 18px;
	background: var(--sai-chat-surface);
	border: 1px solid var(--sai-chat-border);
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	align-self: flex-start;
	max-width: 80px;
}

.sai-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--sai-chat-text-dim);
	animation: sai-bounce 1.4s ease-in-out infinite;
}

.sai-typing span:nth-child(2) { animation-delay: .2s; }
.sai-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes sai-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: .4; }
	30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input Area ─── */
.sai-chat-input-area {
	padding: 12px 16px;
	background: var(--sai-chat-surface);
	border-top: 1px solid var(--sai-chat-border);
	display: flex;
	align-items: flex-end;
	gap: 8px;
	flex-shrink: 0;
}

.sai-chat-input {
	flex: 1;
	background: var(--sai-chat-bg);
	border: 1px solid var(--sai-chat-border);
	border-radius: 12px;
	padding: 10px 14px;
	color: var(--sai-chat-text);
	font-size: 14px;
	font-family: var(--sai-chat-font);
	line-height: 1.5;
	resize: none;
	min-height: 42px;
	max-height: 100px;
	outline: none;
	transition: border-color .2s;
}

.sai-chat-input:focus {
	border-color: var(--sai-chat-accent);
}

.sai-chat-input::placeholder {
	color: var(--sai-chat-text-dim);
}

.sai-chat-send {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	border: none;
	background: linear-gradient(135deg, var(--sai-chat-accent), var(--sai-chat-accent-2));
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all .2s;
	flex-shrink: 0;
}

.sai-chat-send:hover {
	transform: scale(1.05);
	box-shadow: 0 4px 16px rgba(99, 102, 241, .4);
}

.sai-chat-send:disabled {
	opacity: .5;
	cursor: not-allowed;
	transform: none;
	box-shadow: none;
}

.sai-chat-send svg {
	width: 18px;
	height: 18px;
}

/* RTL input */
.sai-chat-input[dir="rtl"] {
	font-family: var(--sai-chat-font-ar);
	text-align: right;
}

/* ─── Welcome State ─── */
.sai-chat-welcome {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 32px 24px;
	gap: 16px;
}

.sai-chat-welcome-logo {
	width: 64px;
	height: 64px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--sai-chat-accent), var(--sai-chat-accent-2));
	display: flex;
	align-items: center;
	justify-content: center;
	animation: sai-float 3s ease-in-out infinite;
}

@keyframes sai-float {
	0%, 100% { transform: translateY(0); }
	50% { transform: translateY(-6px); }
}

.sai-chat-welcome-logo svg {
	width: 32px;
	height: 32px;
	color: #fff;
}

.sai-chat-welcome h3 {
	margin: 0;
	color: #fff;
	font-size: 18px;
	font-weight: 700;
}

.sai-chat-welcome p {
	margin: 0;
	color: var(--sai-chat-text-dim);
	font-size: 14px;
	line-height: 1.6;
}

/* Quick action chips */
.sai-chat-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: center;
	margin-top: 8px;
}

.sai-chat-chip {
	background: var(--sai-chat-surface);
	border: 1px solid var(--sai-chat-border);
	border-radius: 20px;
	padding: 6px 14px;
	color: var(--sai-chat-text);
	font-size: 13px;
	cursor: pointer;
	transition: all .2s;
	font-family: var(--sai-chat-font);
	white-space: nowrap;
}

.sai-chat-chip:hover {
	background: var(--sai-chat-accent);
	color: #fff;
	border-color: var(--sai-chat-accent);
}

/* ─── Powered By Footer ─── */
.sai-chat-footer {
	text-align: center;
	padding: 6px;
	font-size: 10px;
	color: var(--sai-chat-text-dim);
	background: var(--sai-chat-surface);
	flex-shrink: 0;
	letter-spacing: .02em;
}

.sai-chat-footer a {
	color: var(--sai-chat-accent);
	text-decoration: none;
}

/* ─── Error State ─── */
.sai-msg--error .sai-msg__bubble {
	background: rgba(239, 68, 68, .1);
	border: 1px solid rgba(239, 68, 68, .3);
	color: #fca5a5;
	border-bottom-left-radius: 4px;
}

/* ─── Responsive — Mobile ─── */
@media (max-width: 480px) {
	.sai-chat-window {
		bottom: 0;
		right: 0;
		left: 0;
		width: 100%;
		height: 100%;
		border-radius: 0;
		max-height: 100dvh;
	}

	.sai-chat-toggle {
		bottom: 90px;
		right: 16px;
		width: 54px;
		height: 54px;
	}

	.sai-chat-toggle svg {
		width: 24px;
		height: 24px;
	}
}

@media (max-width: 768px) and (min-width: 481px) {
	.sai-chat-window {
		width: calc(100vw - 32px);
		right: 16px;
		bottom: 90px;
		height: 70vh;
	}
}
