/* AI SEO Content Writer — Frontend Chat Shortcode
   All rules scoped under .aiscw-front-chat to avoid leaking into theme styles. */

/* ── Layout ─────────────────────────────────────────────────────────────── */

.aiscw-front-chat {
	display: flex;
	flex-direction: column;
	gap: 0;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 14px;
	color: #1a1a2e;
	line-height: 1.5;
}

.aiscw-front-chat.aiscw-front-chat--with-settings {
	flex-direction: row;
	align-items: flex-start;
	gap: 20px;
}

/* ── Login notice ───────────────────────────────────────────────────────── */

.aiscw-front-chat .aiscw-front-login-msg {
	background: #fff3cd;
	border: 1px solid #ffc107;
	border-radius: 8px;
	padding: 16px 20px;
	color: #664d03;
	margin: 0;
}

/* ── Settings panel ─────────────────────────────────────────────────────── */

.aiscw-front-settings {
	flex: 0 0 260px;
	min-width: 220px;
	max-width: 280px;
	background: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 12px;
	padding: 20px;
	box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.aiscw-front-settings-header {
	text-align: center;
	padding-bottom: 16px;
	border-bottom: 1px solid #f1f5f9;
	margin-bottom: 16px;
}

.aiscw-front-brain-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
	border-radius: 12px;
	margin: 0 auto 10px;
	font-size: 22px;
}

.aiscw-front-settings-title {
	font-size: 15px;
	font-weight: 600;
	margin: 0 0 4px;
	color: #1a1a2e;
}

.aiscw-front-settings-sub {
	font-size: 12px;
	color: #64748b;
	margin: 0;
}

.aiscw-front-field {
	margin-bottom: 12px;
}

.aiscw-front-label {
	display: block;
	font-size: 12px;
	font-weight: 600;
	color: #374151;
	margin-bottom: 4px;
}

.aiscw-front-select,
.aiscw-front-input,
.aiscw-front-textarea {
	display: block;
	width: 100%;
	box-sizing: border-box;
	padding: 7px 10px;
	font-size: 13px;
	color: #374151;
	background: #f8fafc;
	border: 1px solid #cbd5e1;
	border-radius: 6px;
	outline: none;
	transition: border-color .15s, box-shadow .15s;
	font-family: inherit;
}

.aiscw-front-select:focus,
.aiscw-front-input:focus,
.aiscw-front-textarea:focus {
	border-color: #6366f1;
	box-shadow: 0 0 0 3px rgba(99,102,241,.15);
	background: #fff;
}

.aiscw-front-textarea {
	height: 80px;
	resize: vertical;
}

.aiscw-front-divider {
	border: none;
	border-top: 1px solid #f1f5f9;
	margin: 14px 0;
}

/* ── Chat main panel ────────────────────────────────────────────────────── */

.aiscw-front-main {
	flex: 1 1 0;
	min-width: 0;
	display: flex;
	flex-direction: column;
	background: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 12px;
	box-shadow: 0 1px 4px rgba(0,0,0,.06);
	overflow: hidden;
}

/* ── Chat header ────────────────────────────────────────────────────────── */

.aiscw-front-chat-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 18px;
	border-bottom: 1px solid #f1f5f9;
	background: #fff;
}

.aiscw-front-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	min-width: 38px;
	background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
	border-radius: 10px;
	font-size: 18px;
}

.aiscw-front-header-info {
	flex: 1;
	min-width: 0;
}

.aiscw-front-chat-title {
	display: block;
	font-size: 14px;
	font-weight: 600;
	color: #1a1a2e;
}

.aiscw-front-status {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 12px;
	color: #64748b;
}

.aiscw-front-dot {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	flex-shrink: 0;
}

.aiscw-front-dot--online   { background: #22c55e; }
.aiscw-front-dot--thinking { background: #f59e0b; animation: aiscw-pulse .8s ease-in-out infinite; }
.aiscw-front-dot--error    { background: #ef4444; }

@keyframes aiscw-pulse {
	0%, 100% { opacity: 1; }
	50%       { opacity: .35; }
}

.aiscw-front-clear-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	background: transparent;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
	color: #64748b;
	cursor: pointer;
	padding: 0;
	transition: background .15s, color .15s;
}

.aiscw-front-clear-btn:hover {
	background: #fee2e2;
	color: #ef4444;
	border-color: #fca5a5;
}

/* ── Chat body (scrollable) ─────────────────────────────────────────────── */

.aiscw-front-chat-body {
	flex: 1 1 0;
	overflow-y: auto;
	min-height: 320px;
	max-height: 560px;
	padding: 16px;
	background: #f8fafc;
}

.aiscw-front-messages {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

/* ── Message bubbles ────────────────────────────────────────────────────── */

.aiscw-front-msg {
	display: flex;
	gap: 10px;
	align-items: flex-start;
}

.aiscw-front-msg--user {
	flex-direction: row-reverse;
}

.aiscw-front-msg-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	min-width: 32px;
	border-radius: 8px;
	font-size: 16px;
}

.aiscw-front-msg--ai   .aiscw-front-msg-avatar { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); }
.aiscw-front-msg--user .aiscw-front-msg-avatar { background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%); }
.aiscw-front-msg--error .aiscw-front-msg-avatar { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }

/* user avatar icon */
.aiscw-front-msg--user .aiscw-front-msg-avatar::before {
	content: "👤";
	font-size: 14px;
}

.aiscw-front-msg-bubble {
	max-width: calc(100% - 50px);
}

.aiscw-front-msg-text {
	display: inline-block;
	padding: 8px 14px;
	border-radius: 12px;
	font-size: 13px;
	line-height: 1.5;
	margin: 0 0 4px;
	word-break: break-word;
}

.aiscw-front-msg--ai   .aiscw-front-msg-text { background: #fff; border: 1px solid #e2e8f0; color: #374151; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.aiscw-front-msg--user .aiscw-front-msg-text { background: #6366f1; color: #fff; }
.aiscw-front-msg--error .aiscw-front-msg-text { background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; }

.aiscw-front-msg-time {
	display: block;
	font-size: 11px;
	color: #94a3b8;
}

.aiscw-front-msg--user .aiscw-front-msg-time {
	text-align: right;
}

/* ── Thinking animation ─────────────────────────────────────────────────── */

.aiscw-front-thinking-dots {
	display: inline-flex;
	gap: 3px;
	vertical-align: middle;
	margin-left: 4px;
}

.aiscw-front-thinking-dots span {
	display: inline-block;
	width: 5px;
	height: 5px;
	border-radius: 50%;
	background: #6366f1;
	animation: aiscw-bounce .8s ease-in-out infinite;
}

.aiscw-front-thinking-dots span:nth-child(2) { animation-delay: .15s; }
.aiscw-front-thinking-dots span:nth-child(3) { animation-delay: .3s;  }

@keyframes aiscw-bounce {
	0%, 80%, 100% { transform: translateY(0); }
	40%            { transform: translateY(-5px); }
}

/* ── Article result message ─────────────────────────────────────────────── */

.aiscw-front-result-bubble {
	background: #fff !important;
	border: 1px solid #e2e8f0 !important;
	padding: 0 !important;
	border-radius: 12px !important;
	overflow: hidden;
	max-width: 100% !important;
}

.aiscw-front-result-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 10px 14px;
	border-bottom: 1px solid #f1f5f9;
	background: #f8fafc;
}

.aiscw-front-result-title {
	flex: 1 1 auto;
	min-width: 0;
	font-size: 13px;
	font-weight: 600;
	color: #1a1a2e;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.aiscw-front-result-meta {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-shrink: 0;
}

.aiscw-front-result-words {
	font-size: 12px;
	color: #64748b;
}

.aiscw-front-seo-badge {
	display: inline-block;
	padding: 2px 8px;
	border-radius: 20px;
	font-size: 11px;
	font-weight: 600;
}

.aiscw-front-seo-badge--good { background: #dcfce7; color: #15803d; }
.aiscw-front-seo-badge--ok   { background: #fef3c7; color: #92400e; }
.aiscw-front-seo-badge--poor { background: #fee2e2; color: #991b1b; }

.aiscw-front-result-elapsed {
	font-size: 11px;
	color: #94a3b8;
}

/* ── Article preview ─────────────────────────────────────────────────────── */

.aiscw-front-article-preview {
	max-height: 320px;
	overflow-y: auto;
	padding: 14px 16px;
	font-size: 13px;
	line-height: 1.7;
	color: #374151;
}

.aiscw-front-article-preview h1,
.aiscw-front-article-preview h2,
.aiscw-front-article-preview h3,
.aiscw-front-article-preview h4 {
	margin-top: 1em;
	margin-bottom: .4em;
	font-weight: 600;
	color: #1a1a2e;
}

.aiscw-front-article-preview p { margin: 0 0 .8em; }
.aiscw-front-article-preview ul,
.aiscw-front-article-preview ol { padding-left: 20px; margin: 0 0 .8em; }

/* ── Result actions ──────────────────────────────────────────────────────── */

.aiscw-front-result-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 10px 14px;
	border-top: 1px solid #f1f5f9;
	background: #f8fafc;
}

.aiscw-front-btn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 6px 14px;
	font-size: 12px;
	font-weight: 500;
	border: 1px solid transparent;
	border-radius: 6px;
	cursor: pointer;
	transition: background .15s, color .15s, opacity .15s;
	font-family: inherit;
	white-space: nowrap;
}

.aiscw-front-btn:disabled {
	opacity: .55;
	cursor: not-allowed;
}

.aiscw-front-btn--primary {
	background: #6366f1;
	color: #fff;
	border-color: #6366f1;
}

.aiscw-front-btn--primary:hover:not(:disabled) { background: #4f46e5; border-color: #4f46e5; }
.aiscw-front-btn--primary.aiscw-front-btn--success { background: #22c55e; border-color: #22c55e; }

.aiscw-front-btn--secondary {
	background: #fff;
	color: #374151;
	border-color: #cbd5e1;
}

.aiscw-front-btn--secondary:hover:not(:disabled) { background: #f1f5f9; }
.aiscw-front-btn--secondary.aiscw-front-btn--copied { background: #dcfce7; color: #15803d; border-color: #86efac; }

/* inline spinner */
.aiscw-front-spin {
	display: inline-block;
	animation: aiscw-spin .6s linear infinite;
}

@keyframes aiscw-spin {
	from { transform: rotate(0deg); }
	to   { transform: rotate(360deg); }
}

/* ── Chat footer ─────────────────────────────────────────────────────────── */

.aiscw-front-chat-footer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	border-top: 1px solid #f1f5f9;
	background: #fff;
}

.aiscw-front-keyword-input {
	flex: 1;
	box-sizing: border-box;
	padding: 9px 12px;
	font-size: 13px;
	color: #374151;
	background: #f8fafc;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	outline: none;
	resize: none;
	overflow: hidden;
	min-height: 38px;
	max-height: 120px;
	transition: border-color .15s, box-shadow .15s;
	font-family: inherit;
	line-height: 1.5;
}

.aiscw-front-keyword-input:focus {
	border-color: #6366f1;
	box-shadow: 0 0 0 3px rgba(99,102,241,.15);
	background: #fff;
}

.aiscw-front-send-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	min-width: 38px;
	background: #6366f1;
	border: none;
	border-radius: 8px;
	color: #fff;
	cursor: pointer;
	padding: 0;
	transition: background .15s, opacity .15s;
}

.aiscw-front-send-btn:hover:not(:disabled) { background: #4f46e5; }
.aiscw-front-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Edit post link ─────────────────────────────────────────────────────── */

.aiscw-front-edit-link {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	margin-top: 6px;
	padding: 5px 12px;
	background: #6366f1;
	color: #fff !important;
	font-size: 12px;
	font-weight: 500;
	border-radius: 6px;
	text-decoration: none;
	transition: background .15s;
}

.aiscw-front-edit-link:hover { background: #4f46e5; color: #fff !important; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
	.aiscw-front-chat.aiscw-front-chat--with-settings {
		flex-direction: column;
	}

	.aiscw-front-settings {
		flex: none;
		min-width: 0;
		max-width: 100%;
		width: 100%;
	}

	.aiscw-front-chat-body {
		min-height: 260px;
		max-height: 400px;
	}
}
